Write Up 08

Game at the start:

Game with changed position:

 

 

Controls:

Press Escape to quit the application.

 

Press the right arrow key to move the mesh with the three triangles towards the right.

 

Press the left arrow key to move the mesh with the three triangles towards the left.

 

Press the up arrow key to move the mesh with the three triangles up.

 

Press the down arrow key to move the mesh with the three triangles down.

 

The main objective of Assignment08 was to build meshes and assign vertices and indices to them.

In this assignment, to color the vertices of a mesh, a color field was added to the vertex format struct of the mesh. The order of the vertices were not important as an index buffer was added to assign the order of how the triangles should be drawn. Each platform of the mesh class has an index buffer that has a size equal to: indexCount * sizeof(uint16_t)

 

For the winding order of the vertices, I chose left handed convention. In order to make the index array I pass in the mesh’s factory function be platform independent, the OpenGL implementation of the mesh class reorders the elements of the index array so that the second and third elements of each set of three indices are swapped.  

 

To store the positions of each mesh, a new constant buffer s_constantBuffer_perDrawCall is declared in the Graphics.cpp file to cash the positions of each mesh and it is updated before each mesh is drawn.

 

I wrote the following factory function to create a mesh:

 

eae6320::cResult eae6320::Graphics::Mesh::Factory(Mesh* &o_mesh, unsigned int vertexCount,eae6320::Graphics::VertexFormats::sMesh vertexData[], unsigned int indexCount, uint16_t indexData[])

 

Where:

  • parameter 1 is a mesh pointer.

  • parameter 2  is amount of vertices for this mesh.

  • parameter 3 is the array of vertices.

  • parameter 4 is amount of indices for this mesh.

  • parameter 5 is the array of indices.

 

I implement it the following way:

 

eae6320::Graphics::Mesh::Factory(newMesh,5,vertexData,9,indexData);

I wrote the following function to render a mesh:

void eae6320::Graphics::RenderMeshWithEffectAtPosition(Mesh * mesh, Effect * effect, float posX, float posY)

 

Where:

  • parameter 1 is a mesh pointer.

  • parameter 2  is the effect pointer

  • parameter 3 is the x position of the mesh.

  • parameter 4 is the y position of the mesh.

 

I implement it the following way:

 

eae6320::Graphics::RenderMeshWithEffectAtPosition(meshes[0], effects[2], position.x, position.y);

 

I noticed that it is important to render the meshes first and then the sprites because sprites are essentially UI elements which need to be rendered last in order to be drawn in front of the meshes.

 

I implemented the functions UpdateSimulationBasedOnInput() and UpdateSimulationBasedOnTime() to move the mesh with three triangles. In UpdateSimulationBasedOnInput(), I assign a value to the velocity Math::sVector I created in the cExampleGame class. Depending on the arrow key that is pressed I add a value to the x and y components of the velocity. For example, when the right arrow is pressed, the x component of the velocity get a value of 1.0f.

 

I reviewed the code for cbApplication.h and saw that the simulation is updated based on the value returned by the function virtual float GetSimulationUpdatePeriod_inSeconds() const, which in this case is 1.0f/15.0f which is approximately equal to 0.066 seconds. When changing this value to be smaller, I noticed a smoother movement and when changing this value to be larger, I noticed more jerkiness.

 

In UpdateSimulationBasedOnTime(), I calculate the x and y components of the position Math::sVector I created in the cExampleGame class. In this case, position += velocity * i_elapsedSecondCount_sinceLastUpdate.

 

The time it took me to complete this assignment was 17 hours.

© Jean-Paul Peschard. Proudly created with Wix.com