amorgan Posted March 4, 2016 Share Posted March 4, 2016 I'm sure this has been covered before and I've read some of the tutorials covering topics like this, but I'm still struggling. I have a mesh that is parented to my camera and I want to to be able to transform it from the parented position/rotation to the world's position/rotation. Doing position is easy since I can just get _absolutePosition, the rotation I am still stuck on. Could you please advise? Also, if you have any recommendations for references/resources on matrix operations and quaternions that would be greatly appreciated. I have advanced math education (including linear algebra), but it's been a while and I am out of practice. Thank you, amorgan Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted March 4, 2016 Share Posted March 4, 2016 Hello, you should do something like this: var worldMat = mesh.getWorldMatrix(); var translation = new BABYLON.Vector3(); var quaterion = new BABYLON.Quaternion(); var scale = new BABYLON.Vector3(); worldMat.decompose(scale, rotation, translation); http://doc.babylonjs.com/classes/2.3/Matrix#decompose-scale-rotation-translation-rarr-boolean amorgan 1 Quote Link to comment Share on other sites More sharing options...
amorgan Posted March 4, 2016 Author Share Posted March 4, 2016 Ah hah! I saw this in the documentation, but it was unclear to me how to use it. Exactly what I wanted. For completeness I did: // mesh is parented to camera before this line var worldMat = mesh.getWorldMatrix(); var newTranslation = new BABYLON.Vector3(); var newQuaterion = new BABYLON.Quaternion(); var newScale = new BABYLON.Vector3(); worldMat.decompose(newScale, newQuaterion, newTranslation); mesh.parent = null; mesh.rotationQuaternion = newQuaterion; mesh.position = newTranslation; Thanks! GameMonetize 1 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.