小编And*_*her的帖子

如何围绕物体旋转THREE.PerspectiveCamera

我正在制作这个程序,您可以在其中单击一个对象,缩放到它,然后通过按住鼠标右键并拖动从所有角度查看它.我需要相机绕过物体,而不是用相机看着它旋转物体.老实说,我根本不知道如何数学出来!

为了进行测试,我们已经选择并正在查看一个带有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));
Run Code Online (Sandbox Code Playgroud)

因此,相机和物体之间的半径为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 …
Run Code Online (Sandbox Code Playgroud)

javascript math rotation perspectivecamera three.js

5
推荐指数
1
解决办法
2万
查看次数

标签 统计

javascript ×1

math ×1

perspectivecamera ×1

rotation ×1

three.js ×1