Jump to content
  • Advertisement

Archived

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

helix

Mouse input, the camera, and gimbal lock!

This topic is 5933 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

I am making a small cheesy game trying to improve my directx skills and haven''t run into any problems that have stumped me until now. I originally was using keyboard input to move the camera and everything worked fine until I decided to try out mouse input. Now my camera suffers from gimbal lock. I have been trying for the past few days to get this working properly with no success. I have tried a number of ways of using matrices and quaternions but nothing seems to work out. I haven''t found anything very useful online either. Does anyone have any ideas on a technique I can use to get "mouse look" behavior like in quake and all other shooters given the mouse''s delta x and y values? I tried all sorts of combinations of everything so these snippets are just my favorites of the 100+ different methods I have tried. I''ll include a few code snippets of some of my attempts below: // one of my attempts at quaternions D3DXQUATERNION rotQuat; D3DXQUATERNION cameraQuat; // from the example i was looking at, i think this is the camera''s orientation or direction cameraQuat.x = 0.0f; // i couldn''t figure out how to set this thing up properly cameraQuat.y = 0.0f; cameraQuat.z = 0.0f; cameraQuat.w = 1.0f; D3DXQuaternionRotationYawPitchRoll( &rotQuat, g_pMouse->XAxis() * fRotSpeed, g_pMouse->YAxis() * fRotSpeed, 0.0f ); D3DXQUATERNION quat; D3DXMATRIX mat; D3DXQuaternionMultiply( &quat, &rotQuat, &cameraQuat ); D3DXQuaternionNormalize( &quat, &quat ); D3DXMatrixRotationQuaternion( &mat, &quat ); // Update the camera''s direction and up vector D3DXVec3TransformCoord( &d, &d, &mat ); D3DXVec3TransformCoord( &u, &u, &mat ); ......... // one of my attempts with matricies // Left / right D3DXVECTOR vAxis; D3DXVec3Cross( &vAxis, &(g_pCamera->GetDir()), &(g_pCamera->GetRight()) ); // up vector D3DXVec3Normalize( &vAxis, &vAxis ); D3DXMatrixRotationAxis( &mat, &vAxis, g_pMouse->XAxis() * -fRotSpeed ); D3DXVec3TransformCoord( &d, &d, &mat ); D3DXVec3TransformCoord( &u, &u, &mat ); // Up / down D3DXVec3Cross( &vAxis, &d, &u ); // right vector D3DXVec3Normalize( &vAxis, &vAxis ); D3DXMatrixRotationAxis( &mat, &vAxis, g_pMouse->YAxis() * -fRotSpeed ); D3DXVec3TransformCoord( &d, &d, &mat ); D3DXVec3TransformCoord( &u, &u, &mat );

Share this post


Link to post
Share on other sites
Advertisement
oooh, right on! I'll be looking forward to reading that. Any ideas for me to try in the meantime?

[edited by - beoch on September 12, 2002 6:00:18 PM]

Share this post


Link to post
Share on other sites
I just switched my camera from freemove to all movement along the y axis is 0 and my problem went away.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!