Tutorial: Cameras (work in progress)
|By dcantor . March 19, 2014 . tutorials.|
In this tutorial we will learn about the basic camera operations and also about the different types of cameras available in voxelent. Let’s get started
The fastest way to access the active camera is through voxelent current namespace. Let’s take a quick look again to voxelent namespaces (taken from Intro to Voxelent):
The current namespace contains objects that are being currently used: The current view, the current scene and the current camera are among these. To access the current camera all we have to do regardless of where we are in the code is to simply refer to it using
vxl.c.camera. For example:
var cam = vxl.c.camera; // cam now holds a reference to the current camera
In applications where there is only one view, we most likely will be using this method.
We can also access the current camera using the camera manager which is the object that manages all the cameras connected to a view. More information about the
vxlCameraManager in the managing multiple cameras tutorial. We can obtain a reference to the active camera for a new view like this:
var view = new vxlView('canvas-id'); //the HTML5 canvas id var cam = view.cameraman.active;
or if we want to refer to the current view:
var view = vxl.c.view; var cam = view.cameraman.active;
There is a third method that you can use to obtain a reference to the current camera. In this case through the public API:
var cam = vxl.api.getCurrentCamera();
Remember that the public API is one of the 5 different voxelent namespaces (
There are a bunch of operations that a voxelent camera can perform. Let’s take a look at some of them:
var cam = vxl.c.camera; cam.setPosition(2,3,4); //scalars cam.setPosition([-10,3,4]); //vectors
fovparameter is an angle in degrees, (0<fov<=360). [Check Angle of view on wikipedia]
actorNamein the current scene exists and if so, it changes the focal point of the camera to match the actor’s position. The result is the camera looking at the actor.
rollcorrespond to relative increments rather than absolute angles. All the angles are in degrees (instead of radians)
areflects an absolute angle
ereflects an absolute angle
rreflects an absolute angle
There are three different types of cameras in Voxelent (up to version 0.89.7). These are: orbiting, tracking and exploring. These types are defined in the
vxl.def namespace under the
camera.type entry. We use the vxlCamera method setType to establish the type of camera that we want:
var cam = vxl.c.camera; cam.setType(vxl.def.camera.type.ORBITING); //rotates around the focal point cam.setType(vxl.def.camera.type.TRACKING); //rotates around the camera axis cam.setType(vxl.def.camera.type.EXPLORING); //special type of non-restricted orbiting.
An orbiting camera performs all the rotational operations with respect to the focal point instead of using the camera position. This type of camera is useful in applications where 3D objects are being designed or explored.
In contrast, a tracking camera performs all the rotational operations with respect to the camera position. A good example of using a tracking camera occurs in first person shooting games, where the main character moves and looks around the world.
The following diagram explains the differences between orbiting and tracking cameras: