From e18b4cb735a6e1f2d6cb2e7b1709d4a575cfe795 Mon Sep 17 00:00:00 2001 From: Mark Slee Date: Tue, 25 Feb 2014 00:11:13 -0800 Subject: [PATCH] More mapping cleanup, got rid of tons of mess code, clean definitions now --- TestPatterns.pde | 2 +- _Internals.pde | 246 +++++++++++++++--------------------------- _Mappings.pde | 239 +++++++++------------------------------- _UIImplementation.pde | 2 +- 4 files changed, 138 insertions(+), 351 deletions(-) diff --git a/TestPatterns.pde b/TestPatterns.pde index 80754a6..d76aeda 100644 --- a/TestPatterns.pde +++ b/TestPatterns.pde @@ -318,7 +318,7 @@ class MappingTool extends TestPattern { MappingTool(GLucose glucose) { super(glucose); // TODO(mcslee): port channels to grizzly - numChannels = 0; + numChannels = 1; setChannel(); } diff --git a/_Internals.pde b/_Internals.pde index 7eb5f93..6e985f1 100644 --- a/_Internals.pde +++ b/_Internals.pde @@ -35,8 +35,8 @@ final int VIEWPORT_WIDTH = 900; final int VIEWPORT_HEIGHT = 700; // The trailer is measured from the outside of the black metal (but not including the higher welded part on the front) -final float TRAILER_WIDTH = 240; -final float TRAILER_DEPTH = 97; +final float TRAILER_WIDTH = 192; +final float TRAILER_DEPTH = 192; final float TRAILER_HEIGHT = 33; int targetFramerate = 60; @@ -169,7 +169,7 @@ void setup() { UILayer[] layers = new UILayer[] { // Camera layer new UICameraLayer(lx.ui) - .setCenter(TRAILER_WIDTH/2., glucose.model.yMax/2, TRAILER_DEPTH/2.) + .setCenter(model.cx, model.cy, model.cz) .setRadius(290).addComponent(new UICubesLayer()), // Left controls @@ -205,6 +205,8 @@ void setup() { println("Hit the 'o' key to toggle live output"); } +long simulationNanos = 0; + /** * Core render loop and drawing functionality. */ @@ -231,8 +233,8 @@ void draw() { // TODO(mcslee): fix long drawNanos = System.nanoTime() - drawStart; - - long simulationNanos = 0, uiNanos = 0; + long uiNanos = 0; + if (diagnosticsOn) { drawDiagnostics(drawNanos, simulationNanos, uiNanos, gammaNanos); } @@ -252,14 +254,91 @@ class UICubesLayer extends UICameraComponent { if (simulationOn) { drawSimulation(simulationColors); } - long simulationNanos = System.nanoTime() - simulationStart; + simulationNanos = System.nanoTime() - simulationStart; camera(); javax.media.opengl.GL gl = ((PGraphicsOpenGL)g).beginGL(); gl.glClear(javax.media.opengl.GL.GL_DEPTH_BUFFER_BIT); ((PGraphicsOpenGL)g).endGL(); strokeWeight(1); - } + } + + void drawSimulation(color[] simulationColors) { + translate(0, 30, 0); + + noStroke(); + fill(#141414); + drawBox(0, -TRAILER_HEIGHT, 0, 0, 0, 0, TRAILER_WIDTH, TRAILER_HEIGHT, TRAILER_DEPTH, TRAILER_HEIGHT/2.); + fill(#070707); + stroke(#222222); + beginShape(); + vertex(0, 0, 0); + vertex(TRAILER_WIDTH, 0, 0); + vertex(TRAILER_WIDTH, 0, TRAILER_DEPTH); + vertex(0, 0, TRAILER_DEPTH); + endShape(); + + // Draw the logo on the front of platform + pushMatrix(); + translate(0, 0, -1); + float s = .07; + scale(s, -s, s); + image(logo, TRAILER_WIDTH/2/s-logo.width/2, TRAILER_HEIGHT/2/s-logo.height/2-2/s); + popMatrix(); + + noStroke(); + for (Cube c : glucose.model.cubes) { + drawCube(c); + } + + noFill(); + strokeWeight(2); + beginShape(POINTS); + for (LXPoint p : glucose.model.points) { + stroke(simulationColors[p.index]); + vertex(p.x, p.y, p.z); + } + endShape(); + } + + void drawCube(Cube c) { + float in = .15; + noStroke(); + fill(#393939); + drawBox(c.x+in, c.y+in, c.z+in, c.rx, c.ry, c.rz, Cube.EDGE_WIDTH-in*2, Cube.EDGE_HEIGHT-in*2, Cube.EDGE_WIDTH-in*2, Cube.CHANNEL_WIDTH-in); + } + + void drawBox(float x, float y, float z, float rx, float ry, float rz, float xd, float yd, float zd, float sw) { + pushMatrix(); + translate(x, y, z); + rotate(rx / 180. * PI, -1, 0, 0); + rotate(ry / 180. * PI, 0, -1, 0); + rotate(rz / 180. * PI, 0, 0, -1); + for (int i = 0; i < 4; ++i) { + float wid = (i % 2 == 0) ? xd : zd; + + beginShape(); + vertex(0, 0); + vertex(wid, 0); + vertex(wid, yd); + vertex(wid - sw, yd); + vertex(wid - sw, sw); + vertex(0, sw); + endShape(); + beginShape(); + vertex(0, sw); + vertex(0, yd); + vertex(wid - sw, yd); + vertex(wid - sw, yd - sw); + vertex(sw, yd - sw); + vertex(sw, sw); + endShape(); + + translate(wid, 0, 0); + rotate(HALF_PI, 0, -1, 0); + } + popMatrix(); + } } void drawDiagnostics(long drawNanos, long simulationNanos, long uiNanos, long gammaNanos) { @@ -319,159 +398,6 @@ void drawDiagnostics(long drawNanos, long simulationNanos, long uiNanos, long ga } } -void drawSimulation(color[] simulationColors) { - translate(0, 40, 0); - - noStroke(); - fill(#141414); - drawBox(0, -TRAILER_HEIGHT, 0, 0, 0, 0, TRAILER_WIDTH, TRAILER_HEIGHT, TRAILER_DEPTH, TRAILER_HEIGHT/2.); - fill(#070707); - stroke(#222222); - beginShape(); - vertex(0, 0, 0); - vertex(TRAILER_WIDTH, 0, 0); - vertex(TRAILER_WIDTH, 0, TRAILER_DEPTH); - vertex(0, 0, TRAILER_DEPTH); - endShape(); - - // Draw the logo on the front of platform - pushMatrix(); - translate(0, 0, -1); - float s = .07; - scale(s, -s, s); - image(logo, TRAILER_WIDTH/2/s-logo.width/2, TRAILER_HEIGHT/2/s-logo.height/2-2/s); - popMatrix(); - - noStroke(); - if (glucose.model.bassBox.exists) { - drawBassBox(glucose.model.bassBox, false); - } - for (Speaker speaker : glucose.model.speakers) { - drawSpeaker(speaker); - } - for (Cube c : glucose.model.cubes) { - drawCube(c); - } - - noFill(); - strokeWeight(2); - beginShape(POINTS); - for (LXPoint p : glucose.model.points) { - stroke(simulationColors[p.index]); - vertex(p.x, p.y, p.z); - } - endShape(); -} - -void drawBassBox(BassBox b, boolean hasSub) { - - float in = .15; - - if (hasSub) { - noStroke(); - fill(#191919); - pushMatrix(); - translate(b.x + BassBox.EDGE_WIDTH/2., b.y + BassBox.EDGE_HEIGHT/2, b.z + BassBox.EDGE_DEPTH/2.); - box(BassBox.EDGE_WIDTH-20*in, BassBox.EDGE_HEIGHT-20*in, BassBox.EDGE_DEPTH-20*in); - popMatrix(); - } - - noStroke(); - fill(#393939); - drawBox(b.x+in, b.y+in, b.z+in, 0, 0, 0, BassBox.EDGE_WIDTH-in*2, BassBox.EDGE_HEIGHT-in*2, BassBox.EDGE_DEPTH-in*2, Cube.CHANNEL_WIDTH-in); - - pushMatrix(); - translate(b.x+(Cube.CHANNEL_WIDTH-in)/2., b.y + BassBox.EDGE_HEIGHT-in, b.z + BassBox.EDGE_DEPTH/2.); - float lastOffset = 0; - for (float offset : BoothFloor.STRIP_OFFSETS) { - translate(offset - lastOffset, 0, 0); - box(Cube.CHANNEL_WIDTH-in, 0, BassBox.EDGE_DEPTH - 2*in); - lastOffset = offset; - } - popMatrix(); - - pushMatrix(); - translate(b.x + (Cube.CHANNEL_WIDTH-in)/2., b.y + BassBox.EDGE_HEIGHT/2., b.z + in); - for (int j = 0; j < 2; ++j) { - pushMatrix(); - for (int i = 0; i < BassBox.NUM_FRONT_STRUTS; ++i) { - translate(BassBox.FRONT_STRUT_SPACING, 0, 0); - box(Cube.CHANNEL_WIDTH-in, BassBox.EDGE_HEIGHT - in*2, 0); - } - popMatrix(); - translate(0, 0, BassBox.EDGE_DEPTH - 2*in); - } - popMatrix(); - - pushMatrix(); - translate(b.x + in, b.y + BassBox.EDGE_HEIGHT/2., b.z + BassBox.SIDE_STRUT_SPACING + (Cube.CHANNEL_WIDTH-in)/2.); - box(0, BassBox.EDGE_HEIGHT - in*2, Cube.CHANNEL_WIDTH-in); - translate(BassBox.EDGE_WIDTH-2*in, 0, 0); - box(0, BassBox.EDGE_HEIGHT - in*2, Cube.CHANNEL_WIDTH-in); - popMatrix(); - -} - -void drawCube(Cube c) { - float in = .15; - noStroke(); - fill(#393939); - drawBox(c.x+in, c.y+in, c.z+in, c.rx, c.ry, c.rz, Cube.EDGE_WIDTH-in*2, Cube.EDGE_HEIGHT-in*2, Cube.EDGE_WIDTH-in*2, Cube.CHANNEL_WIDTH-in); -} - -void drawSpeaker(Speaker s) { - float in = .15; - - noStroke(); - fill(#191919); - pushMatrix(); - translate(s.x, s.y, s.z); - rotate(s.ry / 180. * PI, 0, -1, 0); - translate(Speaker.EDGE_WIDTH/2., Speaker.EDGE_HEIGHT/2., Speaker.EDGE_DEPTH/2.); - box(Speaker.EDGE_WIDTH-20*in, Speaker.EDGE_HEIGHT-20*in, Speaker.EDGE_DEPTH-20*in); - translate(0, Speaker.EDGE_HEIGHT/2. + Speaker.EDGE_HEIGHT*.8/2, 0); - - fill(#222222); - box(Speaker.EDGE_WIDTH*.6, Speaker.EDGE_HEIGHT*.8, Speaker.EDGE_DEPTH*.75); - popMatrix(); - - noStroke(); - fill(#393939); - drawBox(s.x+in, s.y+in, s.z+in, 0, s.ry, 0, Speaker.EDGE_WIDTH-in*2, Speaker.EDGE_HEIGHT-in*2, Speaker.EDGE_DEPTH-in*2, Cube.CHANNEL_WIDTH-in); -} - -void drawBox(float x, float y, float z, float rx, float ry, float rz, float xd, float yd, float zd, float sw) { - pushMatrix(); - translate(x, y, z); - rotate(rx / 180. * PI, -1, 0, 0); - rotate(ry / 180. * PI, 0, -1, 0); - rotate(rz / 180. * PI, 0, 0, -1); - for (int i = 0; i < 4; ++i) { - float wid = (i % 2 == 0) ? xd : zd; - - beginShape(); - vertex(0, 0); - vertex(wid, 0); - vertex(wid, yd); - vertex(wid - sw, yd); - vertex(wid - sw, sw); - vertex(0, sw); - endShape(); - beginShape(); - vertex(0, sw); - vertex(0, yd); - vertex(wid - sw, yd); - vertex(wid - sw, yd - sw); - vertex(sw, yd - sw); - vertex(sw, sw); - endShape(); - - translate(wid, 0, 0); - rotate(HALF_PI, 0, -1, 0); - } - popMatrix(); -} - void drawFPS() { // Always draw FPS meter fill(#555555); diff --git a/_Mappings.pde b/_Mappings.pde index bb5c438..53ff889 100644 --- a/_Mappings.pde +++ b/_Mappings.pde @@ -13,204 +13,65 @@ * when physical changes or tuning is being done to the structure. */ -public Model buildModel() { - - // Shorthand helpers for specifying wiring more quickly - final Cube.Wiring WFL = Cube.Wiring.FRONT_LEFT; - final Cube.Wiring WFR = Cube.Wiring.FRONT_RIGHT; - final Cube.Wiring WRL = Cube.Wiring.REAR_LEFT; - final Cube.Wiring WRR = Cube.Wiring.REAR_RIGHT; - - // Utility value if you need the height of a cube shorthand - final float CH = Cube.EDGE_HEIGHT; - final float CW = Cube.EDGE_WIDTH ; +static final float SPACING = 27; +static final float RISER = 13.5; +static final float FLOOR = 0; - // Positions for the bass box - final float BBY = BassBox.EDGE_HEIGHT + BoothFloor.PLEXI_WIDTH; - final float BBX = 56; - final float BBZ = 2; +/** + * Definitions of tower positions. This is all that should need + * to be modified. Distances are measured from the left-most cube. + * The first value is the offset moving NE (towards back-right). + * The second value is the offset moving NW (negative comes forward-right). + */ +static final float[][] TOWER_CONFIG = new float[][] { + // x, z, y, # + new float[] { 0, 0, RISER, 4 }, + new float[] { 25, -10, RISER, 4 }, + new float[] { 50, -22.5, FLOOR, 5 }, + new float[] { 17.25, -35.5, FLOOR, 6 }, + new float[] { 43.25, -51.5, RISER, 6 }, + new float[] { 69.25, -56, FLOOR, 6 }, + new float[] { 12.75, -62.5, RISER, 4 }, + new float[] { 38.75, -78.5, FLOOR, 5 }, + new float[] { 65.75, -83, RISER, 5 }, + +}; - // The model is represented as an array of towers. The cubes in the tower - // are represenented relatively. Each tower has an x, y, z reference position, - // which is typically the base cube's bottom left corner. - // - // Following that is an array of floats. A 2-d array contains an x-offset - // and a z-offset from the previous reference position. Typically the first cube - // will just be {0, 0}. Each successive cube uses the position of the previous - // cube as its reference. - // - // A 3-d array contains an x-offset, a z-offset, and a rotation about the - // y-axis. - // - // The cubes automatically increment their y-position by Cube.EDGE_HEIGHT. +public Model buildModel() { - // To-Do: (Mark Slee, Alex Green, or Ben Morrow): The Cube # is determined by the order in this list. + // TODO: (Mark Slee, Alex Green, or Ben Morrow): The Cube # is determined by the order in this list. // "raw object index" is serialized by running through towermapping and then individual cube mapping below. // We can do better than this. The raw object index should be obvious from the code-- looking through the // rendered simulation and counting through cubes in mapping mode is grossly inefficient. - - // Single cubes can be constructed directly here if you need them - Cube[] singleCubes = new Cube[] { - // new Cube(15, int( Cube.EDGE_HEIGHT), 39, 0, 10, 0, WRL), // Back left channel behind speaker - // new Cube(x, y, z, rx, ry, rz, wiring), - // new Cube(0,0,0,0,225,0, WRR), - }; - - // The bass box! - BassBox bassBox = BassBox.noBassBox(); // no bass box at all - - // The speakers! - List speakers = Arrays.asList(new Speaker[] { - // Each speaker parameter is x, y, z, rotation, the left speaker comes first - // new Speaker(TRAILER_WIDTH - Speaker.EDGE_WIDTH + 8, 6, 3, -15) - } - ); - - List scubes = new ArrayList(); - - float[] pos = new float[3]; - pos[0] = 50; - pos[2] = 100; - scubes.add(new StaggeredTower(//tower 1 - pos[0], // x - 0, // y - pos[2], // z - 0, 4, new Cube.Wiring[] { - WRR, WRR, WRR, WRR, WRR, WRR - } - )); - - - pos[0] += 25; - pos[2] -= 10; - scubes.add(new StaggeredTower(// tower 2 - pos[0], // x - 15, // y - pos[2], // z - 0, 4, new Cube.Wiring[] { - WRR, WRR, WRR, WRR, WRR, WRR - } - )); - - pos[0] += 25; - pos[2] += -12.5; - scubes.add(new StaggeredTower(//tower 3 - pos[0], // x - 0, // y - pos[2], // z - 0, 5, new Cube.Wiring[] { - WRR, WRR, WRR, WRR, WRR, WRR - } - )); - - pos[0] += -32.75; - pos[2] += -13; - scubes.add(new StaggeredTower(//tower 4 - pos[0], // x - 0, // y - pos[2], // z - 0, 6, new Cube.Wiring[] { - WRR, WRR, WRR, WRR, WRR, WRR - } - )); - - pos[0] += 26; - pos[2] += -16; - scubes.add(new StaggeredTower(//tower 5 - pos[0], // x - 15, // y - pos[2], // z - 0, 6, new Cube.Wiring[] { - WRR, WRR, WRR, WRR, WRR, WRR - } - )); - - pos[0] += 26; - pos[2] += -4.5; - scubes.add(new StaggeredTower(//tower 6 - pos[0], // x - 0, // y - pos[2], // z - 0, 6, new Cube.Wiring[] { - WRR, WRR, WRR, WRR, WRR, WRR - } - )); - - pos[0] += -56.5; - pos[2] += -6.5; - scubes.add(new StaggeredTower(// tower 7 - pos[0], // x - 15, // y - pos[2], // z - 0, 4, new Cube.Wiring[] { - WRR, WRR, WRR, WRR, WRR, WRR - } - )); - - pos[0] += 26; - pos[2] += -16.5; - scubes.add(new StaggeredTower(//tower 8 - pos[0], // x - 0, // y - pos[2], // z - 0, 5, new Cube.Wiring[] { - WRR, WRR, WRR, WRR, WRR, WRR - } - )); - - pos[0] += 27; - pos[2] += -4.5; - scubes.add(new StaggeredTower(//tower 9 - pos[0], // x - 15, // y - pos[2], // z - 0, 5, new Cube.Wiring[] { - WRR, WRR, WRR, WRR, WRR, WRR - } - )); - - - ////////////////////////////////////////////////////////////////////// - // BENEATH HERE SHOULD NOT REQUIRE ANY MODIFICATION!!!! // - ////////////////////////////////////////////////////////////////////// - - // These guts just convert the shorthand mappings into usable objects - List towerList = new ArrayList(); - List tower; + + List towers = new ArrayList(); Cube[] cubes = new Cube[200]; - int cubeIndex = 1; - - for (Cube cube : singleCubes) { - cubes[cubeIndex++] = cube; - } - for (StaggeredTower st : scubes) { - tower = new ArrayList(); - for (int i = 0; i < st.n; i++) { - Cube.Wiring w = (i < st.wiring.length) ? st.wiring[i] : WRR; - tower.add(cubes[cubeIndex++] = new Cube(st.x, st.y + CH* 4/3.*i, st.z, 0, st.r, 0, w)); + int cubeIndex = 1; + + float rt2 = sqrt(2); + float x, y, z, xd, zd, num; + for (float[] tc : TOWER_CONFIG) { + x = -tc[1]; + z = tc[0]; + y = tc[2]; + num = tc[3]; + if (z < x) { + zd = -(x-z)/rt2; + xd = z*rt2 - zd; + } else { + zd = (z-x)/rt2; + xd = z*rt2 - zd; } - towerList.add(new Tower(tower)); - } - - return new Model(towerList, cubes, bassBox, speakers); -} - -class StaggeredTower { - public final float x, y, z, r; - public final int n; - public final Cube.Wiring[] wiring; - StaggeredTower(float _x, float _y, float _z, float _r, int _n) { - this(_x, _y, _z, _r, _n, new Cube.Wiring[] { + List tower = new ArrayList(); + for (int n = 0; n < num; ++n) { + Cube cube = new Cube(xd + 24, y, zd + 84, 0, -45, 0); + tower.add(cube); + cubes[cubeIndex++] = cube; + y += SPACING; } - ); - } - 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; + towers.add(new Tower(tower)); } + + return new Model(towers, cubes, BassBox.noBassBox(), new ArrayList()); } diff --git a/_UIImplementation.pde b/_UIImplementation.pde index 32c654e..c749ad4 100644 --- a/_UIImplementation.pde +++ b/_UIImplementation.pde @@ -273,7 +273,7 @@ class UIMapping extends UIWindow { protected void onValueChange(int value) { mappingTool.setChannel(value-1); } - }).setRange(0, mappingTool.numChannels()).addToContainer(this); + }).setRange(1, mappingTool.numChannels()).addToContainer(this); yp += 24; new UILabel(4, yp+8, w-10, 20).setLabel("CUBE ID").addToContainer(this); -- 2.34.1