|
|
Cousin Ricky <ric### [at] yahoocom> wrote:
> When I string the objects together, they usually end up rotated with
> respect to each other. Since the objects all start out vertical, a
> simple counter-rotation about y should align them. The question is, by
> what amount?
I'm assuming that you want to rotate them around y the opposite way before
applying the macro which will then cancel your pre-rotation.
Here's my logic, untested.
The transforms in Reorient_Trans() are matrix transformations that have elements
that are cos, sin and -sin of the angle in radians.
Just intercept the values of that before they are used, convert them to degrees,
(make sure they all match), and then rotate your object around -y by that
amount.
I think just uncommenting the two rotate directives below ought to do it.
[I didn't correct the
transform { Axis_Rotate_Trans(vZ,180) }
part in the #else block.]
// Corrected Reorient_Trans() macro by Bill Walker (Bald Eagle) 2019
// based on original Reorient() macro by John VanSickle
#macro Reorient_Trans(Axis1, Axis2)
#local vX1 = vnormalize(Axis1);
#local vX2 = vnormalize(Axis2);
#local Y = vcross(vX1, vX2);
#if(vlength(Y) > 0)
#local vY = vnormalize(Y);
#local vZ1 = vnormalize(vcross(vX1, vY));
#local vZ2 = vnormalize(vcross(vX2, vY));
#declare Angle1A = degrees (acos ( vX1.x));
#declare Angle1B = degrees (asin ( vZ1.x));
#declare Angle1A = degrees (asin (-vX1.x));
#declare Angle1D = degrees (acos ( vZ1.z));
#debug "1st rotation about y in degrees \n"
#debug concat (vstr(3, Angle1A, ", ", 7, 3), "\n")
#debug concat (vstr(3, Angle1B, ", ", 7, 3), "\n")
#debug concat (vstr(3, Angle1C, ", ", 7, 3), "\n")
#debug concat (vstr(3, Angle1D, ", ", 7, 3), "\n")
#declare Angle2A = degrees (acos ( vX2.x));
#declare Angle2B = degrees (asin ( vX2.z));
#declare Angle2A = degrees (asin (-vZ2.x));
#declare Angle2D = degrees (acos ( vZ2.z));
#debug "2nd rotation about y in degrees \n"
#debug concat (vstr(3, Angle2A, ", ", 7, 3), "\n")
#debug concat (vstr(3, Angle2B, ", ", 7, 3), "\n")
#debug concat (vstr(3, Angle2C, ", ", 7, 3), "\n")
#debug concat (vstr(3, Angle2D, ", ", 7, 3), "\n")
//rotate -y * Angle1A
transform {
matrix <
vX1.x, vY.x, vZ1.x,
vX1.y, vY.y, vZ1.y,
vX1.z, vY.z, vZ1.z,
0,0,0 >
}
//rotate -y * Angle1A
transform {
matrix <
vX2.x, vX2.y, vX2.z,
vY.x, vY.y, vY.z,
vZ2.x, vZ2.y, vZ2.z,
0,0,0 >
}
#else
#if (vlength(vX1-vX2)=0)
transform {}
#else
#local vZ = VPerp_To_Vector(vX2);
transform { Axis_Rotate_Trans(vZ,180) }
#end
#end
#end
See:
https://en.wikipedia.org/wiki/Rotation_matrix#Basic_rotations
Post a reply to this message
|
|