matrix
- Last UpdatedSep 17, 2025
- 2 minute read
This topic is about the matrix data type.
Value syntax
matrix m = {1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1};
Syntax notes
Previous assignment syntax can be used only during initialization. The following code will raise an error.
matrix m;
m = {1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1};
After a matrix is declared, it can be populated either by using the implemented API listed below or by assigning it the values from another matrix.
matrix m;
matrix m2 = {1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1};
m = m2;
Description
Matrix type is a 4x4 matrix of double values. It is used to handle geometric transformation.
-
The default value is {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}.
-
The matrix type partially supports arithmetic and comparison operators.
Autocasting
-
string, if in the correct input format (space separated list of sixteen numbers); otherwise it will raise an exception.
string s="1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1";
matrix m=s; //m={1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1}
Properties
These are the properties for matrix.
|
Property |
Return type |
Parameters |
Description |
|---|---|---|---|
|
m11..m44 |
double |
|
Used to obtain single values from the matrix, where the name is composed with m followed by ROW index and COLUMN index. Indexes go from 1 to 4 both for rows and columns. |
Methods
This table shows the currently implemented methods.
|
Method |
Return type |
Parameters |
Description |
|---|---|---|---|
|
GetAt |
vector3 |
Returns At vector |
|
|
GetPosition |
vector3 |
Returns position |
|
|
GetRight |
vector3 |
Returns right vector |
|
|
GetRotation |
quaternion |
Returns rotation as quaternion |
|
|
GetScale |
vector3 |
Returns scale |
|
|
GetUp |
vector3 |
Returns up vector |
|
|
Identity |
|
|
Overwrites the matrix with an identity matrix. |
|
Invert |
Overwrites the matrix with its inverted. |
||
|
Rotation |
quaternion rotation |
Overwrites the matrix transforming it into a rotation matrix according to the given quaternion. |
|
|
RotationX |
|
double angle |
Overwrites the matrix with a rotation matrix of angle around X axis. The values are in radians. |
|
RotationY |
|
double angle |
Overwrites the matrix with a rotation matrix of angle around Y axis. The values are in radians. |
|
RotationZ |
|
double angle |
Overwrites the matrix with a rotation matrix of angle around Z axis. The values are in radians. |
|
RotationAxisAngle |
|
vector3 axis double angle |
Overwrites the matrix with a rotation matrix of angle around axis. The values are in radians. |
|
Scale |
vector3 scale |
Overwrites the matrix transforming it into a scale matrix according to the given vector. |
|
|
Swaplhrh |
Overwrite the matrix changing from left handed to right handed or viceversa. |
||
|
To String |
string |
Returns the matrix content m11 to m44. |
|
|
Translation |
vector3 position |
Overwrites the matrix transforming it into a translation matrix according to the given vector. |
|
|
Transform |
vector3 position quaternion rotation vector3 scale |
Overwrites the matrix creating a new one based on given position, rotation, and scale. |
|
|
TransformPosition |
vector3 |
vector3 input |
Returns the transformation of the input vector from its original space to the space defined by the matrix. |
|
TranformVector |
vector3 |
vector3 input |
Returns the transformation of the input vector from its original space to the space defined by the matrix. This operation does not include the matrix translation contribute. |
|
Zero |
|
|
Overwrites the matrix with a zero matrix. |