# move 3D Cam with mouse

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

## Recommended Posts

How would I move a 3D cam with a mouse (how can I yaw & pitch the cam, based on how I move the mouse), can you please explain any formulas you provide, i asked this question before but I wanna understand how it works. Thanks

##### Share on other sites
Have you implemeneted 3d camera rotation using the keyboard yet? It's ok if you haven't I am just wondering if your question is more about mouse input, or more about rotations.

##### Share on other sites
Quote:
 Original post by CandleJackHave you implemeneted 3d camera rotation using the keyboard yet? It's ok if you haven't I am just wondering if your question is more about mouse input, or more about rotations.

yeah I got it working with keyboard keys and I generally know how to use rotation matrices, so i just need the method of how to transform mouse movements into 3D rotations. btw im not using quaternions.

##### Share on other sites
The way I did it was to set the mouse to center of the window upon application start, then when you detect a mousemove windows message (i am assuming windows here), then you subtract that position from the center to get the amount moved, then you scale some angle by the amount moved. To rotate up and down, you simply perform a rotation on the cameras view direction about its right vector (don't forget to do a cross product to update the up vector). Then, to handle movement of the mouse in the X axis, you just do a rotate around the world space up vector i.e.: (0, 1, 0). You don't rotate about the cameras up vector since this will cause unwanted roll. Hope this helps!

##### Share on other sites
also, don't forget to reset the deltas every time you handle the rotation in the camera, and also reposition the mouse back to the center everytime it moves! otherwise you'll just keep spinning around... which sucks.

1. 1
Rutin
25
2. 2
JoeJ
20
3. 3
4. 4
5. 5

• 9
• 9
• 46
• 41
• 23
• ### Forum Statistics

• Total Topics
631749
• Total Posts
3002051
×