Proper use of translate,rotate in ofPath

#1

Hi, I just figured out calling translate or rotate BEFORE setting the path doesn’t have any effect.
It was only effective when translate, rotate were called after setting the path (e.g rectangle)

For example, when I write

void ofApp::draw(){

ofPath path;
path.translate(ofPoint(100,100,0));
path.rectangle(0, 0, 100, 100);
path.draw();

}

It draws a rectangle at (0,0) so it doesn’t get translated.

but when I set rectangle path first and then translate it like below,

void ofApp::draw(){

ofPath path;
path.rectangle(0, 0, 100, 100);
path.translate(ofPoint(100,100,0));
path.draw();

}

Now it properly draws a rectangle at (100,100)

Is this a normal behavior of ofPath?
I think it’s a bit confusing to use since ofTranslate and ofRotate gets called before drawing any shape to have an effect.
Could someone please explain briefly why order of these are opposite in ofPath? Thank you :slight_smile:

#2

Also, is there any way to do pushMatrix, popMatrix in ofPath?

#3

Hi, it is quite simple actually. When you apply a transformation in ofPath, it is applied to the already existing points of the path. It is done “on the fly”, and the transformation is NOT stored anywhere.

cheers!

1 Like
#4

Thank you!!