Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


Draw order depth


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
2 replies to this topic

#1 Vrokulaf   Members   -  Reputation: 106

Like
0Likes
Like

Posted 08 March 2013 - 05:00 AM

Hi dudes.

 

So I don't really know what this particular thing is called, so I decided to call it "draw order depth" because it kindof describes what it is.

 

SO, I've been having some trouble figuring out this relatively simple thing, depth in 2D.

So imagine you're a dude running around in a semi-tilted camera view (or isometric), and you want to run behind a tree or a house. What SHOULD happen is that the house should now be in front of you, obstructing the view for the camera. Very basic concept, things closer to the camera should be drawn last, so the things behind it gets drawn over (and that way, creating depth). I included an image illustrating what I'm talking about.

 

draworderdepth.jpg

 

So it seems simple enough, but what is a good and efficient way of coding this? Is it putting everything in an array, and using an algorithm to sort them in order how far away from the camera they are, then just run through the list? If thats the case, how do you do it efficiently?

 

One thing I tried, but which took up way too much CPU, was to cut the screen up to slices horizontally, and go through every slice, check every object to see if they are positioned on that particular slice, and if they were, draw them. Were I thinking in the right direction?

 

Any answer is appreciated!

Have a good one

~Vrokulaf


Freelancing musical composer!
For more info check out my website!


Sponsor:

#2 Yourself   Crossbones+   -  Reputation: 1182

Like
0Likes
Like

Posted 08 March 2013 - 07:00 AM

give each object a 'depth' value and during rendering store each object in an array (but do not draw it yet).

When all objects are recorded, sort the array and do the actual drawing.

This way, objects with a lower depth will be drawn first. For dynamic objects (like the player), you can update the depth value as it moves.

For the sorting, you could probably use any sort algorithm but if you use an integer as depth value, radix sort might be the fastest.



#3 Vrokulaf   Members   -  Reputation: 106

Like
0Likes
Like

Posted 09 March 2013 - 04:48 AM

Yes, was just gonna write, I figured it out myself. I actually wrote it in the post even, and thought something like "Hey, I should actually try that out...".

 

If anyone is interested I can post the source code here, I wrote a very simple engine to handle the drawing order.


Freelancing musical composer!
For more info check out my website!





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS