PeasyCam simple "drag" disable?

edited February 2016 in Library Questions

Currently trying to get rid of having to click, hold and drag your mouse to rotate around an object. The camera should just follow mouseX and mouseY from the start up. This is for further implementation of replacing the mouseX and mouseY with another variable as you can see in my sketch. Any feedback is much appreciated.

import peasy.*;
import controlP5.*;
import processing.video.*;

PeasyCam cam;

Capture usbcam;
ControlP5 cp5;

int pointx, pointy;
PShape s;
int cubeWidthSwitch = 0;
int distanceFactor = 1;
float c1 = 0;
float pixelBrightness = 0;

void setup() {
  size (1280, 720, P3D);
  frame.setResizable(true);
  cp5 = new ControlP5(this);

  usbcam = new Capture(this, 1280, 720, "USB Webcam");
  usbcam.start();
  frameRate(30);
  s = loadShape("spike.obj");
  s.scale(0.2);

  cam = new PeasyCam(this, 500);
  cam.setMinimumDistance(500);
  cam.setMaximumDistance(500);
}

void draw () {

  c1+=5;
  c1%=255;
  colorMode(HSB);
  background(0);

  for ( int gridX = -480 ; gridX <240 ; gridX = gridX +90 ) {
    for (int gridY = -480 ; gridY < 240 ; gridY = gridY +90) {
      for (int gridZ = -480 ; gridZ < 240 ; gridZ = gridZ+90) {
        pushMatrix ();

        translate (gridX*distanceFactor*2, gridY*distanceFactor*2, gridZ*distanceFactor*2);
        translate(360, 400, 350);
        fill (c1, 255, 255);
        sphere(1.5);
        noStroke();

        popMatrix();
      }
    }
  }


  s.setFill(color(255));
  shape(s);

  cam.beginHUD();
  gui();
  cam.endHUD();
}

void gui(){
  camera();
  if(usbcam.available()) {
    usbcam.read();
    usbcam.loadPixels();

    int brightest = 0;
    for(int i=0; i<usbcam.pixels.length; i++) {
      if(brightness(usbcam.pixels[i]) < 70) {
        pixelBrightness = brightness(usbcam.pixels[i]);
        brightest = i;
      }
    }
    pointx = brightest % usbcam.width;
    pointy = brightest / usbcam.width;
//    image(usbcam, 0, 0);
//    ellipse(pointx, pointy, 200, 200);

  }
}

Answers

  • You'll get a better response if you format your code. Here's how:

    http://forum.processing.org/two/discussion/8045/how-to-format-code-and-text

  • My apologies, It is now updated. Thank you

  • Answer ✓
    import peasy.*;
    
    PeasyCam cam;
    PeasyDragHandler handler;
    
    void setup() {
      size (500, 500, P3D);
      cam = new PeasyCam(this, 500);
      cam.setMinimumDistance(500);
      cam.setMaximumDistance(500);
      handler = cam.getRotateDragHandler();
    }
    
    void draw () {
      background(255);
      handler.handleDrag((double)(mouseX - pmouseX), (double)(mouseY - pmouseY));
      box(50);
    }
    

    you can call the camera's draghandler with the mouse position. but it actually takes the delta, hence the pmouseX / pmouseY.

  • You my friend are a genius. Thank you so much!

  • you might want to disable other drag handlers as they are still active, just setting them to null will probably work (after grabbing the value, my line 11)

    https://github.com/jdf/peasycam

    camera.setLeftDragHandler(null);  
    camera.setCenterDragHandler(null);  
    camera.setRightDragHandler(null);  
    

    wheel handler too.

Sign In or Register to comment.