Jump to content
  • Advertisement
Sign in to follow this  

Can't figure out the angle between my 'camera' up and 'world' up

This topic is 3192 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'm trying to figure out a way of determining the ange between my camera's up vector and the world's up angle. I know that I can compute the dot product of the two and get the arccosine to get a value that incorporates the pitch angle and the roll angle, but I'm really just interested in the roll angle. How do I constrain the two vectors so that all I'm looking at is the roll angle? What I'm trying to do is have my camera smoothly self-level itself to the horizon in the 3D terrain simulation I'm making. Thoughts? - Goishin

Share this post

Link to post
Share on other sites
If I understand what you mean by "self-level itself," you mean pitch is okay (looking above/below horizon), but the horizon otherwise appears horizontal. Is that correct?

If so:

(this is off the top of my head (I'm just visualizing vectors here) so I could be all wet)

Calculate the camera's direction vector (the axis about which it rolls).
Calculate a vector orthogonal to the camera's direction and up (cross-product).
That ortho vector is the axis about which the camera pitches.
Dot that ortho vector with the world up (and use acos) to get the angle, the roll with respect to the world. If the ortho vector is above the horizontal plane, the dot should be positive. If the ortho vector is below the horizontal plane, the dot should be negative.
Roll the camera left (if dot is negative) or right (if dot is positive) by some fraction of the angle until that dot product = 0.
You might have to reverse left/right rolls depending on which order you do the cross to get the ortho.

See if that comes close.

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!