bartekPL Posted April 5, 2013 Share Posted April 5, 2013 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
DiSaMe Posted April 5, 2013 Share Posted April 5, 2013 getElementMatrix setElementMatrix Link to comment
bartekPL Posted April 5, 2013 Author Share Posted April 5, 2013 I don't understand matrices and i don't know how to use it correctly Link to comment
DiSaMe Posted April 5, 2013 Share Posted April 5, 2013 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
bartekPL Posted April 6, 2013 Author Share Posted April 6, 2013 Thanks, it works! Now i have this what i needed Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now