well, I'm going to continue with it ... I'm going to put it into a class where I can pass (or internally create) paths for the camera to follow and from what I have so far, that's pretty easy. The only thing hanging me up is with the camera constraints as far as methods are concerned. From the random motion, I think it will work for my purposes if I just use the lookAt and scale for constraining. My program is for displaying images that are larger than the sketch window. I set the cam default look to frame the entire image. When the entire image is displayed, you can't pan because I need to constrain the image to fill the entire sketch window with no borders of the image showing, so, at 0 zoom, there's 0 constraint. At different zooming levels, you can pan more because the image is so much larger than the sketch window. So, there's a proportional relationship between the zoom level and how much panning can be done before the edge of the image is reached.
I think I need to just find this proportion and calculate the x and y constraints from the given zoom window, image size, and sketch size.
It may take weeks for me to figure out, but, Im sure it's just two lines of pretty simple code.
I'm too lazy to create a PGraphics background to use for demonstration purposes; you'll have to substitute your own image that's larger than the 640 x 420 or d/l and use the one I'm using from
http://www.deviantart.com/download/202365255/alien_mollusc_homeland_by_unafra3yd-d3che13.png
- import peasy.*;
- PeasyCam cam;
- PeasyDragHandler PanDragHandler;
- PeasyDragHandler ZoomDragHandler;
- //PFont fontA;
- PImage bgimg;
- float cx,cy,cz;
- long time;
- int UpdateInterval;
- int LastUpdate;
-
- int steps;
- void setup(){
-
- size(640,400,P3D);
- cz = 100;
-
- bgimg = loadImage("landscape-crop1.png");
- // fontA = loadFont("BlueHighway-24.vlw");
- cam = new PeasyCam(this,bgimg.width/2, bgimg.height/2, 0, 600);
- cam.setMinimumDistance(100);
- cam.setMaximumDistance(550);
- PanDragHandler = cam.getPanDragHandler();
- ZoomDragHandler = cam.getZoomDragHandler();
- cam.setLeftDragHandler(PanDragHandler);
- cam.setWheelHandler(null);
-
- //cam.lookAt(bgimg.width/2, bgimg.height/2, 0);
-
- LastUpdate = millis();
- UpdateInterval = 1000;
-
- cz = -300;
-
- // width of image = 1280
- // screen width = 640
- // screen height = 420
- // height of image = 790
- // if cz zoom = 0, then we want to constrain cx and cy to a few pixeles.
- }
- void draw() {
- background(0);
- //imageMode(CENTER);
- image(bgimg,0,0);
-
- //println(str(cam.getPosition()));
- cam.beginHUD();
- fill(255);
- rect(0,0,80,44);
- fill(#1419F2);
- text("camX " + str(round(cam.getPosition()[0])) + "\ncamY " + str(round(cam.getPosition()[1])) + "\ncamZ " + str(round(cam.getPosition()[2])) ,12,12);
- cam.endHUD();
-
- if (millis()-LastUpdate >= UpdateInterval) {
- //if (GameMode) { }
- //cam.lookAt(600, 200, 100, 6000);
- // {mvcamBasic();}
- mvcamRand();
- UpdateInterval = int(random(6,15)*1000);
- LastUpdate = millis();
- }
-
- }
- public void mvcamRand() {
- cam.lookAt(random(bgimg.width),random(bgimg.height),cz-100+random(200),UpdateInterval-500);
- }
- public void mvcamBasic(){
- cam.lookAt(215, 235, -450,1000);
- //println(str(cam.getPosition()));
- }
- public void mvcam2(){
- cam.lookAt(254, 522, cz,4000);
- //println(str(cam.getPosition()));
- }
- public void mvcam3(){
- cam.lookAt(857, 527, cz,15000);
- //println(str(cam.getPosition()));
- }
- public void keyPressed() {
- if (key == '1') {mvcamBasic();}
- if (key == '2') {mvcam2();}
- if (key == '3') {mvcam3();}
- if (key == 'x') {cam.reset(3000);}
- }