PDA

View Full Version : suggestions on implementing a viewing system



newbie234
02-19-2004, 01:50 PM
Hey

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.

147-2
02-22-2004, 10:38 PM
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.

3B
03-04-2004, 05:02 AM
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 http://www.opengl.org/discussion_boards/ubb/smile.gif

alternately, you can use quaternions to store the rotation