Archived

This topic is now archived and is closed to further replies.

Please help with mouse look cam

This topic is 5588 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi I have spent many hours trying to get a mouselook cam to work but there is always something that is not working. Can you please write the few lines of code that is necessary for it to work. void Camera::SetCameraRotationRad(float aXAngle,float aYAngle,float aZAngle, D3DXVECTOR3 aTranslation) { D3DXMatrixRotationYawPitchRoll(&myRotMat, aYAngle, aXAngle, aZAngle); // We are expecting euler angles in that are accumulated elsewhere. //We are expecting a translation in aTranslation.z // ??? so how do we multiply all this together ? } Thanks for the help. /Joachim

Share this post


Link to post
Share on other sites
try just setting the translation in the rotation matrix to aTranslation.

so that would be:



void Camera::SetCameraRotationRad(float aXAngle,float aYAngle,float aZAngle, D3DXVECTOR3 aTranslation)
{
D3DXMatrixRotationYawPitchRoll(&myRotMat, aYAngle, aXAngle, aZAngle);

myRotMat._41 = aTranslation.x;
myRotMat._42 = aTranslation.y;
myRotMat._43 = aTranslation.z;

}

Share this post


Link to post
Share on other sites
Here's a piece of code

  void T_DgCamera::GetViewMatrix(T_Matrix *pMat)
{
//

// Precaution(s)

//

assert( NULL != pMat );

// ----------------------------------------------------------------

T_Matrix matTrans,matRot;

// Move the world -CameraPosition

D3DXMatrixTranslation( &matTrans,-m_pos.x,-m_pos.y,-m_pos.z );
// Rotate it -CameraAngles

T_Vec3 angleRad;
angleRad.x = D3DXToRadian( m_angle.x );
angleRad.y = D3DXToRadian( m_angle.y );
angleRad.z = D3DXToRadian( m_angle.z );
MatRotationYXZ( &matRot,-angleRad );

// Translate before rotation ( thus rotation is around the camera, the origin of the camera

// space )

*pMat = matTrans * matRot;
}


Note that I used MatRotationYXZ - which is a routine I coded myself, that produced a rotation matrix about the Y,X and Z ( in that order ) - because D3DXMatrixRotationYawPitchRoll DOESN'T do that. I don't know why, but if you try making 3 rotation matrices about the 3 axes and multiply them in the order Y,X,Z you won't get the same result returned by YawPitchRoll.

Maybe it's my mistake, but that's what happened to me.

Also, note that this code will cause gimbal lock sometimes, if you rotate about one axis 90 degrees. There's an article for MrGamerMaker on solving this problem using a Right-Up-Forward system ( instead of XYZ ) at : Article

The link above is google's cached version of the page, because the server gave me a 404 error when trying the original URL.

[edited by - Coder on August 30, 2002 1:59:20 AM]

Share this post


Link to post
Share on other sites
Thanks guys. I finally got it right. No thanks to me

But the first solution doesn''t work since that translates the camera in object space. The camera works just the opposite of that so you need an inverse of the rotation matrix.

The problem I had was that the translation wasn''t right.

With this little code I got the translation right

myRotMat._41 = myMatrix._41 + myRotMat._31 * aTranslation.z + myRotMat._11 * aTranslation.x;
myRotMat._42 = myMatrix._42 + myRotMat._32 * aTranslation.z + myRotMat._12 * aTranslation.x;
myRotMat._43 = myMatrix._43 + myRotMat._33 * aTranslation.z + myRotMat._13 * aTranslation.x;

Share this post


Link to post
Share on other sites