Matrix3 is a 3x3 transformation matrix particularly useful for two-dimensional transformation. It can be used for rotation, scale and skewing of a two-dimensional object.

Although a 3x3 matrix is represented, configurable values can be considered as a 3x2 matrix:

[ a, c, tx ]
[ c, d, ty ]
[ 0, 0,  1 ]

Constructor

new (a:Float = 1, b:Float = 0, c:Float = 0, d:Float = 1, tx:Float = 0, ty:Float = 0)

Creates a new Matrix instance

Parameters:

a

(Optional) An initial a component value (default is 1)

b

(Optional) An initial b component value (default is 0)

c

(Optional) An initial c component value (default is 0)

d

(Optional) An initial d component value (default is 1)

tx

(Optional) An initial tx component value (default is 0)

ty

(Optional) An initial ty component value (default is 0)

Variables

a:Float

The matrix a component, used in scaling and skewing (default is 1)

b:Float

The matrix b component, used in rotation and skewing (default is 0)

c:Float

The matrix c component, used in rotation and skewing (default is 0)

d:Float

The matrix d component, used in scaling and skewing (default is 1)

tx:Float

The matrix tx component, used in translation (default is 0)

ty:Float

The matrix ty component, used in translation (default is 0)

Methods

inline clone ():Matrix3

Creates a duplicate of the current Matrix3

Returns:

A duplicate Matrix3 instance

concat (m:Matrix3):Void

Concatenates the values of a second matrix to the current Matrix3, combining the effects of both. This is the same as matrix multiplication. The second matrix is not modified.

Parameters:

m

A second Matrix3 to concatenate to the current instance

copyColumnFrom (column:Int, vector4:Vector4):Void

Copies the x and y components from a Vector4 instance to the a/c, b/d or the tx/ty column of the current matrix

Parameters:

column

The column to copy into (0, 1 or 2)

vector4

The Vector4 instance to copy from

copyColumnTo (column:Int, vector4:Vector4):Void

Copies a column of the current matrix into a Vector4 instance. The w value will not be modified.

Parameters:

column

The column to copy from (0, 1 or 2)

vector4

The Vector4 instance to copy to

copyFrom (sourceMatrix3:Matrix3):Void

Copies the values of another Matrix3 and applies it to the current instance

Parameters:

sourceMatrix3

The Matrix3 to copy from

copyRowFrom (row:Int, vector4:Vector4):Void

Copies the values of a Vector4 instance into a row of the current matrix

Parameters:

row

The row to copy into (0 or 1)

vector4

The Vector4 instance to copy from

copyRowTo (row:Int, vector4:Vector4):Void

Copies a row of the current matrix into a Vector4 instance. The w value will not be modified.

Parameters:

row

The row to copy into (0, 1 or 2)

vector4

The Vector4 instance to copy from

createBox (scaleX:Float, scaleY:Float, rotation:Float = 0, tx:Float = 0, ty:Float = 0):Void

Applies a two-dimensional transformation to the current matrix.

This is the same as calling identity(), rotate(), scale() then translate() with these values.

Parameters:

scaleX

An x scale transformation value

scaleY

A y scale transformation value

rotation

(Optional) A rotation value (default is 0)

tx

(Optional) A translate x value (default is 0)

ty

(Optional) A translate y value (default is 0)

createGradientBox (width:Float, height:Float, rotation:Float = 0, tx:Float = 0, ty:Float = 0):Void

Creates a matrix to use for a linear gradient fill

Parameters:

width

The width of the gradient fill

height

The height of the gradient fill

rotation

(Optional) A rotation for the gradient fill (default is 0)

tx

(Optional) An x offset for the gradient fill (default is 0)

ty

(Optional) A y offset for the gradient fill (default is 0)

Returns:

A new Matrix instance

deltaTransformVector (Vector2:Vector2, ?result:Vector2):Vector2

Transforms a Vector2 instance by the current matrix, without considering the tx and ty values of the matrix

Parameters:

result

(Optional) An existing Vector2 instance to fill with the result

Returns:

A new Vector2 instance representing the transformed values

equals (matrix3:Matrix3):Bool

Check if two matrices have the same values

Returns:

Whether both matrices are equal

identity ():Void

Resets the matrix to default identity values

invert ():Matrix3

Inverts the values of the current matrix

Returns:

The current matrix instance

rotate (theta:Float):Void

Applies rotation to the current matrix

Parameters:

theta

A rotation value in degrees

scale (sx:Float, sy:Float):Void

Scales the current matrix

Parameters:

sx

The x scale to apply

sy

The y scale to apply

setTo (a:Float, b:Float, c:Float, d:Float, tx:Float, ty:Float):Void

Sets the values of the current matrix

Parameters:

a

The new matrix a value

b

The new matrix b value

c

The new matrix c value

d

The new matrix d value

tx

The new matrix tx value

ty

The new matrix ty value

transformRect (rect:Rectangle, ?result:Rectangle):Rectangle

Transforms a Rectangle instance by the current matrix and returns Rectangle with the bounds of the transformed rectangle.

Parameters:

transform

A Matrix3 instance to transform by

result

(Optional) A Rectangle instance to use for the result

Returns:

A Rectangle represented the transformed bounds

transformVector (pos:Vector2, ?result:Vector2):Vector2

Transforms a Vector2 instance by the current matrix

Parameters:

result

(Optional) An existing Vector2 instance to fill with the result

Returns:

A new Vector2 instance representing the transformed values

inline translate (dx:Float, dy:Float):Void

Adjusts the tx and ty of the current matrix

Parameters:

dx

The x amount to translate

dy

The y amount to translate