ofNode questions about "...changed" virtuals

guys how to implement these?

virtual void onPositionChanged() {}
virtual void onOrientationChanged() {}
virtual void onScaleChanged() {}

for example, a parent changes it’s position and uses PositionChanged to propagate to the children, how do i do that?

will i have to create a list of childs, to propagate them?

why does
void setPosition(const ofVec3f& p)
ignore parent position?
isnt it relative to the parent position?

thanks, Roger

from a quick check of the code, the callbacks on*Changed don’t propagate to the children, you can propagate them yourself by implementing it in your objects

and yes, setPosition is relative to the parent, if you set a node to be the child of another then it’s position would be that of it’s parent + it’s own

thought so, how would i make them propagate?

the only thing i can think of is some kind of observer/observable.
but like that the set parent would be meaningless, i need to create a collection of childs and get the childs to register to the parent.

something like that right?

mmh, yeah that’s true a node doesn’t know about it’s children only about it’s parents, you can propagate the event upwards but not downwards as it is right now

the position of the children will be affected anyway by the change in it’s parent so probably you don’t need to propagate the event to all the children

what are you trying to do? perhaps there’s another way to do it instead of propagating the callback, or perhaps we need to add a vector of children to each node

I’m not actualy doint stuff with oF now, just trying to understand the pattern.

i think the methods that change position scale and orientation should take in account the parents in all times, but for this to happen we have to save the previous known position of the parent, to find out how to move next.
having a hard time figuring out how to calculate that

Actually using a vector of children, with virtual methods is the best, that way we could just create a setchanged for the parent that informs all the children of the change, and then they can react accordingly

i don’t think that’s necesary the node parenting means that the children don’t need to care about the parent, they just move relative to their origin whatever that is, defined by it’s parent.

imagine a hand rotating, it doesn’t need to know where the arm is to do it, it just rotates around it’s joint with the arm, the arm will move freely and the hand will follow without needing to know where the arm is. same for the arm and the body. a planet orbiting around a sun orbiting around the center of the galaxy. a car moving inside a truck moving along a road on top of the earth rotating around the sun :slight_smile:

the idea of an ofNode children is that it’s coordinate origin is not fixed but defined by it’s parent so it doesn’t need to know where it’s parent is to actually move, rotate…

so i can just take the parent position, normalize it and use it as axis for the child?

Confused over here :stuck_out_tongue: I was banging my head in starUML to get something going, but i’m failing a bit

no, you just move/rotate/scale the children any transformation applied to the parent will be applied automatically to it’s children.

ofNode parent;
ofNode child;

child.setParent(parent);
parent.setPosition(ofVec3f(10,10));
child.setPosition(ofVec3f(10,10));

the child will end up in (20,20) since it’s parent it’s in 10,10 so it’s coordinates origin is that position instead of 0,0 and when it moves to 10,10 it’s actually moving relative to it’s parent so that ends up being 20,20

:smiley: how dumb can one be?

thanks mate

ofNode parent;
ofNode child;
child.setParent(parent);
parent.setPosition(ofVec3f(10,10));
child.setPosition(ofVec3f(10,10));

the child will end up in (20,20) since it’s parent it’s in 10,10 so it’s coordinates origin is that position instead of 0,0 and when it moves to 10,10 it’s actually moving relative to it’s parent so that ends up being 20,20

that is not happening though, just stays at 10,10
maybe i’m missing something

if you query it’s position you’ll get again 10,10, since that’s relative to it’s origin too, you need to actually draw something using that node. getGlobalPosition should also return the absolute position taking into account all the inherited transformations