Commit | Line | Data |
---|---|---|
1ecdb44a MS |
1 | /** |
2 | * DOUBLE BLACK DIAMOND DOUBLE BLACK DIAMOND | |
3 | * | |
4 | * //\\ //\\ //\\ //\\ | |
5 | * ///\\\ ///\\\ ///\\\ ///\\\ | |
6 | * \\\/// \\\/// \\\/// \\\/// | |
7 | * \\// \\// \\// \\// | |
8 | * | |
9 | * EXPERTS ONLY!! EXPERTS ONLY!! | |
10 | * | |
186bc4d3 | 11 | * This file implements the mapping functions needed to lay out the physical |
1ecdb44a MS |
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. | |
14 | */ | |
45f43cc2 | 15 | |
f0cc0ba5 MS |
16 | public Model buildModel() { |
17 | ||
f0cc0ba5 MS |
18 | // Shorthand helpers for specifying wiring more quickly |
19 | final Cube.Wiring WFL = Cube.Wiring.FRONT_LEFT; | |
20 | final Cube.Wiring WFR = Cube.Wiring.FRONT_RIGHT; | |
21 | final Cube.Wiring WRL = Cube.Wiring.REAR_LEFT; | |
22 | final Cube.Wiring WRR = Cube.Wiring.REAR_RIGHT; | |
95c50032 | 23 | |
a3ccf23a | 24 | // Utility value if you need the height of a cube shorthand |
95c50032 | 25 | final float CH = Cube.EDGE_HEIGHT; |
73687629 | 26 | final float CW = Cube.EDGE_WIDTH ; |
7c7625ec AG |
27 | |
28 | ||
ae579223 | 29 | |
a3ccf23a | 30 | // Positions for the bass box |
ae579223 MS |
31 | final float BBY = BassBox.EDGE_HEIGHT + BoothFloor.PLEXI_WIDTH; |
32 | final float BBX = 56; | |
33 | final float BBZ = 2; | |
34 | ||
46fc29d4 MS |
35 | // The model is represented as an array of towers. The cubes in the tower |
36 | // are represenented relatively. Each tower has an x, y, z reference position, | |
37 | // which is typically the base cube's bottom left corner. | |
38 | // | |
39 | // Following that is an array of floats. A 2-d array contains an x-offset | |
f0cc0ba5 MS |
40 | // and a z-offset from the previous reference position. Typically the first cube |
41 | // will just be {0, 0}. Each successive cube uses the position of the previous | |
42 | // cube as its reference. | |
46fc29d4 MS |
43 | // |
44 | // A 3-d array contains an x-offset, a z-offset, and a rotation about the | |
45 | // y-axis. | |
46 | // | |
47 | // The cubes automatically increment their y-position by Cube.EDGE_HEIGHT. | |
e27a8652 | 48 | |
73687629 | 49 | // To-Do: (Mark Slee, Alex Green, or Ben Morrow): The Cube # is determined by the order in this list. |
50 | // "raw object index" is serialized by running through towermapping and then individual cube mapping below. | |
51 | // We can do better than this. The raw object index should be obvious from the code-- looking through the | |
52 | // rendered simulation and counting through cubes in mapping mode is grossly inefficient. | |
e28f168c | 53 | |
7697e5c6 | 54 | |
55 | //////////////////////////////////////////////////////////////////////// | |
56 | // dan's proposed lattice | |
57 | ArrayList<StaggeredTower> scubes = new ArrayList<StaggeredTower>(); | |
41c436e4 | 58 | // if (NumBackTowers != 9) exit(); |
7697e5c6 | 59 | for (int i=0; i<NumBackTowers; i++) scubes.add(new StaggeredTower( |
60 | (i+1)*CW, // x | |
61 | (i % 2 == 0) ? 0 : CH * 2./3. , // y | |
62 | - ((i % 2 == 0) ? 0 : 11) + 97 , // z | |
63 | -135, (i % 2 == 0) ? MaxCubeHeight : MaxCubeHeight-1) ); // num cubes | |
64 | ||
65 | ArrayList<Cube> dcubes = new ArrayList<Cube>(); | |
66 | for (int i=1; i<6; i++) { | |
67 | if (i>1) dcubes.add(new Cube(-6+CW*4/3*i , 0, 0, 0, 0, 0, WRR)); | |
68 | dcubes.add(new Cube(-6+CW*4/3*i+CW*2/3., CH*.5, 0, 0, 0, 0, WRR)); | |
69 | } | |
70 | ||
71 | ||
73687629 | 72 | TowerMapping[] towerCubes = new TowerMapping[] {}; |
f0cc0ba5 MS |
73 | |
74 | // Single cubes can be constructed directly here if you need them | |
75 | Cube[] singleCubes = new Cube[] { | |
e5308763 | 76 | //new Cube(15, int( Cube.EDGE_HEIGHT), 39, 0, 10, 0, WRL), // Back left channel behind speaker |
f1370a0b | 77 | //new Cube(x, y, z, rx, ry, rz, wiring), |
e5308763 | 78 | //new Cube(0,0,0,0,-135,0, WRR), |
f0cc0ba5 MS |
79 | }; |
80 | ||
81 | // The bass box! | |
73687629 | 82 | // BassBox bassBox = BassBox.unlitBassBox(BBX, 0, BBZ); // frame exists, no lights |
83 | BassBox bassBox = BassBox.noBassBox(); // no bass box at all | |
e89eda9f | 84 | // BassBox bassBox = new BassBox(BBX, 0, BBZ); // bass box with lights |
e28f168c | 85 | |
f0cc0ba5 | 86 | // The speakers! |
3b2e0b4a MS |
87 | List<Speaker> speakers = Arrays.asList(new Speaker[] { |
88 | // Each speaker parameter is x, y, z, rotation, the left speaker comes first | |
73687629 | 89 | // new Speaker(TRAILER_WIDTH - Speaker.EDGE_WIDTH + 8, 6, 3, -15) |
3b2e0b4a | 90 | }); |
f0cc0ba5 | 91 | |
a3ccf23a MS |
92 | ////////////////////////////////////////////////////////////////////// |
93 | // BENEATH HERE SHOULD NOT REQUIRE ANY MODIFICATION!!!! // | |
94 | ////////////////////////////////////////////////////////////////////// | |
95 | ||
f0cc0ba5 | 96 | // These guts just convert the shorthand mappings into usable objects |
46fc29d4 MS |
97 | ArrayList<Tower> towerList = new ArrayList<Tower>(); |
98 | ArrayList<Cube> tower; | |
7e3329d2 | 99 | Cube[] cubes = new Cube[100]; |
46fc29d4 | 100 | int cubeIndex = 1; |
f0cc0ba5 MS |
101 | float px, pz, ny; |
102 | for (TowerMapping tm : towerCubes) { | |
103 | px = tm.x; | |
104 | ny = tm.y; | |
105 | pz = tm.z; | |
46fc29d4 | 106 | tower = new ArrayList<Cube>(); |
f0cc0ba5 MS |
107 | for (CubeMapping cm : tm.cubeMappings) { |
108 | tower.add(cubes[cubeIndex++] = new Cube(px = px + cm.dx, ny, pz = pz + cm.dz, 0, cm.ry, 0, cm.wiring)); | |
109 | ny += Cube.EDGE_HEIGHT; | |
46fc29d4 MS |
110 | } |
111 | towerList.add(new Tower(tower)); | |
112 | } | |
73687629 | 113 | |
f1370a0b AG |
114 | |
115 | for (Cube cube : singleCubes) cubes[cubeIndex++] = cube; | |
116 | for (Cube cube : dcubes) cubes[cubeIndex++] = cube; | |
117 | for (StaggeredTower st : scubes) { | |
73687629 | 118 | tower = new ArrayList<Cube>(); |
119 | for (int i=0; i < st.n; i++) | |
120 | tower.add(cubes[cubeIndex++] = new Cube(st.x, st.y + CH* 4/3.*i, st.z, 0, st.r, 0, WRR)); | |
121 | towerList.add(new Tower(tower)); | |
f0cc0ba5 | 122 | } |
e76480d4 | 123 | |
7dceead9 | 124 | return new Model(towerList, cubes, bassBox, speakers); |
186bc4d3 | 125 | } |
e73ef85d | 126 | |
a3ccf23a MS |
127 | /** |
128 | * This function maps the panda boards. We have an array of them, each has | |
129 | * an IP address and a list of channels. | |
130 | */ | |
186bc4d3 | 131 | public PandaMapping[] buildPandaList() { |
1d75c8a9 MS |
132 | final int LEFT_SPEAKER = 0; |
133 | final int RIGHT_SPEAKER = 1; | |
134 | ||
3b2e0b4a | 135 | // 8 channels map to: 3, 4, 7, 8, 13, 14, 15, 16. |
186bc4d3 | 136 | return new PandaMapping[] { |
73687629 | 137 | // new PandaMapping( |
138 | // "10.200.1.30", new ChannelMapping[] { | |
139 | // new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 39, 40, 41, 42 }), // 30 J3 * | |
140 | // new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 37, 38, 36, 35}), // 30 J4 //ORIG * | |
141 | // new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { }), // 30 J7 * | |
142 | // new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 16, 17, 18, 19}), // 30 J8 * | |
143 | // new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { }), // 30 J13 (not working) | |
144 | // new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { }), // 30 J14 (unplugged) | |
145 | // new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { }), // 30 J15 (unplugged) | |
146 | // new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 53, 54, 55, 72 }), // 30 J16 | |
147 | // }), | |
41c436e4 AK |
148 | // new PandaMapping( |
149 | // "10.200.1.29", new ChannelMapping[] { | |
150 | // new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 1,2,3,4}), // 29 J3 (not connected) | |
151 | // new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 1,2,3,4 }), // 29 J4 (not connected) | |
152 | // new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 1,2,3,4}), // 29 J7 | |
153 | // new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 1,2,3,4}), // 29 J8 //XXX | |
154 | // new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 8,9,10}), // 29 J13 //XX //bassbox (not working) | |
155 | // new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 8,9,10 }), // 29 J14 (not working) | |
156 | // new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 14,15,16,17 }), // 29 J15 | |
157 | // new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 14,15,16,17 }), // 29 J16 | |
158 | // }), | |
7c7625ec | 159 | new PandaMapping( |
41c436e4 AK |
160 | "10.200.1.30", new ChannelMapping[] { |
161 | new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 11, 12, 13, 14}), // J3 | |
162 | new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { }), // J4 | |
163 | new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 20, 21, 22, 23}), // J7 | |
164 | new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 29 ,30, 31, 32}), // J8 | |
165 | new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 38, 39, 40, 41}), // J13 | |
166 | new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 47, 48, 49, 50}), // J14 | |
167 | new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 56, 57, 58, 59}), // J15 | |
168 | new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 55, 46, 37}), // J16 | |
73687629 | 169 | }), |
41c436e4 AK |
170 | new PandaMapping( |
171 | "10.200.1.31", new ChannelMapping[] { | |
172 | new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 15, 16, 17, 18}), // J3 | |
173 | new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { }), // J4 | |
174 | new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 24, 25, 26, 27}), // J7 | |
175 | new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 33, 34, 35, 36}), // J8 | |
176 | new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 42, 43, 44, 45}), // J13 | |
177 | new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 51, 52, 53, 54}), // J14 | |
178 | new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 28, 19, 10}), // J15 | |
179 | new ChannelMapping(ChannelMapping.MODE_CUBES, new int[] { 11, 12, 13, 14}), // J16 | |
180 | }), | |
3b2e0b4a | 181 | }; |
45f43cc2 | 182 | } |
e73ef85d | 183 | |
f0cc0ba5 MS |
184 | class TowerMapping { |
185 | public final float x, y, z; | |
186 | public final CubeMapping[] cubeMappings; | |
187 | ||
188 | TowerMapping(float x, float y, float z, CubeMapping[] cubeMappings) { | |
189 | this.x = x; | |
190 | this.y = y; | |
191 | this.z = z; | |
192 | this.cubeMappings = cubeMappings; | |
193 | } | |
194 | } | |
195 | ||
196 | class CubeMapping { | |
197 | public final float dx, dz, ry; | |
198 | public final Cube.Wiring wiring; | |
199 | ||
200 | CubeMapping(float dx, float dz, Cube.Wiring wiring) { | |
73687629 | 201 | this(dx, dz, 0., wiring); |
f0cc0ba5 | 202 | } |
f0cc0ba5 MS |
203 | CubeMapping(float dx, float dz, float ry) { |
204 | this(dz, dz, ry, Cube.Wiring.FRONT_LEFT); | |
205 | } | |
206 | ||
207 | CubeMapping(float dx, float dz, float ry, Cube.Wiring wiring) { | |
208 | this.dx = dx; | |
209 | this.dz = dz; | |
210 | this.ry = ry; | |
211 | this.wiring = wiring; | |
212 | } | |
213 | } | |
214 | ||
73687629 | 215 | class StaggeredTower { |
216 | public final float x, y, z, r; | |
217 | public final int n; | |
218 | StaggeredTower(float _x, float _y, float _z, float _r, int _n) { x=_x; y=_y; z=_z; r=_r; n=_n;} | |
219 | } | |
220 | ||
a922e963 MS |
221 | /** |
222 | * Each panda board has an IP address and a fixed number of channels. The channels | |
223 | * each have a fixed number of pixels on them. Whether or not that many physical | |
224 | * pixels are connected to the channel, we still send it that much data. | |
225 | */ | |
45f43cc2 MS |
226 | class PandaMapping { |
227 | ||
045b432d | 228 | // How many channels are on the panda board |
e28f168c | 229 | public final static int CHANNELS_PER_BOARD = 8; |
045b432d | 230 | |
44b8de9c | 231 | // How many total pixels on the whole board |
84086fa3 | 232 | public final static int PIXELS_PER_BOARD = ChannelMapping.PIXELS_PER_CHANNEL * CHANNELS_PER_BOARD; |
44b8de9c | 233 | |
45f43cc2 | 234 | final String ip; |
84086fa3 | 235 | final ChannelMapping[] channelList = new ChannelMapping[CHANNELS_PER_BOARD]; |
45f43cc2 | 236 | |
84086fa3 | 237 | PandaMapping(String ip, ChannelMapping[] rawChannelList) { |
45f43cc2 | 238 | this.ip = ip; |
a922e963 MS |
239 | |
240 | // Ensure our array is the right length and has all valid items in it | |
84086fa3 MS |
241 | for (int i = 0; i < channelList.length; ++i) { |
242 | channelList[i] = (i < rawChannelList.length) ? rawChannelList[i] : new ChannelMapping(); | |
a922e963 MS |
243 | if (channelList[i] == null) { |
244 | channelList[i] = new ChannelMapping(); | |
245 | } | |
045b432d | 246 | } |
e73ef85d | 247 | } |
1ecdb44a MS |
248 | } |
249 | ||
a922e963 | 250 | /** |
e27a8652 | 251 | * Each channel on a pandaboard can be mapped in a number of modes. The typical is |
a922e963 MS |
252 | * to a series of connected cubes, but we also have special mappings for the bass box, |
253 | * the speaker enclosures, and the DJ booth floor. | |
254 | * | |
255 | * This class is just the mapping meta-data. It sanitizes the input to make sure | |
256 | * that the cubes and objects being referenced actually exist in the model. | |
257 | * | |
258 | * The logic for how to encode the pixels is contained in the PandaDriver. | |
259 | */ | |
84086fa3 MS |
260 | class ChannelMapping { |
261 | ||
262 | // How many cubes per channel xc_PB is configured for | |
263 | public final static int CUBES_PER_CHANNEL = 4; | |
45f43cc2 | 264 | |
84086fa3 MS |
265 | // How many total pixels on each channel |
266 | public final static int PIXELS_PER_CHANNEL = Cube.POINTS_PER_CUBE * CUBES_PER_CHANNEL; | |
267 | ||
268 | public static final int MODE_NULL = 0; | |
269 | public static final int MODE_CUBES = 1; | |
270 | public static final int MODE_BASS = 2; | |
271 | public static final int MODE_SPEAKER = 3; | |
1d75c8a9 | 272 | public static final int MODE_STRUTS_AND_FLOOR = 4; |
84086fa3 MS |
273 | public static final int MODE_INVALID = 5; |
274 | ||
275 | public static final int NO_OBJECT = -1; | |
276 | ||
277 | final int mode; | |
278 | final int[] objectIndices = new int[CUBES_PER_CHANNEL]; | |
279 | ||
280 | ChannelMapping() { | |
281 | this(MODE_NULL); | |
282 | } | |
283 | ||
284 | ChannelMapping(int mode) { | |
285 | this(mode, new int[]{}); | |
286 | } | |
287 | ||
288 | ChannelMapping(int mode, int rawObjectIndex) { | |
289 | this(mode, new int[]{ rawObjectIndex }); | |
290 | } | |
291 | ||
292 | ChannelMapping(int mode, int[] rawObjectIndices) { | |
293 | if (mode < 0 || mode >= MODE_INVALID) { | |
294 | throw new RuntimeException("Invalid channel mapping mode: " + mode); | |
295 | } | |
296 | if (mode == MODE_SPEAKER) { | |
297 | if (rawObjectIndices.length != 1) { | |
298 | throw new RuntimeException("Speaker channel mapping mode must specify one speaker index"); | |
299 | } | |
300 | int speakerIndex = rawObjectIndices[0]; | |
301 | if (speakerIndex < 0 || speakerIndex >= glucose.model.speakers.size()) { | |
3b2e0b4a | 302 | throw new RuntimeException("Invalid speaker channel mapping: " + speakerIndex); |
84086fa3 | 303 | } |
1d75c8a9 | 304 | } else if ((mode == MODE_STRUTS_AND_FLOOR) || (mode == MODE_BASS) || (mode == MODE_NULL)) { |
84086fa3 | 305 | if (rawObjectIndices.length > 0) { |
3b2e0b4a | 306 | throw new RuntimeException("Bass/floor/null mappings cannot specify object indices"); |
84086fa3 MS |
307 | } |
308 | } else if (mode == MODE_CUBES) { | |
309 | for (int rawCubeIndex : rawObjectIndices) { | |
310 | if (glucose.model.getCubeByRawIndex(rawCubeIndex) == null) { | |
311 | throw new RuntimeException("Non-existing cube specified in cube mapping: " + rawCubeIndex); | |
312 | } | |
313 | } | |
314 | } | |
315 | ||
316 | this.mode = mode; | |
317 | for (int i = 0; i < objectIndices.length; ++i) { | |
318 | objectIndices[i] = (i < rawObjectIndices.length) ? rawObjectIndices[i] : NO_OBJECT; | |
319 | } | |
320 | } | |
321 | } |