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