GetElementMatrix: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
|||
Line 23: | Line 23: | ||
--Get our offset components | --Get our offset components | ||
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 | --Return the transformed point | ||
return offX, offY, offZ | |||
end | |||
</syntaxhighlight> | |||
This example is exactly the same as above, but without using the Lua Matrix library. | |||
<syntaxhighlight lang="lua"> | |||
function getPositionInFrontOfElement(element) | |||
-- Get the matrix | |||
local matrix = getElementMatrix ( element ) | |||
-- Get the transformation of a point 5 units in front of the element | |||
local offX = 0 * matrix[1][1] + 5 * matrix[2][1] + 0 * matrix[3][1] + matrix[4][1] | |||
local offY = 0 * matrix[1][2] + 5 * matrix[2][2] + 0 * matrix[3][2] + matrix[4][2] | |||
local offZ = 0 * matrix[1][3] + 5 * matrix[2][3] + 0 * matrix[3][3] + matrix[4][3] | |||
--Return the transformed point | |||
return offX, offY, offZ | return offX, offY, offZ | ||
end | end |
Revision as of 21:53, 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 the transformed point return offX, offY, offZ end
This example is exactly the same as above, but without using the Lua Matrix library.
function getPositionInFrontOfElement(element) -- Get the matrix local matrix = getElementMatrix ( element ) -- Get the transformation of a point 5 units in front of the element local offX = 0 * matrix[1][1] + 5 * matrix[2][1] + 0 * matrix[3][1] + matrix[4][1] local offY = 0 * matrix[1][2] + 5 * matrix[2][2] + 0 * matrix[3][2] + matrix[4][2] local offZ = 0 * matrix[1][3] + 5 * matrix[2][3] + 0 * matrix[3][3] + matrix[4][3] --Return the transformed point return offX, offY, offZ end
See Also
- getElementBoneMatrix
- getElementBonePosition
- getElementBoneRotation
- getElementBoundingBox
- getElementDistanceFromCentreOfMassToBaseOfModel
- getElementLighting
- getElementRadius
- isElementCollidableWith
- isElementLocal
- isElementOnScreen
- isElementStreamable
- isElementStreamedIn
- isElementSyncer
- isElementWaitingForGroundToLoad
- setElementBoneMatrix
- setElementBonePosition
- setElementBoneRotation
- setElementCollidableWith
- setElementStreamable
- updateElementRpHAnim
- Shared
- attachElements
- createElement
- destroyElement
- detachElements
- getAttachedElements
- getElementAlpha
- getElementAttachedOffsets
- getElementAttachedTo
- getElementByIndex
- getElementByID
- getElementChild
- getElementChildren
- getElementChildrenCount
- getElementCollisionsEnabled
- getElementColShape
- getElementData
- getAllElementData
- hasElementData
- getElementDimension
- getElementHealth
- getElementID
- getElementInterior
- getElementMatrix
- getElementModel
- getElementParent
- getElementPosition
- getElementRotation
- getElementsByType
- getElementsWithinColShape
- getElementsWithinRange
- getElementType
- getElementVelocity
- getLowLODElement
- getRootElement
- isElement
- isElementAttached
- isElementCallPropagationEnabled
- isElementDoubleSided
- isElementFrozen
- isElementInWater
- isElementLowLOD
- isElementWithinColShape
- isElementWithinMarker
- setElementAlpha
- setElementAngularVelocity
- getElementAngularVelocity
- setElementAttachedOffsets
- setElementCallPropagationEnabled
- setElementCollisionsEnabled
- setElementData
- setElementDimension
- setElementDoubleSided
- setElementFrozen
- setElementHealth
- setElementID
- setElementInterior
- setElementModel
- setElementParent
- setElementPosition
- setElementRotation
- setElementVelocity
- setLowLODElement
- getPedContactElement
- getResourceDynamicElementRoot
- getResourceRootElement