|
|
Wasn't it Carl who wrote:
>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. Both vectors are unit vectors and they at perpendicular to each
>other. The translate part is easy but the rotations I need to apply to my
>object are giving me trouble. I'm sure I'm making things more complicated
>then necessary. Can someone help?
I always found this a bit tricky. Applying Reorient_Trans() twice
sometimes seemed to cause the thing to get tilted the wrong way. Then
Michael Andrews developed his Three_Point_Trans() that does the whole
thing - translation and rotations.
#macro Three_Point_Trans(T1a, T1b, T1c, T2a, T2b, T2c)
transform {
#local Y = vnormalize(T1b - T1a);
#local X = vnormalize(T1c - T1a);
#local Z = vnormalize(vcross(X, Y));
#local X = vcross(Z, Y);
#local T = Shear_Trans(X, Y, Z)
translate -T1a
transform { T inverse }
#local Y = vnormalize(T2b - T2a);
#local X = vnormalize(T2c - T2a);
#local Z = vnormalize(vcross(X, Y));
#local X = vcross(Z, Y);
Shear_Trans(X, Y, Z)
translate T2a
}
#end
/*
The three points a,b,c define a triangle; a is the origin, b-a is the
primary orientation and abc gives a secondary orientation plane. The two
orientation axes b-a and c-a do not have to be orthogonal, just
independant so vcross(b-a,c-a) doesn't return a zero length vector.
So Three_Point_Trans(0,y,x, P0,P1,P2) gives a transform from the origin
to P0, aligns y with P1-P0 and puts the (x,y) plane in the plane of the
(P0,P1,P2) triangle.
*/
--
Mike Williams
Gentleman of Leisure
Post a reply to this message
|
|
|
|
> 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
|
|