GetElementMatrix: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 1: Line 1:
{{Client function}}
{{Client function}}
__NOTOC__  
__NOTOC__  
This function gets an element's matrix. This contains various components such as position and rotation. It is most useful for matrix calculations such as calculating offsets.
This function gets an element's transform matrix. This contains 16 float values that multiplied to a point will give you the point transformed. It is most useful for matrix calculations such as calculating offsets. For further information, please refer to a tutorial of matrices in computer graphics programming.


==Syntax==
==Syntax==
Line 12: Line 12:


===Returns===
===Returns===
Returns a multi-dimensional array in the format of:
Returns a multi-dimensional array containing a 4x4 matrix.
<syntaxhighlight lang="lua">
{
    { rollX,        rollY,        rollZ,        1    },
    { directionX,  directionY,    directionZ,  1    },
    { wasX,        wasY,          wasZ,        1    },
    { posX,        posY,          posZ,        1    },
}
</syntaxhighlight>
</syntaxhighlight>


Line 26: Line 19:
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
function getPositionInFrontOfElement(element)
function getPositionInFrontOfElement(element)
local posX,posY,posZ = getElementPosition(element)
--Get the position 5 units in front
--Get the position 5 units in front
local transformed = matrix{0,5,0} * matrix(getElementMatrix(element)}
local transformed = matrix{0,5,0} * matrix(getElementMatrix(element)}
Line 32: Line 24:
local offX,offY,offZ = transformed[1][1],transformed[2][1],transformed[3][1]
local offX,offY,offZ = transformed[1][1],transformed[2][1],transformed[3][1]
--Return absolute coordinates by adding the original position
--Return absolute coordinates by adding the original position
return posX + offX, posY + offY, posZ + offZ
return offX, offY, offZ
end
end
</syntaxhighlight>
</syntaxhighlight>

Revision as of 21:49, 26 April 2009

This function gets an element's transform matrix. This contains 16 float values that multiplied to a point will give you the point transformed. It is most useful for matrix calculations such as calculating offsets. For further information, please refer to a tutorial of matrices in computer graphics programming.

Syntax

table getElementMatrix ( element theElement )       

Required Arguments

  • theElement: The element which you wish to retrieve the matrix for

Returns

Returns a multi-dimensional array containing a 4x4 matrix. </syntaxhighlight>

Example

This example creates a utility function that gets the position that is in front of a specified player. Note that it assumes you have the Lua Matrix library installed.

function getPositionInFrontOfElement(element)
	--Get the position 5 units in front
	local transformed = matrix{0,5,0} * matrix(getElementMatrix(element)}
	--Get our offset components
	local offX,offY,offZ = transformed[1][1],transformed[2][1],transformed[3][1]
	--Return absolute coordinates by adding the original position
	return offX, offY, offZ
end

See Also