Saturday, April 4, 2026

Implementation: Camera Data

Overview
In this post discusses camera  and camera data that is used in projections and animations.
It 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. 

Details
Coordinate System
OpenGL uses Right hand side coordinate system where +Z is pointing towards you.
An 3D object can rotate along all the three axes as show below. 
Rotation along X Axis is called Pitch. Rotation along Y Axis is called Yaw. Rotation along Z Axis is called Roll

The following diagram shows how the positive rotation happens in Counter clockwise direction.
        Pitch(X Axis)                                    Yaw (Y Axis)                                  Roll (Z Axis)

Mouse and Keyboard input support
As discussed earlier, the BaseScene object captures all the Mouse and Keyboard activities such as key press, mouse button press, move etc. Later it's processed by BaseCamera class  or its Derivatives.
For example, If key is pressed, its scan code is stored. similarly, if mouse left button is pressed and mouse is moved and then released, delta x and delta y are computed. 

The derived camera classes from BaseCamera may use this information to further compute and  store additional information  in camera data structures.
For Example, SimpleCamera object implements keyboard and mouse handling as below:
Press X key  => rotate around X axis by 10 degrees.
Press Y key  => rotate around X axis by 10 degrees.
Press Z key  => rotate around Z axis by 10 degrees.
Mouse Left Button Down. Mouse Move, Mouse Left Button Up => Compute Delta X, and Delta Y.
Later this is shared with 3D objects in the scene to draw.


Later this data is shared with all the 3D objects in the scene to redraw. 
There different types of Camera Data to store different types of information. There are specialized camera classes to process data differently.


BaseCamera and CameraData
The following diagram depicts relation between   BaseCamera and various CameraData structures.  The details of these are Discussed later.