Urban Interactive – Project Development Blog

Hidden Line Removal Revisited…

Posted in ROTJ by urbaninteractive on March 15, 2009

Hello All,

Since the last post I have finally nailed how to do a basic hidden line removal routine.  I tried coding this a few months back but even though I got it working the routine was way too CPU hungry.  I revisited it because in the first level I want the player to protect the Millennium Falcon.  When I plonked the model into the game using the standard drawing routine it didn’t look nice, and it was difficult to work out exactly what you were looking at.  Here’s and example of what I mean…

Before and After hidden line removal.

Before and After hidden line removal.

Now I think its a bit clearer.

As I say previously I did have routine to do this.  I am using the Painter method, which basically means I draw the furthest away faces first, and then the closers faces will cover up the further faces.  It’s better explained here…

http://www.cosc.brocku.ca/Offerings/3P98/course/lectures/hiddenlines/

The reason my previous version was slow was because I was using BlitzMax’s own graphics routines for drawing polygons.  These proved to be a lot slower than creating them directly using Open GL commands.  Also I discovered some unhelpful “features” of BlitzMax TList class which also had an impact on the performance.  Firstly TLists.Sort method uses a bubble sort.  This is easiest sort to program, but for sure one of the slowest.  Previously I stored all the faces in a list and then sort them in Z order using TLists.Sort, I have now changed this to merge sort and it made a huge difference.  I did a test showing 3 hidden line objects and the speed of the new sort routine was 10 times faster.

Also I found out the the TList.Count method does not point to a stack which stores the current number of items in list.  Instead it actually recounts the list every time which can be slow if you have a lot of items and a lot of lists.  I had previously use the count method a lot to see if a list was empty, I’ve switched these checks now to TList.IsEmpty (which I should have done in the first place).

Making the new Hidden Line routine also meant I needed to modify my existing vector object editor because the hidden line object format is different to the normal wire frame format.  This took a day, but now its really simply to use.  Overall Im please with the speed results, and I think the game will look better for it.

This will probably be my last post of a few weeks now, as my wife is now overdue (sounds like I’ve ordered her from a Russian Brides Website and the delivery is late) – When I mean overdue I mean she is expecting our first child.  So any minute now the sleepless nights and lack of concentration will start…

One Response

Subscribe to comments with RSS.

  1. StuC said, on March 18, 2009 at 7:54 pm

    Is it here yet ? no not the finished game the baby 🙂


Leave a reply to StuC Cancel reply