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 current_x_position = 0;
105 // scubes.add(new StaggeredTower(//tower 1
106 // current_x_position, // x
109 // 45, 6, new Cube.Wiring[] { WFL, WRR, WFL, WRR, WFL, WRR}) );
110 // current_x_position += 25.25;
111 // scubes.add(new StaggeredTower(// tower 2
112 // current_x_position, // x
115 // 45, 6, new Cube.Wiring[] { WFR, WFL, WRR, WRR, WFL, WRR}) );
116 // current_x_position += 25.25;
117 // scubes.add(new StaggeredTower(//tower 3
118 // current_x_position, // x
121 // 45, 6, new Cube.Wiring[] { WRR, WFL, WRR, WRR, WFL, WRR}) );
122 // current_x_position += 25.25;
123 // scubes.add(new StaggeredTower(//tower 4
124 // current_x_position, // x
127 // 45, 6, new Cube.Wiring[] { WFL, WRR, WFL, WRR, WFL, WRR}) );
128 // current_x_position += 28;
129 // scubes.add(new StaggeredTower(//tower 5
130 // current_x_position, // x
133 // 45, 6, new Cube.Wiring[] { WRR, WFL, WRR, WFL, WRR, WFL}) );
134 // current_x_position += 28;
135 // scubes.add(new StaggeredTower(//tower 6
136 // current_x_position, // x
139 // 45, 6, new Cube.Wiring[] { WFL, WRR, WFL, WRR, WFL, WRR}) );
140 // current_x_position += 25.25;
141 // scubes.add(new StaggeredTower(// tower 7
142 // current_x_position, // x
145 // 45, 6, new Cube.Wiring[] { WRR, WFL, WRR, WFL, WRR, WFL}) );
146 // current_x_position += 25.25;
147 // scubes.add(new StaggeredTower(//tower 8
148 // current_x_position, // x
151 // 45, 6, new Cube.Wiring[] { WFL, WRR, WFL, WRR, WFL, WRR}) );
152 // current_x_position += 25.25;
153 // scubes.add(new StaggeredTower(//tower 9
154 // current_x_position, // x
157 // 45, 6, new Cube.Wiring[] { WFL, WRR, WFL, WRR, WFL, WRR}) );
158 // current_x_position += 25.25;
160 // //TOWERS ON DANCE FLOOR
161 // scubes.add(new StaggeredTower(//tower 10
162 // 83.75+39+43-124.5, // x
165 // 45, 4, new Cube.Wiring[]{ WRR, WFL, WFL, WRR}) );
166 // scubes.add(new StaggeredTower(//tower 11
170 // 45, 4, new Cube.Wiring[]{ WFL, WRR, WRR, WFL}) );
171 // scubes.add(new StaggeredTower(//tower 12
175 // 45, 4, new Cube.Wiring[]{ WRR, WFL, WFL, WRR}) );
176 // scubes.add(new StaggeredTower(//tower 13
180 // 45, 4, new Cube.Wiring[]{ WFL, WRR, WFL, WRR}) );
182 // scubes.add(new StaggeredTower(// Single cube on top of tower 4
186 // -10, 1, new Cube.Wiring[]{ WRL}) );
194 //////////////////////////////////////////////////////////////////////
195 // BENEATH HERE SHOULD NOT REQUIRE ANY MODIFICATION!!!! //
196 //////////////////////////////////////////////////////////////////////
198 // These guts just convert the shorthand mappings into usable objects
199 ArrayList<Tower> towerList = new ArrayList<Tower>();
200 ArrayList<Cube> tower;
201 Cube[] cubes = new Cube[200];
204 for (TowerMapping tm : towerCubes) {
208 tower = new ArrayList<Cube>();
209 for (CubeMapping cm : tm.cubeMappings) {
210 tower.add(cubes[cubeIndex++] = new Cube(px = px + cm.dx, ny, pz = pz + cm.dz, 0, cm.ry, 0, cm.wiring));
211 ny += Cube.EDGE_HEIGHT;
213 towerList.add(new Tower(tower));
217 for (Cube cube : singleCubes) {
218 cubes[cubeIndex++] = cube;
220 for (Cube cube : dcubes) {
221 cubes[cubeIndex++] = cube;
223 for (StaggeredTower st : scubes) {
224 tower = new ArrayList<Cube>();
225 for (int i=0; i < st.n; i++) {
226 Cube.Wiring w = (i < st.wiring.length) ? st.wiring[i] : WRR;
227 tower.add(cubes[cubeIndex++] = new Cube(st.x, st.y + CH* 4/3.*i, st.z, 0, st.r, 0, w));
229 towerList.add(new Tower(tower));
232 return new Model(towerList, cubes, bassBox, speakers);
236 * This function maps the panda boards. We have an array of them, each has
237 * an IP address and a list of channels.
239 public PandaMapping[] buildPandaList() {
240 final int LEFT_SPEAKER = 0;
241 final int RIGHT_SPEAKER = 1;
243 // 8 channels map to: 3, 4, 7, 8, 13, 14, 15, 16.
244 return new PandaMapping[] {
246 "10.200.1.28", new ChannelMapping[] {
247 new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 37, 38, 39 }),
248 new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { }),
249 new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 43, 44, 45 }),
250 new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 46, 47, 48 }),
251 new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { }), // new front thing
252 new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { }), // new back thing
253 new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 13, 14, 15 }), // new back thing
256 "10.200.1.29", new ChannelMapping[] {
257 new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 19, 20, 21 }),
258 new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { }),
259 new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 1, 2, 3 }),
260 new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 4, 5, 6 }),
261 new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 7, 8, 9 }),
263 new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 10, 11, 12 }),
264 new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 16, 17, 18 }),
265 // new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 34, 35, 36}),
266 // new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { }),
267 // new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 19, 20, 21}),
268 // new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 22, 23, 24}),
269 // new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 25, 26, 27}),
270 // new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 28, 29, 30}),
271 // new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 31, 32, 33}),
272 // new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { }),
275 "10.200.1.30", new ChannelMapping[] {
276 new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 40, 41, 42 }),
277 new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { }),
278 new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 22, 23, 24 }),
279 new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 25, 26, 27 }),
280 new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 28, 29, 30 }),
281 new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 31, 32, 33 }),
282 new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 34, 35, 36 }),
283 // new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 1,1,1}), // 30 J3 *
284 // new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 1,1,1}), // 30 J4 //ORIG *
285 // new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 37, 38, 39}), // 30 J7 *
286 // new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 40, 41, 42}), // 30 J8 *
287 // new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 43, 44, 45}), // 30 J13 (not working)
288 // new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 46, 47, 48}), // 30 J14 (unplugged)
289 // new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 49, 50, 51}), // 30 J15 (unplugged)
290 // new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 52, 53, 54}), // 30 J16
293 // "10.200.1.31", new ChannelMapping[] {
294 // new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 65, 66}), // J3
295 // new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 1,1}), // J4
296 // new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 55, 56}), // 30 J7
297 // new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 57, 58}), // J8
298 // new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 59, 60}), // J13
299 // new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 61, 62}), // 30 J14
300 // new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 63, 64}), // J15
301 // new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 1,1}), // J16
305 // "10.200.1.32", new ChannelMapping[] {
306 // new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { }), // J3
307 // new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { }), // J4
308 // new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 67, 68}), // 30 J7
309 // new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 69, 70}), // J8
310 // new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { }), // J13
311 // new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { }), // 30 J14
312 // new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { }), // J15
313 // new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { }), // J16
319 public final float x, y, z;
320 public final CubeMapping[] cubeMappings;
322 TowerMapping(float x, float y, float z, CubeMapping[] cubeMappings) {
326 this.cubeMappings = cubeMappings;
331 public final float dx, dz, ry;
332 public final Cube.Wiring wiring;
334 CubeMapping(float dx, float dz, Cube.Wiring wiring) {
335 this(dx, dz, 0., wiring);
337 CubeMapping(float dx, float dz, float ry) {
338 this(dz, dz, ry, Cube.Wiring.FRONT_LEFT);
341 CubeMapping(float dx, float dz, float ry, Cube.Wiring wiring) {
345 this.wiring = wiring;
349 class StaggeredTower {
350 public final float x, y, z, r;
352 public final Cube.Wiring[] wiring;
353 StaggeredTower(float _x, float _y, float _z, float _r, int _n) { this(_x, _y, _z, _r, _n, new Cube.Wiring[]{}); }
354 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;}
358 * Each panda board has an IP address and a fixed number of channels. The channels
359 * each have a fixed number of pixels on them. Whether or not that many physical
360 * pixels are connected to the channel, we still send it that much data.
364 // How many channels are on the panda board
365 public final static int CHANNELS_PER_BOARD = 8;
367 // How many total pixels on the whole board
368 public final static int PIXELS_PER_BOARD = ChannelMapping.PIXELS_PER_CHANNEL * CHANNELS_PER_BOARD;
371 final ChannelMapping[] channelList = new ChannelMapping[CHANNELS_PER_BOARD];
373 PandaMapping(String ip, ChannelMapping[] rawChannelList) {
376 // Ensure our array is the right length and has all valid items in it
377 for (int i = 0; i < channelList.length; ++i) {
378 channelList[i] = (i < rawChannelList.length) ? rawChannelList[i] : new ChannelMapping();
379 if (channelList[i] == null) {
380 channelList[i] = new ChannelMapping();
387 * Each channel on a pandaboard can be mapped in a number of modes. The typical is
388 * to a series of connected cubes, but we also have special mappings for the bass box,
389 * the speaker enclosures, and the DJ booth floor.
391 * This class is just the mapping meta-data. It sanitizes the input to make sure
392 * that the cubes and objects being referenced actually exist in the model.
394 * The logic for how to encode the pixels is contained in the PandaDriver.
396 class ChannelMapping {
398 // How many cubes per channel xc_PB is configured for
399 public final static int CUBES_PER_CHANNEL = 4;
401 // How many total pixels on each channel
402 public final static int PIXELS_PER_CHANNEL = Cube.POINTS_PER_CUBE * CUBES_PER_CHANNEL;
404 public static final int MODE_NULL = 0;
405 public static final int MODE_CUBES = 1;
406 public static final int MODE_BASS = 2;
407 public static final int MODE_SPEAKER = 3;
408 public static final int MODE_STRUTS_AND_FLOOR = 4;
409 public static final int MODE_INVALID = 5;
411 public static final int NO_OBJECT = -1;
414 final int[] objectIndices = new int[CUBES_PER_CHANNEL];
420 ChannelMapping(int mode) {
421 this(mode, new int[]{});
424 ChannelMapping(int mode, int rawObjectIndex) {
425 this(mode, new int[]{ rawObjectIndex });
428 ChannelMapping(int mode, int[] rawObjectIndices) {
429 if (mode < 0 || mode >= MODE_INVALID) {
430 throw new RuntimeException("Invalid channel mapping mode: " + mode);
432 if (mode == MODE_SPEAKER) {
433 if (rawObjectIndices.length != 1) {
434 throw new RuntimeException("Speaker channel mapping mode must specify one speaker index");
436 int speakerIndex = rawObjectIndices[0];
437 if (speakerIndex < 0 || speakerIndex >= glucose.model.speakers.size()) {
438 throw new RuntimeException("Invalid speaker channel mapping: " + speakerIndex);
440 } else if ((mode == MODE_STRUTS_AND_FLOOR) || (mode == MODE_BASS) || (mode == MODE_NULL)) {
441 if (rawObjectIndices.length > 0) {
442 throw new RuntimeException("Bass/floor/null mappings cannot specify object indices");
444 } else if (mode == MODE_CUBES) {
445 for (int rawCubeIndex : rawObjectIndices) {
446 if (glucose.model.getCubeByRawIndex(rawCubeIndex) == null) {
447 throw new RuntimeException("Non-existing cube specified in cube mapping: " + rawCubeIndex);
453 for (int i = 0; i < objectIndices.length; ++i) {
454 objectIndices[i] = (i < rawObjectIndices.length) ? rawObjectIndices[i] : NO_OBJECT;