我正在制作一个程序,您可以单击对象,缩放到它,然后通过按住右鼠标按钮并拖动来从各个角度查看它。我需要相机围绕对象旋转,而不是将对象旋转并让相机观察它。老实说,我真的不知道如何进行数学计算!
为了测试,已经有一个游戏对象,我们已经选择并正在查看其xyz。
var g = new GameObject(500, 0, 0);//The game object with xyz
this.selected = g;//set selected to g
//Create and set the camera
this.camera = new THREE.PerspectiveCamera(45, w/h, 1, 10000);
this.camera.position.x = 0;
this.camera.position.y = 0;
this.camera.position.z = 0;
//set camera to look at the object which is 500 away in the x direction
this.camera.lookAt(new THREE.Vector3(this.selected.x, this.selected.y, this.selected.z));
摄像机与物体之间的半径为500,当选中并旋转时,摄像机应始终保持距离500。
我在这里更新场景:
Main.prototype.update = function(){
this.renderer.render(this.scene, this.camera);//scene is just some ambient lighting
//what to do when mouse right is held down
if(this.rightMouseDown){
//placeholder functionality, needs to rotate around object based on mouse movements
this.camera.position.x -= 5;
}
}
如何以500的半径围绕g旋转此相机?!?!