三.js如何找到对象局部Up向量的世界方向向量? [英] Three.js How to find World orientation vector of object's local Up vector?

查看:42
本文介绍了三.js如何找到对象局部Up向量的世界方向向量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的 object3D 有一个向上向量 (0,1,0).object3D 围绕偏航、俯仰和滚动移动其原点.

My object3D has an up vector (0,1,0). The object3D moves its origin around yawing, pitching and rolling.

我的问题:如何找到在世界坐标中显示 object3D 上向量方向的向量?

My Question: How do I find the vector which shows the direction of the object3D's up vector in world coordinates?

编码上下文示例:-

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

推荐答案

你想得到一个对象的 up 向量的世界方向.为此,请对应用于对象的 up 向量应用相同的旋转.

You want to get the world orientation of an object's up vector. To do so, apply the same rotation to the up vector that is applied to the object.

如果对象直接是场景的子对象,那么您可以这样做:

If the object is a child of the scene directly, then you can do this:

var v1 = new THREE.Vector3(); // create once and reuse it
...
v1.copy( object.up ).applyQuaternion( object.quaternion );

如果对象有一个旋转的父对象,那么你需要使用这个模式:

If the object has a rotated parent, then you need to use this pattern:

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

three.js r.74

这篇关于三.js如何找到对象局部Up向量的世界方向向量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