Muffle Posted February 21, 2012 Share Posted February 21, 2012 Hi community, excuse my rude question, but is there by chance a utility function to get a position relative to an Element taking all of its rotations into account? Basically I want to create a marker on the back of a car. In an ideal world, I would like to use it like attachElemtents: give it offset coordinates and rotations. The ideal form would be this: float, float, float, float, float, float = getPositionRelativeToElementWithOffsets(element theElement, offsetPosX, offsetPosY, offsetPosZ, offsetRotationX, offsetRotationY, offsetRotationZ) Returns: float absoluteWorldPosX, float absoluteWorldPosY, float absoluteWorldPosZ, float absoluteWorldRotationX, float absoluteWorldRotationY, float absoluteWorldRotationZ The name is of course disputable. If I e.g. use GetPointFromDistanceRotation I can neither give exact offset positions nor any rotations. Also, if the car is on an angle down, the marker will not be on the back of the car but inside of it. So, do you guys know of such a function? Are there any mathematicians among you guys that know trigonometry in a three dimensional coordinate system? EDIT: Maybe I should also say that I tried a workaround by attaching a dummy that I grab the coords off to then delete it again, but that didn't work either: local posX, posY, posZ = getElementPosition(vehicle) local dummy = createObject(3910, posX, posY, posZ) attachElements(dummy, vehicle, -0.0, 0.5, 1.5, 0, 0, 0) local posX2, posY2, posZ2 = getElementPosition(dummy) destroyElement(dummy) local marker = createMarker(posX2, posY2, posZ2, "cylinder", .5, 255, 255, 0, 255, root) didn't work here means that posX == posX2... Link to comment
Discord Moderators Zango Posted February 21, 2012 Discord Moderators Share Posted February 21, 2012 There is no such function, however you can use sinus/cosine to calculate it based on the third rotation value, or you can use getElementMatrix. The wiki example already contains a function to get the point 5 meters ahead, perhaps inverse those values? function getPositionInBackOfElement(element) local matrix = getElementMatrix ( element ) local offX = 0 * matrix[1][1] + -5 * matrix[2][1] + 0 * matrix[3][1] + 1 * matrix[4][1] local offY = 0 * matrix[1][2] + -5 * matrix[2][2] + 0 * matrix[3][2] + 1 * matrix[4][2] local offZ = 0 * matrix[1][3] + -5 * matrix[2][3] + 0 * matrix[3][3] + 1 * matrix[4][3] return offX, offY, offZ end Link to comment
Muffle Posted February 21, 2012 Author Share Posted February 21, 2012 Thanks for the tips, but neither getElementMatrix is available server side, nor I know how to use sine/cosine taking all rotation axis into account. 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