Jump to content
  • Advertisement
Sign in to follow this  
Walde

Mousemovement around character

This topic is 4614 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 there. What I want to do is to be able to move the camera around my character when the left mouse button is pushed down while moving the mouse. The problem is that to do that I have to do two rotations, since I want to rotate both width the x and y axis. And when you do two rotations after eachother the second rotation will get new axis directions because of the previous rotation, and that is not the result I want. I tried to fix the problem doing this: glRotatef(mouseXMove, 0.0f, 1.0f, 0.0f); glRotatef(mouseYMove, dcos(mouseXMove), 0.0f, dsin(mouseXMove)); where mouseXMove and mouseYMove are getting their value increased or decreased depending on the mouse movement. dcos() findes the cosinus value and dsin() findes the sinus value. My idea was to make a vector, who always had the old x-axis direction, to rotate around. Though the result wasn't as I wanted. Any ideas of how to make this work? If you didn't understand what I want think about 3. person games where you can click and rotate the camera around your character. And ps: moving around the character with one glRotatef() going with either the x or y axis works. So the other code is fine.

Share this post


Link to post
Share on other sites
Advertisement
I think the problem that you're experiencing here is called gimble lock. Rotating around one axis first, which then's screwed up the other axis for rotation.

People us a mathematical concept called quaternions to fix this. Instead of rotating about the three axis seperately, you pick a axis of rotation (a vector) and rotate about it all at the same time.

Anyway, look here: http://www.gamedev.net/reference/list.asp?categoryid=28#250

Share this post


Link to post
Share on other sites
Most games I've seen that have a third person camera don't worry about gimbal lock really, it seems quite natural in many cases. You could try changing the order in which you rotate.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!