Archived

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

MouseMovement (2D -> 3D)

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

Hello everybody! I''ve got a question concerning the old looking-around-with-the-mouse topic. My problem is the following: Every frame I get the movement of the mouse-cursor in X and Y-direction (via DirectInput). Then I have to take these 2 values and somehow change my LookAt vector according to them. But I have simply no idea how to apply the mouse-movement to my vector..... At the moment I do this: LookAt.x += (float)MovementX /10; LookAt.y -= (float)MovementY /10; As you can imagine this really sucks HARD ;-) !!! What would be a better approach??? Thanks, Bobby

Share this post


Link to post
Share on other sites
I''d use two angles: Yaw and Pitch. Every time you need your LookAt-vector, calculate it from the above two angles.

To actually look around with the two angles:

yaw += mx * xSens;
pitch += (invertemouse ? -my : my) * ySens;

Or something like it.

Share this post


Link to post
Share on other sites
http://www.deakin.edu.au/~bradleyj/unsanity

There''s a tutorial there along with some SDL/OpenGL source... it''s nothing special, but it explains things fairly straightforwardly.

Share this post


Link to post
Share on other sites