roll my own scene graph or find a library?

General discussion about LÖVE, Lua, game development, puns, and unicorns.
Post Reply
samwan
Prole
Posts: 3
Joined: Thu Mar 08, 2012 7:52 pm
Location: Seattle
Contact:

roll my own scene graph or find a library?

Post by samwan »

Hi all, I am looking for a way to manipulate graphical objects in a simple hierarchy with efficient rendering. Do Love developers typically roll their own scene graph libraries, or is there one out there with the basics?

- add/remove/reindex children nodes
- translate/transform a scene node
- draw anti-aliased geometries and bitmaps into a scene node
- hit detection on the hierarchy of nodes

I understand that Love has primitives for redrawing the whole screen, but a scene graph with make the management and rendering of graphical objects more efficient. Any suggestions?

Thanks,
Sam
User avatar
miko
Party member
Posts: 410
Joined: Fri Nov 26, 2010 2:25 pm
Location: PL

Re: roll my own scene graph or find a library?

Post by miko »

samwan wrote:Hi all, I am looking for a way to manipulate graphical objects in a simple hierarchy with efficient rendering. Do Love developers typically roll their own scene graph libraries, or is there one out there with the basics?
I guess everyone makes his own library, because there are different models of scene graphs, so everyone uses something optimized for his game.

I am (slowly) working on such library, inspired by clutter.
samwan wrote: - add/remove/reindex children nodes
- translate/transform a scene node
- draw anti-aliased geometries and bitmaps into a scene node
- hit detection on the hierarchy of nodes
Of the above points, the hit detection is the most difficult part (unless you don't use scaling nor rotating). Clutter uses helper functions using optimized matrix functions. I wish love2d had similar low-level matrix API. Until then, you need to implement such helper functions in plain lua.
My lovely code lives at GitHub: http://github.com/miko/Love2d-samples
User avatar
slime
Solid Snayke
Posts: 3162
Joined: Mon Aug 23, 2010 6:45 am
Location: Nova Scotia, Canada
Contact:

Re: roll my own scene graph or find a library?

Post by slime »

For any game that uses box2d with LÖVE 0.8.0 you can use the world:queryBoundingBox method to cull offscreen objects. Most of the time you probably won't need to do any sort of optimization like that though - 2d games are generally fillrate-bound.
samwan
Prole
Posts: 3
Joined: Thu Mar 08, 2012 7:52 pm
Location: Seattle
Contact:

Re: roll my own scene graph or find a library?

Post by samwan »

Thanks for your responses, Miko and Slime. Can I ask three follow up questions?

1. Slime, what do you mean by "fill rate bound"? I realize it's a low-level graphics concept, but I have never worked below a certain level of abstraction before with computer graphics, which is why I'm interested in learning these things via Love.

2. Miko, thanks for the pointer to Clutter (really interesting, but big!). In your comment about hit detection, do you mean having to run a mouse coordinate through the stack of matrix transforms walking down the tree of elements? This gets into the whole set of problems around optimizing hit detection with partitioning strategies, caching transforms, etc., right?

3. Miko, with the library you're working on, are you taking the strategy of drawing to a cached framebuffer for each node (element, entity, component, whatever you call them), so that you only have to render the node once per local state change rather than drawing the whole screen every tick?

Thanks for any tips you can provide!
User avatar
miko
Party member
Posts: 410
Joined: Fri Nov 26, 2010 2:25 pm
Location: PL

Re: roll my own scene graph or find a library?

Post by miko »

samwan wrote: 2. Miko, thanks for the pointer to Clutter (really interesting, but big!). In your comment about hit detection, do you mean having to run a mouse coordinate through the stack of matrix transforms walking down the tree of elements? This gets into the whole set of problems around optimizing hit detection with partitioning strategies, caching transforms, etc., right?
Unfortunately, yes. You can go either with vector math (like transform/rotate/scale for each child in a tree), or use some matrix operations. The latter could have more sense when using hardware optimization (ac clutter/cogl does), in plain lua the former would be easier.
samwan wrote: 3. Miko, with the library you're working on, are you taking the strategy of drawing to a cached framebuffer for each node (element, entity, component, whatever you call them), so that you only have to render the node once per local state change rather than drawing the whole screen every tick?
My idea is to have one library for different backends, some of which use translate/rotate/scale (like Love), while others do not (libGD). For now, I have just tested only non-caching cases, but the caching could be relatively easy added. You just need the tree elements to be able to signal "redraw-needed", and add a step of redrawing all "dirty" elements (which would be different than "relayout-needed", but the idea is similar: notify which nodes needs redrawing, and redraw them later).

Anyways, I am just playing with the idea, not sure how far it will go. And my initial plan was to be able to draw some graphs (in multiple backends), so I did not need collision detection at start.
My lovely code lives at GitHub: http://github.com/miko/Love2d-samples
samwan
Prole
Posts: 3
Joined: Thu Mar 08, 2012 7:52 pm
Location: Seattle
Contact:

Re: roll my own scene graph or find a library?

Post by samwan »

Cool, thanks a lot for your answers, Miko!
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Amazon [Bot] and 5 guests