In this assignment we start our preparation to go full 3D! We add a mesh class that will represent a set of vertices that make up a mesh, create some new shaders to support rendering of a mesh and move the mesh around using keyboard input.
The new Mesh class takes in an array of vertices and indices and uses them to draw a mesh on the screen. The array of vertices describe all the points that make up the mesh, and the indices tell the graphics card how to connect the vertices. Each vertex is made up of a position and a color that is associated with the vertex. I pass each vertex and its color to the vertex shader which then passes them to the fragment shader and in this process, the color gets interpolated which can lead to some interesting color patterns in the mesh. I rendered two meshes: one that is made up of 1 triangle and another that is made up of 3 triangles.
To move the mesh around I had to associate a position with it. This position gets passed to the vertex shader, this acts as an offset which will get added to the position of each vertex that makes up the mesh. I check for button press in the “UpdateSimulationBasedOnInput” and set the mesh velocity, this velocity is used to update the mesh position in two functions “UpdateSimulationBasedOnTime” and “SubmitDataToBeRendered”. This allows the position to be updated more smoothly because when the application tries to render as fast as possible, which can mean that there can be multiple draw calls that can occur before the simulation updates, I can predict the position of the mesh at each draw call based off the velocity. Looking at the code in cbApplication.cpp, we can see that the simulation updates at a fixed rate of 0.067 seconds. This means that unless something unexpected happens, the simulation will always lag the draw calls.
To move the mesh around, I use the arrow keys (up, down, left, right).