Sign in to follow this  
Walde

Mousemovement around character

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this