# Creating a Scene Graph Questions

This topic is 4582 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I know there have been a lot of posts about this topic in the past, and I understand the jist of scene graphs, (1) just how do you create them? When loading objects, how should nodes be made, and then connected? (2) Another "problem" I dont understand, is the scene graph is constantly changing, so how would you change parents / children. This is how I am thinking of structuring it ( have not done this before so any tips would be good ;) )
Base
|
Quadtree Terrain ( any lod method )
|-> Terrain Node 1
|-> another quadtree to get finer culling of objects
|- Node
|    |---------------> Some 3d obj
|    			|-----------> obj fx
|- Node
|    |----------------> Torch
|    |		        |----------------> Torch FX
|    |---------------> Player
|- Node
|    |---------------> Gun
|- Node
|-> Terrain Node 2
|-> another quadtree to get finer culling of objects
|- Node
|    |--------------->Car

Say the player picks up the torch, now the parent of the torch is the player. I guess that would be detected and handled when the player picks up the torch, but, what if the player walks into another node? how should it be detected? and for that matter, how would the player move (now with the torch) into terrain node 2 and get into the car?

##### Share on other sites
I honestly didn't get scene graph until I took CS2. Basically each node has a list (or vector/array) of pointer to other nodes. You can "attach" a new node by setting a pointer to it in the parent node. All you functions wil pass through all the nodes recursively by processing the node, then calling the function in all the child nodes.

If you are confused still, you may want to ry googling "n-trees" and polymorphism.

##### Share on other sites
well I know that, I have built and used quadtrees for my terrain, - I know recursiveness and pointers to other objects. My main question is how to move objects through the graph, and how do you load it since it is not like a terrain node that you know will be there and there will only be one.

##### Share on other sites
Hmm... I'm still confused what you want. Do you want to know how to load all the scene graph data from the hard drive? What do you mean by "move objects through the graph"? Sorry for all the questions.

##### Share on other sites
When you load objects into the world, like from a script, how do you put them in the correct order. I can see them filling into the correct terrain parent by checking the location on load, but like if you load a house and then a table. the table would have a parent as the house ( am I correct? ) how would that be done - has to be in script/loading file, correct? (I think I just answered that myself)

By moving through the graph, perhaps I am wrong, but you have them bound to tiles of terrain, perhaps in a quadtree. How would you move one object to another positionsuch as a player moving from node 1 to 2, I would have to hard code it in,
if (object_location > node_bounds ) set parent as the next terrain node, but that would be a lot of looping if there is a bunch of moving objects or pc/npc's

Perhaps I am just trying to add a culling type into the SG.

##### Share on other sites
Personally, I would try to keep your scene graph seperate from your quadtree. The scene graph should be more or less static for a given level. Adding objects as they are needed is ok, but nothing should be changing parents. It justs adds a bunch of extra complexity.

Quote:
 Original post by Valor KnightBy moving through the graph, perhaps I am wrong, but you have them bound to tiles of terrain, perhaps in a quadtree. How would you move one object to another positionsuch as a player moving from node 1 to 2, I would have to hard code it in,if (object_location > node_bounds ) set parent as the next terrain node, but that would be a lot of looping if there is a bunch of moving objects or pc/npc's

The player should be a child of a root terrain node (which all the chunks are also children of). Then you don't have to attach a model to seperate tiles and such. The player would have to switch between nodes in the quadtree still, however. You will probably have to hard code that like you mentioned.

##### Share on other sites
Humm, so the scene graph is primarly for static objects, otherwise they are children of the base node? If this is the case, since they are static objects, perhaps I can still do a quad or octtree in the graph, but also use a more flexable one for moving objects

base|------->Player ( computes location in quadtree every update needed )|------->NPC's and non-static objects(cars, monsters) ( computes location in quadtree every update needed )|------->Pickups ( weapons, item drops ) can be added in at will and uses npc/pc culling system ( computes location in quadtree every update needed )|------->Terrain Quadtree                   |----> terrain node 1                           |-> Quad/octtree for objects                                  |---->Objects                                           |->...

Then after load, all objects that have parents of the terrain quadtree should not change. All items/nodes that can change parents are children to the base.

Is this a better setup, or what it should look like? I just dont see why you would not include a quadtree inside of the tree, because you can do two things at once. How would/do you do it?

##### Share on other sites
I am just working through this issue myself, and to put it simple, I'll point you to this thread:

##### Share on other sites
Quote:
 Original post by ShaminoI am just working through this issue myself, and to put it simple, I'll point you to this thread:http://cboard.cprogramming.com/showthread.php?t=76448

Didnt really seen anything that pertains to the structure, though it looks as though you were hinting at it, but went to editors. Yea from what I have come up with, you will need to load the objects with refrences to the parents, but from the position, can compute the location on the map, and what terrain node is its parent.

Currently I belive I have the jist ( I hope ) - I just need to find the correct structure and how to handle moving objects

##### Share on other sites
The thread was more dealing with the first question of yours..

The creation and destruction of complex objects, like your torch for example, either needs to be hard coded, or loaded in modularily.. With files, created with an Editor..

You could fill out a structure of object info yourself, instead of creating an editor which uses files, but this is where your engine might begin to come inflexible...

1. 1
2. 2
Rutin
23
3. 3
4. 4
frob
16
5. 5

• 9
• 33
• 13
• 12
• 10
• ### Forum Statistics

• Total Topics
632578
• Total Posts
3007172

×