> Date:         Wed, 1 Mar 2000 03:56:48 -0800
> From: PK <[EMAIL PROTECTED]>
>    I succesfully got the camera to move around a scene, using
>    RotPosScaleTCBSplinePathInterpolator. There's one small problem however.
>    The camera moves around OK, but it allways points in the negative z
>    direction, i.e. - straight into the screen. What I want to do is the
>    following, as the camera moves from one point to another, it's view
>    points towards the next point, instead of straight ahead all the time.

You can use the OpenGL compatibility method Transform3D.lookat() to get a
Transform3D which transforms virtual world coordinates to view coordinates
using a simple camera model; you just need the eye (camera) location, the
point of interest (center) to look at, and a vector defining the up
direction.  If you take the inverse of this Transform3D then you can use it
as the ViewPlatform transformation.

You can also compute the ViewPlatform transformation matrix for this model
directly, which is somewhat simpler than the computations that lookat()
performs and avoids a matrix inversion (although the inversion is simple in
this case since Java 3D knows the matrix contains only rotations and a
translation).  I'll present this standard technique below since it may help
others trying to understand how to orient ViewPlatforms.

You may want to compute the view direction (Z basis vector below) based on
on some sort of interpolation between center points as you pass them,
otherwise the immediate switch in view could be disorienting.

-- Mark Hood

---------------------------------------
To orient a ViewPlatform from camera parameters eye, center, and up:

Get the Z basis vector [z0 z1 z2] of the ViewPlatform coordinate system by
subtracting the center point from the eye point [e0 e1 e2] and normalizing
it to unit length.

The X basis vector [x0 x1 x2] is computed from the cross product (up x Z) of
the up vector and the Z basis.  If the length of the cross product is close to
or equal to 0 then the up and Z vectors are too coincident and you have to
choose another up vector.  Otherwise normalize the cross product to unit
length to get the X basis.

The Y basis vector [y0 y1 y2] is the cross product (Z x X) of the Z and X
basis vectors.

Now to create a matrix from identity which transforms points from ViewPlatform
coordinates to virtual world coordinates, just use the X, Y, and Z basis
vectors as the columns of the upper 3x3 rotational components, and put the eye
coordinates into the 1st 3 entries of the 4th translational column:

M[ 0] = x0; M[ 1] = y0; M[ 2] = z0; M[ 3] = e0;
M[ 4] = x1; M[ 5] = y1; M[ 6] = z1; M[ 7] = e1;
M[ 8] = x2; M[ 9] = y2; M[10] = z2; M[11] = e2;
M[12] =  0; M[13] =  0; M[14] =  0; M[15] =  1;

When this matrix is applied to a column vector representing a point in
ViewPlatform coordinates, it just scales the orthonormal basis vectors by the
x, y, and z components of the point, sums them, and adds the eye translation.
It can be used directly to create a Transform3D to place and orient a
ViewPlatform.  It is the inverse of what is usually considered the view matrix
which transforms points from world coordinates to view coordinates.

Notes:

The length of a vector V is sqrt(VxVx + VyVy + VzVz).  To normalize a vector
to unit length divide its components by the length.

A cross product (V x W) of two vectors V and W is another vector
[(Vy*Wz-Wy*Vz) (Wx*Vz-Vx*Wz) (Vx*Wy-Wx*Vy)]; this vector is normal to the
plane containing V and W, points in the right-handed orientation, and has a
length equal to the product of the lengths of V and W and the sine of the
angle between them.
---------------------------------------

===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff JAVA3D-INTEREST".  For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".

Reply via email to