Every 3D object such as cube derives from BaseGeometry class. The following describes this in details.
CameraData class 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. It's implemented in VOGLLib\Camera \CameraData,h file. CamaraData of a 3D object is modified by BaseCameraInputHandler object the of the scene discussed earlier.
IGeometryMesh structure defines the abstract class that every 3D object must override. It defines methods for generating vertices for the 3D object and populating VBO and EBO buffers of VAOUtil object. It's declared in VOGLLib\Geometry\GeometryMesh.h file.
VAOUtil class defines a VAO and its associated VBOs and EBO discussed in the previous post. The VertexData class stores VBO and EBO data and manages its lifetime. VaoUtil class and VertexData class are implemented in VOGLLib\Geometry\VAOUtil.h file. VAOUtil class defines VertexData class for Position, Color, Normal, Texture Coordinates and Indices.
In a typical usage scenario, a 3D object first loads all the vertex data such as position by calling GenerateVerticesData method of the mesh. Then it calls SetupVBO method for all the vertex data with location number of the the vertex data. Note that the location number has to match with the location number defined in the vertex shader. First time, this will generate a VAO and bind it. VBO is created, data is loaded for GL_STATIC_DRAW, bound and associated with the location and the location is enabled.
In cases of indices, the indices are loaded by calling GenerateIndicesData method. Later BindEBO method is called. This will generate a EBO, data is loaded for GL_STATIC_DRAW, bound.
ShaderUtil class loads shader code such as vertex shader and fragment shader , creates program object, attaches shader code and links them to the program object. In addition shaderUtil also stores attribute locations and uniform locations. Errors in compilation are written to the errorlogs.
In usage, first the shader code is attached and linked. At the time of drawing, uniforms are updated and program is set for use. Draw method is called to draw the 3D object. finally program is reset for use.
ShaderUtil class is implemented in VOGLLib\Geometry\ShaderUtil.h file.
BaseGeometry class implements base class for all the 3D objects. All the 3D objects such as cube must derive from this class. BaseGeometry class defines
Init method that loads and attach shaders to program object.
Cleanup method that does cleanup.
UpdateUniform updates Projection matrix uniform.
Draw method calls OpenGL APIs such as glDrawArrays or glDrawElements are used to draw the 3D objects.
In usage, VertexShaderSource and FragmentShaderSource are overridden to supply shader code. Init, Cleanup, UpdateUniforms methods are overridden based on the customization.
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 BaseCameraInputHandler class. For example, If key is pressed, it's 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. All the data is stored in CameraData.
Later this data is shared with all the 3D objects in the scene to redraw.
For Example, SimpleCameraInputHandler 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.