Jump to content

Tranform from Parent Reference to World


amorgan
 Share

Recommended Posts

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...