Tiny 2D-animation-sprite composer for placing animation loops and making them interactive
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

před 7 roky
1234567891011121314151617181920212223242526272829303132333435363738394041
  1. void calculateViewport() {
  2. //fokkin mahjick viewport calculateion scale translate tath bitch back and map to mouse
  3. viewportX = map(-translateX/scaleFactor, 0, width, 0, renderer.width);
  4. viewportW = map((-translateX+width)/scaleFactor - (-translateX/scaleFactor), 0, width, 0, renderer.width);
  5. viewportR = map((-translateX+width)/scaleFactor, 0, width, 0, renderer.width);
  6. viewportY = map(-translateY/scaleFactor, 0, height, 0, renderer.height);
  7. viewportH = map((-translateY+height)/scaleFactor - (-translateY/scaleFactor), 0, height, 0, renderer.height);
  8. viewportB = map((-translateY+height)/scaleFactor, 0, height, 0, renderer.height);
  9. viewX = map(mouseX, 0, width, viewportX, viewportR);
  10. viewY = map(mouseY, 0, height, viewportY, viewportB);
  11. }
  12. float viewyfyX(float x) {
  13. return map(x, 0, width, viewportX, viewportR);
  14. }
  15. float viewyfyY(float y) {
  16. return map(y, 0, height, viewportY, viewportB);
  17. }
  18. void zoom(float delta) {
  19. translateX -= mouseX;
  20. translateY -= mouseY;
  21. scaleFactor *= delta;
  22. translateX *= delta;
  23. translateY *= delta;
  24. translateX += mouseX;
  25. translateY += mouseY;
  26. collisionDetection();
  27. }
  28. void collisionDetection() {
  29. while (translateX*scaleFactor > 0.0) translateX--;
  30. while (translateY*scaleFactor > 0.0) translateY--;
  31. while (translateX+width*scaleFactor < width) translateX++;
  32. while (translateY+height*scaleFactor < height) translateY++;
  33. }
  34. void reset() {
  35. scaleFactor = 1;
  36. translateX = 0.0;
  37. translateY = 0.0;
  38. }