Difference between revisions of "Matrix"

From GiderosMobile
m (fixed some typo)
Line 1: Line 1:
 
__NOTOC__
 
__NOTOC__
 +
 
<languages />
 
<languages />
 +
 
<!-- GIDEROSOBJ:Matrix -->
 
<!-- GIDEROSOBJ:Matrix -->
'''<translate>Supported platforms</translate>:''' [[File:Platform android.png]][[File:Platform ios.png]][[File:Platform mac.png]][[File:Platform pc.png]][[File:Platform html5.png]][[File:Platform winrt.png]][[File:Platform win32.png]]<br/>
+
'''<translate>Supported platforms</translate>:''' [[File:Platform android.png]][[File:Platform ios.png]][[File:Platform mac.png]][[File:Platform pc.png]][[File:Platform html5.png]][[File:Platform winrt.png]][[File:Platform win32.png]]
'''<translate>Available since</translate>:''' Gideros 2011.6<br/>
+
<br/>
'''<translate>Inherits from</translate>:''' [[Special:MyLanguage/Object|Object]]<br/>
+
'''<translate>Available since</translate>:''' Gideros 2011.6
 +
<br/>
 +
'''<translate>Inherits from</translate>:''' [[Special:MyLanguage/Object|Object]]
 +
<br/>
 +
 
 
=== <translate>Description</translate> ===
 
=== <translate>Description</translate> ===
<translate><br />
+
<translate>
The Matrix class specifies transformation from one coordinate space to another.<br />
+
The Matrix class specifies transformation from one coordinate space to another.
These transformations include translation, rotation, scaling and skewing.<br />
+
<br/>
<br />
+
These transformations include translation, rotation, scaling and skewing.
A 2D transformation matrix is a 3 x 3 matrix in homogenous coordinate system:<br />
+
 
<br />
+
 
[[File:Matrix props.png]]<br />
+
A 2D transformation matrix is a 3 x 3 matrix in homogeneous coordinate system:
<br />
+
<br/>
You can get and set the values of all six of the properties in a<br />
+
[[File:Matrix props.png]]
Matrix object: ''m11'', ''m12'', ''m21'', ''m22'', ''tx'', and ''ty''.<br />
+
<br/>
<br />
+
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.
 +
</translate>
  
Since Gideros 2016.6, Matrix can also hold 3D (4x4) matrices.</translate>
 
 
=== <translate>Examples</translate> ===
 
=== <translate>Examples</translate> ===
'''Applying matrix to Sprite objects'''<br/>
+
'''Applying matrix to Sprite objects'''
<source lang="lua">local angle = math.rad(30)
+
<br/>
 +
<source lang="lua">
 +
local angle = math.rad(30)
 
-- create skew matrix
 
-- create skew matrix
 
local m = Matrix.new(1, math.tan(angle), math.tan(angle), 1, 0, 0)
 
local m = Matrix.new(1, math.tan(angle), math.tan(angle), 1, 0, 0)
--aply to Sprite
+
-- apply to Sprite
 
local sprite = Sprite.new()
 
local sprite = Sprite.new()
sprite:setMatrix(m)</source>
+
sprite:setMatrix(m)
 +
</source>
 +
 
 
{|-
 
{|-
 
| style="width: 50%; vertical-align:top;"|
 
| style="width: 50%; vertical-align:top;"|

Revision as of 03:43, 16 September 2019



Supported platforms: Platform android.pngPlatform ios.pngPlatform mac.pngPlatform pc.pngPlatform html5.pngPlatform winrt.pngPlatform win32.png
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:
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)
-- apply to Sprite
local sprite = Sprite.new()
sprite:setMatrix(m)

Methods

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

Events

Constants