>
Transformations in AS3 using tranformaion matrix
Welcome, Guest

by pooja on Friday, 14 November 2008
Transformations in AS3 using tranformaion matrix


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;



Blogger Image
My Blog Title

Product Engineering, software engineering company, Product Development, Product Migration, Product Re-engineering, Product Maintenance, Product Testing Commercial Application Development, Business Software development, commercial software for startups, Application Support and Maintenance, software testing Product Maintenance, Outsource product maintenance, product support and maintenance Product Migration, Product Re-engineering, product re-engineering services Product Research, Product Engineering, UI Prototyping Services Software Testing Services, Quality Assurance services, professional software testers, Load Testing, Functional Testing, Cross Platform, Browser Testing, Test Automation, Testing Tools, software quality analysis Functional Testing Services, software quality analysis, Software Testing Services, Application Testing Services, Functional Testing Types Automated Testing, Automated Testing Services, automation testing, test script development, Automation Test Tools, outsource automation testing Load Testing, Performance Testing Services, Load Testing Tools Offshore Software Development, Outsource software services, offshore outsourcing services, offshore software development services, IT outsourcing services, software quality assurance services, Offshore IT services, Custom Application Development Services, Offshore Product Engineering Benefits of IT Outsourcing, Offshore Software Development companies, offshore software development firms Outsource planning, IT outsourcing, IT development services, offshore IT companies, offshore software development Offshore Software Development, Outsource software services, offshore outsourcing services, offshore software development services, IT outsourcing services, software quality assurance services, Offshore IT services, Custom Application Development Services, Offshore Product Engineering Offshore Software Development, Outsource software services, offshore outsourcing services, offshore software development services, IT outsourcing services, software quality assurance services, Offshore IT services, Custom Application Development Services, Offshore Product Engineering