Represents a 4x4 matrix that stores both the position and the orientation of an object.
NOTE: Matrix4x4 objects are temporary. You can only use them in the frame in which they were generated. If you need to save a Matrix4x4 across multiple frames, use a Matrix4x4Box instead. For more information, see Object Lifetimes and Userdata Binding.
Constructors and accessors
Related sample code
Other related reference items
axis ( m, i ) : stingray.Vector3Retrieves the local X, Y, or Z axis of the matrix.
|
m : | The matrix whose axis will be returned. | |
i : | integer | The index of the axis to retrieve. Use 1 to get the X axis, 2 for the Y axis, or 3 for the Z axis. |
The axis at the specified index. |
copy ( m ) : stingray.Matrix4x4Returns a new copy of the specified matrix, with the same rotation and translation values.
|
m : | The matrix to copy. |
The newly created matrix. |
element ( m, i, j ) : numberReturns the element at index (i, j) in the matrix.
|
m : | The matrix whose element will be returned. | |
i : | integer | The row index. Use 1 to access the local X axis rotation, 2 for the local Y axis rotation, 3 for the local Z axis rotation, or 4 for the translation. |
j : | integer | The column index. Use 1 to access the global X component, 2 for the global Y component, 3 for the global Z component, or 4 for the translation. |
number |
The value of the element with the specified indices. |
Indices are 1-based, so for example, element(1,2) returns the Y-component (2) of the X-axis (1) stored in the matrix.
equal ( m1, m2 ) : booleanIndicates whether or not two matrices are equivalent.
|
m1 : | The first matrix. | |
m2 : | The second matrix. |
boolean |
Returns true if the two matrices are identical, or false otherwise. |
forward ( m ) : stingray.Vector3Returns the forward (Y) axis of the specified matrix.
|
m : | The matrix whose axis value will be returned. |
The forward axis of the matrix. |
from_axes ( x, y, z, t ) : stingray.Matrix4x4Returns a matrix that represents the specified rotation and translation.
|
x : | The orientation of the local X axis. | |
y : | The orientation of the local Y axis. | |
z : | The orientation of the local Z axis. | |
t : | The translation that will be stored in the new matrix. |
The newly created matrix. |
Related sample code
from_elements ( xx, xy, xz, yx, yy, yz, zx, zy, zz, tx, ty, tz ) : stingray.Matrix4x4Creates a matrix with x-axis (xx, xy, xz), y-axis (yx, yy, yz), z-axis (zx, zy, zz) and translation (tx, ty, tz).
|
xx : | number | The magnitude of the local X axis along the global X axis. |
xy : | number | The magnitude of the local X axis along the global Y axis. |
xz : | number | The magnitude of the local X axis along the global Z axis. |
yx : | number | The magnitude of the local Y axis along the global X axis. |
yy : | number | The magnitude of the local Y axis along the global Y axis. |
yz : | number | The magnitude of the local Y axis along the global Z axis. |
zx : | number | The magnitude of the local Z axis along the global X axis. |
zy : | number | The magnitude of the local Z axis along the global Y axis. |
zz : | number | The magnitude of the local Z axis along the global Z axis. |
tx : | number | The translation along the global X axis. |
ty : | number | The translation along the global Y axis. |
tz : | number | The translation along the global Z axis. |
The newly created matrix. |
Equivalent to Matrix4x4().
from_quaternion ( q ) : stingray.Matrix4x4Returns a matrix that represents the specified rotation, with no translation.
|
q : | The rotation that will be stored in the new matrix. |
The newly created matrix. |
from_quaternion_position ( q, t ) : stingray.Matrix4x4Returns a matrix that represents the specified rotation and translation.
|
q : | The rotation that will be stored in the new matrix. | |
t : | The translation that will be stored in the new matrix. |
The newly created matrix. |
Related sample code
from_translation ( t ) : stingray.Matrix4x4Returns a matrix that represents the specified translation, with no rotation.
|
t : | The translation that will be stored in the new matrix. |
The newly created matrix. |
identity ( ) : stingray.Matrix4x4Returns the identity matrix, which represents an object with no translation and no rotation.
|
This function does not accept any parameters. |
The identity matrix. |
Related sample code
Basic template: /main_menu.lua Character template: /main_menu.lua Vehicle template: /main_menu.lua Oculus VR template: /main_menu.lua Oculus VR template: /project.lua Steam VR template: /project.lua |
Other related reference items
inverse ( m ) : stingray.Matrix4x4Returns the inverse of the specified matrix.
|
m : | The matrix to invert. |
The inverted matrix. |
is_valid ( m ) : booleanIndicates whether or not the matrix is composed entirely of valid values.
|
m : | The matrix to validate. |
boolean |
Returns true if all components of the matrix are valid numbers, or false if any component is #NaN or #INF. |
is_valid_for_physics ( m ) : booleanIndicates whether or not the matrix can be applied to a physics object.
|
m : | The matrix to validate. |
boolean |
Returns true if this matrix can be applied to a physics object, or false otherwise. |
For example, a matrix may be unfit for use with physics objects if it contains shearing (non-orthogonal axes) or other unexpected geometry.
lerp ( m1, m2, t ) : stingray.Matrix4x4Produces a new matrix by interpolating, or "lerping", between the two specified matrices.
|
m1 : | The first matrix. | |
m2 : | The second matrix. | |
t : | number | The ratio, or interpolation point, between the two matrices. May be any value between 0 and 1 inclusive. Values closer to 0 produce matrices closer to m1; values closer to 1 produce matrices closer to m2. |
The resulting matrix. |
This is done by lerping the translation and rotation separately. Scale, etc., are not lerped.
multiply ( m1, m2 ) : stingray.Matrix4x4Multiplies two matrices.
|
m1 : | The first matrix to multiply. | |
m2 : | The second matrix to multiply. |
The product of the multiplication. |
This will create the composite transform of the individual matrix transforms.
right ( m ) : stingray.Vector3Returns the right (X) axis of the specified matrix.
|
m : | The matrix whose axis value will be returned. |
The right axis of the matrix. |
rotation ( m ) : stingray.QuaternionRetrieves the rotation of the matrix.
|
m : | The matrix whose rotation will be returned. |
The rotation of the matrix. |
Related sample code
scale ( m ) : stingray.Vector3Retrieves the scale of the matrix.
|
m : | The matrix whose scale will be returned. |
The scale of the matrix. |
Related sample code
set_axis ( m, i, v )Sets the local X, Y, or Z axis of the matrix.
|
m : | The matrix whose axis will be set. | |
i : | integer | The index of the axis to set. Use 1 to get the X axis, 2 for the Y axis, or 3 for the Z axis. |
v : | The axis value to set. |
This function does not return any values. |
set_element ( m, i, j, value )Sets a new value for the element at index (i, j) in the matrix.
|
m : | The matrix whose element will be set. | |
i : | integer | The row index. Use 1 to set the local X axis rotation, 2 for the local Y axis rotation, 3 for the local Z axis rotation, or 4 for the translation. |
j : | integer | The column index. Use 1 to set the global X component, 2 for the global Y component, 3 for the global Z component, or 4 for the translation. |
value : | number | The value to set for the element with the specified indices. |
This function does not return any values. |
Indices are 1-based, so for example, set_element(1,2) sets the Y-component (2) of the X-axis (1) stored in the matrix.
set_forward ( m, forward )Sets the forward (Y) axis of the specified matrix.
|
m : | The matrix whose axis value will be set. | |
forward : | The new forward axis of the matrix. |
This function does not return any values. |
set_right ( m, right )Sets the right (X) axis of the specified matrix.
|
m : | The matrix whose axis value will be set. | |
right : | The new right axis of the matrix. |
This function does not return any values. |
set_rotation ( m, r )Sets the rotation of the matrix.
|
m : | The matrix whose rotation will be set. | |
r : | The new rotation of the matrix. |
This function does not return any values. |
set_scale ( m, s )Sets the scale of the matrix.
|
m : | The matrix whose scale will be set. | |
s : | The new scale of the matrix. |
This function does not return any values. |
Related sample code
set_translation ( m, t )Sets the translation of the matrix.
|
m : | The matrix whose translation will be set. | |
t : | The new translation of the matrix. |
This function does not return any values. |
Related sample code
set_up ( m, up )Sets the up (Z) axis of the specified matrix.
|
m : | The matrix whose axis value will be set. | |
up : | The new up axis of the matrix. |
This function does not return any values. |
set_x ( m, x )Sets the X axis of the specified matrix.
|
m : | The matrix whose axis value will be set. | |
x : | The new X axis of the matrix. |
This function does not return any values. |
set_y ( m, y )Sets the Y axis of the specified matrix.
|
m : | The matrix whose axis value will be set. | |
y : | The new Y axis of the matrix. |
This function does not return any values. |
set_z ( m, z )Sets the Z axis of the specified matrix.
|
m : | The matrix whose axis value will be set. | |
z : | The new Z axis of the matrix. |
This function does not return any values. |
to_elements ( m ) : number, number, number, number, number, number, number, number, number, number, number, numberDecomposes a Matrix4x4 into the orientations of its X, Y, Z axes and its translation.
|
m : | The matrix to break down into its elements. |
number |
The magnitude of the local X axis along the global X axis. |
number |
The magnitude of the local X axis along the global Y axis. |
number |
The magnitude of the local X axis along the global Z axis. |
number |
The magnitude of the local Y axis along the global X axis. |
number |
The magnitude of the local Y axis along the global Y axis. |
number |
The magnitude of the local Y axis along the global Z axis. |
number |
The magnitude of the local Z axis along the global X axis. |
number |
The magnitude of the local Z axis along the global Y axis. |
number |
The magnitude of the local Z axis along the global Z axis. |
number |
The translation along the global X axis. |
number |
The translation along the global Y axis. |
number |
The translation along the global Z axis. |
to_string ( m ) : stringReturns a string representation of the specified matrix.
|
m : | The matrix to return as a string. |
string |
The string representation. |
Use this function only for debugging purposes.
transform ( m, p ) : stingray.Vector3Transforms the specified point using the specified matrix.
|
m : | The matrix to use for the transform. | |
p : | The position to be transformed. |
The new position, after being transformed by the matrix. |
Related sample code
transform_without_translation ( m, v ) : stingray.Vector3Transforms the specified vector using the specified matrix, without translating the vector.
|
m : | The matrix to use for the transform. | |
v : | The vector to be transformed. |
The new position, after being transformed by the matrix. |
This function may be useful when translating directions (rather than positions) between two different coordinate systems.
translation ( m ) : stingray.Vector3Retrieves the translation of the matrix.
|
m : | The matrix whose translation will be returned. |
The translation of the matrix. |
Related sample code
up ( m ) : stingray.Vector3Returns the up (Z) axis of the specified matrix.
|
m : | The matrix whose axis value will be returned. |
The up axis of the matrix. |
x ( m ) : stingray.Vector3Returns the X axis of the specified matrix.
|
m : | The matrix whose axis value will be returned. |
The X axis of the matrix. |
y ( m ) : stingray.Vector3Returns the Y axis of the specified matrix.
|
m : | The matrix whose axis value will be returned. |
The Y axis of the matrix. |
z ( m ) : stingray.Vector3Returns the Z axis of the specified matrix.
|
m : | The matrix whose axis value will be returned. |
The Z axis of the matrix. |
zero ( ) : stingray.Matrix4x4Returns the zero matrix, with all fields initialized to zero.
|