Mousemovement around character

Started by
1 comment, last by Bezben 18 years, 4 months ago
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.
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

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.

This topic is closed to new replies.

Advertisement