# 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.

## 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 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 on other sites
That's the guy, right there.

Thanks Buckeye, you got it in one.

- Goishin

1. 1
Rutin
42
2. 2
3. 3
4. 4
5. 5

• 9
• 27
• 20
• 14
• 14
• ### Forum Statistics

• Total Topics
633388
• Total Posts
3011620
• ### Who's Online (See full list)

There are no registered users currently online

×