简体   繁体   English

THREE.JS:无法旋转相机

[英]THREE.JS : Can't rotate camera

I need my camera to look behind (the x=0,z=0 are in the middle of the pong table) how can i do it?我需要我的相机向后看(x=0,z=0 在乒乓球台的中间)我该怎么做? ( i tried to change everything on camera.lookAt) camera look front (我试图改变camera.lookAt上的一切)相机看前面

scene = new THREE.Scene();
    scene.id=1;
    camera = new THREE.PerspectiveCamera(75, w / h, 0.1, 1000);
    camera.lookAt(0,0,0);
    camera.position.set(0, 3.75, -5);

You need to change the order of your operations.您需要更改操作的顺序。 When you initialize a new camera, its position is automatically (0, 0, 0) and when you do .lookAt(0, 0, 0) it probably doesn't know what to do because you're telling it to look at the same point where it already is!当您初始化一个新相机时,它的 position 自动为(0, 0, 0)而当您执行.lookAt(0, 0, 0)时,它可能不知道该怎么做,因为您告诉它查看它已经在同一点!

Just do .lookAt() after setting position:只需在设置 position 后执行.lookAt()

camera = new THREE.PerspectiveCamera(75, w / h, 0.1, 1000);
camera.position.set(0, 3.75, -5); // Change position FIRST
camera.lookAt(0, 0, 0); // Then tell it to look at origin

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM