VRML cameras

Mike Wray ([email protected])
Wed, 11 Oct 1995 13:49:50 +0100


There's been a lot of discussion about cameras in VRML.
This note describes how I understand (and have implemented)
the VRML camera spec. We've seen hand-waving and code,
but no maths, so here goes...

Notation
========
I use x/\y for vector product, x.y for scalar (dot) product.

I sometimes write 4x4 matrixes in block form:

[ M p' ]
[ t s ]

where M is a 3x3 matrix, t is a (1x3) row vector,
p' is a (3x1) column vector and s is a scalar.
The ' in p' denotes transpose by the way.

I write homogeneous vectors in block form too: [x r]
where x is a (1x3) row vector, r is a scalar.

We multiply these (on the right) as follows:

[x r] [ M p' ] = [ (x M + r t) (x.p + r s) ]
[ t s ]

( using the fact that x p' = x.p ).
This means that t represents a translation, and p' and s do perspective.

Transforms
==========
The current transform is initially the identity.
Let the current (4x4) transform be T, let the transform defined by a VRML
node (Translation, Rotation etc.) be M. After the node the
current transform is M T, so a point x will go to x M T.

Cameras
=======
Let the current transform be T, and the camera have position p,
rotation about axis n by angle a.
Let R = R(a,n), the 3X3 matrix for rotation by a about n (see Appendix).

The default lookat vector is s3 = (0,0,1), up vector is s2 = (0,1,0).
The effect of the rotation is to change these to s3 R and e2 R.
Note that e1 = e2/\e3, and e1 R = (e2 R) /\ (e3 R),
because R is a rotation and has orthonormal rows ( R R' = I).
This means that row 3 of R is the lookat vector, row 2 is the up vector,
and R is the transformation between the default basis and the rotated basis
for the camera space.

The camera position is affected by T and becomes q = p T.
So the viewpoint is at p T with lookat vector e3 R, up vector e2 R.
(I'm applying T to a 3-vector but you know what I mean.)

If the viewing transformation is set up to be looking along e3 from
(0,0,0) we can get the effect of the camera by applying a modelling
transform to the whole world of

[ R 0 ] = [ I 0 ] [ R 0 ]
[ -(q R) 1 ] [ -q 1 ] [ 0 1 ]

Then [ x 1 ] [ R 0 ] = [ (x - q)R 1 ]
[ -(q R) 1 ]

Appendix: Rotation
==================
The (3x3) rotation matrix by angle a about axis n is

R(a,n) = cos(a) I + sin(a) N + (1 - cos(a)) n' n

where I is the identity matrix,
N is the matrix such that v N = n /\ v (vector product).

Using the fact that row 1 of N is (1 0 0)/\n, row 2 is (0 1 0)/\n etc.
we have

[ 0 nz -ny ]
N = [ -nz 0 nx ]
[ ny -nx 0 ]

Note
[ (nx nx) (nx ny) (nx nz) ]
n' n = [ (nx ny) (ny ny) (ny nz) ]
[ (nx nz) (ny nz) (nz nz) ]


+-------------------------------+-----------------------------------+
| [email protected] | Mike Wray |
| [email protected] | Hewlett-Packard Laboratories |
| | Filton Road |
| | Stoke Gifford |
| Phone +44 117 9228262 | Bristol BS12 6QZ |
| Fax +44 117 9228003 | UK |
+-------------------------------+-----------------------------------+


  • Next message: Dan Zwillinger: "How are existing 3D models being crsated?"
  • Previous message: Master Zap: "Re: Distributed Collision Detection"