Tuesday, August 9, 2011

Velocita Part II

I had made quite a mess of the project by now, I had all the buildings look 3D by keeping track of the angle of the car from the position of the building and projecting the image of the building in the opposite direction to fake the effect of height. I figured that the best way out would be to start all the way from the beginning. So I did just that, but this time in DirectX. I had myself convinced that it was Allegro that was slowing down the game, and not the multiple textures that were being loaded at runtime!

This version of the game was less complicated and stayed a 2D car physics simulator for the longest time. All you could do was drive around and pull a few powerslides. The sound and graphics were almost the same, except with light trails and motion blur! It took a while for me to get to know the DirectX 9 API especially because I was starting off with 2D. Soon after I was done setting it all up, I had a dear friend draw out some images of a few cars from the top down perspective. We used a camera on a tripod to take shots of the artwork and cropped it to put it into the game. Even though we had a more realistic car it was still just an image. I was bored of looking at a static image of a car which was not fitting in with the graphics of the rest of the world which were still being prepared in MS Paint. That was when I decided that it was time to step things up a bit.

Before starting off, I had myself convinced that it'll be really simple, just the same physics but models instead of images. All  I though I had to do was learn how to load in some models of a car, a set of wheels and a simple world and position them properly. Obviously, I had no idea what I was getting myself into and I ended up spending the next three years on a 3D car physics simulator before it was complete.

Everything went according to plan, importing models, positioning the camera and running the same simulation on it. I learned how to set up a DirectX window, load up models, store them as meshes, get textures, set rendering states, position lights(fixed function), set transforms and draw meshes using subsets. I ran into pitfalls on every step. The tutorials in the DirectX SDK weren't any help at all. All you could do is copy a whole sample project and tell yourself that you've successfully learned how to set up instanced skinned meshes which didn't sound very exciting to me. Books, forums and other helpful articles on the internet were of great help,  I had a car run on an open field with a camera looking down on it. I accomplished the task quite easily, but it was sad to see how my car reacted when it went over a bump - it didn't.

I applied a not-so-quick fix to the game where the car oriented itself according to the height of the wheels from the ground mesh. A few raycasts to the ground were easy to figure out but I got really stuck when I started working with matrices and quaternions, I hadn't braced myself for 3D math. Though the car was now reacting to the heightmap, it misbehaved when it went off a cliff so I knew that we needed a proper suspension set up to makes those reactions more physically acceptable.

That was when my hard drive gave up on me and I lost all my files.