Three types of transformation objects in the Transform class
The Transform class has several kinds of transformation objects as its properties.
The Transform class provides access to color adjustment properties and two- or three-dimensional transformation objects that can be applied to a display object.
I noticed three types of properties from the point of view of getting and seting their values.
The first example is the Transform.matrix property. It does not provide its Matrix object reference but its copy. It means that operations to the copy will not affect to the property’s Matrix object. To set a Matrix object to the Transform.matrix property, the object should be assigned to the property.
var mySprite:Sprite = new Sprite(); var myMatrix:Matrix = new Matrix(); mySprite.transform.matrix = myMatrix; myMatrix.translate(100, 50); trace(mySprite.transform.matrix); // Output: (a=1, b=0, c=0, d=1, tx=0, ty=0) mySprite.transform.matrix = myMatrix; trace(mySprite.transform.matrix); // Output: (a=1, b=0, c=0, d=1, tx=100, ty=50) myMatrix = mySprite.transform.matrix; myMatrix.scale(2, 1.5); trace(mySprite.transform.matrix); // Output: (a=1, b=0, c=0, d=1, tx=100, ty=50) trace(mySprite.transform.matrix == myMatrix); // Output: false
The second example is the Transform.matrix3D property. Unlike to the Transform.matrix property, a Matrix3D object’s reference is obtained from the property. Therefore, once its reference is gotten, operations to the reference affects to the Transform.matrix3D property.
var mySprite:Sprite = new Sprite(); var myMatrix3D:Matrix3D = new Matrix3D(); mySprite.transform.matrix3D = myMatrix3D; myMatrix3D.prependTranslation(100, 50, 0); trace(mySprite.transform.matrix3D.position); // Output: Vector3D(100, 50, 0) trace(mySprite.transform.matrix3D == myMatrix3D); // Output: true
The third one is the Transform.perspectiveProjection property. When a new PerspectiveProjection instance is assigned to the property, operations to the instance do not affect to the property as well as the Transform.matrix property. Then, try to get the object from the property and set it to a variable again. You can operate the variable as if it was the object reference of the property. However the variable’s object is not evaluated to be equal to the property’s value. It is a mysterious property, isn’t it.
var mySprite:Sprite = new Sprite(); var myPerspective:PerspectiveProjection = new PerspectiveProjection(); mySprite.transform.perspectiveProjection = myPerspective; myPerspective.fieldOfView = 20; trace(mySprite.transform.perspectiveProjection.fieldOfView); // Output: 55 myPerspective = mySprite.transform.perspectiveProjection; myPerspective.fieldOfView = 100; trace(mySprite.transform.perspectiveProjection.fieldOfView); // Output: 100 trace(mySprite.transform.perspectiveProjection == myPerspective); // Output: false