Skip to content

Commit

Permalink
Merge pull request #53 from lex128/SetOrbitTarget
Browse files Browse the repository at this point in the history
Fix setCameraTarget calculation
  • Loading branch information
Jusonex committed Jul 29, 2016
2 parents e8bf3b5 + 02b1421 commit e09c652
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions MTA10/mods/shared_logic/CClientCamera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -283,15 +283,23 @@ void CClientCamera::SetOrbitTarget ( const CVector& vecPosition )
{
if ( m_pCamera )
{
CVector vecCameraPosition;
GetPosition ( vecCameraPosition );
CClientEntity* pCameraTarget = GetTargetEntity ( );

float fDistance = (vecPosition - vecCameraPosition).Length ();
float fAngleHorz = -atan2 ( vecPosition.fX - vecCameraPosition.fX, vecPosition.fY - vecCameraPosition.fY ) - PI/2;
float fAngleVert = atan2 ( vecPosition.fZ - vecCameraPosition.fZ, fDistance );
if ( pCameraTarget != NULL ){
CVector vecTargetPosition;
pCameraTarget->GetPosition ( vecTargetPosition );
if ( pCameraTarget->GetType ( ) == CCLIENTPLAYER )
vecTargetPosition.fZ += 0.6;

CCam* pCam = m_pCamera->GetCam ( m_pCamera->GetActiveCam () );
pCam->SetDirection ( fAngleHorz, fAngleVert );
CVector vecDirection = vecPosition - vecTargetPosition;
vecDirection.Normalize ();

float fAngleHorz = -atan2 ( vecDirection.fX, vecDirection.fY ) - PI / 2;
float fAngleVert = asin ( vecDirection.fZ );

CCam* pCam = m_pCamera->GetCam ( m_pCamera->GetActiveCam () );
pCam->SetDirection ( fAngleHorz, fAngleVert );
}
}
}

Expand Down

0 comments on commit e09c652

Please sign in to comment.