Sorry, no new binary release. The last one can be found here.Sorry, no new source release. The last one can be found here.

Sometimes I'm insanely OCD. I don't even like tower-defense games that have pixel-perfect tower positioning. Just placing a tower 1 pixel unaligned with other towers drives me insane! Those tower defense with free positioning should at least introduce something like a 4-pixel sub-grid or maybe a snap-functionality. I'm not sure why I'm OCD in these games though. It's not like I have a lot of compulsive behavior in real life. Well... I die a little inside whenever I see people walking on a zebra crossing without placing their feet in the middle of the white stripes, but that's all, I swear. Hmmm, that makes me think of a panic attack not that long ago :|:

TrianglesOnSphereThis is quite the funny topic actually (cubifying, not zebra crossings :D). Most people I know that work with voxels have an axis-aligned 3D-grid with voxels that they try to smooth it out with algorithms like marching cubes to generate smoothed-out polygons. We start with a world that is spherical and try to get some sort of workable aligned grid on this sphere. No matter what technique we use, if we want to have a cube-like structure on top of the sphere there will exist some warping. This was one of the reasons I used a tetrahedron as base and tessellated it a couple of times to make it spherical. This technique gets me near perfect equilateral triangles so I don't introduce a lot of warping yet. This is a reasonably difficult issue to tackle and a whole lot of work just to get a spherical world with cube-like interactions. But I don't care, not one bit. It's fun because it's a challenge. As far as I know, no one had successfully implemented something like this, which makes it a bit more exciting for me (no copy-paste-adjust of existing algorithms). The problem I need to face: "How can I create voxelized sphere-surface with semi-aligned cube-like blocks and keep warping to a minimum?".

Having cubes is a reasonably new idea based on my OCD habits, so maybe it was just wrong to use a tetrahedron as base geometric shape. Creating convex quadrilateral in equilateral triangles is kind of sucky if you want it to be as much cube-like as possible. Maybe I should just have used a cube as base shape and tessellate that to create a more spherical object. Hmm... well let's just see how things will go.

"Wait! cubify or squarify?" For some of my future tests, I intend to only have a couple of layers of cubes on the surface of the planet, so adding height becomes reasonably trivial with minimal amount of warping. For now I'll just focus on creating square-like quadrilaterals, while calling them cubes. I try to be as confusing as possible and hopefully this causes my mistakes to get overlooked :)

Cubifying triangles

Having the whole planet voxelized (axis-aligned) is just not a real option for me. Gravity should work towards the center of the planet and I'm not using voxels just for polygon-creation. I have some ideas about cellular automata that I want to try out, so this is a no-go. Let's just look at the problem of creating cube-like structures on our sphere.

For simplicity I'm using a very small amount of cubes per triangle, but I indent to have a whole lot more in the actual implementation.

 Triangle Triangle6Corner Triangle5Corner
 Normal situationNormal bordered triangles Pentagon-exception

Well the arrows are not all that nicely mirrored in real life, damn that OCD again... I just had to try to make it look good. When we are implementing our (not yet existing) solution we can't just place the arrows wherever we want.

I played around with some code in JavaScript (see the triangle on the right) and it seems that the result is not that great. There is a lot of warping going on and none of the quadrilaterals really looks like a cube. Hmmm, I could have guessed that it was going to look like this. 😐 I just don't want to rewrite the code of the tetrahedron (with all the maze-generation stuff going on).

Okay, let's just create a 3D cube we can tessellate and see how that looks before making a decision. Grmbl.. this is what I get for just playing around with code instead of thinking before I do something.

[Drawing Canvas]

Tessellating cubes

Let's build the alternative, a cube that we are tessellating to become more sphere-like. Where did I put my hammer? Oh right *tinker tinker*, *bang*, *dunk*, *crash*, *tinker tinker*. DONE~!


Ahh... so frustrating :(, these cubes are so much better. There are only 8 places on the whole sphere where there are weird connections.

A different type of tessellation for a tetrahedron

Hmmm... what if I use the base tetrahedron with just 4 triangles and cubify it just like that JavaScript example above? That would also give me 8 weird places. Let's try it out, we just need to port some JavaScript so it'll be quick. *tinker tinker*, *bang*, *dunk*, *crash*, *tinker tinker*. DONE~!


Hmm not bad, not bad. It looks like it is actually better :)

Yeah the right one (tetra) is definitely better. There aren't any weird corners when crossing the red borders. Wow, who who'd have thought :D. The algorithm for creating those spheres is a bit heavy on the CPU, but that is not a big concern for me because the data can be pre-computed if I so desire.

Simple crash report

While refactoring some of the code, I noticed that I use a lot of exception-throwing but I never really catch them. I taught myself to program in such manner that I do a lot of error-checking (and exception-throwing), while it should never happen that any exception is thrown. I have no personal need for nice exception-handling because Visual Studio will pause and give me time to analyze and fix the problem. It would be nice if exceptions are also shown when the application is not run using Visual Studio's debugger though, so this small GUI has been added:


Resource Manager

ResourceManagerJust as shaders, textures can now be automatically reloaded from the original (or some other) image file during run-time. This is just a feature for easy development as I don't want to go to the endless cycle of "modify texture -> run game -> modify texture -> run game -> ..." just to get the image (or shader) perfect. The directory with the original images will be found automatically so a single click refreshes the texture.

Currently the resource manager creates a Gui-control for each of the resources (with handles and everything). This is okay for the first version, but when we are getting over a couple hundred resources with frequent add's and remove's this will be a bad idea. We need a bit of sophisticated code for pooling and reusing these controls. For a good solution we also need to manually handle the vertical scrollbar and calculate the height of the controls, without actually creating the controls.

Next time

Since I'm throwing away my IcoSphere-idea, I need to recreate some of that  maze/temperature/biome stuff. Ah well, it's good that I've come so see the errors of my way. I'm still in the process of refactoring and cleaning up the project so the new source and binary downloads will have to wait. It needs to be worthy of a v2. release :). I'll probably take another look at the Resource Manager too, there is enough room for improvement.

Review and RefacturingMultithreaded Game Engine