The Assignment:
Assignment 5 is mainly about adding a representation of a game object and modifying the graphics system so that it renders moving objects.
The Results:
A Windows application that renders a square-shaped mesh in a window where both the camera and the mesh object are movable.
Control of the game: Hold W/A/S/D to move the camera up/left/down/right. Hold Q/E to move the camera forward/backward. Hold arrow keys to move the mesh up/left/down/right. Hold Ctrl key change the mesh of the game object.
The Game at the default state
When the Camera and the Object Moved
When the Mesh of the Game Object Changed
Representation of a Game Object :
I created a GameObject class for the representation of game objects. Within the class I defined some basic functions of setting, getting and updating the basic properties of an object.
For the data, I stored a pointer to a Mesh, a pointer to an effect and an instance of sRigidBodyState. The two pointers are used to store the data needed for rendering purposes. The sRigidBodyState instance is used to keep track and update the position and orientation of the object, which is also indispensable for rendering movable objects.
Submitting GameObjects to Be Rendered :
I defined a helper method called SubmitGameObjectInformationForRendering which takes a reference of a GameObject and the time for extrapolation as input. The function gathers needed information from the passed in GameObject instance then calls the submit function in the Graphics library to pass all the data.
Sized of Data Needed for Each Draw Call:
Comparing to the last assignment, I needed to let the graphics system to cache the transforms of game objects. Other than caching an actual transform matrix, I decided to add a quaternion and a vector to my mesh data struct since those cost less memory.
The size of my sMeshData struct is 48 bytes in the x64 implementation and 36 bytes in the x86 implementation.
Why Extrapolation Is Necessary When Rendering :
The transform of a game object in this system is updated by the simulation. Similar to the FixedUpdate loop in the Unity engine, the simulation update loop only runs every fixed frame-rate frame. However, draw calls run as fast as possible, which means it is possible to have multiple draw calls in between two simulation update calls. Without extrapolation, we would see an object stays at the same location for multiple draw calls, then all of a sudden the next draw call teleports it to somewhere else, which causes the movement look “jerky”.
Good Practice Note:
Use typedef to eliminate differences in syntax .