Re: position, lookat, and up -> PerspectiveCamera

Mike Wray (mjw@hplb.hpl.hp.com)
Fri, 13 Oct 1995 09:45:51 +0100


You can turn a position and lookat into a rotation
about an axis and angle without using quaternions too.
This method also has the advantage of giving you a way
of turning a rotation matrix into an axis and angle.

Let the default lookat vector be e3 = (0,0,1), up vector e2=(0,1,0),
and the desired lookat and up vectors be v and u respectively.
The the rotation matrix R such that e3 R = v and e2 R = u
is

[ u/\v ]
R = [ u ]
[ v ]

assuming u and v are orthonormal.

Given R we find its axis, m, and angle, theta, as follows:

Put a = 0.5(trace(R) - 1) = 0.5(R[0][0] + R[1][1] + R[2][2] - 1)
put b = sqrt(1- a^2)

case 1: a=1, b=0.

theta=0, m=(0,0,0)

case 2: a=-1, b=0.

Put d = max R[i,i], c = sqrt((d+1)/2)

theta = pi, m = R[i] / c

case 3: b!=0

theta = acos(a)

m = (R[2][3]-R[3][2], R[3][1]-R[1][3], R[1][2]-R[2][1])/(2b)


  • Next message: Nicholas S Drew: "Re: Q#3: Crystal Ball"
  • Previous message: Stephen Chenney: "Re: position, lookat, and up -> PerspectiveCamera"
  • Maybe in reply to: Keith D Rule: "position, lookat, and up -> PerspectiveCamera"