Getting and Setting ofNode Children

One thing I don’t understand about ofNode is the way that you can only get or set the parent of a node. It makes sense when thinking of common usage, a hand doesn’t need to know about its fingers, only the wrist it’s attached to, etc. If you want to, say, send a jolt of electricity down that hand, you need to be able to treat each of it’s children independently, top down.

What are some methods for structures that require a parent to child relationship? I would just go ahead and make a vector of pointers for each node and call it children, if it wasn’t for pointer vectors being advised against for memory issues (from what I can tell).

Essentially my hierarchy is this:

I have an of3dPrimitive, and for each of its vertices, I have a corresponding ofNode. Each of these nodes/vertices have a child of3dPrimitive with the same structure.

My 2ct.

When computing 3D transforms you don’t need to know about children transform, only parent’s. That’s why ofNode does just that and nothing more.

You need to create a “GameObject” class that has an ofNode, and also tracks children GameObjects. You can do this with pointer vectors or however you want. You just need to be careful… what happens if objects are destroyed? Who updates all parent’s lists of children? You may want to use shared_ptr

Good luck!

1 Like