如何旋转对象使其面向某个方向?

时间:2014-03-09 13:29:30

标签: three.js

如果我知道对象面向的方向,例如(0,0,1)。旋转对象以面向方向矢量(1,1,1)的最简单方法是什么?

编辑:

我试过这个,但这个逻辑出了点问题:

var newDir = new THREE.Vector3(1,1,1);

var objectDir= new THREE.Vector3(0, 0, 1); 
objectDir.applyQuaternion(object.quaternion); // rotate this vector to object's facing direction

var pos = new THREE.Vector3();
pos.addVectors(newDir, object.position);

var axis = objectDir.cross(newDir).normalize();
var angle = objectDir.angleTo(pos);
object.rotateOnAxis(axis, angle);

1 个答案:

答案 0 :(得分:7)

用lookAt解决了它:

var newDir = new THREE.Vector3(1, 1, 1);
var pos = new THREE.Vector3();
pos.addVectors(newDir, object.position);
object.lookAt(pos);