7.19  transforms.inc

Several useful transformation macros. All these macros produce transformations, you can use them anywhere you can use scale, rotate, etc. The descriptions will assume you are working with an object, but the macros will work fine for textures, etc.

Shear_Trans(A, B, C). This macro reorients and deforms an object so its original XYZ axes point along A, B, and C, resulting in a shearing effect when the vectors are not perpendicular. You can also use vectors of different lengths to affect scaling, or use perpendicular vectors to reorient the object.
Parameters:

Matrix_Trans(A, B, C, D). This macro provides a way to specify a matrix transform with 4 vectors. The effects are very similar to that of the Shear_Trans() macro, but the fourth parameter controls translation.
Parameters:

Axial_Scale_Trans(Axis, Amt). A kind of directional scale, this macro will "stretch" an object along a specified axis.
Parameters:

Axis_Rotate_Trans(Axis, Angle). This is equivalent to the transformation done by the vaxis_rotate() function, it rotates around an arbitrary axis.
Parameters:

Rotate_Around_Trans(Rotation, Point). Ordinary rotation operates around the origin, this macro rotates around a specific point.
Parameters:

Reorient_Trans(Axis1, Axis2). This aligns Axis1 to Axis2 by rotating the object around a vector perpendicular to both axis1 and axis2.
Parameters:

Point_At_Trans(YAxis). This macro is similar to Reorient_Trans(), but it points the y axis along Axis.
Parameters:

Center_Trans(Object, Axis). Calculates a transformation which will center an object along a specified axis. You indicate the axes you want to center along by adding "x", "y", and "z" together in the Axis parameter.

Note: this macro actually computes the transform to center the bounding box of the object, which may not be entirely accurate. There is no way to define the "center" of an arbitrary object.

Parameters:

Usage:
object {MyObj Center_Trans(MyObj, x)} //center along x axis
 
You can also center along multiple axes:
object {MyObj Center_Trans(MyObj, x+y)} //center along x and y axis
 

Align_Trans(Object, Axis, Pt). Calculates a transformation which will align the sides of the bounding box of an object to a point. Negative values on Axis will align to the sides facing the negative ends of the coordinate system, positive values will align to the opposite sides, 0 means not to do any alignment on that axis.
Parameters:

Usage:
  object {
     MyObj 
     Align_Trans(MyObj, x, Pt) //Align right side of object to be
                               //coplanar with Pt
     Align_Trans(MyObj,-y, Pt) //Align bottom of object to be
                               // coplanar with Pt
  } 
 

vtransform(Vect, Trans) and vinv_transform(Vect, Trans).
The vtransform() macro takes a transformation (rotate, scale, tranlate, etc...) and a point, and returns the result of applying the transformation to the point. The vinv_transform() macro is similar, but applies the inverse of the transform, in effect "undoing" the transformation. You can combine transformations by enclosing them in a transform block.
Parameters:

Spline_Trans(Spline, Time, SkyVector, ForeSight, Banking). This macro aligns an object to a spline for a given time value. The Z axis of the object will point in the forward direction of the spline and the Y axis of the object will point upwards.
Parameters:

Usage:
   object {MyObj Spline_Trans(MySpline, clock, y, 0.1, 0.5)}