Skip to content

Instantly share code, notes, and snippets.

@error454
Created July 29, 2014 18:18
Show Gist options
  • Save error454/4d4b15086c772c3f1bda to your computer and use it in GitHub Desktop.
Save error454/4d4b15086c772c3f1bda to your computer and use it in GitHub Desktop.
Local Space to Global Space
-- I have cube whose origin is in the center of the cube.
-- I want to place a joint on the end face of the cube, the +Z end.
-- --------------
-- | |
-- | |<--- Joint here
-- | |
-- --------------
--
-- I know that the width of the box is boxLength, so the localspace coordinate that gives me the
-- end of the box is 0, 0, boxLength * 0.5 (remember that the origin is in the center)
-- So now I can get the global space coordinates where that joint should go.
local fx, fy, fz = object.transformPoint ( hPrev, 0, 0, boxLength * 0.5, object.kLocalSpace, object.kGlobalSpace )
-- Now I have a 2nd object that I want to connect to this joint. I already have the global space coordinates and now
-- I need the local space coordinates for this other object
local otherX, otherY, otherZ = object.transformPoint ( hOtherObject, fx, fy, fz, object.kGlobalSpace, object.kLocalSpace )
local scaleX, scaleY, scaleZ = object.getScale ( hOtherObject )
-- Now that I have the local space coordinates, I can create the joint. I need to apply the scale of the object to
-- the local space coordinates. (The first object is not scaled btw).
SmanPX.createJoint ( hPrev, hOtherObject, 0, 0, boxLength * 0.5, otherX * scaleX, otherY * scaleY, otherZ * scaleZ, SmanPX.kJointTypeSpherical )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment