Archived

This topic is now archived and is closed to further replies.

bzroom

Scene Graph questions

Recommended Posts

In the past when I made game I just always did like: cTank *tanks = new cTank[6]; //the tanks in the game Then I was thinking about a scene graph. But I get confused when I try to actualy make it. I made a base node class and then I could create all the differnt nodes off that. Such as a transformation class, a renderstate class, a texture class, a geometry class. while im thinking of it it all seems easy and makes sense. But when I want to add a character should I add a character node or should I add a node for each bone with its mesh parts as children. The first seems easier, but the second would allow you to attach objects such as guns to the hands of the characters. When I try to write the code to execute the tree I get stuck because it seems like my animated mesh classes need time info from nodes 2-3 nodes higher up the tree. Also when you create your node class do you have it like this: cNode *children; int childcount; and have children an array or a linked list. A linked list would be easier to reorder and add on too but an array seems faster. I''m so confused, sorry if my post didnt make too much sense. Thanks.

Share this post


Link to post
Share on other sites
My implementation is as follows:
1) I have a class that holds info of a world object, such as world and local PRS, parent world object, etc...
2) I derive specialiced objects from there, like Mesh and Node.
3) Then I have a KFMesh derivated from mesh to implement keyframing animation and a QuadNode class specialized from Node class to implement a QuadTree in the scene graph.

So my scene graph is a Node instance that has a list of children (world objects, thanks to polymorphysm hehe). A sample pseudo code would be as follows:


Node *sceneGraph;
QuadNode *quadTree = InitQuadTree("heightmap.tga");
sceneGraph = quadTree;
KFMesh *pGoblin = MeshManager::Load("goblin");

quadTree.AddChild(pGoblin);

Share this post


Link to post
Share on other sites
I would recommend a linked list (std::list preferably). Since they are faster when it comes to add/remove nodes, and you don''t need to know the number of nodes before adding nodes. (of course, you could use the std::vector which can grow. but it also reserves extra memory, making the whole scene a little bigger)

}-- Programmer/Gamer/Dreamer --{

Share this post


Link to post
Share on other sites