three.js如何围绕摄像机坐标旋转对象?

时间:2015-04-21 10:18:45

标签: javascript html5 three.js

var object = new THREE.CSS3DObject(element);

object.matrix=camera.matrix.clone();

object.matrix.setPosition(new THREE.Vector3(tarx,tary,tarz));

//object.applyMatrix(new THREE.Matrix4().makeRotationY(rY));
//object.applyMatrix(new THREE.Matrix4().makeRotationZ(rX));

它将围绕世界坐标Y旋转,但我只想围绕相机旋转

1 个答案:

答案 0 :(得分:0)

1 - 创建一个复制camera.position的对象(就像你所做的那样)
2 - 向此对象添加卫星

var orbit = 100;

var geometry = new THREE.BoxGeometry(1,1,1);
var material = new THREE.MeshBasicMaterial( { color: 0xffff00, side: THREE.DoubleSide } );
satellite = new THREE.Mesh( geometry, material );
satellite.position.set(orbit,0,0);

将卫星添加到对象

object.add( satellite );

如果您旋转对象
 卫星围绕摄像机坐标旋转。