inxs Posted August 31, 2018 Share Posted August 31, 2018 Hello Guys, when I drag a rotated Mesh with the Gizmo in the direction of the rotation. How do I calculate the Distance in Local Space (Drag X Distance)? Thanks Jonny Quote Link to comment Share on other sites More sharing options...
inxs Posted August 31, 2018 Author Share Posted August 31, 2018 I tried this so far: this.parentMesh.computeWorldMatrix(); console.log('Parent: ' + this.parentMesh.position); console.log('Origin: ' + this.origin); const mat = new Matrix(); const diff = this.parentMesh.position.subtract(this.origin); if (diff) { console.log('Diff: ' + diff); const quat = Helper.QuaternionToBabylon(this.assemblyItem.quaternion); quat.toRotationMatrix(mat); const trans = BABYLON.Vector3.TransformCoordinates(diff, mat); console.log('Transformed: ' + trans); } But X Value is correct but also there is a difference in Y, even If i didnt drag Y. Quote Link to comment Share on other sites More sharing options...
babbleon Posted August 31, 2018 Share Posted August 31, 2018 The difference in Y is very small though. If you rounded to, say, 8 decimal places it would = 0. Quote Link to comment Share on other sites More sharing options...
trevordev Posted August 31, 2018 Share Posted August 31, 2018 Which gizmo are you using? Do you have playground code I can look at? Quote Link to comment Share on other sites More sharing options...
inxs Posted September 3, 2018 Author Share Posted September 3, 2018 On 8/31/2018 at 6:01 PM, babbleon said: The difference in Y is very small though. If you rounded to, say, 8 decimal places it would = 0. The diff is 4.6 and it should be 0 because in local space I only moved on X Axis. On 8/31/2018 at 6:49 PM, trevordev said: Which gizmo are you using? Do you have playground code I can look at? The PositionGizmo with updateGizmoRotationToMatchAttachedMesh = true; When I rotate the Mesh for 30 degrees and move it to with the x direction, then I want the distance I move on this axis. I will create a PG and post it here. Quote Link to comment Share on other sites More sharing options...
babbleon Posted September 3, 2018 Share Posted September 3, 2018 Hi @inxs, have a closer look at the number.. it's 4.6e-16, a very small number indeed! Try this: console.log(.00000000000000046) Quote Link to comment Share on other sites More sharing options...
inxs Posted September 3, 2018 Author Share Posted September 3, 2018 Ah ok thanks I didn't see that. But I dont think the calculation is correct. I just want a short formula how to calculate the distance of two points in the localspace of my mesh? Quote Link to comment Share on other sites More sharing options...
inxs Posted September 3, 2018 Author Share Posted September 3, 2018 Ok already got the solution after browsing git repo const tmpMatrix = new BABYLON.Matrix(); const localDelta = new BABYLON.Vector3(); this.parentMesh.computeWorldMatrix().invertToRef(tmpMatrix); tmpMatrix.setTranslationFromFloats(0, 0, 0); Vector3.TransformCoordinatesToRef(diff, tmpMatrix, localDelta); 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.