|  |  | 
| Line 27: | Line 27: | 
|  | local sprite = Sprite.new() |  | local sprite = Sprite.new() | 
|  | sprite:setMatrix(m) |  | sprite:setMatrix(m) | 
| − | </source> | + | </syntaxhighlight> | 
|  |  |  |  | 
|  | {|- |  | {|- | 
		Revision as of 14:30, 13 July 2023
Supported platforms: 






Available since: Gideros 2011.6
Inherits from: Object
Description
The Matrix class specifies transformation from one coordinate space to another.
These transformations include translation, rotation, scaling and skewing.
A 2D transformation matrix is a 3 x 3 matrix in homogeneous coordinate system:
 
You can get and set the values of all six of the properties in a Matrix object: m11, m12, m21, m22, tx, and ty.
Since Gideros 2016.6, Matrix can also hold 3D (4x4) matrices.
Examples
Applying matrix to Sprite objects
local angle = math.rad(30)
-- create skew matrix
local m = Matrix.new(1, math.tan(angle), math.tan(angle), 1, 0, 0)
-- apply to Sprite
local sprite = Sprite.new()
sprite:setMatrix(m)
| MethodsMatrix.new creates a new Matrix object[[1]] returns a copy of this matrix
 Matrix.fromSRT builds a matrix from scale/rotation/translation components
 [[2]] gets anchor position from matrix transformation
 [[3]] returns the elements of this matrix instance
 [[4]] returns the value of the m11 component
 [[5]] returns the value of the m12 component
 [[6]] returns the value of the m21 component
 [[7]] returns the value of the m22 component
 [[8]] gets all 16 elements of 4x4 matrix
 [[9]] gets position from matrix transformation
 [[10]] gets rotation on x axis
 [[11]] gets rotation on y axis
 [[12]] get rotation on z axis
 [[13]] gets scale from matrix transformation
 [[14]] gets scale on x axis
 [[15]] gets scale on y axis
 [[16]] gets scale on z axis
 [[17]] returns the value of the tx component
 [[18]] returns the value of the ty component
 [[19]] returns the value of the tz component
 [[20]] gets x position
 [[21]] gets y position
 [[22]] gets z position
 [[23]] inverts the matrix
 [[24]] multiplies current matrix with new one
 [[25]] replaces this matrix by an orthographic projection
 [[26]] replaces this matrix by a perspective projection
 [[27]] replaces this matrix by a perspective projection
 [[28]] combines existing rotation with provided rotation
 [[29]] combines existing scale with provided scale
 [[30]] transform matrix for setting anchor position
 [[31]] sets all 6 elements of this matrix instance
 [[32]] sets the value of the m11 component
 [[33]] sets the value of the m12 component
 [[34]] sets the value of the m21 component
 [[35]] sets the value of the m22 component
 [[36]] set all 16 elements of 4x4 matrix
 [[37]] transform matrix for setting position
 [[38]] sets rotation on x axis
 [[39]] sets rotation on y axis
 [[40]] sets rotation on z axis
 [[41]] transform matrix for setting scale
 [[42]] sets scale on x axis
 [[43]] sets scale on y axis
 [[44]] sets scale on z axis
 [[45]] sets the value of the tx component
 [[46]] sets the value of the ty component
 [[47]] sets the value of the tz component
 [[48]] sets x position
 [[49]] sets y position
 [[50]] sets z position
 [[51]] transforms the matrix
 [[52]] combines existing translation with provided translation
 
 | EventsConstants |