Game Development Reference
In-Depth Information
Our basic camera does not take the lookAtPosition (target object's position) value
but the lookAt function of glMatrix requires one. Hence, we first calculate the
lookAtPosition value from the position and the direction vectors by adding them
up. Then, we invoke the lookAt function to calculate our view matrix. The projection
matrix is calculated using the perspective function of glMatrix .
Understanding the free camera
The FreeCamera class that we are going to write will be controlled by the keyboard.
We would like to move forward, backward, left, right, and rotate on its axes.
Let's first define the actions that we want our free camera to perform with the
corresponding key combinations. The key combinations and the respective actions
to be performed are shown in the following table:
Key combination
Action to be performed
Left arrow
Move to the left along the x axis
Right arrow
Move to the right along the x axis
S
Move to the left along the y axis
W
Move to the right along the y axis
Up arrow
Move to the left along the z axis
Down arrow
Move to the right along the z axis
Shift + A
Tilt to the left
Shift + left arrow
Rotate counter clockwise
Shift + D
Tilt to the right
Shift + right arrow
Rotate clockwise
Shift + up arrow
Look down
Shift + down arrow
Look up
We don't want the users of the FreeCamera class to set the up, left, and direction
vectors either. It would be very confusing for the user to provide the value for
these vectors. Hence, we decided that the user would provide two settings to our
camera class:
Position : This setting will define the position of the camera.
"look at" position : This setting will define the point on the scene that the
camera looks at. If we set the "look at" point, then the behavior becomes more
like a target camera. We have explained how other vectors are adjusted when
we set the "look at" position.
Search WWH ::




Custom Search