Simplify the creation of transformation matrix by the chain operations
TransformBuilder
class which simplifies the creation of the transformation matrix by the chain operations.
Suppose, there is a TransformBuilder
instance tb, and chain operations:
Python
import aspose.threed as a3d
# Change the (x, y, z) into (x + 1, y, z)
tb = a3d.utilities.TransformBuilder(a3d.utilities.ComposeOrder.APPEND)
a = tb.translate(1, 0, 0)
# Rotate alone with the Y axis with 180 deg will change the (x, y, z) into (-x, y, -z)
.rotate_euler_degree(0, 180, 0)
# Scale by 2 will change the (x, y, z) into (2x, 2y, 2z)
.scale(2)
# change the (x, y, z) into (z, y, x)
.rearrange(a3d.Axis.Z_AXIS, a3d.Axis.Y_AXIS, a3d.Axis.X_AXIS)
.matrix
If the compose order of this instance is Prepend, the final matrix is calculated from the left to right, that means the final transformation matrix will do these tasks:
- Change the (x, y, z) into (x + 1, y, z)
- Rotate alone with the Y axis with 180deg will change the (x, y, z) into (-x, y, -z)
- Scale by 2 will change the (x, y, z) into (2x, 2y, 2z)
- Change the (x, y, z) into (z, y, x)
But if the compose order is Append, the order will be reversed like:
- Change the (x, y, z) into (z, y, x)
- Scale by 2 will change the (x, y, z) into (2x, 2y, 2z)
- Rotate alone with the Y axis with 180deg will change the (x, y, z) into (-x, y, -z)
- Change the (x, y, z) into (x + 1, y, z)
Python
import aspose.threed as a3d
# use prepend order so the calculation is performed from left to right:
m = (a3d.utilities.TransformBuilder(a3d.utilities.ComposeOrder.PREPEND))
# Change the (x, y, z) into (x + 1, y, z)
.translate(1, 0, 0)
# Rotate alone with the Y axis with 180deg will change the (x, y, z) into (-x, y, -z)
.rotate_euler_degree(0, 180, 0)
# Scale by 2 will change the (x, y, z) into (2x, 2y, 2z)
.scale(2)
# change the (x, y, z) into (z, y, x)
.rearrange(a3d.Axis.Z_AXIS, a3d.Axis.Y_AXIS, a3d.Axis.X_AXIS)
.matrix
# Apply this matrix on a (0, 0, 0) vector, then we get the right result (0, 0, -2)
t = m * a3d.utilities.Vector3.ORIGIN;
The new added methods in the Matrix4
and TransformBuilder
classes are the utilities for developers to model the scene by program, so they do not need to manually construct the transform matrix, this is usually used by expert developers.
Ordinal developers can use the Transform
property of class Node
to change the translation/scaling/rotation of an object.
Developers can also assign the matrix created by TransformBuilder
to Node.Transform
.
More information about transformation matrix can be found at Wikipedia Transformation matrix and Affine Transofrmation