Overview
In this post understand cameras space and Perspective and Orthographic projections interactively.
Details
A multi colored cube is rendered interactively after applying inputs for LookAt, Perspective or Ortho projections from an Input dialog. The cube can be rotated using x, y and z keys. The The camera space can be changed by checking LookAt checkbox and supplying varying input for Position, Target and Up vectors.
Similarly, Perspective Projection can be changed by checking Perspective checkbox and supplying varying input for FOV, Near Plane and Far Plane. The FOV can be changed by typing page up and down keys or mouse wheel.Orthographic Projection can be changed by checking Orthographic checkbox and supplying varying input for X minmax, y minmax and Z minmax values.
System class diagram
The scene class overrides camera with an instance of DualProjectionCamera. It has an instance of MultiColoredCube called cube derived from BaseGeometry class.
cube overrides mesh with an instance of CubeMesh to generate geometry.
The scene class overrides camera with an instance of DualProjectionCamera. It has an instance of MultiColoredCube called cube derived from BaseGeometry class.
cube overrides mesh with an instance of CubeMesh to generate geometry.
Implementation
Scene
The functionality is implemented in the Scene class derived from BaseScene class.
The three methods Init,DrawScene and Cleanup are overridden as below:
The Init method calls
- BaseScene::Init to create hosting window and OpenGL Context.
- It also attaches camera to a DualProjectionCamera class object. This camera processes keyboard and mouse inputs as explained earlier.
- It calls init function on the MultiColoredCube object to populate VBO buffers and bind them. It also compiles and links shader programs.
The DrawScene method draws the multi colored cube and rotates as per keyboard or mouse inputs and Input dialog settings.
The Cleanup method releases the resources related to VBO and shader programs.
Finally the WM_CLOSE event is handled in OnCloseWindow function and the window is destroyed and application is shutdown when the window is closed or Escape key is pressed.
Application
Scene class is hosted main.cpp. which creates the scene object and displays it. Message pump is added to process windows messages.
Input dialog
The input dialog as shown below can be used to change settings and understand lighting.Output
The output looks as shown in the top.
No comments:
Post a Comment