OpenGL weird behavior when combining Roll Pitch & Yaw

410 views Asked by At

I am noticing some strange behavior in my openGL program. Basically it generates some shapes, and the main focus is to have the camera 'fly' around the world with functionality for roll, pitch, and yaw changing. I have everything currently implemented, but now when I roll, followed by changing pitch or yaw, the scene follows a strange curve and flies out of view. In my code I maintain 3 vectors, VRP for the coordinates of the eye, VPN for the focus point, and VUP indicating the up direction of the eye. The code for rotating I have is:

s_rotateAxis(VUP, VPN[0], VPN[1], VPN[2], 0.1);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(VRP[0], VRP[1], VRP[2], (VPN[0] + VRP[0]), (VPN[1] + VRP[1]), (VPN[2] + VRP[2]),         VUP[0], VUP[1], VUP[2]);

with the other direction just having -0.1 for an angle. s_rotateAxis simply rotates a vector about an arbitrary point. So in the above code snippet, VUP is rotated about VPN by 0.1 degrees. To yaw to the left the code is as follows:

s_rotateAxis(VPN, VUP[0], VUP[1], VUP[2], 0.1);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(VRP[0], VRP[1], VRP[2], (VRP[0] + VPN[0]), (VRP[1] + VPN[1]), (VRP[2] + VPN[2]), VUP[0], VUP[1], VUP[2]);

Again, focus point is rotated about VUP 0.1 degrees, and a point to look at is generated in gluLookAt. Pitching up as follows:

productUP = xProduct(VPN, VUP);
s_rotateAxis(VPN, productUP[0], productUP[1], productUP[2], 0.1);
s_rotateAxis(VUP, productUP[0], productUP[1], productUP[2], 0.1);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(VRP[0], VRP[1], VRP[2], (VRP[0] + VPN[0]), (VRP[1] + VPN[1]), (VRP[2] + VPN[2]), VUP[0], VUP[1], VUP[2]);

Here, xProduct computes the cross product of 2 points, giving a point perpendicular to both. In this case VPN and VUP. I'm hoping someone can spot my mistake easily as I'm just starting out with openGL, without me having to post the entire program.

0

There are 0 answers