A downloadable game

About the Assignment

This assignment is about responding to input and to get to know how the rendering works based on the extrapolation. It also helps to think of a good design approach to make an entity or an object that contains all the data needed for an object/entity to get drawn and move around with physics.

Controls for movement

Shift – moves camera left

Ctrl – moves camera right

Del- moves camera towards the object

Backspace – moves camera away from the object

Arrow Keys – move the square in corresponding arrow direction

Screenshots


Screenshot of a two objects



One of the objects moved to a different position(square moved up a little)



A different object (triangle) at the square’s position


Camera zoomed in on the objects

How I finished the assignment

I started by making a gameobject class which has all the data needed to move around and render an object with an effect. I hooked up the Physics::sRigidBodyState to handle all the physics related data. Then I finished the drawCall buffer struct by making necessary changes to the shader code. Once I got the movement working with the game object, I created a camera class. And added movement to it too. The hard part was figuring out where to update the physics and the extrapolation needed for submitting data to Graphics.

Why the extrapolation is necessary when rendering with our engine?

Since we’ve to threads and we’re caching data in the graphics project to render at a future frame, we’ve to submit data that is supposed to be in that future frame. This means if we submit the current position, then it gets cached and the graphics is drawing the object somewhere in the past. So we extrapolate the position and tell the Graphics to Okay draw at this position, this is where the object is going to be when you are drawing the frame.

Here is the representation of my GameObject class


The data I’m storing in the gameobject representation is a pointer to the Geometry3D object, a pointer to the cEffect object and a pointer to the sRigidBodyState. I believe all those are needed for a game object, and I’m not storing anything else which isn’t needed. The sRigidBodyState is the way to control all the physics stuff of the gameobject.

Here is the representation of the struct that I submit to the Graphics

 

The only thing I added is the drawCall constantBuffer. This is needed because every object has a different drawCall buffer, the drawCall buffer specifies where a certain object needs to be drawn in the game.

And this is how my submission of data to Graphics look like


The things that were added were obviously the draw call and then the camera transforms. You can see in the drawCall buffer, I’m setting the transform by predicting the future position of the object. The same thing happens with the camera too. This basically needs 4 parameters – the struct that has all the data related to the game object, how many such structs are there, the world to camera transform and the camera to projected transform. I feel the struct is important because it helps in giving the graphics only what it needs and makes the game programmer understand what all needs to be given in order to render a frame.

Size of the data that I needed to cache in order to draw a mesh


OpenGL – 308

Direct3D – 328

The one thing that was added was the sDrawCall struct which is 64 bytes (It was added to the sGameObjectDataNeededToRenderAFrame struct). So now each sGameObjectDataNeededToRenderAFrame struct takes 80 bytes. That added 128 bytes effectively to my previous representation.

Credits

 I had a hard time figuring out why my gameobject sometimes gets drawn at a future position and then reverts back to the actual position. Joseph Moyle and Sid helped me understand what I was doing wrong. The problem was I was updating the velocity based on input in the UpdateBasedOnInput function and updating the position in the UpdateBasedOnSimulationTime. Both uses unique times and so the Graphics is getting data the wrong data. I moved the velocity update code to UpdateSimulationBasedOnInput and it worked fine.

 

 

Download

Download
Download Game here 171 kB

Leave a comment

Log in with itch.io to leave a comment.