Zoom an image in cinder

Hi,

by default in Cinder, the origin (0,0) of an image is in the upper-left corner. This is the point around which the image is rotated or from which it is scaled. If you want to scale from the center, you’ll first have to translate the image so that (0,0) is in the center:

gl::translate( -0.5f * imageWidth, -0.5f * imageHeight );

Then you scale or rotate the image:

gl::scale( 2.0f, 2.0f );

And finally you translate the origin of the image (which is now its center) to the center of the window:

gl::translate( 0.5f * getWindowWidth(), 0.5f * getWindowHeight() );

It’s important to remember that, because of the way the transformation matrices are defined in OpenGL, you have to reverse the order of operations. Finally, make sure to push and pop the model matrix. The code therefor becomes:

gl::pushModelMatrix();
gl::translate( 0.5f * getWindowWidth(), 0.5f * getWindowHeight() );
gl::scale( 2.0f, 2.0f );
gl::translate( -0.5f * imageWidth, -0.5f * imageHeight );
gl::draw( texture );
gl::popModelMatrix();

-Paul