Rotate the camera around the scene

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

cosole.log(camera.position);

      

and set the camera to the correct position that I saw in the magazine, but it just 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);

      

What I have:

enter image description here

What I would like to have (rotate 90 degrees counterclockwise):

enter image description here

EDIT

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

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

      

but I'm still wondering how to achieve the same effect when rotating the camera.

+3


source to share


1 answer


You need to move the position of the camera in a circle, the position of lookAt should be an 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);

      



Clockwise, change the plus and minus for the other direction.

0


source







All Articles