From: <are...@us...> - 2009-01-07 23:52:00
|
Revision: 2841 http://planeshift.svn.sourceforge.net/planeshift/?rev=2841&view=rev Author: aresilek Date: 2009-01-07 23:51:53 +0000 (Wed, 07 Jan 2009) Log Message: ----------- - Fixed FS#2458 : Make NPCs face player when talking, patch by kougaro. Modified Paths: -------------- trunk/src/client/pscamera.cpp trunk/src/client/pscelclient.cpp trunk/src/client/pscelclient.h Modified: trunk/src/client/pscamera.cpp =================================================================== --- trunk/src/client/pscamera.cpp 2009-01-07 20:58:23 UTC (rev 2840) +++ trunk/src/client/pscamera.cpp 2009-01-07 23:51:53 UTC (rev 2841) @@ -232,10 +232,33 @@ // enable npc mode if the targeted npc is in talking distance if(GetCameraMode() != CAMERA_NPCTALK && actor->RangeTo(target, false) < NPC_MODE_DISTANCE) { + //rotate the target so that it faces the player + csVector3 playerPos = psengine->GetCelClient()->GetMainPlayer()->Pos(); + csVector3 targetPos = target->GetPosition(); + + csVector3 diff = playerPos - targetPos; + if (!diff.x) + diff.x = 0.00001F; // div/0 protect + + float angle = atan2(-diff.x,-diff.z); + + float npcrot = target->GetRotation(); + + GEMClientActor* targetActor = dynamic_cast<GEMClientActor*>(target); + + csVector3 velocity; + velocity = targetActor->GetVelocity(); + float velNormSquared = velocity.SquaredNorm(); + + + if((angle-npcrot) < 3.14159F && (angle-npcrot) > -3.14159F && velNormSquared == 0) + target->SetPosition(target->GetPosition(), angle, target->GetSector()); + + npcModeTarget = target; npcModePosition = actor->GetMesh()->GetMovable()->GetFullPosition(); - SetCameraMode(CAMERA_NPCTALK); - } + SetCameraMode(CAMERA_NPCTALK); + } return 0; } Modified: trunk/src/client/pscelclient.cpp =================================================================== --- trunk/src/client/pscelclient.cpp 2009-01-07 20:58:23 UTC (rev 2840) +++ trunk/src/client/pscelclient.cpp 2009-01-07 23:51:53 UTC (rev 2841) @@ -1165,6 +1165,13 @@ return pcmesh->GetMovable ()->GetFullPosition(); } +float GEMClientObject::GetRotation() +{ + // Rotation + csMatrix3 transf = pcmesh->GetMovable()->GetTransform().GetT2O(); + return psWorld::Matrix2YRot(transf); +} + iSector* GEMClientObject::GetSector() { if(pcmesh->GetMovable()->InSector()) Modified: trunk/src/client/pscelclient.h =================================================================== --- trunk/src/client/pscelclient.h 2009-01-07 20:58:23 UTC (rev 2840) +++ trunk/src/client/pscelclient.h 2009-01-07 23:51:53 UTC (rev 2841) @@ -317,6 +317,9 @@ /** Get position of entity */ virtual csVector3 GetPosition(); + /** Get rotation of entity */ + virtual float GetRotation(); + /** Get sector of entity */ virtual iSector* GetSector(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |