Commit 02563489 authored by Philip Levis's avatar Philip Levis
Browse files

Start adding support for drawing flyers on the stairwell.

This introduces a dependency between the Engine and Processing;
the Engine uses Processing's 3D Matrices to compute positions.
We may want to transition to Java3D or another approach.
It looks like Java3D requires a separate download, though,
so that would be one more dependency.
parent c0f45fd4
......@@ -53,10 +53,14 @@ class UIFlightDrawer extends UI3dComponent implements GeometryConstants {
}
protected void onDraw(UI ui, PGraphics pg) {
pg.pushMatrix();
drawBuilding(pg);
drawFlyers(pg);
pg.popMatrix();
try { pg.pushMatrix();
drawBuilding(pg);
drawFlyers(pg);
pg.popMatrix();
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
/**
......
......@@ -2,6 +2,6 @@
cd "$( dirname "$0" )"
mkdir -p build
javac -source 1.8 -target 1.8 -cp "lib/*:lib/lx/*" -d build src/*.java
javac -source 1.8 -target 1.8 -cp "lib/*:lib/lx/*:lib/lx/processing-3.5.4/*" -d build src/*.java
cd build
jar cf flight.jar *.class
......@@ -8,6 +8,7 @@ import java.util.ArrayList;
import heronarts.lx.model.LXModel;
import heronarts.lx.model.LXPoint;
import processing.core.PMatrix3D;
class Model implements GeometryConstants {
static FlightModel flight;
......@@ -366,7 +367,7 @@ class FlyerModel extends LXModel implements Flyer {
// VBAR_OFFSETS[4], and BACK_WALL_OFFSETS[3] == VBAR_OFFSETS[6].
private final float[] BACK_WALL_OFFSETS;
// StairEdgePoint describes how the stairwell moves through
// space. It's used to place Flyers along the stairwell.
// The fraction field describes how far along the stairwell this
......@@ -385,8 +386,20 @@ class FlyerModel extends LXModel implements Flyer {
this.y = y;
this.z = z;
}
StairEdgePoint(float faction, PMatrix3D matrix) {
this.fraction = fraction;
float[] origin = {1, 1, 1};
float[] newPos = new float[3];
matrix.mult(origin, newPos);
this.x = newPos[0];
this.y = newPos[1];
this.z = newPos[2];
}
}
private final StairEdgePoint[] OUTER_STAIR_EDGE;
private final StairEdgePoint[] INNER_STAIR_EDGE;
FlyerModel(FlyerConfig config,
WingModel leftWing,
......@@ -432,8 +445,53 @@ class FlyerModel extends LXModel implements Flyer {
}
OUTER_STAIR_EDGE = new StairEdgePoint[10];
PMatrix3D matrix = new PMatrix3D();
// Move so center of bottom platform is at 0,0
matrix.translate(FRONT_WINDOW_WIDTH * (1f + 0.707f) / 2f,
0f,
FRONT_WINDOW_WIDTH * (0.707f) / 2f);
matrix.rotateY(- 5.0f/8.0f * (float)Math.PI);
matrix.translate(168.0f - 126.0f * (float)Math.sin((float)Math.PI/8f),
0,
32.0f + 126f * (float)Math.cos((float)Math.PI/8f));
OUTER_STAIR_EDGE[0] = new StairEdgePoint(0f, matrix);
matrix.rotateY((float)Math.PI/8f);
matrix.translate(0, 90f, 186f);
OUTER_STAIR_EDGE[1] = new StairEdgePoint(0.125f, matrix);
matrix.translate(0, 0, 128f);
OUTER_STAIR_EDGE[2] = new StairEdgePoint(0.25f, matrix);
matrix.rotateY(3f *(float) Math.PI / 4f);
matrix.translate(0, 0, 128f);
OUTER_STAIR_EDGE[3] = new StairEdgePoint(0.375f, matrix);
matrix.translate(0, 90f, 186f);
OUTER_STAIR_EDGE[4] = new StairEdgePoint(0.5f, matrix);
matrix = new PMatrix3D();
// Move so center of middle platform is at 0,0
matrix.translate(FRONT_WINDOW_WIDTH * (1f + 0.707f) / 2f,
90f,
FRONT_WINDOW_WIDTH * (0.707f) / 2f);
matrix.rotateY(- 5.0f/8.0f *(float) Math.PI);
matrix.translate(168.0f - 126.0f *(float)Math.sin((float)Math.PI/8f),
0,
32.0f + 126f * (float)Math.cos((float)Math.PI/8f));
OUTER_STAIR_EDGE[5] = new StairEdgePoint(0.5f, matrix);
matrix.rotateY((float)Math.PI/8f);
matrix.translate(0, 90f, 186f);
OUTER_STAIR_EDGE[6] = new StairEdgePoint(0.625f, matrix);
matrix.translate(0, 0, 128f);
OUTER_STAIR_EDGE[7] = new StairEdgePoint(0.75f, matrix);
matrix.rotateY(3f * (float)Math.PI / 4f);
matrix.translate(0, 0, 128f);
OUTER_STAIR_EDGE[8] = new StairEdgePoint(0.875f, matrix);
matrix.translate(0, 90f, 186f);
OUTER_STAIR_EDGE[9] = new StairEdgePoint(1.0f, matrix);
//OUTER_STAIR_EDGE[0] =
INNER_STAIR_EDGE = new StairEdgePoint[10];
}
......@@ -449,7 +507,19 @@ class FlyerModel extends LXModel implements Flyer {
if (face.equals("F")) {
return this.faceConfig.x;
} else if (face.equals("E")) {
return this.index;
float position = this.faceConfig.position;
for (int i = 1; i < OUTER_STAIR_EDGE.length; i++) {
if (position <= OUTER_STAIR_EDGE[i].fraction) {
float start = OUTER_STAIR_EDGE[i - 1].x;
float end = OUTER_STAIR_EDGE[i].x;
float distance = end - start;
float ratio = (position - start) / distance;
float x = (ratio * end +
(1f - ratio) * start);
return x;
}
}
return 10f;
} else if (face.equals("I")) {
return this.index;
} else if (face.equals("C")) {
......@@ -508,7 +578,9 @@ class FlyerModel extends LXModel implements Flyer {
} else if (face.equals("C")) {
offset = GeometryConstants.FRONT_WINDOW_NADIR_HEIGHT - 20f;
}
else {
else if (face.equals("E")) {
return 200f;
} else {
return this.index;
}
return offset - this.faceConfig.hangDistance;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment