# OpenGL gluLookAt, spherical coordinates, and the up vector

This topic is 4234 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hello all. I am still rather new to OpenGL so I am hoping someone can point out what I am doing so horribly wrong here. I've read a couple similar threads but non seem to quite have my problem. I have been fiddling with on of the early NeHe tutorials and decided I wanted to rotate around the scene via gluLookAt. I have inputs rhoValue, phiValue, and thetaValue. rhoValue goes between 0 and 20, phiValue and thetaValue range from -180 to 180 (converted to radians). As far as I can tell the conversion from spherical to cartesian coordinates is fine. When I plug the values into gluLookAt, it _almost_ works, except when phi cross the 90 degree boundary at which point the scene 'flips' but otherwise seems to keep going. My gluLookAt looks like: gluLookAt(rhoValue*sin(phiValue)*cos(thetaValue), rhoValue*sin(phiValue)*sin(thetaValue), rhoValue*cos(phiValue), 0.0f, 0.0f,0.0f, cos(thetaValue),sin(thetaValue),1.0f); If I set the up vector to {0,1,0} instead then movement along phi works fine, but I get zero movement from theta (at least as long as phi is zero). Now in my above example of when I get the 'flip', thetaValue is zero so the up vector is technically {1,0,0}, which if I manually set I get the same result but with out the ability to move along theta. So, can anyone spot what I am doing wrong here?

##### Share on other sites
Are you using radians or degrees? The C++ math library uses radians, which could be your problem.

##### Share on other sites
Quote:
 Original post by sevensevensAre you using radians or degrees? The C++ math library uses radians, which could be your problem.

I was passing radians into libc.

Turns out the problem was a real 'well duh' Since I was allowing a phi value from -180 to 180, the camera was going over the zenith/nadir, at which point one would expect to be looking at the scene 'upside down', but the up vector was adjusting and thus the scene 'jumped' so it was properly aligned again.

So it was a *headdesk* mistake.

1. 1
2. 2
3. 3
Rutin
15
4. 4
5. 5

• 13
• 26
• 10
• 11
• 9
• ### Forum Statistics

• Total Topics
633730
• Total Posts
3013579
×