Overview
A scene consists of a set of 3D objects. Transformations such as translation, scaling and rotation brings them into life. The source for these transformations are mouse and keyboard inputs, which are further computed resulting in camera placements,
For example the following diagram shows a multi color cube with 50 degrees pitch and 20 degrees yaw. The cube looks elongated horizontally because aspect ratio is not applied.
Details
This post discusses camera and camera data that are used in projections and animations.
The Camera data holds transformation information such as pitch, yaw and roll angles, translation, scaleby as well as Model, View and Projection matrix information of the 3D object.
Coordinate System
OpenGL uses Right hand side coordinate system where +Z is pointing towards you.
Pitch, Yaw and Roll
A 3D object can rotate along all the three axes as shown below.
Rotation along X Axis is called Pitch. Rotation along Y Axis is called Yaw. Rotation along Z Axis is called Roll
Pitch(X Axis) Yaw (Y Axis) Roll (Z Axis)
For example in BaseCamera class, if a key is pressed, its scan code is stored. Similarly if mouse left button is pressed and the mouse is dragged, delta x and delta y are computed.
The derived camera classes from BaseCamera use this information to further compute and store additional information in Camera Data structures.
For Example, ThreeDCamera class implements keyboard and mouse handling as below:
Camera and CameraData
There are many specialized camera classes that are associated with different types of camera data.
The class diagram below shows their association, The light blue classes are camera data and the others are camera classes.
The details will be provided in the next posts.
BaseCamera
BaseCamera implements handlers for mouse and keyboard events. This is a base class that can be further specialized. It's located in VedaOGLLib\Scene\BaseCamera.h.
| Name | Description |
|---|---|
| windowrect clientrect | Upon events like resize, windowrect and clientrect are updated. windowrect stores window rectangle of the hosting window after calling GetWindowRect() method. clientrect stores client rectangle of the hosting window after calling GetClientRect() method. |
| mouseX,mouseY deltaX,deltaY | Upon mouse move event, the current X and Y coordinates are stored in mouseX and mouseY. Delta of X and Y coordinates are stored in deltaX and deltaY. |
| mouseLeftDown mouseMiddleDown mouseRightDown | Upon mouse button down event, one of these is set to true based on the button pressed. Rest are set to false. |
Methods
| Name | Description |
|---|---|
| CenterCursor | This method places the cursor at the center of the screen. |
| OnKey | This method handles keyboard input events. |
| OnMouseBtnDown | This method handle mouse button click events. |
| OnMouseMove | This method handle mouse move events. |
| OnMouseWheel | This method handles Mouse scroll wheel inputs. |
| UpdateWH | This method handles window resize events. |
ModelMatrixData
As discussed earlier, ModelMatrixData class contains 3D information. It's updated by by ThreeDCamera class based on mouse and keyboard inputs and is shared with 3D objects based on BaseGeometry class to redraw.
| Name | Description |
|---|---|
| pitch yaw roll | Computed values based on mouse and keyboard inputs. These are stored as degrees. |
| ScaleBy TranslateBy | Affine transformation values for scaling and Translation, These are stored 3x3 matrices. |
Methods
| Name | Description |
|---|---|
| augment | Augments itself from another ModelMatrixData object. |
| getModelMatrix | Returns self as 4x4 matrix. |
| Reset | Resets itself to scratch. |

