我的 object3D 有一个向上向量 (0,1,0)。 object3D 围绕偏航、俯仰和滚动移动其原点。
我的问题: 如何找到在世界坐标中显示 object3D 向上向量方向的向量?
编码上下文示例:-
var v1 = new THREE.Vector3();
v1.add( givenObject3D.up ); // now v1 = (0,1,0)
givenObject3D.updateMatrixWorld();
FunctionXXX (v1, givenObject3D.matrixWorld );
//... now v1 is a vector in world coordinates
//... v1 points in the same direction as the givenObject3D's up vector.
v1.normalize();
最佳答案
您想要获取对象的向上
向量的世界方向。为此,请对应用于对象的向上
向量应用相同的旋转。
如果该对象直接是场景的子对象,那么您可以这样做:
var v1 = new THREE.Vector3(); // create once and reuse it
...
v1.copy( object.up ).applyQuaternion( object.quaternion );
如果该对象有一个旋转的父对象,那么您需要使用此模式:
var v1 = new THREE.Vector3(); // create once and reuse it
var worldQuaternion = new THREE.Quaternion(); // create once and reuse it
...
object.getWorldQuaternion( worldQuaternion );
v1.copy( object.up ).applyQuaternion( worldQuaternion );
三.js r.74
关于vector - 三.js 如何求物体局部Up向量的世界方向向量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35641875/