In 3D graphics, a camera allows you to navigate through the 3D space; it can be used to perform the rotation and displacement on any arbitrary axis. In OpenGL ES, there is nothing such as a camera. This has to be implemented programmatically. Implementing a camera is extremely simple. In fact, we do not require any specific OpenGL ES APIs for this and it's all about manipulating matrices. In this recipe, we will simulate a first person camera.
Reuse the last implement recipe and perform the following steps to implement the camera system:
Create a
Camera.h
/.cpp
file and define aCamera
class derived fromObject
. This class contains three unit vectors:Left
,Up
, andForward
, which store directional unit vectors in the 3D space along the x, y, and z axis respectively. ThePosition
specifies the location of the camera and Target specifies the location of the camera view:struct ViewPort{ int x, y, width, height; }; struct CameraViewParams...