Yay, yet another productive day of development
I love this feeling. I wonder how long I’ll have this energy to do all-day development before I burn out…
Boxes and Collisions
First, I added boxes to the scene as obstacles. I figured it would be a good idea to create a unit cube (1 x 1 x 1) and scale it in the X, Y, and Z directions as needed. I would also need to create a bounding box to do the actual collision detection, since XNA doesn’t provide a bounding box by default. The code to check for bounding box collisions with spheres wasn’t too difficult (I used a game physics books I picked up at the library), but for some reason the balls were sinking into the box before bouncing out. Weird. I decided to draw the corners of the bounding box using green spheres as markers, and this is what I discovered:

strange scaling issues, wtf?
What’s going on here? Apparently the unit cube I exported from 3ds max wasn’t really a unit cube. I went back and double checked my cube but it seems perfectly normal. After racking my head a bit, I couldn’t come up with any valid explanation. I ended up using Maya to recreate a unit cube, and I imported it into my program without incident. I’ll have to investigate this further since it could cause more problems down the line. So now, I have balls that collide with boxes, which can be overlayed on top of one another to create some interesting designs.

box with collisions

stacked boxes
While implementing collisions with boxes, I decided to switch to a more formal approach to collisions. Before, it was a bunch of ad-hoc vectors and names all over the place. I implemented a ContactInfo struct, which contains a contactNormal and a penetrationDepth. These two variables allow me to do collision response separately from collision detection, and it makes things much, much cleaner (removes a lot of duplicate code). I also discovered that XNA has a handle Vector3.Reflect(direction, normal) method, which allows me to easily reflect a ball off of a collision contactNormal. Penetration depth is used to separate two objects that are in collision. Most of the time, you just move the object by (contactNormal * penetrationDepth) to get to a stable state.
Multiplayer
The second part that I finished today was multiplayer. Games are so much more fun when you can shoot at your friends
This involved setting up the correct viewports for each player, in addition to setting player colors, and only rendering the path tracer for the current player (we don’t want player 2 to see player 1′s firing arc, otherwise it’s too easy to dodge and it clutters up the view space). Right now, all the health bars and status messages are still rendered at exactly the same size no matter how many players are on the screen. I’ll consider shrinking it, but for now, it seems to be okay.
multiplayer
Special Effects
Next was explosions and sound effects, which I stole from previous projects. Explosions are based off of the XNA particle system sample, with some minor tweaks. Since I’m using XNA, I used the XACT Audio Framework for doing my sounds. One of the cool things about this is that I can play a sound, but have it be a random sound from several different files – all done at the sound effects project level. So as a programmer, I don’t have to care how many files are behind a specific “sound”, I just play that sound and watch the magic happen.
explosions
Camera
Last, I implemented a free camera that can view the scene from any direction. If you press ‘Y’ while in a game, it’ll switch from the tank-following camera to a free-floating camera. This allows me to view models and effects from angles I wouldn’t normally be able to see.
free camera
That’s all for today. It’s finally starting to evolve into a playable game (luckily, since there’s only 3 days left until it’s due). Coming up next – shadows.