Iterating through the nodes in a scenegraph???

Started by
2 comments, last by jon723 19 years, 10 months ago
Hello all, I''ve just implemented a scene graph and I''m able to render the children. I''m have some trouble though because I want to start at the root and iterate through the whole scene. Since each node (including the root) can have as many nodes as they want how would I go about iterating through the whole tree?? I hope my question is clear. The way I have it now I have to set a pointer to a certain child and from there I''m able to do transformations on it and its children.
www.lefthandinteractive.net
Advertisement
call the function recursively (can''t spell it :/..)

procedure update(node: tnode);
begin
for i := 0 to high(nodes) do
update(nodes);
the rest of the update code here..
end;

sorta delphi code but that''s the way i do it!
Here''s some pseudocode that should,
hopefully, give you the basic idea.

void SceneNode::doSomething() {
// Perform some operation like rendering
// updating

// Now process all child nodes
processChildren();
}

void SceneNode:rocessChildren() {
// Process all chldren, if any
for all children begin
current_child->doSomething();
end loop;
}

Look up preorder tree traversal.

This topic is closed to new replies.

Advertisement