Manipulating Matrices

From Multi Theft Auto: Wiki
Revision as of 22:49, 19 June 2014 by Qaisjp (talk | contribs) (Created page with "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 p...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

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.

What is a Matrix?

A Matrix (plural: Matrices) ...

What can you do with it?

Say you wanted to create a bin - object 1337 - two units in front of a player. You don't want to manually do maths sin/cos/tan and you don't want to play with the ugly manual tables. You just want to get the position two units in front of the player whilst taking into account rotation.

It's easy. As simple as:

Object ( 1337, player.matrix.front * 2 )

Yes, it's just player.matrix.front * 2. Two units in front of the player!

Why not stick to the good ol' tables?

Say you'd like to get find the position underneath a vehicle. The position at any rotation, so if it was upside down, the z value would be higher than the vehicle Z value. If the vehicle was the right way round, the z value for underneath car would be less than the z value for the car. Would you really prefer this?

local matrix = getElementMatrix(vehicle)
local offX = 0 * matrix[1][1] + 0 * matrix[2][1] - 1 * matrix[3][1] + matrix[4][1]
local offY = 0 * matrix[1][2] + 0 * matrix[2][2] - 1 * matrix[3][2] + matrix[4][2]
local offZ = 0 * matrix[1][3] + 0 * matrix[2][3] - 1 * matrix[3][3] + matrix[4][3]

local pX, pY, pZ = getElementPosition(vehicle)

positionbelow = {offX-pX, offY-pY, offZ-pZ}

than this?

positionBelow = vehicle.matrix.top * -1

Simples. [[Category:Incomplete}}