We finally got into 3D rendering with this assignment. The change involved changing our vertex information to hold an additional float value for the Z position.
Here is an example of the vertex layout of a cube mesh. Each of these meshes holds its vertex data in model space, which is the relative location of the vertices with respect to a pivot.
The next step in getting this mesh rendered onto the screen is to get it into world coordinates. Each of the vertices will be transformed by a “Model space to World space” matrix, which converts the vertex positions to positions in the world
Our mesh is now in world co-ordinates. In order to get it onto the screen, we need to know where the camera (or eye) is placed, and which directions it is facing. We use this information to calculate the “View space to world space” matrix. The inverse of this matrix, when applied to each of the meshes in our game, transform the vertex positions of our mesh in such a way that they are now located in a world where the camera is at the origin and facing the positive z direction ( for direct X).
This makes it easy for the graphics hardware to compute which of the vertices will be visible on the screen, and which of them are located closest to the screen ( so that we do not render vertices unnecessarily, since they will be rendered over by other meshes closer to the screen)
At the end of these transformations, we can finally render our meshes onto the screen!
Here’s a screenshot of my program rendering two meshes: A cube, and a floor
Here’s a screenshot of Pix showing debug information of my vertex shader.
You can move the cube and the camera around in the game. The cube is controlled by the arrow keys, and the camera is controlled by the Numpad keys 8,6,4 and 2 ( Make sure the numlock is turned on)
You can download a zip of my program here: Click Here
[EDIT]: Restructuring had messed up my error handling. Here’s a better build which does not crash when it doesn’t find files it needs to run( like shaders, materials etc.): Click Here
[EDIT]: I’ve added functionality from my previous programming classes into my game now. So I can implement shared pointers, memory pools, store data as actors, have a world which keeps track of all the Actors etc.! I plan to use them for my upcoming assignments 🙂