Overview
In the previous post, we understood how view matrix, perspective matrix and orthographic matrix. Two new cameras are used to provide perspective and orthographic views.
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.
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.
ViewMatrixData
ViewMatrixData class contains Model to World transformation information such as camera position, object position in the world, and the World up vector. They are used by DualProjectionCamera class for calling lookAt function to generate view matrix.
| Name | Description |
|---|---|
| Position | Camera position in world Coordinates. |
| Target | Position of the object in world Coordinates. |
| Up | Worlds Up vector. |
| V | Contains view Matrix |
Methods
| Name | Description |
|---|---|
| getViewMatrix | Returns latest View matrix. |
| setViewMatrix | Stores inputs such as positions, Target and up. Computes view matrix by internally calling lookAt function. Stores the result in V. |
PerspectiveProjectionMatrixData
PerspectiveProjectionMatrixData class contains perspective view frustum information such as near plane, far plane and fov angle. Also the aspect ratio. They are used by by DualProjectionCamera class to redraw.
| Name | Description |
|---|---|
| AspectRatio | An aspect ratio is the proportional relationship between the width and height of a shape, image, or screen, expressed as width:height (e.g., 16:9). It defines an object's proportions rather than its physical size, ensuring visuals scale cleanly without distortion. |
| FOV | Field of view (FOV) is the angular extent of the observable world that can be seen or captured at any given moment. It dictates how wide or narrow your view is. |
| NearPlane | A near plane (often called the clipping or projection plane) is the imaginary flat boundary closest to the camera in a 3D perspective view. It acts as a "window" that captures the scene. Everything closer to the camera than this plane is invisible to prevent visual clipping and rendering errors. |
| FarPlane | A far plane (or far clipping plane) is a boundary defining the maximum distance a virtual camera can "see". Any object or geometry beyond this plane is clipped, meaning it is excluded from the rendered image |
| P | Contains latest Perspective Projection Matrix. |
Methods
| Name | Description |
|---|---|
| getProjectionMatrix | returns latest Perspective Projection Matrix stored in P |
| setProjectionMatrix | Stores inputs such as near plane and far plane and computes Perspective Projection Matrix. Stores the result in P |
| setFOV | Stores FOV angle after clipping the input is lower or higher than tolerance. Later computes Perspective Projection Matrix. Stores the result in P |
| setAspectRatio | If the input is a float, aspect ratio is stored from the input parameter. If the input is an integer, the current FOV is doubled and sign is applied. typically used for zooming in or out. Later computes Perspective Projection Matrix. Stores the result in P |
OrthographicProjectionMatrixData
OrthographicProjectionMatrixData class contains orthographic view frustum information such as xmin, xmax, ymin, ymax, zmin, zmax. They are used by by DualProjectionCamera class to redraw.
| Name | Description |
|---|---|
| XMinMax | xmin and xmax define the left and right clipping planes (boundaries) of the 3D viewing volume in an orthographic projection. |
| YMinMax | ymin and ymax define the left and right clipping planes (boundaries) of the 3D viewing volume in an orthographic projection. |
| ZMinMax | zmin and zmax define the nearest and farthest clipping planes (boundaries) of the 3D viewing volume in an orthographic projection. |
| P | Contains latest projection matrix. |
Methods
| Name | Description |
|---|---|
| getProjectionMatrix | returns latest Orthographic Projection Matrix stored in P |
| setProjectionMatrix | Stores inputs such as X,Y, Z min and max distance and computes Orthographic Projection Matrix. Stores the result in P |
DualProjectionCamera
DualProjectionCamera class is derived from ThreeDCamera class. It process mouse and keyboard inputs and calculates zoom factor, view matrix, perspective and orthographic projection matrices. They are updated into ViewMatrixData, PerspectiveProjectionMatrixData, OrthographicProjectionMatrixData object.
Constructor
Initializes hwnd with the Window handle of the hosting window. Internally calls ThreeDCamera constructor.
Members
| Name | Description |
|---|---|
| VM | contains 3D transformation information such as camera position, object position in the world, and the World up vector. . They are updated by based on mouse and keyboard inputs and are shared with 3D objects based on BaseGeometry class to redraw. |
| PPM | contains perspective view frustum information such as near plane, far plane and fov angle. Also the aspect ratio. They are updated by based on mouse and keyboard inputs and are shared with 3D objects based on BaseGeometry class to redraw Perspective projection. |
| OPM | contains orthographic view frustum information such as xmin, xmax, ymin, ymax, zmin, zmax. They are updated by based on mouse and keyboard inputs and are shared with 3D objects based on BaseGeometry class to redraw Orthographic projection. |
Methods
| Name | Description |
|---|---|
| CopyToClipboard | Copies Unproject() information to clipboard. |
| OnKey | This method handles keyboard input events as below: P => Captures x,y,z coordinates at current mouse position in the world space and copies to clipboard. PageUp => doubles current FOV resulting in Zooms Out effect or items on the screen becomes smaller. This affects only Perspective projection. PageUp => current FOV is halved resulting in Zooms in effect or items on the screen becomes bigger. This affects only Perspective projection. |
| OnMouseWheel | This simulates ZoomOut when scroll wheel is moved up and ZoomIn when scroll wheel is moved down. |
| setOrthographicProjectionMatrix | Applies latest Orthographic Projection Matrix stored in OPM to the geometry object. |
| setPerspectiveProjectionMatrix | Applies latest Perspective Projection Matrix stored in PPM to the geometry object. |
| setViewMatrix | Applies latest View Matrix stored in VM to the geometry object. |
| Unproject | Internally called by keyboard handler to capture x,y,z coordinates at the mouse cursor |
| UpdateWH | Calls BaseCamera's method to reset window sizes and sets aspect ratio. |
No comments:
Post a Comment