suggestions on implementing a viewing system


So I got a simple viewing system where I can change pitch and yaw. I store these as euler angles xrot and yrot and apply them using glRotate. Now I want to add roll.

First I thought I’ll just add a third rotation variable(zrot) and that works good if I only have simple keyboard input. But with mouse input it gets trickier. If roll=0, mouse y movement effects pitch and x movement effects yaw. But when roll!=0 this doesn’t work.

So then I thought I’ll just define the viewing through dir/up/right vectors and rotate around them. This almost works. The problem is that by storing the vectors as floats and continuisly updating them the coordinate system gets misaligned. I read some recommendations about resetting the coordinate system byt recalculating the right/up vectors by using a predefined up vector like (0,1,0). This doesn’t work great either since my original up vector might not always be ‘up’. There must be an easier way.

Any help or recommendations greatly appreciated. If at all possible I like to keep using euler angles/math.

Sorry, to survive that, I went to a library of matrix math functions. Now almost all my math is done on CPU. I just make sure it’s optimized, that’s all.

one way to fix the front/up/right vectors would be something like

right = front x up
up = right x front

where x is cross product, and where i might have the right hand side of either or both of those backwards

alternately, you can use quaternions to store the rotation