|
Kyle,
(it
looks like you just figured it out, but I was about to send this response
anyway; let me know if it is consistent with your newly found
wisdom)
It looks like you
want to be able to describe an object in world coordinates, and view that
object from a camera positioned in world
coordinates.
Let's
say that the camera origin is at (Px, Py, Pz), the camera's "up" direction is
VUP = (VUPx, VUPy, VUPz), and the camera is looking in the direction DIR =
(DIRx, DIRy, DIRz). These are all defined in world coordinates, which we
will call W-space. This position and two directions ("up"
and "forward") define a "frame" or coordinate system, which we will
call C-space. You probably want to have the VUP vector align with the +Y
axis of C-space, and the DIR direction align with the -Z axis of
C-space.
We are
missing a vector to align with the +X axis of C-space, the "right" vector: RT =
(RTx, RTy, RTz). So, we need a new "right" vector (in world space) which
is perpendicular to VUP and DIR. This can be computed with a cross
product. Assuming DIR and VUP are normalized (unit
length):
RT =
DIR x VUP
Note
that RT is normalized, perpendicular to VUP and DIR, and points to the "right"
as required. If you do the cross product in the opposite order, RT will
point "left" which is not what we want.
With
these three vectors, and the camera position (all in W-space) we can easily
build a matrix that will take points in C-space and tell us where they are in
W-space. This matrix is:
RTx VUPx -DIRx
Px
RTy VUPy -DIRy
Py
RTz VUPz -DIRz
Pz
0 0 0
1
Notice
that the first column, the "X column", contains the RT vector, and similarly
with the second and third columns. (DIR is negated because we want to look
down the -Z axis, not the +Z)
However, this matrix is not quite what you need: this
matrix take points in C-space and expresses them in W-space, i.e. a "C-to-W"
matrix. I think you really want a matrix that will take points in W-space
and express them in C-space, a "W-to-C" matrix. This is simply the inverse
of the C-to-W matrix:
RTx RTy RTz
-Px
VUPx
VUPy VUPz -Py
-DIRx
-DIRy -DIRz
-Pz
0
0 0 1
(sorry for the
bad formatting) Using the terminology for most graphics APIs, this is a
view matrix.
This
explanation assumes that your are using the "typical" transformation matrix
orientation, where the translation parameters are in the fourth column (not
the fourth row), i.e.
R R R
T
R R R
T
R R R
T
0 0 0
1
|
- [JAVA3D] Let me try to say this more clearly Kyle Wayne Kelly
- Re: [JAVA3D] Let me try to say this more clearly Kyle Wayne Kelly
- Re: [JAVA3D] Let me try to say this more clearly Kyle Wayne Kelly
- Re: [JAVA3D] Let me try to say this more clearly Mauricio Vives
- Re: [JAVA3D] Let me try to say this more clearly Mauricio Vives
- Re: [JAVA3D] Let me try to say this more clearly Kyle Wayne Kelly
