Thursday, May 5, 2011

Block Engine

Okay, so forget Infiniminer. I just came up with a good algorithm for deciding which faces of a block need to be drawn. It's working perfectly. Quite simply, it checks whether the block adjacent to the face is transparent. If so, the face needs to be drawn. BAM. I bake it into the blocks at first world gen, and will update it whenever transparency of an adjacent block changes.

Also, at most three faces will need to be drawn on any block at any time, depending on the position of the player relative to the block. If the camera is higher that the block, the bottom obviously doesn't need to be drawn. Same for all sides. It's a simple "is a greater than b" check, and saves a face needing to be drawn.

The tricky part now is drawing individual faces in 3D space. Not to mention it will need proper texture sometime. So, I'm looking through XNA guides for drawing things in 3D space. A lot of the tutorials are for 3.1, and don't work with 4.0 which I'm using. Others are 4.0, but use stuff that only the HiDef profile can use, which my computer isn't wanting to play nice with. I got one tutorial working that drew a textured square perfectly... directly onto the 2D plane of the screen. I need it in 3D space, where the camera can move around it. I'm looking at a MSDN guide at the moment.

I'll keep you posted on progress. As soon as this is worked out, I should be able to post screenshots.

No comments:

Post a Comment