Hi all,
I have a look-at function like that :
// Set the look at matrix.
CMatrix4 LookAtMatrix;
const CVector3 From = CVector3( 0.0f, 0.0f, 0.0f );
const CVector3 To = ( TargetPoint - m_TranslationVector ).Normalized();
LookAtMatrix.LookAt( From, To, CVector3( 0.0f, 1.0f, 0.0f ) );
// Update the orientation quaternion.
m_OrientationQuaternion.FromMatrix( LookAtMatrix.Transposed() );
I would change to not use FromMatrix to have better perf, this version doesn't work sometimes :
const CVector3 Direction = ( TargetPoint - m_TranslationVector ).Normalized();
const CVector3 RotationAxis = VectorCross( m_ForwardVector, Direction ).Normalized();
const float RotationAngle = CMath::ACos( VectorDot( m_ForwardVector, Direction ) );
m_OrientationQuaternion *= CQuaternion( RotationAxis, RotationAngle );
Why does that give bad result sometimes ?
Thanks