A transformation matrix is a shorthand way of describing the positioning, rotating, and sizing of an object. The Matrix class represents a transformation matrix that determines how to map points from one coordinate space to another. You can perform various graphical transformations on a display object by setting the properties of a Matrix object, applying that Matrix object to the matrix property of a Transform object, and then applying that Transform object as the transform property of the display object. These transformation functions include translation (x and y repositioning), rotation, scaling, and skewing.
Matrix Contents
Within the Matrix Class we have read/write access to the following member variables of the Matrix Class:
Values in a transformation matrix
a b tx
c d ty
u v w
a - x scale
b - y skew
c - x skew
d - y scale
tx - x translation ( positioning along the x axis )
ty - y translation ( positioning along the y axis )
The Matrix values for u, v, and w cannot be modified and assume the values 0, 0, and 1, respectively.
That makes the matrix equivalent to :
a b tx
c d ty
0 0 1
There are four basic ways to transform a MovieClip/BitmapData instance:
* Translation: The values "tx" and "ty" represent the x and y translation values, respectively, in pixels.
* Scale: The values "a" and "d" represent the x and y scale values, respectively. A value of 1 indicates 100% of scale.
* Skew: The values "b" and "c" represent the y and x skew values, respectively. A value of 0 indicates no skew, while a value of 1 indicates a skew value equal to the width or height of the object at a scale of 1.
* Rotation: The values "a", "b", "c", and "d" can be used in combination to affect the rotation of an object. For an angle "q", rotation is achieved in the matrix by using the following values:
a = cos(q)
b = sin(q)
c = –sin(q)
d = cos(q)
You can adjust the scaling, rotation, and translation effects of a Matrix object by using the scale(), rotate(), and translate() methods.
Note that these methods combine with the values of the existing Matrix object.
For instance, the following code sets a Matrix object that scales an object by a factor of 4 and rotates it 60 degrees, since the scale() and rotate() methods are called twice:
var matrix:Matrix = new Matrix();
var rotation:Number = 2 * Math.PI * (30 / 360); // 30
var scaleFactor:Number = 2;
var tx:Number =10;
var ty:Number = 10;
matrix.translate( tx, ty );
matrix.scale(scaleFactor, scaleFactor);
matrix.rotate(rotation);
matrix.scale(scaleX, scaleY);
matrix.rotate(rotation);
myDisplayObject.transform.matrix = matrix;
|
My Blog Title
|