2 * DOUBLE BLACK DIAMOND DOUBLE BLACK DIAMOND
5 * ///\\\ ///\\\ ///\\\ ///\\\
6 * \\\/// \\\/// \\\/// \\\///
9 * EXPERTS ONLY!! EXPERTS ONLY!!
11 * This file implements the mapping functions needed to lay out the physical
12 * cubes and the output ports on the panda board. It should only be modified
13 * when physical changes or tuning is being done to the structure.
16 final int MaxCubeHeight = 6;
17 final int NumBackTowers = 16;
19 public Model buildModel() {
21 // Shorthand helpers for specifying wiring more quickly
22 final Cube.Wiring WFL = Cube.Wiring.FRONT_LEFT;
23 final Cube.Wiring WFR = Cube.Wiring.FRONT_RIGHT;
24 final Cube.Wiring WRL = Cube.Wiring.REAR_LEFT;
25 final Cube.Wiring WRR = Cube.Wiring.REAR_RIGHT;
27 // Utility value if you need the height of a cube shorthand
28 final float CH = Cube.EDGE_HEIGHT;
29 final float CW = Cube.EDGE_WIDTH ;
31 // Positions for the bass box
32 final float BBY = BassBox.EDGE_HEIGHT + BoothFloor.PLEXI_WIDTH;
36 // The model is represented as an array of towers. The cubes in the tower
37 // are represenented relatively. Each tower has an x, y, z reference position,
38 // which is typically the base cube's bottom left corner.
40 // Following that is an array of floats. A 2-d array contains an x-offset
41 // and a z-offset from the previous reference position. Typically the first cube
42 // will just be {0, 0}. Each successive cube uses the position of the previous
43 // cube as its reference.
45 // A 3-d array contains an x-offset, a z-offset, and a rotation about the
48 // The cubes automatically increment their y-position by Cube.EDGE_HEIGHT.
50 // To-Do: (Mark Slee, Alex Green, or Ben Morrow): The Cube # is determined by the order in this list.
51 // "raw object index" is serialized by running through towermapping and then individual cube mapping below.
52 // We can do better than this. The raw object index should be obvious from the code-- looking through the
53 // rendered simulation and counting through cubes in mapping mode is grossly inefficient.
55 TowerMapping[] towerCubes = new TowerMapping[] {};
57 // Single cubes can be constructed directly here if you need them
58 Cube[] singleCubes = new Cube[] {
59 // new Cube(15, int( Cube.EDGE_HEIGHT), 39, 0, 10, 0, WRL), // Back left channel behind speaker
60 //new Cube(x, y, z, rx, ry, rz, wiring),
61 //new Cube(0,0,0,0,225,0, WRR),
65 // BassBox bassBox = BassBox.unlitBassBox(BBX, 0, BBZ); // frame exists, no lights
66 BassBox bassBox = BassBox.noBassBox(); // no bass box at all
67 // BassBox bassBox = new BassBox(BBX, 0, BBZ); // bass box with lights
70 List<Speaker> speakers = Arrays.asList(new Speaker[] {
71 // Each speaker parameter is x, y, z, rotation, the left speaker comes first
72 // new Speaker(TRAILER_WIDTH - Speaker.EDGE_WIDTH + 8, 6, 3, -15)
76 ////////////////////////////////////////////////////////////////////////
77 // dan's proposed lattice
78 ArrayList<StaggeredTower> scubes = new ArrayList<StaggeredTower>();
79 //if (NumBackTowers != 25) exit();
80 // for (int i=0; i<NumBackTowers/2; i++) scubes.add(new StaggeredTower(
82 // (i % 2 == 0) ? 0 : CH * 2./3. , // y
83 // - ((i % 2 == 0) ? 11 : 0) + 80 , // z
84 // -45, (i % 2 == 0) ? MaxCubeHeight : MaxCubeHeight) ); // num cubes
86 // for (int i=0; i<NumBackTowers/2; i++) scubes.add(new StaggeredTower(
88 // (i % 2 == 0) ? 0 : CH * 2./3. , // y
89 // - ((i % 2 == 0) ? 0 : 11) + 80 - pow(CH*CH + CW*CW, .5), // z
90 // 225, (i % 2 == 0) ? MaxCubeHeight : MaxCubeHeight-1) );
92 // for (int i=0; i<2 ; i++) scubes.add(new StaggeredTower(
95 // - 0 + 97 - 2*pow(CH*CH + CW*CW, .5), // z
96 // 225, MaxCubeHeight ) );
98 ArrayList<Cube> dcubes = new ArrayList<Cube>();
99 // for (int i=1; i<6; i++) {
100 // if (i>1) dcubes.add(new Cube(-6+CW*4/3*i , 0, 0, 0, 0, 0, WRR));
101 // dcubes.add(new Cube(-6+CW*4/3*i+CW*2/3., CH*.5, 0, 0, 0, 0, WRR));
104 float[] pos = new float[3];
107 scubes.add(new StaggeredTower(//tower 1
111 0, 4, new Cube.Wiring[] { WRR, WRR, WRR, WRR, WRR, WRR}) );
116 scubes.add(new StaggeredTower(// tower 2
120 0, 4, new Cube.Wiring[] { WRR, WRR, WRR, WRR, WRR, WRR}) );
124 scubes.add(new StaggeredTower(//tower 3
128 0, 5, new Cube.Wiring[] { WRR, WRR, WRR, WRR, WRR, WRR}) );
132 scubes.add(new StaggeredTower(//tower 4
136 0, 6, new Cube.Wiring[] { WRR, WRR, WRR, WRR, WRR, WRR}) );
140 scubes.add(new StaggeredTower(//tower 5
144 0, 6, new Cube.Wiring[] { WRR, WRR, WRR, WRR, WRR, WRR}) );
148 scubes.add(new StaggeredTower(//tower 6
152 0, 6, new Cube.Wiring[] { WRR, WRR, WRR, WRR, WRR, WRR}) );
156 scubes.add(new StaggeredTower(// tower 7
160 0, 4, new Cube.Wiring[] { WRR, WRR, WRR, WRR, WRR, WRR}) );
164 scubes.add(new StaggeredTower(//tower 8
168 0, 5, new Cube.Wiring[] { WRR, WRR, WRR, WRR, WRR, WRR}) );
172 scubes.add(new StaggeredTower(//tower 9
176 0, 5, new Cube.Wiring[] { WRR, WRR, WRR, WRR, WRR, WRR}) );
178 // //TOWERS ON DANCE FLOOR
179 // scubes.add(new StaggeredTower(//tower 10
180 // 83.75+39+43-124.5, // x
183 // 45, 4, new Cube.Wiring[]{ WRR, WRR, WRR, WRR}) );
184 // scubes.add(new StaggeredTower(//tower 11
188 // 45, 4, new Cube.Wiring[]{ WRR, WRR, WRR, WRR}) );
189 // scubes.add(new StaggeredTower(//tower 12
193 // 45, 4, new Cube.Wiring[]{ WRR, WRR, WRR, WRR}) );
194 // scubes.add(new StaggeredTower(//tower 13
198 // 45, 4, new Cube.Wiring[]{ WRR, WRR, WRR, WRR}) );
200 // scubes.add(new StaggeredTower(// Single cube on top of tower 4
204 // -10, 1, new Cube.Wiring[]{ WRL}) );
212 //////////////////////////////////////////////////////////////////////
213 // BENEATH HERE SHOULD NOT REQUIRE ANY MODIFICATION!!!! //
214 //////////////////////////////////////////////////////////////////////
216 // These guts just convert the shorthand mappings into usable objects
217 ArrayList<Tower> towerList = new ArrayList<Tower>();
218 ArrayList<Cube> tower;
219 Cube[] cubes = new Cube[200];
222 for (TowerMapping tm : towerCubes) {
226 tower = new ArrayList<Cube>();
227 for (CubeMapping cm : tm.cubeMappings) {
228 tower.add(cubes[cubeIndex++] = new Cube(px = px + cm.dx, ny, pz = pz + cm.dz, 0, cm.ry, 0, cm.wiring));
229 ny += Cube.EDGE_HEIGHT;
231 towerList.add(new Tower(tower));
235 for (Cube cube : singleCubes) {
236 cubes[cubeIndex++] = cube;
238 for (Cube cube : dcubes) {
239 cubes[cubeIndex++] = cube;
241 for (StaggeredTower st : scubes) {
242 tower = new ArrayList<Cube>();
243 for (int i=0; i < st.n; i++) {
244 Cube.Wiring w = (i < st.wiring.length) ? st.wiring[i] : WRR;
245 tower.add(cubes[cubeIndex++] = new Cube(st.x, st.y + CH* 4/3.*i, st.z, 0, st.r, 0, w));
247 towerList.add(new Tower(tower));
250 return new Model(towerList, cubes, bassBox, speakers);
254 * This function maps the panda boards. We have an array of them, each has
255 * an IP address and a list of channels.
257 public PandaMapping[] buildPandaList() {
258 final int LEFT_SPEAKER = 0;
259 final int RIGHT_SPEAKER = 1;
261 // 8 channels map to: 3, 4, 7, 8, 13, 14, 15, 16.
262 return new PandaMapping[] {
264 "192.168.88.100", new ChannelMapping[] { // G1
265 new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 6}),
266 new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 5}),
267 new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 6}),
268 new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 7}),
269 new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 7}),
270 new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 8}),
271 new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 1}),
272 new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 2}),
274 new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 4}),
275 new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 3}),
276 new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 11}),
277 new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 10}),
278 new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 9}),
279 new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 9}),
280 new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 12}),
281 new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 13}),
285 "192.168.88.101", new ChannelMapping[] { //G4
286 new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 25}),
287 new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 23}),
288 new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 24}),
289 new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 43}),
290 new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 45}),
291 new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 44}),
292 new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 1}),
293 new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 1}),
295 new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 1}),
296 new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 1}),
297 new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 1}),
298 new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 41}),
299 new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 42}),
300 new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 21}),
301 new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 20}),
302 new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 22}),
306 "192.168.88.104", new ChannelMapping[] { // G3
307 new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 26}),
308 new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 28}),
309 new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 27}),
310 new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 19}),
311 new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 18}),
312 new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 17}),
313 new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 1}),
314 new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 1}),
316 new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 18}),
317 new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 19}),
318 new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 15}),
319 new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 16}),
320 new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 14}),
321 new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 29}),
322 new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 30}),
323 new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 31}),
327 "192.168.88.105", new ChannelMapping[] { // G2
328 new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 1}),
329 new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 1}),
330 new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 1}),
331 new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 39}),
332 new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 38}),
333 new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 40}),
334 new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 34}),
335 new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 35}),
337 new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 33}),
338 new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 32}),
339 new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 37}),
340 new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 37}),
341 new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 1}),
342 new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 1}),
343 new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 1}),
344 new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 1}),
350 public final float x, y, z;
351 public final CubeMapping[] cubeMappings;
353 TowerMapping(float x, float y, float z, CubeMapping[] cubeMappings) {
357 this.cubeMappings = cubeMappings;
362 public final float dx, dz, ry;
363 public final Cube.Wiring wiring;
365 CubeMapping(float dx, float dz, Cube.Wiring wiring) {
366 this(dx, dz, 0., wiring);
368 CubeMapping(float dx, float dz, float ry) {
369 this(dz, dz, ry, Cube.Wiring.FRONT_LEFT);
372 CubeMapping(float dx, float dz, float ry, Cube.Wiring wiring) {
376 this.wiring = wiring;
380 class StaggeredTower {
381 public final float x, y, z, r;
383 public final Cube.Wiring[] wiring;
384 StaggeredTower(float _x, float _y, float _z, float _r, int _n) { this(_x, _y, _z, _r, _n, new Cube.Wiring[]{}); }
385 StaggeredTower(float _x, float _y, float _z, float _r, int _n, Cube.Wiring[] _wiring) { x=_x; y=_y; z=_z; r=_r; n=_n; wiring=_wiring;}
389 * Each panda board has an IP address and a fixed number of channels. The channels
390 * each have a fixed number of pixels on them. Whether or not that many physical
391 * pixels are connected to the channel, we still send it that much data.
395 // How many channels are on the panda board
396 public final static int CHANNELS_PER_BOARD = 16;
398 // How many total pixels on the whole board
399 public final static int PIXELS_PER_BOARD = ChannelMapping.PIXELS_PER_CHANNEL * CHANNELS_PER_BOARD;
402 final ChannelMapping[] channelList = new ChannelMapping[CHANNELS_PER_BOARD];
404 PandaMapping(String ip, ChannelMapping[] rawChannelList) {
407 // Ensure our array is the right length and has all valid items in it
408 for (int i = 0; i < channelList.length; ++i) {
409 channelList[i] = (i < rawChannelList.length) ? rawChannelList[i] : new ChannelMapping();
410 if (channelList[i] == null) {
411 channelList[i] = new ChannelMapping();
418 * Each channel on a pandaboard can be mapped in a number of modes. The typical is
419 * to a series of connected cubes, but we also have special mappings for the bass box,
420 * the speaker enclosures, and the DJ booth floor.
422 * This class is just the mapping meta-data. It sanitizes the input to make sure
423 * that the cubes and objects being referenced actually exist in the model.
425 * The logic for how to encode the pixels is contained in the PandaDriver.
427 class ChannelMapping {
429 // How many cubes per channel xc_PB is configured for
430 public final static int CUBES_PER_CHANNEL = 1;
432 // How many total pixels on each channel
433 public final static int PIXELS_PER_CHANNEL = Cube.POINTS_PER_CUBE * CUBES_PER_CHANNEL;
435 public static final int MODE_NULL = 0;
436 public static final int MODE_CUBES = 1;
437 public static final int MODE_BASS = 2;
438 public static final int MODE_SPEAKER = 3;
439 public static final int MODE_STRUTS_AND_FLOOR = 4;
440 public static final int MODE_INVALID = 5;
442 public static final int NO_OBJECT = -1;
445 final int[] objectIndices = new int[CUBES_PER_CHANNEL];
451 ChannelMapping(int mode) {
452 this(mode, new int[]{});
455 ChannelMapping(int mode, int rawObjectIndex) {
456 this(mode, new int[]{ rawObjectIndex });
459 ChannelMapping(int mode, int[] rawObjectIndices) {
460 if (mode < 0 || mode >= MODE_INVALID) {
461 throw new RuntimeException("Invalid channel mapping mode: " + mode);
463 if (mode == MODE_SPEAKER) {
464 if (rawObjectIndices.length != 1) {
465 throw new RuntimeException("Speaker channel mapping mode must specify one speaker index");
467 int speakerIndex = rawObjectIndices[0];
468 if (speakerIndex < 0 || speakerIndex >= glucose.model.speakers.size()) {
469 throw new RuntimeException("Invalid speaker channel mapping: " + speakerIndex);
471 } else if ((mode == MODE_STRUTS_AND_FLOOR) || (mode == MODE_BASS) || (mode == MODE_NULL)) {
472 if (rawObjectIndices.length > 0) {
473 throw new RuntimeException("Bass/floor/null mappings cannot specify object indices");
475 } else if (mode == MODE_CUBES) {
476 for (int rawCubeIndex : rawObjectIndices) {
477 if (glucose.model.getCubeByRawIndex(rawCubeIndex) == null) {
478 throw new RuntimeException("Non-existing cube specified in cube mapping: " + rawCubeIndex);
484 for (int i = 0; i < objectIndices.length; ++i) {
485 objectIndices[i] = (i < rawObjectIndices.length) ? rawObjectIndices[i] : NO_OBJECT;