Jump to content
  • Advertisement
Sign in to follow this  
Neeneko

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.

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by sevensevens
Are 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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!