Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Translate a vector from global space to local vector in three.js

With a rotated object in my scene, how can I translate a global vector into the local space of that rotated object, so that they are rendered in the same spot of the global vector?

Take for example a cube that is rotated but at the global origin. Now I would like to render lines for each global dimension (x, y, z), but added as children to the rotated cube, not the global scene. How do I calculate and in three.js implement the rotation of those vectors so they will line up?

like image 707
kontur Avatar asked Feb 11 '23 19:02

kontur


1 Answers

You want to add an object as a child of a parent object such that the world position and orientation of the child do not change.

You can do that using the following pattern:

parent.attach( object );

three.js r.107

like image 198
WestLangley Avatar answered Feb 15 '23 11:02

WestLangley