简体   繁体   中英

Rotate camera around the scene

I would like to rotate my camera 90 degrees around the scene. I have tried using

cosole.log(camera.position);

and setting the camera to my desired position that I have seen in the log but this simply won't work.

This is how the camera is initialized (for the first image):

var width  = window.innerWidth,
    height = window.innerHeight;
var camera = new THREE.PerspectiveCamera(45, width / height, 0.1, 1000);
camera.position.set(0, -22, 22);

That's what I have:

在此输入图像描述

That's what I would like to have (90 degrees counter-clockwise camera turn):

在此输入图像描述

EDIT

I have noticed that I can rotate the object itself (: doing this :

plane.rotation.z = 90 * Math.PI / 180;

but I am still curious how to achieve the same effect with rotating the camera.

You have to move the camera position in a circle, the lookAt position should be the object or scene:

var rotSpeed = .02 
camera.position.x = x * Math.cos(rotSpeed) - z * Math.sin(rotSpeed);
camera.position.z = z * Math.cos(rotSpeed) + x * Math.sin(rotSpeed);
camera.lookAt(scene.position);

That's clockwise, for the other direction swap the plus and minus.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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