Manipulating Matrices: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
(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...")
 
mNo edit summary
Line 1: Line 1:
{{Needs Checking|should this be on the Matrix page?}}
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.
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.
Now, with the new [[Matrix]] class, we can make and magically manipulate Matrices.

Revision as of 22:50, 19 June 2014

Dialog-information.png This article needs checking.

Reason(s): should this be on the Matrix page?

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}}