Rotating ofTexture

Hello,

I can see that ofTexture contains "setAnchorPoint(float, float) method, which it says can be usefull
for rotation. However ofTexture doesn’t contain rotation, it’s done via ofPushMatrix apparently.
If so, what’s the purpose of setAnchorPoint and how can I use it ?

Thanks
M

You’ll need to do all transformations in a push and pop matrix.

setAnchorPoint(float, float) allows you to change the drawing position. So therefore if you were to rotate your texture you will get different results if you change the drawn position. For example, if you can change the drawing position to the centre of the texture (width/2, height/2) that will rotate from the centre. If you rotate without changing anything it will default to the top left corner of the texture hence will rotate/move differently based on the transformations you apply through PushMatrix.

Here is an example

ofPushMatrix();
ofRotate(45);//What is drawn is roated by 45
setAnchorPoint(50,50) //changes drawing point to 50, 50. Therefore will rotate 45 from this point
myTexture.draw();
ofPopMatrix();
Setup:
texture.setAnchorPercent(0.5, 0.5);
deg = 0.0; // float
w = (ofGetWidth() - texture.getWidth())/2;
h = (ofGetHeight() - texture.getHeight())/2;

Update: deg +=0.1;

Draw:

ofTranslate(w, h);
ofScale(1, -1);
ofRotateZ(deg);
texture.draw(0,0);