Skip to content
This repository
Browse code

Merge pull request #31 from SableRaf/master

New Processing example
  • Loading branch information...
commit fd80de370d341248bc19c8c2d1a10e9206cb0d0c 2 parents 09aeeac + fddd305
Thomas Perl authored October 30, 2012
68  examples/processing/multiple_controllers_tracker/multiple_controllers_tracker.pde
... ...
@@ -0,0 +1,68 @@
  1
+
  2
+// Import the PS Move API Package
  3
+import io.thp.psmove.*;
  4
+
  5
+PSMoveTracker tracker;
  6
+
  7
+PImage img;
  8
+byte [] pixels;
  9
+
  10
+int connectedControllers = 2; // Number of connected Move controllers (a more generic solution would be to use count_connected() in the setup)
  11
+PSMove[] controllers; // Define an array of controllers
  12
+
  13
+void setup() {
  14
+  size(640, 480);
  15
+
  16
+  controllers = new PSMove[connectedControllers];
  17
+
  18
+  // Fill the array with controllers and light them up in white
  19
+  for (int i = 0; i<controllers.length; i++) {
  20
+    controllers[i] = new PSMove(i);
  21
+    controllers[i].set_leds(255, 255, 255);
  22
+    controllers[i].update_leds();
  23
+  }
  24
+
  25
+  tracker = new PSMoveTracker(); // Create a tracker object
  26
+
  27
+  tracker.set_mirror(1); // Mirror the tracker image horizontally
  28
+
  29
+  // Try to calibrate each move
  30
+  for (int i = 0; i<controllers.length; i++) {
  31
+    while (tracker.enable (controllers[i]) != Status.Tracker_CALIBRATED);
  32
+  } // Every call to the controllers will have to use a loop like this one and controllers[i] to refer to each Move
  33
+}
  34
+
  35
+void draw() {
  36
+  tracker.update_image();
  37
+  tracker.update();
  38
+
  39
+  // Get the pixels from the tracker image and load them into a PImage
  40
+  PSMoveTrackerRGBImage image = tracker.get_image();
  41
+  if (pixels == null) {
  42
+    pixels = new byte[image.getSize()];
  43
+  }
  44
+  image.get_bytes(pixels);
  45
+  if (img == null) {
  46
+    img = createImage(image.getWidth(), image.getHeight(), RGB);
  47
+  }
  48
+  img.loadPixels();
  49
+  for (int i=0; i<img.pixels.length; i++) {
  50
+    // We need to AND the values with 0xFF to convert them to unsigned values
  51
+    img.pixels[i] = color(pixels[i*3] & 0xFF, pixels[i*3+1] & 0xFF, pixels[i*3+2] & 0xFF);
  52
+  }
  53
+
  54
+  img.updatePixels();
  55
+  image(img, 0, 0); // Display the tracker image in the sketch window
  56
+
  57
+  for (int i = 0; i<controllers.length; i++) {
  58
+
  59
+    float x[] = new float[1];
  60
+    float y[] = new float[1];
  61
+    float r[] = new float[1];
  62
+
  63
+    tracker.get_position(controllers[i], x, y, r);
  64
+
  65
+    println("controllers["+i+"]: x= "+ x[0] +" y= "+ y[0] + " r= " + r[0]);
  66
+  }
  67
+}
  68
+

0 notes on commit fd80de3

Please sign in to comment.
Something went wrong with that request. Please try again.