Kill RGB mappings and various other cleanups
[SugarCubes.git] / _PandaDriver.pde
index ad870aaa9d59aacc6a1d1630b0720114a864752b..60ab343ab2add9faca1d12e2c2d0da5829b4fabb 100644 (file)
@@ -25,13 +25,10 @@ public class PandaDriver {
   // List of point indices on the board
   private final int[] points;
 
-  // Bit for flipped status of each point index
-  private final boolean[] flipped;
-
   // Packet data
   private final byte[] packet = new byte[4*352]; // TODO: de-magic-number
 
-  public PandaDriver(NetAddress address, Model model, int[][] channelList, int[][] flippedList) {
+  public PandaDriver(NetAddress address, Model model, int[][] channelList) {
     this.address = address;
     message = new OscMessage("/shady/pointbuffer");
     List<Integer> pointList = buildMappedList(model, channelList);
@@ -40,7 +37,6 @@ public class PandaDriver {
     for (int value : pointList) {
       points[i++] = value;
     }
-    flipped = buildFlippedList(model, flippedList);
   }
 
   private ArrayList<Integer> buildMappedList(Model model, int[][] channelList) {
@@ -56,8 +52,14 @@ public class PandaDriver {
           if (cube == null) {
             throw new RuntimeException("Non-zero, non-existing cube specified in channel mapping (" + cubeNumber + ")");
           }
-          for (Point p : cube.points) {
-            points.add(p.index);
+          final int[] stripOrder = new int[] {
+            2, 1, 0, 3, 13, 12, 15, 14, 4, 7, 6, 5, 11, 10, 9, 8
+          };
+          for (int stripIndex : stripOrder) {
+            Strip s = cube.strips.get(stripIndex);
+            for (int j = s.points.size() - 1; j >= 0; --j) {
+              points.add(s.points.get(j).index);
+            }
           }
         }
       }
@@ -65,27 +67,6 @@ public class PandaDriver {
     return points;
   }
 
-  private boolean[] buildFlippedList(Model model, int[][] flippedRGBList) {
-    boolean[] flipped = new boolean[model.points.size()];
-    for (int i = 0; i < flipped.length; ++i) {
-      flipped[i] = false;
-    }
-    for (int[] cubeInfo : flippedRGBList) {
-      int cubeNumber = cubeInfo[0];
-      Cube cube = model.getCubeByRawIndex(cubeNumber);
-      if (cube == null) {
-        throw new RuntimeException("Non-existing cube specified in flipped RGB mapping (" + cubeNumber + ")");
-      }
-      for (int i = 1; i < cubeInfo.length; ++i) {
-        int stripIndex = cubeInfo[i];
-        for (Point p : cube.strips.get(stripIndex-1).points) {
-          flipped[p.index] = true;
-        }
-      }
-    }
-    return flipped;
-  } 
-
   public final void send(int[] colors) {
     int len = 0;
     int packetNum = 0;
@@ -94,11 +75,6 @@ public class PandaDriver {
       byte r = (byte) ((c >> 16) & 0xFF);
       byte g = (byte) ((c >> 8) & 0xFF);
       byte b = (byte) ((c) & 0xFF);
-      if (flipped[index]) {
-        byte tmp = r;
-        r = g;
-        g = tmp;
-      }
       packet[len++] = 0;
       packet[len++] = r;
       packet[len++] = g;
@@ -123,7 +99,7 @@ public class PandaDriver {
     message.add(len);
     message.add(packet);
     try {
-      OscP5.flush(message, address);     
+      OscP5.flush(message, address);
     } catch (Exception x) {
       x.printStackTrace();
     }