The
The
This method can be used in conjunction with the
The Vector3D class can also represent a direction, an arrow pointing from the origin of the coordinates, such as (0,0,0), to an endpoint; or a floating-point component of an RGB (Red, Green, Blue) color model.
Quaternion notation introduces a fourth element, the
The result of adding two vectors together is a resultant vector. One way to visualize the result is by drawing a vector from the origin or tail of the first vector to the end or head of the second vector. The resultant vector is the distance between the origin point of the first vector and the end point of the second vector.
The
To convert a degree to a radian, you can use the following formula:
You can use the normalized cross product of two vertices of a polygon surface with the normalized vector of the camera or eye viewpoint to get a dot product. The value of the dot product can identify whether a surface of a three-dimensional object is hidden from the viewpoint.
The
If the current Vector3D object is the result of multiplying a Vector3D object by a projection Matrix3D object,
the
Quaternion notation employs an angle as the fourth element in its calculation of
three-dimensional rotation. The
In addition, the
To support a camera viewpoint and motion, create a camera class that keeps a Matrix3D object for
handling the movement of the display objects relative to the camera. In the camera space, the display objects
move in the opposite direction of the camera movement. For example, when the camera moves closer, the objects
become bigger. In other words, if the camera moves down the world z axis, the objects moves up
the z axis. One way to produce this effect is by setting the Matrix3D object of the camera class
to the inverse of the display objects' transformation. If the display objects are children of the root
display object, the Matrix3D object of the camera class can be set to the inverse of the root
display object. Another option is to have the display objects as children of a camera object.
A single matrix can combine multiple transformations and apply them at once to a 3D display object. For example, a matrix can be applied to 3D coordinates to perform a rotation followed by a translation.
When you explicitly set the
You can access a 3D display object's Matrix3D object through the
The value of the
Note: If the same Matrix3D object is assigned to two different display objects, a runtime error is thrown.
The Matrix3D class uses a 4x4 square matrix: a table of four rows and columns of numbers that hold the data for the transformation. The first three rows of the matrix hold data for each 3D axis (x,y,z). The translation information is in the last column. The orientation and scaling data are in the first three columns. The scaling factors are the diagonal numbers in the first three columns. Here is a representation of Matrix3D elements:
You don't need to understand matrix mathematics to use the Matrix3D class.
It offers specific methods that simplify the task of transformation and projection, such as the
Display objects cache their axis rotation properties to have separate rotation for each axis and to manage the different combinations of rotations. When a method of a Matrix3D object is called to transform a display object, the rotation cache of the object is invalidated.
If no parameter is defined, the constructor produces an identity or unit Matrix3D object.
In matrix notation, an identity matrix has a value of one for all elements on the main diagonal
position and a value of zero for all other elements. The value of the
The display object's rotation is defined by an axis, an incremental degree
of rotation around the axis, and an optional pivot point for the center of the object's rotation.
The axis can be any general direction. The common axes are the
The order of transformation matters. A rotation followed by a translation transformation produces a different effect than a translation followed by a rotation transformation.
The rotation effect is not absolute. It is relative to the current position and orientation.
To make an absolute change to the transformation matrix, use the
When the
One way to have a display object rotate around a specific point relative to its location is
to set the translation of the object to the specified point, rotate the object using the
The scale is defined as a set of three incremental changes along the three axes (x,y,z).
You can multiply each axis with a different number. When the scale changes are applied to
a display object, the object's size increases or decreases. For example, setting
the x, y, and z axes to two doubles the size of the object, while
setting the axes to
The
The order of transformation matters. A resizing followed by a translation transformation produces a different effect than a translation followed by a resizing transformation.
The translation is defined as a set of three incremental changes along the three axes (x,y,z). When the transformation is applied to a display object, the display object moves from it current location along the x, y, and z axes as specified by the parameters. To make sure that the translation only affects a specific axis, set the other parameters to zero. A zero parameter means no change along the specific axis.
The translation changes are not absolute. They are relative to the current
position and orientation of the matrix. To make an absolute change to the transformation matrix,
use the
Matrix multiplication is different from matrix addition. Matrix multiplication is not commutative.
In other words, A times B is not equal to B times A. With the
The first time the
The
Some Matrix3D methods, such as the
To modify the matrix's transformation with an absolute parent frame of reference,
retrieve the settings with the
The
You can use the
An object transformed by applying an identity matrix performs no transformation. In other words, if a matrix is multiplied by an identity matrix, the result is a matrix that is the same as (identical to) the original matrix.
The
Consecutive calls to the
The
Consecutive calls to the
An inverse of a matrix can be used to divide one matrix by another. The way to divide matrix A by matrix B is to multiply matrix A by the inverse of matrix B. The inverse matrix can also be used with a camera space. When the camera moves in the world space, the object in the world needs to move in the opposite direction to transform from the world view to the camera or view space. For example, if the camera moves closer, the objects becomes bigger. In other words, if the camera moves down the world z axis, the object moves up world z axis.
The
The Matrix3D object must be invertible.
The
Note: If you use the
The display object's rotation is defined by an axis, an incremental degree
of rotation around the axis, and an optional pivot point for the center of the object's rotation.
The axis can be any general direction. The common axes are the
The order of transformation matters. A rotation followed by a translation transformation produces a different effect than a translation followed by a rotation.
The rotation effect is not absolute. The effect is object-relative, relative to the frame
of reference of the original position and orientation. To make an absolute change to the transformation,
use the
When the
One way to have a display object rotate around a specific point relative to its location is
to set the translation of the object to the specified point, rotate the object using
the
The scale is defined as a set of three incremental changes along the three axes (x,y,z).
You can multiply each axis with a different number. When the scale changes are applied to
a display object, the object's size increases or decreases. For example, setting
the x, y, and z axes to two doubles the size of the object, while
setting the axes to
The
The order of transformation matters. A resizing followed by a translation transformation produces a different effect than a translation followed by a resizing transformation.
Translation specifies the distance the display object moves from its current location along
the x, y, and z axes. The
The translation changes are not absolute. The effect is object-relative, relative to the frame
of reference of the original position and orientation. To make an absolute change to the transformation
matrix, use the
Matrix multiplication is different from matrix addition. Matrix multiplication is not commutative.
In other words, A times B is not equal to B times A. With the
The modifications made by
The
To modify the matrix's transformation with an absolute parent frame of reference, retrieve
the settings with the
The
If the result of the
The
An orthogonal matrix is a square matrix whose transpose is equal to its inverse.
A Matrix3D object must be invertible. You can use the
Only a square matrix, like the Matrix3D class, has a determinant.
With the
An exception is thrown if the
To apply color transformations: create a ColorTransform object,
set the color adjustments using the object's methods and properties, and then assign the
To apply two-dimensional transformations: create a Matrix object,
set the matrix's two-dimensional transformation, and then assign the
To apply three-dimensional transformations: start with a three-dimensional display object.
A three-dimensional display object has a
To modify a perspective projection of the stage or root object:
use the
Since both PerspectiveProjection and Matrix3D objects perform perspective transformations, do not assign both to a display object at the same time. Use the PerspectiveProjection object for focal length and projection center changes. For more control over the perspective transformation, create a perspective projection Matrix3D object.
blueColorTransform
to
the Transform object trans
. This ColorTransform converts the color of the MovieClip
rect
from red to blue.
blueColorTransform
is then applied to the Transform object parentTrans
which
adjusts the color of both parent and child MovieClips towards blue. Notice how child.concatenatedColorTransform
is the
combination of parentTrans
and childTrans
.
scaleMatrix
is then applied to the Transform object parentTrans
which
scales both parent and child MovieClips. Notice how child.concatenatedMatrix
is the
combination of parentTrans
and childTrans
.
If the
scaleMatrix
to the Transform
object trans
. This Matrix scales the MovieClip rect
by a factor of two.
If the
Based on the field of view and aspect ratio (dimensions) of the stage, a default PerspectiveProjection object is assigned to the root object.
trans
and traces out
its pixelBounds
. Notice that pixel bounds returns a bounding box with values
equal to MovieClip's getBounds()
and getRect()
methods.
Together these types of transformations are known as affine transformations. Affine transformations preserve the straightness of lines while transforming, so that parallel lines stay parallel.
To apply a transformation matrix to a display object, you create a Transform
object, set its
A transformation matrix object is a 3 x 3 matrix with the following contents:
In traditional transformation matrixes, the
You can get and set the values of all six of the other properties in a Matrix
object:
The Matrix class supports the four major types of transformations: translation, scaling, rotation, and skewing. You can set three of these transformations by using specialized methods, as described in the following table:
Each transformation function alters the current matrix properties so that
you can effectively combine multiple transformations. To do this, you call more than one
transformation function before applying the matrix to its display object target (by using the
Use the
If you do not provide any parameters to the
a = 1
b = 0
c = 0
d = 1
tx = 0
ty = 0
In matrix notation, the identity matrix looks like this:
clonedMatrix
from myMatrix
.
Notice that the Matrix class does not have an equals method, so the following example
uses a custom written function to test the equality of two Matricies.
rotate45Matrix
and doubleScaleMatrix
are applied to the two rectangles
rectangleMc_1
and rectangleMc_2
. Then, the third
Matrix is created using the concat()
method on rotate45Matrix
and
doubleScaleMatrix
to create scaleAndRotateMatrix
.
This Matrix is then applied to rectangleMc_3
to scale and rotate it.
For example, if matrix
This method replaces the source matrix with the concatenated matrix. If you
want to concatenate two matrixes without altering either of the two source matrixes,
first copy the source matrix by using the
Using the
For example, consider a gradient with the following characteristics:
The following illustrations show gradients in which the matrix was defined using the
width = 25; height = 25; rotation = 0; tx = 0; ty = 0;
width = 25; height = 25; rotation = 0; tx = 25; ty = 0;
width = 50; height = 50; rotation = 0; tx = 0; ty = 0;
width = 50; height = 50; rotation = Math.PI / 4; // 45 degrees tx = 0; ty = 0;
deltaTransformPoint()
method
to create deltaTransformedPoint
from myPoint
. Notice that
the translate()
method has no affect on the position of deltaTransformedPoint
.
In the example, however, scale()
does affect the position. It
increases the original x
value by a factor of three from 50 to 150.
After calling the
In matrix notation, the identity matrix looks like this:
rotate()
method rotates rectangleMc
30 degrees clockwise. Notice that applying myMatrix
to rectangleMc
resets its _x value leaving us to reset it to 100 manually.
_x
property of the MovieClip object
to position rectangleMc
. Generally, when dealing with Matrix
positioning, mixing positioning techniques is considered bad style. The
example above written in good style would concatenate a translation Matrix to
myMatrix
to change the horizontal location of rectangleMc
.
The following example demonstrates this.
The
scale()
method to
scale myMatrix
by a factor of 3 horizontally and a factor of 4
vertically.
The
myMatrix
and converts its values
to a String in the format of (a=A, b=B, c=C, d=D, tx=TX, ty=TY).
transformPoint()
method
to create transformedPoint
from myPoint
. Notice that
the translate()
method does have an affect on the position of transformedPoint
.
In the example, scale()
increases the original x
value by a factor of three from 50 to 150, and translate()
increases
x
by 300 for a total value of 450.
translate()
method to position
rectangleMc
x:100 and y:50. Notice that translate()
affects
the translate values tx
and ty
but not a
, b
,
c
, or d
.
The
The
The following methods and properties use Rectangle objects:
You can use the
Note: The Rectangle class does not define a rectangular Shape display object. To draw
a rectangular Shape object onscreen, use the
clone
member.
The following two code examples give the same result:
width
by 16 ~~ 2 (32) and it's height
by 32 ~~ 2 (64)
rect_1
between rect_2
?
rect_1
intersect with rect_2
?
This method sets the values of the
rect_1
with some helpful
debugging text.
For example, consider a rectangle with properties x=20
, y=50
, width=60
, and
height=30
(20, 50, 60, 30) and a second rectangle with properties (150, 130, 50, 30).
The union of these two rectangles would be a larger rectangle encompassing the two rectangles
with the properties (20, 50, 180, 110).
Note: The
rect.right
is also
changed.
width
property
from 10 to 20. Notice that rect.right
also
changes.
rect.left
is also changed.
The value of the
rect.top
is also changed.
The value of the
bottomRight
property as a Point object.
rect.height
is also
changed.
rect.x
is also changed.
The value of the
rect.width
is also
changed.
size
,
changes the size
and sets the new values on the Rectangle instance.
It is critical to remember that the Point
object used by size
uses x and y values to represent the width
and height
properties
of the Rectangle.
topLeft
property as a Point object.
rect.y
is also changed.
The value of the
When a ColorTransform object is applied to a display object, a new value for each color channel is calculated like this:
If any of the color channel values is greater than 255 after the calculation, it is set to 255. If it is less than 0, it is set to 0.
You can use ColorTransform objects in the following ways:
You must use the
Color transformations do not apply to the background color of a movie clip (such as a loaded SWF object). They apply only to graphics and symbols that are attached to the movie clip.
colorTrans_2
to colorTrans_1
resulting in a full red offset combined with a .5 alpha multiplier.
colorTrans
and calls its toSting()
method. This method results in a string with the format
(redMultiplier=RM, greenMultiplier=GM, blueMultiplier=BM, alphaMultiplier=AM, redOffset=RO, greenOffset=GO, blueOffset=BO, alphaOffset=AO).
colorTrans
and adjusts its alphaMultiplier
from 1 to .5.
If you set the alpha transparency value of a display object directly by using the
colorTrans
and adjusts its alphaOffset
from 0 to -128.
colorTrans
and adjusts its blueMultiplier
from 1 to .5.
colorTrans
and adjusts its blueOffset
from 0 to 255.
colorTrans
and adjusts its greenMultiplier
from 1 to .5.
colorTrans
and adjusts its greenOffset
from 0 to 255.
colorTrans
and adjusts its redMultiplier
from 1 to .5.
colorTrans
and adjusts its redOffset
from 0 to 255.
my_mc
. To see this code work, place a movie clip on the Stage with the instance name my_mc
. Then place the following code on Frame 1 in the main Timeline and select Control > Test Movie:
var my_color:Color = new Color(my_mc);
my_color.setRGB(0xFF0000); // my_mc turns red
When you set this property, it changes the three color offset values (
When you pass a value for this property, use the format 0xRRGGBB. RR, GG, and BB each consist of two hexadecimal digits that specify the offset of each color component. The 0x tells the ActionScript compiler that the number is a hexadecimal value.
The following code creates a point at (0,0):
Methods and properties of the following classes use Point objects:
You can use the
point_1
with the default constructor.
point_2
with the coordinates x = 1 and y = 2.
resultPoint
by adding point_2
to
point_1
.
clonedPoint
from the values found in
myPoint
. The clonedPoint
contains all the
the values from myPoint
but is not the same object.
interpolatedPoint
) half way (50%) between point_1
and point_2
.
normalizedPoint
object from 5 to 10.
cartesianPoint
from the value of angleInRadians
and a line length of 5. The angleInRadians
value equal to Math.atan(3/4)
is used because of the characteristics of right triangles with sides that
have ratios of 3:4:5.
Math.PI
, consider using the Math.round()
function, as shown
in the following example.
point_3
by subtracting point_2
from point_1
.
myPoint
and gets myX
from myPoint.x
.
myPoint
and gets myY
from myPoint.y
.
myPoint
, and determines the length of a line from (0, 0) to that Point.
The
Euler angles can sometimes lead to animation errors because of problems such as singularities when rotating around the x axis or gimbal lock. For example, since with Euler angles each axis is handled independently, gimbal lock can occur during the rotation around two or more axes. The axes can become aligned, leading to unexpected results.
The axis rotation properties of the display object perform Euler angles rotation.
The
Projection is a way of representing a three-dimensional object in a two-dimensional space, like a cube projected onto a computer screen. Perspective projection uses a viewing frustum (a rectangular pyramid) to model and project a three-dimensional world and its objects on the screen. The viewing frustum becomes increasingly wider as it moves further from the origin of the viewpoint. The origin of the viewpoint could be a camera or the eyes of an observer facing the screen. The projected perspective produces the illusion of three dimensions with depth and distance, where the objects closer to the screen appear larger than the objects farther from the screen.
A default PerspectiveProjection object is a framework defined for perspective transformation
of the root object, based on the field of view and aspect ratio (dimensions) of the stage.
The projection center, the vanishing point, is set to the center of the stage, which means the
three-dimensional display objects disappear toward the center of the stage as they move
back in the z axis. The default viewpoint is at point (0,0) looking down the positive
z axis. The y-axis points down toward the bottom of the screen. You can
gain access to the
You can also set a different perspective projection setting for a display object through
the parent's perspective projection. First, create a PerspectiveProjection object and set
its
A display object, like the root object, can have a PerspectiveProjection object without
needing a Matrix3D property defined for its transformations. In fact, use either
a PerspectiveProjection or a Matrix3D object to specify the perspective transformation.
If when using the PerspectiveProjection object, a Matrix3D object was needed, the
A degree close to
A value close to
The