GetElementBoneMatrix: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
(Remove obsolete Requirements section)
 
(2 intermediate revisions by 2 users not shown)
Line 18: Line 18:


==Example==  
==Example==  
addCommandHandler ("getbonematrix",
this example will output bone position and rotation for id 5.
function(commandName, boneID)
<syntaxhighlight lang="lua">
     local matrix = {getElementBoneMatrix(localPlayer, boneID)}
local boneMatrix = getElementBoneMatrix(localPlayer, 5) -- get the bone matrix for localPlayer, id: 5
    iprint(matrix[1])
if boneMatrix then
end)
    -- extract position and rotation from the matrix
<sub>function</sub>
     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]))


==Requirements==
    outputChatBox("Bone position: (" .. posX .. ", " .. posY .. ", " .. posZ .. ")")
{{Requirements|n/a|1.5.8-9.20704|}}
    outputChatBox("Bone rotation: (" .. rotX .. ", " .. rotY .. ", " .. rotZ .. ")")
else
    outputChatBox("Invalid element or bone ID.")
end
</syntaxhighlight>


==See Also==
==See Also==
{{Client_element_functions}}
{{Client_element_functions}}

Latest revision as of 17:23, 7 November 2024

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

See Also