Difference between revisions of "Matrix"

From GiderosMobile
Line 27: Line 27:
 
| style="width: 50%;"|
 
| style="width: 50%;"|
 
=== Methods ===
 
=== Methods ===
[[Matrix.new]] - creates a new Matrix object<br/>
+
[[Matrix.new]] {{<translate>creates a new Matrix object</translate>}}<br/>
[[Matrix:getAnchorPosition]] - get anchor position from matrix transformation<br/>
+
[[Matrix:getAnchorPosition]] {{<translate>get anchor position from matrix transformation</translate>}}<br/>
[[Matrix:getElements]] - returns the elements of this matrix instance<br/>
+
[[Matrix:getElements]] {{<translate>returns the elements of this matrix instance</translate>}}<br/>
[[Matrix:getM11]] - returns the value of the m11 component<br/>
+
[[Matrix:getM11]] {{<translate>returns the value of the m11 component</translate>}}<br/>
[[Matrix:getM12]] - returns the value of the m12 component<br/>
+
[[Matrix:getM12]] {{<translate>returns the value of the m12 component</translate>}}<br/>
[[Matrix:getM21]] - returns the value of the m21 component<br/>
+
[[Matrix:getM21]] {{<translate>returns the value of the m21 component</translate>}}<br/>
[[Matrix:getM22]] - returns the value of the m22 component<br/>
+
[[Matrix:getM22]] {{<translate>returns the value of the m22 component</translate>}}<br/>
[[Matrix:getMatrix]] - get all 16 elements of 4x4 matrix<br/>
+
[[Matrix:getMatrix]] {{<translate>get all 16 elements of 4x4 matrix</translate>}}<br/>
[[Matrix:getPosition]] - get position from matrix transformation<br/>
+
[[Matrix:getPosition]] {{<translate>get position from matrix transformation</translate>}}<br/>
[[Matrix:getRotationX]] - get rotation for x axis<br/>
+
[[Matrix:getRotationX]] {{<translate>get rotation for x axis</translate>}}<br/>
[[Matrix:getRotationY]] - get rotation on y axis<br/>
+
[[Matrix:getRotationY]] {{<translate>get rotation on y axis</translate>}}<br/>
[[Matrix:getRotationZ]] - get rotation for z axis<br/>
+
[[Matrix:getRotationZ]] {{<translate>get rotation for z axis</translate>}}<br/>
[[Matrix:getScale]] - get scale from matrix transformation<br/>
+
[[Matrix:getScale]] {{<translate>get scale from matrix transformation</translate>}}<br/>
[[Matrix:getScaleX]] - get scale on x axis<br/>
+
[[Matrix:getScaleX]] {{<translate>get scale on x axis</translate>}}<br/>
[[Matrix:getScaleY]] - get scale on y axis<br/>
+
[[Matrix:getScaleY]] {{<translate>get scale on y axis</translate>}}<br/>
[[Matrix:getScaleZ]] - get scale on z axis<br/>
+
[[Matrix:getScaleZ]] {{<translate>get scale on z axis</translate>}}<br/>
[[Matrix:getTx]] - returns the value of the tx component<br/>
+
[[Matrix:getTx]] {{<translate>returns the value of the tx component</translate>}}<br/>
[[Matrix:getTy]] - returns the value of the ty component<br/>
+
[[Matrix:getTy]] {{<translate>returns the value of the ty component</translate>}}<br/>
[[Matrix:getTz]] - returns the value of the tz component<br/>
+
[[Matrix:getTz]] {{<translate>returns the value of the tz component</translate>}}<br/>
[[Matrix:getX]] - get x position<br/>
+
[[Matrix:getX]] {{<translate>get x position</translate>}}<br/>
[[Matrix:getY]] - get y position<br/>
+
[[Matrix:getY]] {{<translate>get y position</translate>}}<br/>
[[Matrix:getZ]] - get z position<br/>
+
[[Matrix:getZ]] {{<translate>get z position</translate>}}<br/>
[[Matrix:invert]] - <br/>
+
[[Matrix:invert]] {{<translate></translate>}}<br/>
[[Matrix:multiply]] - Multiply current matrix with new one<br/>
+
[[Matrix:multiply]] {{<translate>Multiply current matrix with new one</translate>}}<br/>
[[Matrix:orthographicProjection]] - <br/>
+
[[Matrix:orthographicProjection]] {{<translate></translate>}}<br/>
[[Matrix:perspectiveProjection]] - <br/>
+
[[Matrix:perspectiveProjection]] {{<translate></translate>}}<br/>
[[Matrix:perspectiveProjection]] - <br/>
+
[[Matrix:perspectiveProjection]] {{<translate></translate>}}<br/>
[[Matrix:rotate]] - combine existing rotation with provided<br/>
+
[[Matrix:rotate]] {{<translate>combine existing rotation with provided</translate>}}<br/>
[[Matrix:scale]] - combine existing scale with provided scale<br/>
+
[[Matrix:scale]] {{<translate>combine existing scale with provided scale</translate>}}<br/>
[[Matrix:setAnchorPosition]] - transform matrix for setting anchor position<br/>
+
[[Matrix:setAnchorPosition]] {{<translate>transform matrix for setting anchor position</translate>}}<br/>
[[Matrix:setElements]] - sets all 6 elements of this matrix instance<br/>
+
[[Matrix:setElements]] {{<translate>sets all 6 elements of this matrix instance</translate>}}<br/>
[[Matrix:setM11]] - sets the value of the m11 component<br/>
+
[[Matrix:setM11]] {{<translate>sets the value of the m11 component</translate>}}<br/>
[[Matrix:setM12]] - sets the value of the m22 component<br/>
+
[[Matrix:setM12]] {{<translate>sets the value of the m22 component</translate>}}<br/>
[[Matrix:setM21]] - <br/>
+
[[Matrix:setM21]] {{<translate></translate>}}<br/>
[[Matrix:setM22]] - <br/>
+
[[Matrix:setM22]] {{<translate></translate>}}<br/>
[[Matrix:setMatrix]] - set all 16 elements of 4x4 matrix<br/>
+
[[Matrix:setMatrix]] {{<translate>set all 16 elements of 4x4 matrix</translate>}}<br/>
[[Matrix:setPosition]] - transform matrix for setting position<br/>
+
[[Matrix:setPosition]] {{<translate>transform matrix for setting position</translate>}}<br/>
[[Matrix:setRotationX]] - set rotation on x axis<br/>
+
[[Matrix:setRotationX]] {{<translate>set rotation on x axis</translate>}}<br/>
[[Matrix:setRotationY]] - set rotation on y axis<br/>
+
[[Matrix:setRotationY]] {{<translate>set rotation on y axis</translate>}}<br/>
[[Matrix:setRotationZ]] - set rotation on z axis<br/>
+
[[Matrix:setRotationZ]] {{<translate>set rotation on z axis</translate>}}<br/>
[[Matrix:setScale]] - transform matrix for setting scale<br/>
+
[[Matrix:setScale]] {{<translate>transform matrix for setting scale</translate>}}<br/>
[[Matrix:setScaleX]] - set scale on x axis<br/>
+
[[Matrix:setScaleX]] {{<translate>set scale on x axis</translate>}}<br/>
[[Matrix:setScaleY]] - set scale on y axis<br/>
+
[[Matrix:setScaleY]] {{<translate>set scale on y axis</translate>}}<br/>
[[Matrix:setScaleZ]] - set scale on z axis<br/>
+
[[Matrix:setScaleZ]] {{<translate>set scale on z axis</translate>}}<br/>
[[Matrix:setTx]] - sets the value of the tx component<br/>
+
[[Matrix:setTx]] {{<translate>sets the value of the tx component</translate>}}<br/>
[[Matrix:setTy]] - sets the value of the ty component<br/>
+
[[Matrix:setTy]] {{<translate>sets the value of the ty component</translate>}}<br/>
[[Matrix:setTz]] - sets the value of the tz component<br/>
+
[[Matrix:setTz]] {{<translate>sets the value of the tz component</translate>}}<br/>
[[Matrix:setX]] - set x position<br/>
+
[[Matrix:setX]] {{<translate>set x position</translate>}}<br/>
[[Matrix:setY]] - set y position<br/>
+
[[Matrix:setY]] {{<translate>set y position</translate>}}<br/>
[[Matrix:setZ]] - set z position<br/>
+
[[Matrix:setZ]] {{<translate>set z position</translate>}}<br/>
[[Matrix:transformPoint]] - <br/>
+
[[Matrix:transformPoint]] {{<translate></translate>}}<br/>
[[Matrix:translate]] - combine existing translation with provided translation<br/>
+
[[Matrix:translate]] {{<translate>combine existing translation with provided translation</translate>}}<br/>
 
