Zed Said ‘No!’….

Whilst putting the new contour system through its paces I noticed a particularly annoying bug:

See the bug? (click for a larger image)

See the bug? (click for a larger image)

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.

Why?

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:

The fix was changing from drawing lines to drawing triangles... (click for a larger image)

The fix was changing from drawing lines to drawing triangles… (click for a larger image)

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:

Whoops! That's not supposed to happen! (click for a larger image)

Whoops! That’s not supposed to happen! (click for a larger image)

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:

Contour lines are now clipped to the map boundary. (click for a larger image)

Contour lines are now clipped to the map boundary. (click for a larger image)

Whilst in the contour system, I decided to update the code that deals with the elevation numbers to add a small enhancement:

Large contour elevations now have commas put in them for that more 'authentic map look'. (click for a larger image)

Large contour elevations now have commas put in them for that more ‘authentic map look’. (click for a larger image)

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…

On the plus side, I can now manipulate contour thickness.... (click for a larger image)

On the plus side, I can now manipulate contour thickness…. (click for a larger image)

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:

Contours - now in their 'All-Fixed' Edition! (click for a larger image)

Contours – now in their ‘All-Fixed’ Edition! (click for a larger image)

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.

Laters

RobP

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s