Three.js - Cameras



Types of Cameras

There are two types of cameras are in Three.js.

Sr.No Cameras & Description
1

PerspectiveCamera

There are different cameras in Three.js. The most common camera and the one we've been using is the PerspectiveCamera.

2

OrthographicCamera

The 2nd most common camera is the OrthographicCamera. It specifies a box with the settings left, right top, bottom, near, and far. It represents three-dimensional objects in two dimensions.

Making the Camera Follow an Object

In the animation function, we use the camera.lookAt function to point the camera to the position function of the object. We do this in every frame that we render. It looks like the camera is exactly following the object's position.

function animate() {
   const object = scene.getObjectByName('sphere')
   renderer.render(scene, camera)
   camera.lookAt(object.position)
   requestAnimationFrame(render)
}
Advertisements