class openfl.geom.Matrix3D

Available on all platforms

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.

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 matrix property to the transformation matrix, and then set the transform property of the display object to the Transform object. Matrix objects are also used as parameters of some methods, such as the following:

  • The draw() method of a BitmapData object
  • The beginBitmapFill() method, beginGradientFill() method, or lineGradientStyle() method of a Graphics object

A transformation matrix object is a 3 x 3 matrix with the following contents:

In traditional transformation matrixes, the u, v, and w properties provide extra capabilities. The Matrix class can only operate in two-dimensional space, so it always assumes that the property values u and v are 0.0, and that the property value w is 1.0. The effective values of the matrix are as follows:

You can get and set the values of all six of the other properties in a Matrix object: a, b, c, d, tx, and ty.

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 transform property of that display object).

Use the new Matrix() constructor to create a Matrix object before you can call the methods of the Matrix object.

Class Fields

static function create2D(x:Float, y:Float, ?scale:Float = 1, ?rotation:Float = 0):Matrix3D

static function createABCD(a:Float, b:Float, c:Float, d:Float, tx:Float, ty:Float):Matrix3D

static function createOrtho(x0:Float, x1:Float, y0:Float, y1:Float, zNear:Float, zFar:Float):Matrix3D

static function interpolate(thisMat:Matrix3D, toMat:Matrix3D, percent:Float):Matrix3D

Instance Fields

function new(?v:Vector<Float> = null):Void

Creates a new Matrix object with the specified parameters. In matrix notation, the properties are organized like this:

If you do not provide any parameters to the new Matrix() constructor, it creates an identity matrix with the following values:

In matrix notation, the identity matrix looks like this:

function append(lhs:Matrix3D):Void

function appendRotation(degrees:Float, axis:Vector3D, ?pivotPoint:Vector3D = null):Void

function appendScale(xScale:Float, yScale:Float, zScale:Float):Void

function clone():Matrix3D

Returns a new Matrix object that is a clone of this matrix, with an exact copy of the contained object.

returns

A Matrix object.

function copyColumnFrom(column:Int, vector3D:Vector3D):Void

function copyColumnTo(column:Int, vector3D:Vector3D):Void

function copyFrom(other:Matrix3D):Void

function copyRawDataFrom(vector:Vector<Float>, ?index:UInt = 0, ?transpose:Bool = false):Void

function copyRawDataTo(vector:Vector<Float>, ?index:UInt = 0, ?transpose:Bool = false):Void

function copyRowFrom(row:UInt, vector3D:Vector3D):Void

function copyRowTo(row:Int, vector3D:Vector3D):Void

function copyToMatrix3D(other:Matrix3D):Void

function decompose(?orientationStyle:Orientation3D = null):Vector<Vector3D>

Returns the transformation matrix's translation, rotation, and scale settings as a Vector of three Vector3D objects.

function identity():Void

function interpolateTo(toMat:Matrix3D, percent:Float):Void

function invert():Bool

Performs the opposite transformation of the original matrix. You can apply an inverted matrix to an object to undo the transformation performed when applying the original matrix.

function pointAt(pos:Vector3D, ?at:Vector3D = null, ?up:Vector3D = null):Void

function prepend(rhs:Matrix3D):Void

function prependRotation(degrees:Float, axis:Vector3D, ?pivotPoint:Vector3D = null):Void

function prependScale(xScale:Float, yScale:Float, zScale:Float):Void

function recompose(components:Vector<Vector3D>, ?orientationStyle:Orientation3D = null):Bool

function transpose():Void