|
|
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
|
|