Calculate up vector of a camera looking at a point

I'm experimenting with some ray tracing, and I'm stuck on camera calculation. Let's say i have a point of interest i'm looking at, p, and i have a vantage point, p0. So my camera origin is o = p0 and my camera direction is d = p - p0, but how do i get the up vector? As i understand o and d defines a plane and i need a vector on that plane by supplying either a roll value or a two dimensional vector on that plane. Not really sure how to approach this problem.

Can anyone point me at the right direction ?

Upvotes: 0

Views: 1258

Answers (1)

joojaa
joojaa

Reputation: 4434

Normally you would use another vector as a proxy, such as world up. To build the right up vector you use a trick. Since a cross product is guaranteed to give a vector that is orthogonal to the original vectors you can use this to build the matrix up.

What you do is you cross the direction vector with you proxy world up, and you'd get the side vector, you can now use direction cross the side vector to gain a up vector that points in the general direction of the world up.

So you end up with sides that are projection parallel with your proxy. This will obviously fail if you look exactly top down on bottom up.

Upvotes: 2

Related Questions