three.js旋转面向物体

时间:2014-08-31 13:26:37

标签: javascript rotation three.js angle

我已经做了13年的传播,但我仍然在努力解决三个问题.js处理事情的方式。所以我最喜欢用风扇来描述,它总是面向相机,当然还有旋转。

这就是我用另一种语言实现这一目标的方法:

// Create a vector facing in camera direction.
temp.x = 0;
temp.y = 1;
temp.z = 0;
vec_rotate(temp, camera.pan);

// Apply vector direction to scene object.
vec_to_angle(entity.pan, temp);

// Rotate scene object's angle around another angle / imaginary line from camera to object.
ang_rotate(
    entity.pan, 
    vector(random(360), 0, 0)
);

因此,在应用entity.lookAt(camera.position)之后,我缺少基于当前角度的角度旋转(示例的最后一个函数调用)。

1 个答案:

答案 0 :(得分:3)

为风扇建模的一种方法是:

var fan = new THREE.Mesh( ... );

var pivot = new THREE.Object3D();
scene.add( pivot );
pivot.lookAt( camera.position );

pivot.add( fan );

然后在动画循环中(假设风扇网格默认面向正z轴),

fan.rotation.z += 0.01;

three.js r.68

相关问题