It allows to orientate an object using a target vector and a postion vector.
Here it is :
D3DXVECTOR2 GetYawPitchFromVectors(D3DXVECTOR3* pvEyePt, D3DXVECTOR3* pvLookatPt)
{
D3DXMATRIX m_mView;
// Calc the view matrix
D3DXVECTOR3 vUp( 0,1,0 );
D3DXMatrixLookAtLH( &m_mView, pvEyePt, pvLookatPt, &vUp );
D3DXMATRIX mInvView;
D3DXMatrixInverse( &mInvView, NULL, &m_mView );
// The axis basis vectors and camera position are stored inside the
// position matrix in the 4 rows of the camera's world matrix.
// To figure out the yaw/pitch of the camera, we just need the Z basis vector
D3DXVECTOR3* pZBasis = ( D3DXVECTOR3* )&mInvView._31;
D3DXVECTOR2 data;
data.x = atan2f( pZBasis->x, pZBasis->z );
float fLen = sqrtf( pZBasis->z * pZBasis->z + pZBasis->x * pZBasis->x );
data.y = -atan2f( pZBasis->y, fLen );
return data;
}
Edited by pachesantiago, 15 October 2012 - 11:39 AM.






