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.
Mouse and Keyboard input support
For example in BaseCamera class, if a key is pressed, its scan code is stored. Similarly if mouse is moved, the current X and Y coordinates are saved, if 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 to calculate 3D rotational angles. Later this is stored in ModelMatrixData class and shared with 3D objects in the scene to draw.
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.
Members
| 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 | his method handles window resize events. |
ModelMatrixData
ModelMatrixData class contains 3D transformation information such as pitch, yaw and roll angles, translation, scaleby . They are updated by ThreeDCamera class based on mouse and keyboard inputs and are 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. |
ThreeDCamera
ThreeDCamera class process mouse and keyboard inputs and calculates 3D transformation information such as pitch, yaw and roll angles, translation, scaleby . They are updated into ModelMatrixData object.
Constructor
Initializes hwnd with the Window handle of the hosting window. Calls BaseCamera contractor and resets ModelMatrixData Instance.
Members
| Name | Description |
|---|---|
| MM | contains 3D transformation information such as pitch, yaw and roll angles, translation, scaleby . They are updated by ThreeDCamera class based on mouse and keyboard inputs and are shared with 3D objects based on BaseGeometry class to redraw. |
Methods
| Name | Description |
|---|---|
| augumentModelMatrix | Augments ModelMatrixData instance of the BaseGeometry class with the values of MM during redraw based on Keyboard/Mouse Input. |
| OnKey | This method handles keyboard input events as below: X => Add pitch by +10 degrees. Y => Add yaw by +10 degrees. Z => Add roll by +10 degrees. |
| OnMouseBtnDown | This method handle mouse button click events. |
| OnMouseMove | Upon Mouse LB drag, Computes Pitch and Yaw angles from Delta X, and Delta Y. |
| UpdateWH | Calls BaseCamera's method to reset window sizes. |
No comments:
Post a Comment