// 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);
for (int value : pointList) {
points[i++] = value;
}
- flipped = buildFlippedList(model, flippedList);
}
private ArrayList<Integer> buildMappedList(Model model, int[][] channelList) {
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);
+ }
}
}
}
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;
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;
message.add(len);
message.add(packet);
try {
- OscP5.flush(message, address);
+ OscP5.flush(message, address);
} catch (Exception x) {
x.printStackTrace();
}