Fps like camera/entity rotation?

Hi,

I have the function to generate the x,y,z axsis needed for the rotation, but it’s not working because as soon as I call,

glrotatef(pitch,1,0,0)

it rotates the matrix, so when I do the next two lines,

glRotateF(yaw,0,1,0)
glRotateF(roll,0,0,1)

they just end up messing everything up.

Feel free to explain but I’d be happy with a couple of lines of code, basic/c++ etc that just basically converts the variables pitch,yaw,roll into compatible glRotate pars.

So basically when I rotate the yaw, it affects it’s facing, no matter of the pitch, so that,

pitch=pitch+mouseYDelta
yaw=yaw+MouseXDela

would give me fps like controls.

Any help would be great, I’ve searched everywhere :wink:

Think carefully about the order in which you call those rotations. I’m thinking roll, heading, pitch in that order may be what you want.

Doesn’t make any difference.

It’s because as soon as I turn it with the yaw. the matrix is rotated, but applying pitch still affects it as if the camera was facing it’s original direction. so that pitch becomes roll if yaw is say at 90 degrees.

I need a way to make rotatefs accumlate based on the new matrix…any idesa?

FPSs generally just let you yaw and pitch, with roll not being a factor at all - is that what you’re looking for?

If so, and assuming that yaw is around the camera’s Y axis, and pitch is around the camera’s X axis then you first yaw the camera around it’s Y axis, and then pitch the camera about the camera’s yawed X axis.

Which means you need some way of either accessing or calculating the camera’s yawed X axis in absolute coordinates, in order to feed it into glRotateF…

If you know the absolute yaw angle, then you can do that with basic trigonometry - your yawed x axis will be
something like:

{cos(absolute yaw),0,sin(absolute yaw)}

with the position and/or signs of the cos and sin functions changing depending on whether you measure the absolute yaw angle against the positive or negative X or Z axis.

CanOfCode, I may have mis-spoken yesterday. Neglecting roll for a moment, you should be able to put the transformations in an order such that you don’t have these problems. Bottom line: try reordering the transformations, one way should work.

charliejay, roll can be implimented…(think leaning). CanOfCode, you might want to look at using glLookAt instead of doing rotations and transformations. It is very useful and doesn’t alter anything but the camera. Take a look at any opengl tutorial at www.gametutorials.com

Good point, dlswimmer.

Can someone remind me again, what coordinate system is the axis you feed into glRotateF supposed to be defined in?

ie world space, or modelview space?

model space.

Note about the problem with the 3 rotations. One rotation changes the local (object) coordinate, so the other will look weird. This is called gimbal lock as well. You need to either perform world coordinate transformations or use quaternions.

What Rizo says, is what i meant.

Only he says it better, and in fewer words.