Lots of code cleanup, removed Panda code, all grizzly, cleaning up mapping
[SugarCubes.git] / _Mappings.pde
1 /**
2 * DOUBLE BLACK DIAMOND DOUBLE BLACK DIAMOND
3 *
4 * //\\ //\\ //\\ //\\
5 * ///\\\ ///\\\ ///\\\ ///\\\
6 * \\\/// \\\/// \\\/// \\\///
7 * \\// \\// \\// \\//
8 *
9 * EXPERTS ONLY!! EXPERTS ONLY!!
10 *
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.
14 */
15
16 public Model buildModel() {
17
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;
23
24 // Utility value if you need the height of a cube shorthand
25 final float CH = Cube.EDGE_HEIGHT;
26 final float CW = Cube.EDGE_WIDTH ;
27
28 // Positions for the bass box
29 final float BBY = BassBox.EDGE_HEIGHT + BoothFloor.PLEXI_WIDTH;
30 final float BBX = 56;
31 final float BBZ = 2;
32
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
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.
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.
46
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.
51
52 // Single cubes can be constructed directly here if you need them
53 Cube[] singleCubes = new Cube[] {
54 // new Cube(15, int( Cube.EDGE_HEIGHT), 39, 0, 10, 0, WRL), // Back left channel behind speaker
55 // new Cube(x, y, z, rx, ry, rz, wiring),
56 // new Cube(0,0,0,0,225,0, WRR),
57 };
58
59 // The bass box!
60 BassBox bassBox = BassBox.noBassBox(); // no bass box at all
61
62 // The speakers!
63 List<Speaker> speakers = Arrays.asList(new Speaker[] {
64 // Each speaker parameter is x, y, z, rotation, the left speaker comes first
65 // new Speaker(TRAILER_WIDTH - Speaker.EDGE_WIDTH + 8, 6, 3, -15)
66 }
67 );
68
69 List<StaggeredTower> scubes = new ArrayList<StaggeredTower>();
70
71 float[] pos = new float[3];
72 pos[0] = 50;
73 pos[2] = 100;
74 scubes.add(new StaggeredTower(//tower 1
75 pos[0], // x
76 0, // y
77 pos[2], // z
78 0, 4, new Cube.Wiring[] {
79 WRR, WRR, WRR, WRR, WRR, WRR
80 }
81 ));
82
83
84 pos[0] += 25;
85 pos[2] -= 10;
86 scubes.add(new StaggeredTower(// tower 2
87 pos[0], // x
88 15, // y
89 pos[2], // z
90 0, 4, new Cube.Wiring[] {
91 WRR, WRR, WRR, WRR, WRR, WRR
92 }
93 ));
94
95 pos[0] += 25;
96 pos[2] += -12.5;
97 scubes.add(new StaggeredTower(//tower 3
98 pos[0], // x
99 0, // y
100 pos[2], // z
101 0, 5, new Cube.Wiring[] {
102 WRR, WRR, WRR, WRR, WRR, WRR
103 }
104 ));
105
106 pos[0] += -32.75;
107 pos[2] += -13;
108 scubes.add(new StaggeredTower(//tower 4
109 pos[0], // x
110 0, // y
111 pos[2], // z
112 0, 6, new Cube.Wiring[] {
113 WRR, WRR, WRR, WRR, WRR, WRR
114 }
115 ));
116
117 pos[0] += 26;
118 pos[2] += -16;
119 scubes.add(new StaggeredTower(//tower 5
120 pos[0], // x
121 15, // y
122 pos[2], // z
123 0, 6, new Cube.Wiring[] {
124 WRR, WRR, WRR, WRR, WRR, WRR
125 }
126 ));
127
128 pos[0] += 26;
129 pos[2] += -4.5;
130 scubes.add(new StaggeredTower(//tower 6
131 pos[0], // x
132 0, // y
133 pos[2], // z
134 0, 6, new Cube.Wiring[] {
135 WRR, WRR, WRR, WRR, WRR, WRR
136 }
137 ));
138
139 pos[0] += -56.5;
140 pos[2] += -6.5;
141 scubes.add(new StaggeredTower(// tower 7
142 pos[0], // x
143 15, // y
144 pos[2], // z
145 0, 4, new Cube.Wiring[] {
146 WRR, WRR, WRR, WRR, WRR, WRR
147 }
148 ));
149
150 pos[0] += 26;
151 pos[2] += -16.5;
152 scubes.add(new StaggeredTower(//tower 8
153 pos[0], // x
154 0, // y
155 pos[2], // z
156 0, 5, new Cube.Wiring[] {
157 WRR, WRR, WRR, WRR, WRR, WRR
158 }
159 ));
160
161 pos[0] += 27;
162 pos[2] += -4.5;
163 scubes.add(new StaggeredTower(//tower 9
164 pos[0], // x
165 15, // y
166 pos[2], // z
167 0, 5, new Cube.Wiring[] {
168 WRR, WRR, WRR, WRR, WRR, WRR
169 }
170 ));
171
172
173 //////////////////////////////////////////////////////////////////////
174 // BENEATH HERE SHOULD NOT REQUIRE ANY MODIFICATION!!!! //
175 //////////////////////////////////////////////////////////////////////
176
177 // These guts just convert the shorthand mappings into usable objects
178 List<Tower> towerList = new ArrayList<Tower>();
179 List<Cube> tower;
180 Cube[] cubes = new Cube[200];
181 int cubeIndex = 1;
182
183 for (Cube cube : singleCubes) {
184 cubes[cubeIndex++] = cube;
185 }
186 for (StaggeredTower st : scubes) {
187 tower = new ArrayList<Cube>();
188 for (int i = 0; i < st.n; i++) {
189 Cube.Wiring w = (i < st.wiring.length) ? st.wiring[i] : WRR;
190 tower.add(cubes[cubeIndex++] = new Cube(st.x, st.y + CH* 4/3.*i, st.z, 0, st.r, 0, w));
191 }
192 towerList.add(new Tower(tower));
193 }
194
195 return new Model(towerList, cubes, bassBox, speakers);
196 }
197
198 class StaggeredTower {
199 public final float x, y, z, r;
200 public final int n;
201 public final Cube.Wiring[] wiring;
202 StaggeredTower(float _x, float _y, float _z, float _r, int _n) {
203 this(_x, _y, _z, _r, _n, new Cube.Wiring[] {
204 }
205 );
206 }
207 StaggeredTower(float _x, float _y, float _z, float _r, int _n, Cube.Wiring[] _wiring) {
208 x=_x;
209 y=_y;
210 z=_z;
211 r=_r;
212 n=_n;
213 wiring=_wiring;
214 }
215 }
216