1234567891011121314151617181920212223242526272829303132333435363738394041 |
- void calculateViewport() {
- //fokkin mahjick viewport calculateion scale translate tath bitch back and map to mouse
- viewportX = map(-translateX/scaleFactor, 0, width, 0, renderer.width);
- viewportW = map((-translateX+width)/scaleFactor - (-translateX/scaleFactor), 0, width, 0, renderer.width);
- viewportR = map((-translateX+width)/scaleFactor, 0, width, 0, renderer.width);
- viewportY = map(-translateY/scaleFactor, 0, height, 0, renderer.height);
- viewportH = map((-translateY+height)/scaleFactor - (-translateY/scaleFactor), 0, height, 0, renderer.height);
- viewportB = map((-translateY+height)/scaleFactor, 0, height, 0, renderer.height);
- viewX = map(mouseX, 0, width, viewportX, viewportR);
- viewY = map(mouseY, 0, height, viewportY, viewportB);
- }
- float viewyfyX(float x) {
- return map(x, 0, width, viewportX, viewportR);
- }
- float viewyfyY(float y) {
- return map(y, 0, height, viewportY, viewportB);
- }
-
- void zoom(float delta) {
- translateX -= mouseX;
- translateY -= mouseY;
- scaleFactor *= delta;
- translateX *= delta;
- translateY *= delta;
- translateX += mouseX;
- translateY += mouseY;
- collisionDetection();
- }
-
- void collisionDetection() {
- while (translateX*scaleFactor > 0.0) translateX--;
- while (translateY*scaleFactor > 0.0) translateY--;
- while (translateX+width*scaleFactor < width) translateX++;
- while (translateY+height*scaleFactor < height) translateY++;
- }
-
- void reset() {
- scaleFactor = 1;
- translateX = 0.0;
- translateY = 0.0;
- }
|