Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import processing.awt.PGraphicsJava2D;
- // Create 3 x 3 matrix to store camera info.
- PMatrix2D camMat = new PMatrix2D();
- /* ... */
- void draw() {
- camera(camMat, hero.x, hero.y, 0.0, 1.0, 1.0);
- /* ... */
- }
- PMatrix2D camera(PMatrix2D cameraMatrix,
- float tx, float ty, float angle,
- float zoomW, float zoomH) {
- // The default matrix is
- // 1, 0, 0,
- // 0, 1, 0,
- // 0, 0, 1
- // with the bottom row omitted because
- // it doesn't change in 2D transformations.
- // This shifts the camera to look at the
- // screen's center.
- cameraMatrix.set(
- 1.0, 0.0, width * 0.5,
- 0.0, 1.0, height * 0.5);
- cameraMatrix.rotate(angle);
- cameraMatrix.scale(zoomW, zoomH);
- cameraMatrix.translate(-tx, -ty);
- // Set this PApplet renderer's matrix.
- setMatrix(cameraMatrix);
- return cameraMatrix;
- }
- // Static variant of the above.
- // Supply the 2D renderer from the outside.
- static PMatrix2D camera(PGraphicsJava2D rndr,
- PMatrix2D cameraMatrix,
- float tx, float ty, float angle,
- float zoomW, float zoomH) {
- /* ... */
- rndr.setMatrix(cameraMatrix);
- return cameraMatrix;
- }
Add Comment
Please, Sign In to add comment