Saturday, April 4, 2026

OpenGL Library Implementation - Camera

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.
The following diagram shows how the positive rotation happens in Counter clockwise direction.
        Pitch(X Axis)                                    Yaw (Y Axis)                                  Roll (Z Axis)




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


Constructor
Initializes hwnd with the Window handle of the hosting window.

Members
NameDescription
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
NameDescription
CenterCursor
This method places the cursor at the center of the screen.
OnKeyThis method handles keyboard input events.
OnMouseBtnDown
This method handle mouse button click events.
OnMouseMoveThis method handle mouse move events.
OnMouseWheelThis method handles Mouse scroll wheel inputs. 
UpdateWHThis method handles window resize events.