Jump to content

Convert global coordinates to local coordinates


binyan
 Share

Recommended Posts

Given a vector expressed in global space and a mesh, how can I get the position of this vector within a mesh local space?

Or, alternatively, how can I get a parent position within a child local space?

 

Update:

Just figured it out... It is simply vector.subtract(Mesh.getAbsolutePosition()), right? 

 

Update2:

Ok it's not... Because it doesn't take in account the mesh rotation. 

Link to comment
Share on other sites

  • 2 years later...

Hello !

This is very useful for those who want to transform a vector into a mesh's space.  But I don't know why you use Matrix.InvertToRef.

I understand better this function :

       var vector = new BABYLON.Vector3(100,0,0);
        var m = mesh1.getWorldMatrix();
        var v = BABYLON.Vector3.TransformCoordinates(vector, m);
       mesh2.position = v;

 

 

Link to comment
Share on other sites

  • 1 year later...

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...