Sign in to follow this  
jakovo

Scene Graph implementation dilemma

Recommended Posts

jakovo    476
ok, this is more philosofical than anything else.

basically, the scenegraph should keep a hierarchy of objects within a scene, when one node is attached to another, then it inherits all/some of its properties (translation, rotation, etc)... however I came into a dillema while implementing a scene graph for my graphics engine:

should each node in the scene graph keep track of its current position? (making the graphics engine user just update how much will it translate from its current position) like this:

[CODE]
MyNode->translate( 10, 0, 0 ); // located at <10,0,0>

// next frame

MyNode->translate( 10, 0, 0 ); // located at <20,0,0>

// next frame

MyNode->translate( 10, 0, 0 ); // located at <30,0,0>
[/CODE]

making MyNode to move on steps of 10 units each loop.

Or should the user keep track of each object's position and just update on what position should the object be placed, like this:

[CODE]
MyNode->translate( 10, 0, 0 ); // located at <10,0,0>

// next frame

MyNode->translate( 20, 0, 0 ); // located at <20,0,0>

// next frame

MyNode->translate( 30, 0, 0 ); // located at <30,0,0>
[/CODE]



what do you think would be more appropriate?

Share this post


Link to post
Share on other sites
Hodgman    51336
[img]http://i1.kym-cdn.com/entries/icons/original/000/006/759/both.png[/img]
[code]struct MyNode { Transform transform; };
myNode->transform.translate = Vec3( 20, 0, 0 );
myNode->transform.translate += Vec3( 10, 0, 0 );[/code]The transform-hierarchy/"scene graph" doesn't have to be concerned with [i]where your translation data comes from.[/i] By allowing the user to set/update the data in either way, as above, you might make your "scene graph" simpler and more re-usable.

The "scene graph" only has to be concerned with how to inherit/propagate data along a hierarchy -- in the case of a transform-hierarchy, you've basically got an array of [i]transform nodes[/i], which contain a [i]transform[/i] and an optional link to a [i]parent node[/i].
The only task that your [i]transform-graph[/i] should focus on, is producing an array of [i]global/absolute transforms[/i] out of your input graph of [i]local/from-parent[/i] [i]transforms[/i]. If it focuses on more responsibilities than that, then you'll fall into the classic "scene graphs" trap of trying to use a single data-structure for too many different tasks Edited by Hodgman

Share this post


Link to post
Share on other sites
alh420    5995
Usually you have the position and rotation encoded in a matrix saved in the node.

Then you can add support for postTranslate (or whatever you want to call it) on your matrix class, and do either or, depending on your use-case that day.

Edit: hodgman beat me to it.. Edited by Olof Hedman

Share this post


Link to post
Share on other sites
jakovo    476
haha.. I really wasted a lot of time trying to figure out which was more appropriate hahaha... but yeah, I guess you're right.. thanks to both of you!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this