|
|
> I have an object with a defined up (say the y-direction) and a defined
> forward (say the x-direction). I'd like to place this object at a new
> location with a new orientation specified by given new up and forward
> vectors.
This is practically what matrix transformations are *for*. The matrix
transformation can be thought of as four vectors: what the X axis is mapped
to, what the Y axis is mapped to, what the Z axis is mapped to, and what to
translate by afterwards. So let's say you have the two vectors that you want
to map the Y and X axes to, called newydir and newxdir. First, you calculate
what you'll be mapping the Z axis to via a cross product (assuming newydir
and newxdir are normalized):
#declare newzdir = vcross(newxdir, newydir);
Then you just use a matrix transformation like so:
matrix <
newxdir.x, newxdir.y, newxdir.z,
newydir.x, newydir.y, newydir.z,
newzdir.x, newzdir.y, newzdir.z,
transamnt.x, transamnt.y, transamnt.z
>
where transamnt is where you want to translate the object to.
- Slime
[ http://www.slimeland.com/ ]
Post a reply to this message
|
|