Created
May 2, 2013 09:37
-
-
Save hiroyuki/5501205 to your computer and use it in GitHub Desktop.
scaling image with anchor point
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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