| style="width: 50%;"|
 
| style="width: 50%;"|
 
=== Events ===
 
=== Events ===
 
=== Constants ===
 
=== Constants ===
 
|}
 
|}

Revision as of 15:19, 23 August 2018

Supported platforms: android, ios, mac, pc
Available since: Gideros 2011.6

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 homogenous coordinate system:

![images/matrix_props.png]

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)
--aply to Sprite
local sprite = Sprite.new()
sprite:setMatrix(m)

Methods

Matrix.new Template:Creates a new Matrix object
[[1]] Template:Get anchor position from matrix transformation
[[2]] Template:Returns the elements of this matrix instance
[[3]] Template:Returns the value of the m11 component
[[4]] Template:Returns the value of the m12 component
[[5]] Template:Returns the value of the m21 component
[[6]] Template:Returns the value of the m22 component
[[7]] Template:Get all 16 elements of 4x4 matrix
[[8]] Template:Get position from matrix transformation
[[9]] Template:Get rotation for x axis
[[10]] Template:Get rotation on y axis
[[11]] Template:Get rotation for z axis
[[12]] Template:Get scale from matrix transformation
[[13]] Template:Get scale on x axis
[[14]] Template:Get scale on y axis
[[15]] Template:Get scale on z axis
[[16]] Template:Returns the value of the tx component
[[17]] Template:Returns the value of the ty component
[[18]] Template:Returns the value of the tz component
[[19]] Template:Get x position
[[20]] Template:Get y position
[[21]] Template:Get z position
[[22]] {{}}
[[23]] Template:Multiply current matrix with new one
[[24]] {{}}
[[25]] {{}}
[[26]] {{}}
[[27]] Template:Combine existing rotation with provided
[[28]] Template:Combine existing scale with provided scale
[[29]] Template:Transform matrix for setting anchor position
[[30]] Template:Sets all 6 elements of this matrix instance
[[31]] Template:Sets the value of the m11 component
[[32]] Template:Sets the value of the m22 component
[[33]] {{}}
[[34]] {{}}
[[35]] Template:Set all 16 elements of 4x4 matrix
[[36]] Template:Transform matrix for setting position
[[37]] Template:Set rotation on x axis
[[38]] Template:Set rotation on y axis
[[39]] Template:Set rotation on z axis
[[40]] Template:Transform matrix for setting scale
[[41]] Template:Set scale on x axis
[[42]] Template:Set scale on y axis
[[43]] Template:Set scale on z axis
[[44]] Template:Sets the value of the tx component
[[45]] Template:Sets the value of the ty component
[[46]] Template:Sets the value of the tz component
[[47]] Template:Set x position
[[48]] Template:Set y position
[[49]] Template:Set z position
[[50]] {{}}
[[51]] Template:Combine existing translation with provided translation

Events

Constants