Whilst putting the new contour system through its paces I noticed a particularly annoying bug:
If you look carefully you can see that the contour is drawn over the unit and not under it as expected.
Fixing this bug resulted in a major re-write of the contour system.
Basically, Direct-X has an issue where it treats lines and polygons quite differently with regard to Z calculations (depth). Especially if one is using any kind of bias.
Of course, I didn’t realise this straight away and spent a number of hours banging my head against the wall trying to work out what was going on! After all, my contour lines Z values were calculated to draw them under the units and not over them.
Once I made this discovery I realised that the fix for this issue would be quite major:
This might seem like a simple change, but calculating the triangles’ corner points to fit the requested bezier curve is not an easy problem. Luckily, I had already solved this issue with my linear terrain features, so I could reuse many of the algorithms from that section of code.
With most of the contour system re-written to work with triangles rather than lines, I then set about fixing other issues…
First up was contour clipping. When one draws a hill contour it should be clipped so that it fits the map. Alas, I had forgotten to test this aspect. So I was a little surprised when I saw this:
The hill was being clipped, but not the contour! Had I not re-written the system, I would not have been wise to this issue. Anyways, it is now fixed:
Whilst in the contour system, I decided to update the code that deals with the elevation numbers to add a small enhancement:
Although the re-write sucked up a large amount of time, the one positive thing to come from it, is that we can now set the thickness of our contours! From very thin to very thick…
I’m not sure why anyone would want contours this thick, but hey, the system can now do them! 🙂
Back in the main game the new contours perform flawlessly:
Notice how the units now appear over the contours? – Perfect! Just wish that it didn’t require a re-write to fix…
That’s it for this week’s unexpected tour of the contour system.