GetElementBoneMatrix: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
 
(9 intermediate revisions by 2 users not shown)
Line 1: Line 1:
{{Client function}}
{{Client function}}
__NOTOC__  
__NOTOC__  
{{Added feature/item|3.0159|1.5.8|20704|This function returns the transformation matrix of a specific bone. Currently the [[Element/Player|Player]] and [[Element/Ped|Ped]] element types are accepted.}}
{{Added feature/item|1.5.9|1.5.8|20704|This function returns the transformation matrix of a specific bone. Currently the [[Element/Player|Player]] and [[Element/Ped|Ped]] element types are accepted.}}
 
{{Tip|If you want to attach an element to a bone, see [[attachElementToBone]].}}
{{Tip|If you want to attach an element to a bone, see [[attachElementToBone]].}}
{{Tip|For [[matrix]] manipulation which goes beyond the basic examples given on this page, see the [[Lua matrix library]]. Using the built-in [[matrix]] class is also recommended.}}
{{Tip|For [[matrix]] manipulation which goes beyond the basic examples given on this page, see the [[Lua matrix library]]. Using the built-in [[matrix]] class is also recommended.}}
Line 19: Line 18:


==Example==  
==Example==  
{{Needs Example}}
this example will output bone position and rotation for id 5.
<syntaxhighlight lang="lua">
local boneMatrix = getElementBoneMatrix(localPlayer, 5) -- get the bone matrix for localPlayer, id: 5
if boneMatrix then
    -- extract position and rotation from the matrix
    local posX, posY, posZ = boneMatrix[4][1], boneMatrix[4][2], boneMatrix[4][3]
    local rotX, rotY, rotZ = math.deg(math.asin(-boneMatrix[3][2])), math.deg(math.atan2(boneMatrix[3][1], boneMatrix[3][3])), math.deg(math.atan2(boneMatrix[1][2], boneMatrix[2][2]))
 
    outputChatBox("Bone position: (" .. posX .. ", " .. posY .. ", " .. posZ .. ")")
    outputChatBox("Bone rotation: (" .. rotX .. ", " .. rotY .. ", " .. rotZ .. ")")
else
    outputChatBox("Invalid element or bone ID.")
end
</syntaxhighlight>


==Requirements==
==Requirements==

Latest revision as of 20:25, 12 December 2023

This function returns the transformation matrix of a specific bone. Currently the Player and Ped element types are accepted.

[[{{{image}}}|link=|]] Tip: If you want to attach an element to a bone, see attachElementToBone.
[[{{{image}}}|link=|]] Tip: For matrix manipulation which goes beyond the basic examples given on this page, see the Lua matrix library. Using the built-in matrix class is also recommended.

Syntax

table getElementBoneMatrix ( element theElement, int boneId )

Required Arguments

  • theElement: the element to get the bone matrix on.
  • boneId: the ID of the bone to get the matrix of. See Bone IDs.

Returns

Returns a multi-dimensional array (which can be transformed into a proper matrix class using Matrix.create method) containing a 4x4 matrix. Returns false if invalid arguments were passed.

Example

this example will output bone position and rotation for id 5.

local boneMatrix = getElementBoneMatrix(localPlayer, 5) -- get the bone matrix for localPlayer, id: 5
if boneMatrix then
    -- extract position and rotation from the matrix
    local posX, posY, posZ = boneMatrix[4][1], boneMatrix[4][2], boneMatrix[4][3]
    local rotX, rotY, rotZ = math.deg(math.asin(-boneMatrix[3][2])), math.deg(math.atan2(boneMatrix[3][1], boneMatrix[3][3])), math.deg(math.atan2(boneMatrix[1][2], boneMatrix[2][2]))

    outputChatBox("Bone position: (" .. posX .. ", " .. posY .. ", " .. posZ .. ")")
    outputChatBox("Bone rotation: (" .. rotX .. ", " .. rotY .. ", " .. rotZ .. ")")
else
    outputChatBox("Invalid element or bone ID.")
end

Requirements

Minimum server version n/a
Minimum client version 1.5.8-9.20704

Note: Using this feature requires the resource to have the above minimum version declared in the meta.xml <min_mta_version> section. e.g. <min_mta_version client="1.5.8-9.20704" />

See Also