We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
Page Index Toggle Pages: 1
SceneGraph (Read 995 times)
SceneGraph
Dec 12th, 2006, 4:37pm
 
Hi all,

I just was hoping someone could give me a quick 101 on coding a scenegraph.
(with some small code please)

I understand the concept for having a tree of items and propagating events up the tree.

The thing I can't understand is passing things from the leafs to the branches and so on... back down the tree.

E.g.
A scenegraph for a Hand with fingers and finger tips.

Root to Leaf
Pull the hand back and then the fingers will follow and the finger tips to.
(for this I can get the parent to move and it will call the move on the objects under it)

Leaf to Root
Now, if I prick the finger tip it moves, then the finger move and then the hand.
But how can the objects know about there parent AND at the same time keeping encapsulation.

Huge thanks
Re: SceneGraph
Reply #1 - Dec 12th, 2006, 4:51pm
 
I think the easiest way to do it is to pass "this" to any leaf as a parameter, so that it knows who its parent is, in the same way taht a branch will have a lsit of leaves.

e.g.

Code:
class part
{
part[] children;
part parent;
part(/* other options for creation*/, part _parent)
{
/* normal setup */
parent=_parent;
}
}


Than all you have to do in a child, when you need to tell your parent object about some change is do parent.somethingHappened(someOptions); in the child, and the parent will be informed.

What kind of information you need to supply and how it shoudl react is left as an exercise for the reader.
Re: SceneGraph
Reply #2 - Dec 12th, 2006, 5:53pm
 
Thanks JohnG,

I was actually afraid, that this was how it would be done because it exposes the entire object system and thus changes can be made any where with out a direct relationship been there.

E.g.
A bad guy in another room can change how I move. There is not a direct relationship!!

This is why I was thinking about the encapsulation.
But I suppose this is the only way Sad
Re: SceneGraph
Reply #3 - Dec 12th, 2006, 6:00pm
 
Ok, maybe I have an incomplete understanding of what a scene graph is, but the hand example you've described sounds more complex than a scene graph.  Typically, if you set up a hierarchy of things in a scene, the point of the hierarchy is so that you can move groups of objects easily. So if you create a node that you attach all the parts of a composite object to, you can then move the object by just moving the node. If you move one of the objects directly, it moves relative to its relationship to the node, without affecting the position of the node or any other objects attached to it.

However, if you're just creating a traverseable tree structure, then the method JohnG explains is normal. It's how you traverse the DOM with JavaScript for example.
Re: SceneGraph
Reply #4 - Dec 12th, 2006, 6:08pm
 
SuperDuffMan wrote on Dec 12th, 2006, 5:53pm:
Thanks JohnG,

I was actually afraid, that this was how it would be done because it exposes the entire object system and thus changes can be made any where with out a direct relationship been there.


I think you're misunderstanding, they can't directly interact. An object can only "talk to" its parent and its children.

e.g. (ignore the . they're there to stop the board messing it up)

Code:

. +-----World-------+
. | . | . . |
+-player badguy object
| | . |
hand foot gun
|
finger


World ahs 3 children and no parent, since it's the root of everything.

hand can talk to finger with it's list of children, and player as it's parent.

Badguy can't affect player, except by talking to world, and world then talking to player.
Re: SceneGraph
Reply #5 - Dec 12th, 2006, 6:40pm
 
Im really sorry! I get it now. I was thinking of pass pApplet to each object Not the parent as a this!!

Now I see how they are link!

thank you all so much!



//=======================================================

Quote:
I think you're misunderstanding, they can't directly interact. An object can only "talk to" its parent and its children.


a parent, would be an extends!
But a finger is not a type of hand.

Quote:

hand can talk to finger with it's list of children, and player as it's parent.


how can finger generates an event that calls the parent (Hand) it would have to going world/player/hand witch all must have public methods witch also means other things in the world can call them!

Quote:
I think the easiest way to do it is to pass "this" to any leaf as a parameter, so that it knows who its parent is, in the same way taht a branch will have a lsit of leaves.

If I use "this" I can move from the root in any directshon to any object.

>>>>

I suppose I’m thinking that a scene graph is a data system that could do something like Ragdoll physics.

will my CG lecturer was saying that a scenegraph links all the object dynamically.
If you were (not really) to throw the system box out the window it would that a few seconds but then the screen & keyboard would follow it out the window, because they are linked to the to the system box with the scenegraph!

Code:

/*this is more a sudo code*/
class hand
{
finger pinker
hand()
{
pinker = new finger();
}
move()
{

}
}
class finger
{
finger()
{
//...search for fire()
}

fire()//thread
{
if(found)
hand.move();//away!!
}
/* how can finger call hand with out going round the world to get back to the hand*/
}


big thanks agen ^_^
Re: SceneGraph
Reply #6 - Dec 12th, 2006, 7:18pm
 
Code:
 /*this is more a sudo code*/
class hand
{
finger pinker
hand()
{
pinker = new finger(this);
// "this" in this case means the hand that creates the finger, not the PApplet or suchlike
}
move()
{

}
}
class finger
{
hand parent;
finger(hand _parent;)
{
//...search for fire()
parent=_parent;
}

fire()//thread
{
if(found)
parent.move();//away!!
}
/* how can finger call hand with out going round the world to get back to the hand*/
// It knows because it's parent hand tells it who it's parent hand is.
}
Page Index Toggle Pages: 1