Manipulating Matrices: Difference between revisions
mNo edit summary |
No edit summary |
||
Line 11: | Line 11: | ||
It's easy. As simple as: | It's easy. As simple as: | ||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
Object ( 1337, player.matrix. | Object ( 1337, player.matrix.forward * 2 ) | ||
</syntaxhighlight> | </syntaxhighlight> | ||
Yes, it's just player.matrix. | Yes, it's just player.matrix.forward * 2. Two units in front of the player! | ||
== Why not stick to the good ol' tables? == | == Why not stick to the good ol' tables? == | ||
Line 30: | Line 30: | ||
than this? | than this? | ||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
positionBelow = vehicle.matrix. | positionBelow = vehicle.matrix.up * -1 | ||
</syntaxhighlight> | </syntaxhighlight> | ||
Simples. | Simples. | ||
[[Category:Incomplete}} | [[Category:Incomplete}} |
Revision as of 17:15, 23 June 2014
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.forward * 2 )
Yes, it's just player.matrix.forward * 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.up * -1
Simples. [[Category:Incomplete}}