Game Development Reference
In-Depth Information
The camera
There are two types of cameras, namely orthographic and perspective. Here, we use
the perspective camera to view the scene from a certain perspective, as shown here:
public PerspectiveCamera cam;
cam = new PerspectiveCamera(67, Gdx.graphics.getWidth(),
Gdx.graphics.getHeight());
cam.position.set(2, 2, 2);
cam.lookAt(0, 0, 0);
cam.near = 1f;
cam.far = 300f;
cam.update();
Using the preceding code, we create a perspective camera of field view 67 degrees
keeping the current aspect ratio. The position of the camera is set at ( x , y , z )
coordinates ( 2 , 2 , 2 ) and is set by calling cam.position.set(2, 2, 2) .
The coordinate system in LibGDX has the z axis aligned towards the viewer as
visualized in the following figure:
The camera is made to look at the origin ( 0 , 0 , 0 ) using the call cam.lookAt(0, 0,
0) . We set the near and far values to make sure we can always see our object. Finally,
we update the camera so all the changes we made are reflected by the camera.
 
Search WWH ::




Custom Search