【问题标题】:Three.js How to find World orientation vector of object's local Up vector?三.js如何找到物体局部Up向量的世界方向向量?
【发布时间】:2016-06-09 02:06:10
【问题描述】:

我的 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();

【问题讨论】:

    标签: vector three.js rotation


    【解决方案1】:

    您想要获取对象的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

    【讨论】:

      猜你喜欢
      • 2016-01-07
      • 2016-06-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-09-14
      相关资源
      最近更新 更多