JackFalcon Posted April 23, 2018 Share Posted April 23, 2018 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. Quote Link to comment Share on other sites More sharing options...
JackFalcon Posted April 23, 2018 Author Share Posted April 23, 2018 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. Wingnut and GameMonetize 2 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.