camera work

This example demonstrates following and tracking cameras. A following camera behaves as if it is attached to the object it follows.

if (followCamera) {
  bug.mesh.add(camera);
  camera.position.set(0,3,-10);
  // Rotation needed because of YZ flip from Blender export?
  camera.rotation.y = Math.PI;
}

This is achieved by adding the camera as a child to the model. The position and orientation of the camera may then need adjustment to suit.

Tracking cameras do not translate, but rotate only to keep a specific model in the center of the field of view. The tracking camera code in the example is activated by changing the value of followCamera to false. The camera's lookAt function is used in each frame to update the camera. Note that this is not the lookAt function of the matrix used to orient models (i.e. model.matrix.lookAt(). A model faces a point by turning its +Z axis to intersect it. The camera renders in the -Z direction, so it needs to do the opposite.

1-2-three
example 16: camera work