Nesting shapes in ofNode

Hi there,

Is there any way to add 2d shapes such as ofDrawCircle as children of an ofNode?

I come from iOS dev background and I’m trying to achieve a similar layout system with child views being drawn on top of parents and having their own local coordinate systems etc.

As far as I can tell the one way to add 2d shapes to an ofNode is to convert them to ofMesh from ofPath. Is there something simpler I might be overlooking?

I’ve noticed ofNode also has a customDraw method — could I use this method instead to draw the 2d shapes?

Hey I like this idea of extending ofNode with a customDraw() function. But since the new class will inherit from ofNode, you could add other functions to it too. I found an example of this in the forum here: Extending ofNode class.

Also be aware that ofNode has a c-style pointer for the parent, so you have to be a bit careful when using it with vectors and other containers.

1 Like

yes. that is what is intended for. you need to make a new class that inherits from ofNode.
Otherwise if you dont want to make new clases you can use the node´s transformGL() which will apply its transformation to whatever you draw next.

class CircleNode : public ofNode{

	virtual void customDraw() {
         ofDrawCircle(0,0, 10);


CircleNode circle; // instantiate somewhere.
// call inside the draw function.

The above code should render the same as the following.
It depends on who you use these which will be the best option

// instatiate somewhere
ofNode node;

// call inside draw() function.
1 Like

@roymacdonald That did exactly what I needed it to!

I think I’m wrapping my head around this now, thank you both for your replies!

1 Like

Hey @roymacdonald , does customDraw() need to be virtual, or does it just get redefined in the derived class. Maybe it can be either?

1 Like

It is already defined as virtual in ofNode, so if you override it, it will still be virtual. I think that even if you dont specify it as virtual, as it is overriding a virtual function it automatically becomes virtual.