Rotating images
The image.draw()
method does not have parameters to rotate images on arbitrary angles. To achieve this effect, we need to work with coordinate system transformations, which are described in detail in the Coordinate system transformations section in Chapter 2, Drawing in 2D.
We need to carry out the following steps for drawing a rotated image:
Store the current transformation matrix using
ofPushMatrix()
.Change the matrix by applying rotation transformation using
ofRotate()
.Draw the image using
image.draw()
.Restore the original transformation matrix using
ofPopMatrix()
.
The following code illustrates these steps. It draws the image rotated at 10 degrees around the current center of coordinates, which is (0, 0).
void testApp::draw(){ ofPushMatrix(); //Store the transformation matrix ofRotate( 10.0 ); //Applying rotation on 10 degrees image.draw( 0, 0 ); //Draw image ofPopMatrix(); //Restore the transformation }
Sometimes, we will want to...