Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Code Snippets / [GDK] Optimization using scene graphs

Author
Message
Zotoaster
19
Years of Service
User Offline
Joined: 20th Dec 2004
Location: Scotland
Posted: 14th Jul 2010 03:10 Edited at: 14th Jul 2010 03:11
Hi there,

I jut tested out something and I thought it looked cool so I thought I'd post it. The idea is quite simple.

Imagine you're in a huge city. How do you render it fast? You don't want to render buildings that are too far away in order to save precious rendering time on closer objects which you're more likely to see, BUT, if you do a distance check on every object to see if it's too far away, you'll again lose valid time, just for distance checking.

But intuitively, everything isn't that separately arranged. In a city, you have building blocks, and entire square. Think about it, if you can't see a block of buildings (the actual encompassing block), then you obviously can't see the actual buildings either. Scene graphs solve this, because they are based on a tree structure. If one node is too far away, you don't only not render the child nodes, but you don't even do a distance check on them.

Here's the code. Move the mouse around, and up/down to change viewing radius.




I had to do this in 2D because the GDK engine automatically renders 3D objects for you (i.e., it just loops through a linear list). If you have a linear list, the amount of time it takes to go through it depends on the size of the list. But with a tree, you can skip entire sections, meaning it takes significantly less time to traverse. Of course, you don't create lines in DBP, you just draw them, which is important in this example.

"everyone forgets a semi-colon sometimes." - Phaelax
CocaCola
14
Years of Service
User Offline
Joined: 23rd Mar 2010
Location: CocaCola.x CocaCola.y CocaCola.z
Posted: 27th Oct 2010 01:12
Build errors.

Always program as if the person maintaining your program is a psychopath that knows where you live
Zotoaster
19
Years of Service
User Offline
Joined: 20th Dec 2004
Location: Scotland
Posted: 29th Oct 2010 21:16
You need to set the build to /MT (multithreaded). Haven't used VS for a while but as far as I remember, you click Project, Preferences, Build options (I think), and set the code generation to /MT.

"everyone forgets a semi-colon sometimes." - Phaelax

Login to post a reply

Server time is: 2024-11-21 21:01:42
Your offset time is: 2024-11-21 21:01:42