# Coordinate Transformation Puzzle

## Recommended Posts

Hello,

How would WORLDSPACE Mouse Pick and Move (observable), translate into LOCALSPACE of a picked mesh?

CONTEXT: a smaller child cube is picked and moved around on a parent cube.

BEHAVIOR: without parent rotation, Pick Move works as expected.

After parent rotation the following RESULTS:

-Z move by mouse in WORLD SPACE results in -Z move of child object in LOCAL SPACE. So, it does not follow the mouse... in WORLDSPACE.

GOAL:  rotated LOCALSPACE child to follow WORLDSPACE mouse move (e.g. converting -Z mousemove into +X rotated child move). Strange but true.

QUESTION: How to convert the WORLDSPACE mouse  into LOCALSPACE ... and is that the correct way?

The "Frame of Reference" docs are excellent. Found out that vectors do not work in TransformCoordinates.

So, guessing that the World Coordinate on Move needs to be converted to local before the vector is calculated... then move the child in local space. Hmmm.

Any tips or examples on something like that?

Thx.

##### Share on other sites

SOLUTION:

Thanks to @Convergence and this thread...

The solution of converting MouseMove WORLDSPACE into rotated child cube LOCALSPACE was:

``````            /*CONVERT WORLD COORDINATES INTO LOCAL*/
var invertParentWorldMatrix = parentObj.getWorldMatrix().clone();
invertParentWorldMatrix.invert();
var local_position = BABYLON.Vector3.TransformCoordinates(pickPointMove, invertParentWorldMatrix);
childObj.position.copyFrom(local_position);``````

Hope that helps someone else.

## Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

×   Pasted as rich text.   Paste as plain text instead

Only 75 emoji are allowed.