Game Development Reference
In-Depth Information
Camera and User Interaction
It is impossible to imagine a 3D game without a camera. WebGL does not provide
a camera class. We have learned that WebGL is a low-level API, but it gives us
a rendering API to help us write one of our own implementations. This chapter
is focused on evolving our own camera class for our game scene. We will also
empower our users to view the game scene from different angles and positions by
adding mouse and keyboard interactivity. We will also implement different types of
cameras used in gaming. The topics we will cover are as follows:
ModelView transformations
Perspective transformations
The basic camera
The free camera
Controlling the camera with the keyboard and mouse
The orbit camera
Understanding ModelView
transformations
In all our previous chapters, we used model transformations. We used glMatrix
( http://glmatrix.net/ ) functions to calculate translation and rotation. Let's look at
what we are talking about here:
// Create an identity matrix
var mvMatrix=mat4.create();
// Translate the matrix by objects location and replace the matrix
with the result(mat4.translate(out,in,vec3))
mat4.translate(mvMatrix, mvMatrix,
stage.stageObjects[i].location);
Search WWH ::




Custom Search