Difference between revisions of "Matrix"

From GiderosMobile
m (Text replacement - "<source" to "<syntaxhighlight")
Line 20: Line 20:
 
=== Examples ===
 
=== Examples ===
 
'''Applying matrix to Sprite objects'''
 
'''Applying matrix to Sprite objects'''
<source lang="lua">
+
<syntaxhighlight lang="lua">
 
local angle = math.rad(30)
 
local angle = math.rad(30)
 
-- create skew matrix
 
-- create skew matrix

Revision as of 15:28, 13 July 2023

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 <syntaxhighlight lang="lua"> 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) </source>

Methods

Matrix.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

Events

Constants