peasycam, LeapMotionP5
in
Contributed Library Questions
•
2 months ago
I've been trying to get peasycam to work with the Leap Motion -- I've been trying to replace the mouse movement to move the cam in peasycam around a shape with movement on the Leap Motion.
I was able to get some control with the following code, but the rotation in peasycam seems to refresh with each new frame.
- PShape s;
- import peasy.*;
- import com.leapmotion.leap.Finger;
- import com.onformative.leap.LeapMotionP5;
- LeapMotionP5 leap;
- PeasyCam cam;
- PeasyDragHandler RotateDragHandler;
- void setup() {
- size(displayWidth, displayHeight, P3D);
- if (frame != null) {
- frame.setResizable(true);
- }
- s = loadShape("sculpture.obj");
- s.scale(6,6,6);
- cam = new PeasyCam(this, 500);
- cam.setMinimumDistance(10);
- cam.setMaximumDistance(800);
- leap = new LeapMotionP5(this);
- RotateDragHandler = cam.getRotateDragHandler();
- }
- void draw() {
- background(0);
- shape(s);
- for (Finger f : leap.getFingerList()) {
- PVector screenPos = leap.getTipOnScreen(f);
- println(screenPos.x + ", " + screenPos.y);
- RotateDragHandler.handleDrag(screenPos.x, screenPos.y);
- }
- }
- PShape s;
- import peasy.*;
- import com.leapmotion.leap.Finger;
- import com.onformative.leap.LeapMotionP5;
- LeapMotionP5 leap;
- PeasyCam cam;
- PeasyDragHandler RotateDragHandler;
- int x;
- int y;
- int xx;
- int yy;
- void setup() {
- size(displayWidth, displayHeight, P3D);
- if (frame != null) {
- frame.setResizable(true);
- }
- s = loadShape("sculpture.obj");
- s.scale(6,6,6);
- cam = new PeasyCam(this, 500);
- cam.setMinimumDistance(10);
- cam.setMaximumDistance(800);
- leap = new LeapMotionP5(this);
- RotateDragHandler = cam.getRotateDragHandler();
- }
- void draw() {
- background(0);
- shape(s);
- for (Finger f : leap.getFingerList()) {
- PVector screenPos = leap.getTipOnScreen(f);
- println(int(screenPos.x) + ", " + int(screenPos.y));
- if (int(screenPos.x) < (x-50)) {
- x = int(screenPos.x);
- } else if (int(screenPos.x) > (x+50)) {
- x = int(screenPos.x);
- }
- if (int(screenPos.y) < (y-50)) {
- y = int(screenPos.y);
- } else if (int(screenPos.y) > (y+50)) {
- y = int(screenPos.y);
- }
- if (xx != x) {
- RotateDragHandler.handleDrag(x, y);
- xx = x;
- } else if (yy != y) {
- RotateDragHandler.handleDrag(x, y);
- yy = y;
- }
- }
- }
Any help is appreciated. Thanks for checking this out.
2