Kiwi.Geom.Matrix Class
Represents a 2d transformation matrix. This can be used to map points between different coordinate spaces. Matrices are used by Transform objects to represent translation, scale and rotation transformations, and to determine where objects are in world space or camera space. Objects such as entities and groups may be nested, and their associated transforms may represent how they are scaled, translated and rotated relative to a parent transform. By concatenating an object's transformation matrix with its ancestors matrices, it is possible to determine the absolute position of the object in world space. See http://en.wikipedia.org/wiki/Transformation_matrix#Examples_in_2D_graphics for an in depth discussion of 2d tranformation matrices.
Constructor
Kiwi.Geom.Matrix
-
[a=1]
-
[b=0]
-
[c=0]
-
[d=1]
-
[tx=0]
-
[ty=0]
Parameters:
-
[a=1]
Number optionalposition 0,0 of the matrix, affects scaling and rotation.
-
[b=0]
Number optionalposition 0,1 of the matrix, affects scaling and rotation.
-
[c=0]
Number optionalposition 1,0 of the matrix, affects scaling and rotation.
-
[d=1]
Number optionalposition 1,1 of the matrix, affects scaling and rotation.
-
[tx=0]
Number optionalposition 2,0 of the matrix, affects translation on x axis.
-
[ty=0]
Number optionalposition 2,1 of the matrix, affects translation on y axis.
Returns:
(Object) This object.
Item Index
Methods
Methods
append
-
[a=1]
-
[b=0]
-
[c=0]
-
[d=1]
-
[tx=0]
-
[ty=0]
Append values to this matrix, parameters supplied individually.
Parameters:
-
[a=1]
Number optionalposition 0,0 of the matrix, affects scaling and rotation.
-
[b=0]
Number optionalposition 0,1 of the matrix, affects scaling and rotation.
-
[c=0]
Number optionalposition 1,0 of the matrix, affects scaling and rotation.
-
[d=1]
Number optionalposition 1,1 of the matrix, affects scaling and rotation.
-
[tx=0]
Number optionalposition 2,0 of the matrix, affects translation on x axis.
-
[ty=0]
Number optionalposition 2,1 of the matrix, affects translation on y axis.
Returns:
This object.
appendMatrix
-
m
Append a matrix to this matrix.
Parameters:
-
m
Kiwi.Geom.MatrixThe matrix to append.
Returns:
This object.
copyFrom
-
m
Copy another matrix to this matrix.
Parameters:
-
m
Kiwi.Geom.MatrixThe matrixto be copied from.
Returns:
This object.
copyTo
-
m
Copy this matrix to another matrix.
Parameters:
-
m
Kiwi.Geom.MatrixThe matrix to copy to.
Returns:
This object.
equals
-
matrix
Check whether this matrix equals another matrix.
Parameters:
-
matrix
Kiwi.Geom.Matrix
Returns:
boolean
getPosition
()
Kiwi.Geom.Point
public
Get the x and y position of the matrix as an object with x and y properties
Returns:
An object constructed from a literal with x and y properties.
identity
()
Kiwi.Geom.Matrix
public
Set the matrix to the identity matrix - when appending or prepending this matrix to another there will be no change in the resulting matrix
Returns:
This object.
invert
()
Kiwi.Geom.Matrix
public
Invert this matrix so that it represents the opposite of its orginal tranformaation.
Returns:
This object.
objType
()
String
public
The type of object this is.
Returns:
"Matrix"
prepend
-
[a=1]
-
[b=0]
-
[c=0]
-
[d=0]
-
[tx=0]
-
[ty=0]
Prepend values to this matrix, paramters supplied individually.
Parameters:
-
[a=1]
Number optionalposition 0,0 of the matrix, affects scaling and rotation.
-
[b=0]
Number optionalposition 0,1 of the matrix, affects scaling and rotation.
-
[c=0]
Number optionalposition 1,0 of the matrix, affects scaling and rotation.
-
[d=0]
Number optionalposition 1,1 of the matrix, affects scaling and rotation.
-
[tx=0]
Number optionalposition 2,0 of the matrix, affects translation on x axis.
-
[ty=0]
Number optionalposition 2,1 of the matrix, affects translation on y axis.
Returns:
This object.
prependMatrix
-
m
Prepend a matrix to this matrix.
Parameters:
-
m
Kiwi.Geom.MatrixThe matrix to prepend.
Returns:
This object.
rotate
-
radians
Rotate the matrix by "radians" degrees
Parameters:
-
radians
NumberThe angle (in radians) to rotate this matrix by.
Returns:
This object.
scale
-
scaleX
-
scaleY
Scales the matrix by the amount passed.
Parameters:
-
scaleX
NumberThe amount to scale on the x axis.
-
scaleY
NumberThe amount to scale on the y axis.
Returns:
This object.
setFromOffsetTransform
-
tx
-
ty
-
scaleX
-
scaleY
-
rotation
-
rotPointX
-
rotPointY
Set matrix values from transform values, with rotation point data included
Parameters:
-
tx
Numbertx. Translation on x axis.
-
ty
Numberty. Translation on y axis.
-
scaleX
NumberscaleX. Scale on x axis.
-
scaleY
NumberscaleY. Scale on y axis.
-
rotation
Numberrotation.
-
rotPointX
NumberRotation point offset on x axis.
-
rotPointY
NumberRotation point offset on y axis.
Returns:
This object.
setFromTransform
-
tx
-
ty
-
scaleX
-
scaleY
-
rotation
Set matrix values from transform values
Parameters:
-
tx
NumberTranslation on x axis.
-
ty
NumberTranslation on y axis.
-
scaleX
NumberscaleX. Scale on x axis.
-
scaleY
NumberscaleY. Scale on y axis.
-
rotation
Numberrotation.
Returns:
This object.
setPosition
-
x
-
y
Set the tx and ty elements of the matrix.
Parameters:
-
x
NumberTranslation on x axis.
-
y
NumberTranslation on y axis.
Returns:
This object.
setPositionPoint
-
p
Set the tx and ty elements of the matrix from an object with x and y properties.
Parameters:
-
p
NumberThe object from which to copy the x and y properties from.
Returns:
This object.
setTo
-
[a=1]
-
[b=0]
-
[c=0]
-
[d=1]
-
[tx=0]
-
[ty=0]
Set all matrix values
Parameters:
-
[a=1]
Number optionalposition 0,0 of the matrix, affects scaling and rotation.
-
[b=0]
Number optionalposition 0,1 of the matrix, affects scaling and rotation.
-
[c=0]
Number optionalposition 1,0 of the matrix, affects scaling and rotation.
-
[d=1]
Number optionalposition 1,1 of the matrix, affects scaling and rotation.
-
[tx=0]
Number optionalposition 2,0 of the matrix, affects translation on x axis.
-
[ty=0]
Number optionalposition 2,1 of the matrix, affects translation on y axis.
Returns:
This object.
toString
()
String
public
Returns a string representation of this object.
Returns:
A string representation of the instance.
transformPoint
-
pt
Apply this matrix to a an object with x and y properties representing a point and return the transformed point.
Parameters:
-
pt
ObjectThe point to be translated.
Returns:
This object.
translate
-
tx
-
ty
Translate the matrix by the amount passed.
Parameters:
-
tx
NumberThe amount to translate on the x axis.
-
ty
NumberThe amount to translate on the y axis.
Returns:
This object.
Properties
a
Number
public
Position 0,0 of the matrix, affects scaling and rotation
Default: 1
b
Number
public
Position 0,1 of the matrix, affects scaling and rotation.
Default: 0
c
Number
public
Position 1,0 of the matrix, affects scaling and rotation.
Default: 0
d
Number
public
Position 1,1 of the matrix, affects scaling and rotation.
Default: 1
tx
Number
public
Position 2,0 of the matrix, affects translation on x axis.
Default: 0
ty
Number
public
Position 2,1 of the matrix, affects translation on y axis.
Default: 0