Matrix
Element category: Matrix
Matrices are one of the most powerful features of MTA OOP. We did have a presence of Matrices before with getElementMatrix, but we were given an ugly disgusting table to play with. Now, with the new Matrix class, we can make and magically manipulate Matrices.
OOP-Only Methods and Variables
create
Default constructor for the Matrix class. Returns a Matrix object. Can be instantiated in multiple ways.
create ( Vector3 position, Vector3 rotation )- position: The position vector of the matrix
- rotation (optional): The rotation vector of the matrix
create ( Matrix matrixToClone )- matrixToClone: A matrix you want to make a clone of
create ( )Initialize a zero matrix
transformPosition
Transforms a given position vector using the Matrix.
transformPosition ( Vector3 position )- position: The position vector you want to transform
getPosition
Returns the position vector of the matrix.
getPosition ( )getRotation
Returns the rotation vector of the matrix.
getRotation ( )getForward
Returns the forward vector of the matrix.
getForward ( )getRight
Returns the right vector of the matrix.
getRight ( )getUp
Returns the up vector of the matrix.
getUp ( )Code Examples
Say you wanted to create a bin - object 1337 - two units in front of a player. You don't want to manually do trigonometry and you don't want to play with the complicated tables. You just want to get the position two units in front of the player whilst taking into account the rotation of the player. You only need to use Matrix.getForward, Matrix.getPosition and getElementMatrix. It's just:
Object ( 1337, player.matrix.position + player.matrix.forward * 2 )