Guest User

Untitled

a guest
Jul 22nd, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 KB | None | 0 0
  1. import processing.awt.PGraphicsJava2D;
  2.  
  3. // Create 3 x 3 matrix to store camera info.
  4. PMatrix2D camMat = new PMatrix2D();
  5.  
  6. /* ... */
  7.  
  8. void draw() {
  9. camera(camMat, hero.x, hero.y, 0.0, 1.0, 1.0);
  10. /* ... */
  11. }
  12.  
  13. PMatrix2D camera(PMatrix2D cameraMatrix,
  14. float tx, float ty, float angle,
  15. float zoomW, float zoomH) {
  16.  
  17. // The default matrix is
  18. // 1, 0, 0,
  19. // 0, 1, 0,
  20. // 0, 0, 1
  21. // with the bottom row omitted because
  22. // it doesn't change in 2D transformations.
  23.  
  24. // This shifts the camera to look at the
  25. // screen's center.
  26. cameraMatrix.set(
  27. 1.0, 0.0, width * 0.5,
  28. 0.0, 1.0, height * 0.5);
  29. cameraMatrix.rotate(angle);
  30. cameraMatrix.scale(zoomW, zoomH);
  31. cameraMatrix.translate(-tx, -ty);
  32.  
  33. // Set this PApplet renderer's matrix.
  34. setMatrix(cameraMatrix);
  35. return cameraMatrix;
  36. }
  37.  
  38. // Static variant of the above.
  39. // Supply the 2D renderer from the outside.
  40. static PMatrix2D camera(PGraphicsJava2D rndr,
  41. PMatrix2D cameraMatrix,
  42. float tx, float ty, float angle,
  43. float zoomW, float zoomH) {
  44. /* ... */
  45. rndr.setMatrix(cameraMatrix);
  46. return cameraMatrix;
  47. }
Add Comment
Please, Sign In to add comment