<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.multitheftauto.com/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Sultanskyman</id>
	<title>Multi Theft Auto: Wiki - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.multitheftauto.com/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Sultanskyman"/>
	<link rel="alternate" type="text/html" href="https://wiki.multitheftauto.com/wiki/Special:Contributions/Sultanskyman"/>
	<updated>2026-05-22T03:12:25Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.39.3</generator>
	<entry>
		<id>https://wiki.multitheftauto.com/index.php?title=Matrix&amp;diff=45359</id>
		<title>Matrix</title>
		<link rel="alternate" type="text/html" href="https://wiki.multitheftauto.com/index.php?title=Matrix&amp;diff=45359"/>
		<updated>2015-06-22T23:56:16Z</updated>

		<summary type="html">&lt;p&gt;Sultanskyman: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;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.&lt;br /&gt;
__TOC__&lt;br /&gt;
==Methods==&lt;br /&gt;
===create===&lt;br /&gt;
This is default constructor for the Matrix class and returns a Matrix object.&lt;br /&gt;
&lt;br /&gt;
====Syntax====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;matrix Matrix ( Vector3 position, Vector3 rotation )&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;matrix Matrix ( Matrix matrixToClone )&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;matrix Matrix (  )&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=====Required Arguments=====&lt;br /&gt;
* '''position''': The position vector of the matrix&lt;br /&gt;
* '''rotation''': The rotation vector of the matrix&lt;br /&gt;
OR&lt;br /&gt;
* '''matrixToClone''': A matrix you want to instantiate a clone of&lt;br /&gt;
OR&lt;br /&gt;
* You can call this method without parameters to initialize a zero matrix.&lt;br /&gt;
&lt;br /&gt;
===transformPosition===&lt;br /&gt;
This method transforms a given position vector using the Matrix.&lt;br /&gt;
&lt;br /&gt;
====Syntax====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;Vector3 Matrix:transformPosition ( Vector3 position )&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=====Required Arguments=====&lt;br /&gt;
* '''position''': The position vector you want to transform&lt;br /&gt;
&lt;br /&gt;
====Example====&lt;br /&gt;
This example teleports a random player to a location 5 meters in front of him&lt;br /&gt;
&amp;lt;section name=&amp;quot;Shared&amp;quot; class=&amp;quot;both&amp;quot; show=&amp;quot;true&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
local player = getRandomPlayer()&lt;br /&gt;
local desiredRelativePosition = Vector3(0, 5, 0) -- 5 meters front of player is a y = 5 vector&lt;br /&gt;
local matrix = player.matrix&lt;br /&gt;
local newPosition = matrix.transformPosition(desiredRelativePosition)&lt;br /&gt;
player.position = newPosition&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/section&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===getPosition===&lt;br /&gt;
This method returns the position vector of a given matrix.&lt;br /&gt;
&lt;br /&gt;
====Syntax====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;Vector3 Matrix:getPosition ( )&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Example====&lt;br /&gt;
This example prints the position of a random player.&lt;br /&gt;
&amp;lt;section name=&amp;quot;Shared&amp;quot; class=&amp;quot;both&amp;quot; show=&amp;quot;true&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
local player = getRandomPlayer()&lt;br /&gt;
local matrix = player.matrix&lt;br /&gt;
local position = matrix:getPosition()&lt;br /&gt;
outputChatBox(&amp;quot;x: &amp;quot; .. position:getX() .. &amp;quot;, y: &amp;quot; .. position:getY() .. &amp;quot;, z:&amp;quot; .. position:getZ())&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/section&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===getRotation===&lt;br /&gt;
===getForward===&lt;br /&gt;
===getRight===&lt;br /&gt;
===getUp===&lt;br /&gt;
&lt;br /&gt;
==Using Matrices==&lt;br /&gt;
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:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
Object ( 1337, player.matrix.position + player.matrix.forward * 2 )&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Why not stick to the good ol' tables? ==&lt;br /&gt;
Say you'd like to get find the position underneath a vehicle. This is 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.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
--&lt;br /&gt;
-- Instead of:&lt;br /&gt;
--&lt;br /&gt;
local matrix = getElementMatrix(vehicle)&lt;br /&gt;
local offX = 0 * matrix[1][1] + 0 * matrix[2][1] - 1 * matrix[3][1] + matrix[4][1]&lt;br /&gt;
local offY = 0 * matrix[1][2] + 0 * matrix[2][2] - 1 * matrix[3][2] + matrix[4][2]&lt;br /&gt;
local offZ = 0 * matrix[1][3] + 0 * matrix[2][3] - 1 * matrix[3][3] + matrix[4][3]&lt;br /&gt;
&lt;br /&gt;
local pX, pY, pZ = getElementPosition(vehicle)&lt;br /&gt;
local positionBelow = {offX-pX, offY-pY, offZ-pZ}&lt;br /&gt;
&lt;br /&gt;
--&lt;br /&gt;
-- You only have to do:&lt;br /&gt;
--&lt;br /&gt;
local positionBelow = vehicle.position - vehicle.matrix.up&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[ru:Matrix]]&lt;br /&gt;
[[Category:OOP]]&lt;/div&gt;</summary>
		<author><name>Sultanskyman</name></author>
	</entry>
</feed>