admin管理员组文章数量:1327254
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?
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?
Share Improve this question asked Oct 16, 2014 at 9:15 konturkontur 5,2192 gold badges39 silver badges67 bronze badges 6-
Is
object.worldToLocal( vector )
what you are looking for? – WestLangley Commented Oct 16, 2014 at 9:33 -
@WestLangley That was my first instinct as well, but that doesn't seem to get me what I want... so either I might be using it wrong, or that is not the solution. Assuming this does what I want, drawing a line along the following vector it should line up to the global X axis (which for me, it doesn't), should it not?
var translatedAxis = myRotatedObject.worldToLocal(new THREE.Vector3(1, 0, 0));
– kontur Commented Oct 16, 2014 at 10:24 - Can you provide a simple live example, such as a jsfiddle? – WestLangley Commented Oct 16, 2014 at 10:30
- See here: jsbin./datiyekaroti/1 – kontur Commented Oct 16, 2014 at 10:56
-
Hey @WestLangley thanks for checking again. I ended up translating the Vector3 itself with applyMatrix4, but the
parent.updateMatrixWorld(); // important!
was the crucial missing piece. Feel free to add a reference to that as an answer and I'll gladly accept. :) – kontur Commented Oct 16, 2014 at 19:49
1 Answer
Reset to default 8You 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
本文标签: javascriptTranslate a vector from global space to local vector in threejsStack Overflow
版权声明:本文标题:javascript - Translate a vector from global space to local vector in three.js - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742210201a2433571.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论