Scene Graph questions

Started by
2 comments, last by bzroom 20 years, 5 months ago
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.
Advertisement
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); 
So do you attach your children as a linked list or as an array?
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 --{
[ ThumbView: Adds thumbnail support for DDS, PCX, TGA and 16 other imagetypes for Windows XP Explorer. ] [ Chocolate peanuts: Brazilian recipe for home made chocolate covered peanuts. Pure coding pleasure. ]

This topic is closed to new replies.

Advertisement