how to use Camera.interpolateToZoomOnRegion in Proscene
in
Contributed Library Questions
•
2 years ago
I'm trying to use Proscenes interpolateToZoomOnRegion method to zoom in/out to different sized boxes in the scene but I cant get it to work. I got interpolateToFitScene but i want it to fit the scene to the region/size of the box
.
-
import remixlab.proscene.*; Scene scene; ArrayList<Box> boxes = new ArrayList<Box>(); int sizeMin = 5; int sizeMax = 30; int columns = 5; int rows = 5; int xSpacing = 25; int ySpacing = 25; float xOffset = (sizeMax + xSpacing) * (columns - 1); float yOffset = (sizeMax + ySpacing) * (rows - 1); public void setup() { size(640, 360, P3D); scene = new Scene(this); scene.setCameraType(Camera.Type.ORTHOGRAPHIC); scene.setRadius(200); scene.disableKeyboardHandling(); scene.showAll(); setupBoxes(); } public void setupBoxes() { boxes.clear(); for (int i = 0; i < columns; i++) { for (int j = 0; j < rows; j++) { float x = xOffset / 2 - i * (sizeMax + xSpacing); float y = yOffset / 2 - j * (sizeMax + ySpacing); Box box = new Box(scene); box.setSize(random(sizeMin, sizeMax), random(sizeMin, sizeMax), random(sizeMin, sizeMax)); box.setPosition(new PVector(x, y)); box.setColor(color(random(255), 0, 255)); boxes.add(box); } } } public void draw() { background(155); for (int i = 0; i < boxes.size(); i++) boxes.get(i).draw(); } public void keyPressed() { if (key == ' ') if (scene.mouseGrabber() != null) { Box box = (Box) scene.mouseGrabber(); scene.camera().interpolateToZoomOnRegion(box.rect()); // comment the line above and uncomment the lines below to use // interpolateToFitScene // PVector sceneCenter = scene.camera().sceneCenter().get(); // float sceneRadius = scene.camera().sceneRadius(); // // scene.setCenter(box.position()); // scene.setRadius(scene.camera().type() == // Camera.Type.ORTHOGRAPHIC ? 40 // : 20); // scene.camera().interpolateToFitScene(); // // scene.setCenter(sceneCenter); // scene.setRadius(sceneRadius); } } public class Box extends InteractiveFrame { InteractiveFrame frame; float w, h, d; int c; Box(Scene _scene) { super(_scene); } public void draw() { pushMatrix(); pushStyle(); applyTransformation(); noStroke(); if (grabsMouse()) fill(255, 0, 0); else fill(c); box(w, h, d); popStyle(); popMatrix(); } public void setSize(float myW, float myH, float myD) { w = myW; h = myH; d = myD; } public void setColor(int myC) { c = myC; } public Rectangle rect() { return new Rectangle((int) position().x, (int) position().y, (int) w, (int) h); } }
1