#### Archived

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

# 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.

## 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 on other sites
I''m writing an article on just the topic right now. Includes theory and implemtation in d3dx of both a firstperson camera and a more general space shooter type camera.

will be finished hopefully by the end of the weeekend.

Toby

Gobsmacked - by Toby Murray

##### Share on other sites
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 on other sites
I just switched my camera from freemove to all movement along the y axis is 0 and my problem went away.

1. 1
2. 2
3. 3
Rutin
14
4. 4
5. 5

• 9
• 9
• 11
• 11
• 23
• ### Forum Statistics

• Total Topics
633674
• Total Posts
3013277
×