2016-02-26 82 views
2

我object3D有一个向上向量(0,1,0)。 object3D围绕偏航,俯仰和滚动移动其原点。Three.js如何查找对象局部向量矢量的世界方向向量?

我的问题: 如何找到它显示的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(); 

回答

3

你要得到一个对象的up矢量的世界方向。要做到这一点,应用相同的旋转,以施加到物体的矢量up

如果对象是直接在现场的孩子,那么你可以这样做:

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); 

three.js所r.74