Jump to content

Custom attachElements


bartekPL

Recommended Posts

Hi,

I'm writing custom function attachElementsEx (alternative for attachElements https://wiki.multitheftauto.com/wiki/AttachElements).

function attachElementsEx( theElement, theAttachToElement, ox, oy, oz, orx, ory, orz ) 
    ...  -- here I saving offsets etc. 
end 
  
addEventHandler( "onClientRender", getRootElement(), 
    function() 
        ...  -- here I calculating and updating positions and rotations of attached elements 
    end 
) 

While I'm calculating end point XYZ (including rotation), I have the following variables:

local px,py,pz = getElementPosition( theElement )  -- position XYZ of source element 
local rx,ry,rz = getElementPosition( theElement )  -- rotation XYZ of source element 
local ox,oy,oz  -- position offsets 
local orx,ory,orz  -- rotation offsets 

From this data i have to calculate end position (and rotation) of attached element, but i don't know how to do it. I know how to make same script in 2D dimension, but 3D it's too hard for me.

THX for help :)

Link to comment

Matrix is probably the most intuitive representation of element's position and rotation. matrix[1] (X) vector points to the right from the element. matrix[2] (Y) points to the front. matrix[3] (Z) points up. matrix[4] is the position of the element. The first example in the getElementMatrix page may help you to understand how it works.

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...