Sunday, August 13, 2006

Marching cubes

Still spending all my spare time working on the game and have made good progress. Particularly proud of implementing path finding and 3D object picking in the last week.

Path finding has always been something I'd been interested in implementing but never got a chance in my previous projects. For the uninitiated path finding is basically calculating the best way to get from one point to another. This is especially important in an RTS game like this one as players will constantly be issueing orders to their units to move to sections of the map or attack the enemy.

I've utilised a modified version of the A* algorithm to solve my path finding problems in the game. The basic gist of it is to partition the area into sections which the unit can move through. Then move through all these sections prioritised by proximity to the end point while ignoring any obstacles along the way. Thanks to my decision to compose the map as a grid of 19x19 squares and elimination of diagonal movement the search space actually turned out to be fairly small and simple.

After finishing that I had to take a break from the game engine to add a few more features to the graphics and local interface. My main focus was to add functionality to the mouse cursor.

You would think that calculating what a user clicks on with the mouse wouldn't be too hard. All my previous games which supported a mouse have been two-dimensional. It's fairly trivial to determine if a user has clicked on an object in two dimensions as you just take the mouse screen coordinates on the click (x,y) and check to see if this coordinate falls within a rectangular area.

In three dimensions however the screen doesn't translate well to object positions in the world due to the current position of the "camera". In order to determine what a user has clicked on in this case a ray has to be calculated from the camera origin into the world space and intersection tested against all objects. The closest intersected object is the object clicked on. Sort of like using a laser pen to point at something in the room.

With that out of the way and a few graphical improvements (still all placeholder textures mind you) I'm now about ready to get back to working on the game engine logic. Next steps are to support unit attacks, unit creation and capturing structures. Phew, going to be busy.

No comments: