Skip to content

Instantly share code, notes, and snippets.

@hiroyuki
Created May 2, 2013 09:37
Show Gist options
  • Save hiroyuki/5501205 to your computer and use it in GitHub Desktop.
Save hiroyuki/5501205 to your computer and use it in GitHub Desktop.
scaling image with anchor point
void testApp::setup()
{
img.loadImage("history.png");
ofSetWindowShape(img.getWidth(), img.getHeight());
scale = 1.0;
}
void testApp::update()
{
}
void testApp::draw()
{
mtrx.makeIdentityMatrix();
mtrx.scale(scale, scale, scale);
mtrx.translate(-imagePoint*(scale-1));
mtrx.translate((touchBeginPoint - imagePoint));
ofPushMatrix();
ofMultMatrix(mtrx);
img.draw(0, 0);
ofPopMatrix();
}
void testApp::keyPressed(int key)
{
if (key == 'a' && scale < 5.0)
scale += 0.1;
else if (key == 's' && scale - 0.1 >= 1.0)
scale -= 0.1;
}
void testApp::mousePressed(int x, int y, int button)
{
imagePoint = (ofPoint(x, y) - mtrx.getTranslation()) / scale; //画像の相対座標でのポイント
touchBeginPoint = ofPoint(x, y);//screenのポイント
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment