Commit 3e91cfc1 authored by Ashley Chen's avatar Ashley Chen
Browse files

simplify and clean up getters on FlightModel

parent 848c43a7
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.function.IntPredicate;
import heronarts.lx.transform.LXVector;
......@@ -58,8 +59,8 @@ interface GeometryConstants {
(float)(13 * FEET + 10.0 + 5.0/16.0),
(float)(13 * FEET + 10.0 + 5.0/16.0),
(float)(13 * FEET + 10.0 + 5.0/16.0)
};
};
/**
* num_x_per_y constants
*/
......@@ -79,10 +80,20 @@ interface GeometryConstants {
default int wingLightIndex(int flyer, boolean right, int which) {
return 1 + (flyer * NUM_LIGHT_POINTS_PER_FLYER) + (right? NUM_LIGHT_POINTS_PER_WING: 0) + which;
}
default int wingIndex(int flyer, boolean right) {
return (flyer * NUM_WINGS_PER_FLYER) + (right? 1: 0);
}
default IntPredicate isLeftWingLight() {
return lightIndex -> lightIndex % NUM_LIGHT_POINTS_PER_FLYER < NUM_LIGHT_POINTS_PER_WING;
}
default IntPredicate isRightWingLight() {
return lightIndex -> (lightIndex % NUM_LIGHT_POINTS_PER_FLYER >= NUM_LIGHT_POINTS_PER_WING &&
lightIndex % NUM_LIGHT_POINTS_PER_FLYER != LightSamplePoint.LightCorners.BODY.position);
}
/**
* indexing scheme constants
*/
......
......@@ -17,12 +17,12 @@ class Model implements GeometryConstants {
public Model(FlyerConfig[] flyerConfig) {
flight = new FlightModel(flyerConfig);
}
FlightModel getFlightModel() {
return flight;
}
}
class FlightModel extends LXModel implements Flight {
......@@ -87,6 +87,7 @@ class FlightModel extends LXModel implements Flight {
/* ------------- all flyers, motion ------------- */
@Override
public List<WingModel> getAllWings() {
return IntStream
.range(0, wings.length)
......@@ -94,6 +95,7 @@ class FlightModel extends LXModel implements Flight {
.collect(Collectors.toList());
}
@Override
public List<WingModel> getAllLeftWings() {
return IntStream
.range(0, wings.length)
......@@ -102,6 +104,7 @@ class FlightModel extends LXModel implements Flight {
.collect(Collectors.toList());
}
@Override
public List<WingModel> getAllRightWings() {
return IntStream
.range(0, wings.length)
......@@ -110,6 +113,7 @@ class FlightModel extends LXModel implements Flight {
.collect(Collectors.toList());
}
@Override
public int[] getAllWingsSkew() {
return IntStream
.range(0, wings.length)
......@@ -117,6 +121,7 @@ class FlightModel extends LXModel implements Flight {
.toArray();
}
@Override
public int[] getAllLeftWingsSkew() {
return IntStream
.range(0, wings.length)
......@@ -125,6 +130,7 @@ class FlightModel extends LXModel implements Flight {
.toArray();
}
@Override
public int[] getAllRightWingsSkew() {
return IntStream
.range(0, wings.length)
......@@ -136,10 +142,12 @@ class FlightModel extends LXModel implements Flight {
/* ------------- all flyers, lights ------------- */
@Override
public List<LightSamplePointModel> getAllLights() {
return Arrays.asList(lightPoints);
}
@Override
public List<LightSamplePointModel> getAllBodyLights() {
return IntStream
.range(0, flyers.length)
......@@ -147,6 +155,7 @@ class FlightModel extends LXModel implements Flight {
.collect(Collectors.toList());
}
@Override
public List<LightSamplePointModel> getAllWingsLights() {
return IntStream
.range(0, lightPoints.length)
......@@ -155,69 +164,76 @@ class FlightModel extends LXModel implements Flight {
.collect(Collectors.toList());
}
@Override
public List<LightSamplePointModel> getAllWingsPositionIndexedLights(int positionIndex) {
return IntStream
.range(0, lightPoints.length)
.filter(i -> i % NUM_LIGHT_POINTS_PER_FLYER == positionIndex || i % NUM_LIGHT_POINTS_PER_FLYER == (positionIndex + NUM_LIGHT_POINTS_PER_WING))
.mapToObj(i -> lightPoints[i])
.collect(Collectors.toList());
.range(0, wings.length)
// (wingIndex / 2) -> flyerIndex, due to integer division rounding down
// (wingIndex % 2 == 1) -> false/true, left/right
.mapToObj(i -> lightPoints[wingLightIndex(i / 2, i % 2 == 1, positionIndex)])
.collect(Collectors.toList());
}
@Override
public List<LightSamplePointModel> getAllLeftWingLights() {
return IntStream
.range(0, lightPoints.length)
.filter(i -> (i % NUM_LIGHT_POINTS_PER_FLYER < NUM_LIGHT_POINTS_PER_WING))
.filter(isLeftWingLight())
.mapToObj(i -> lightPoints[i])
.collect(Collectors.toList());
}
@Override
public List<LightSamplePointModel> getAllLeftWingPositionIndexedLights(int positionIndex) {
return IntStream
.range(0, lightPoints.length)
.filter(i -> i % NUM_LIGHT_POINTS_PER_FLYER == positionIndex)
.mapToObj(i -> lightPoints[i])
.collect(Collectors.toList());
.range(0, flyers.length)
.mapToObj(i -> lightPoints[wingLightIndex(i, false, positionIndex)])
.collect(Collectors.toList());
}
@Override
public List<LightSamplePointModel> getAllRightWingLights() {
return IntStream
.range(0, lightPoints.length)
.filter(i -> (i % NUM_LIGHT_POINTS_PER_FLYER >= NUM_LIGHT_POINTS_PER_WING && i % NUM_LIGHT_POINTS_PER_FLYER != LightSamplePoint.LightCorners.BODY.position))
.filter(isRightWingLight())
.mapToObj(i -> lightPoints[i])
.collect(Collectors.toList());
}
@Override
public List<LightSamplePointModel> getAllRightWingPositionIndexedLights(int positionIndex) {
return IntStream
.range(0, lightPoints.length)
.filter(i -> i % NUM_LIGHT_POINTS_PER_FLYER == (positionIndex + NUM_LIGHT_POINTS_PER_WING))
.mapToObj(i -> lightPoints[i])
.collect(Collectors.toList());
.range(0, flyers.length)
.mapToObj(i -> lightPoints[wingLightIndex(i, true, positionIndex)])
.collect(Collectors.toList());
}
/* ------------- one flyer, lights ------------- */
@Override
public List<LightSamplePointModel> getFlyerLights(int flyerIndex) {
return IntStream
.range(flyerLightStartIndex(flyerIndex), flyerLightStartIndex(flyerIndex + 1))
.range(flyerLightStartIndex(flyerIndex), flyerLightStartIndex(flyerIndex + 1))
.mapToObj(i -> lightPoints[i])
.collect(Collectors.toList());
}
@Override
public LightSamplePointModel getFlyerBodyLight(int flyerIndex) {
return lightPoints[bodyLightIndex(flyerIndex)];
}
@Override
public List<LightSamplePointModel> getFlyerWingsLights(int flyerIndex) {
return IntStream
.range(0, NUM_LIGHT_POINTS_PER_FLYER)
.filter(i -> i % NUM_LIGHT_POINTS_PER_FLYER != 0)
.mapToObj(i -> lightPoints[NUM_LIGHT_POINTS_PER_FLYER * flyerIndex + i])
.range(0, NUM_WING_LIGHT_POINTS)
.mapToObj(i -> lightPoints[flyerLightStartIndex(flyerIndex) + i])
.collect(Collectors.toList());
}
@Override
public List<LightSamplePointModel> getFlyerLeftWingLights(int flyerIndex) {
return IntStream
.range(0, NUM_LIGHT_POINTS_PER_WING)
......@@ -225,6 +241,7 @@ class FlightModel extends LXModel implements Flight {
.collect(Collectors.toList());
}
@Override
public List<LightSamplePointModel> getFlyerRightWingLights(int flyerIndex) {
return IntStream
.range(0, NUM_LIGHT_POINTS_PER_WING)
......@@ -232,55 +249,65 @@ class FlightModel extends LXModel implements Flight {
.collect(Collectors.toList());
}
@Override
public List<LightSamplePointModel> getFlyerWingsPositionIndexedLights(int flyerIndex, int positionIndex) {
return IntStream
.range(0, 2)
.mapToObj(i -> lightPoints[wingLightIndex(flyerIndex, i == 1, positionIndex)])
.collect(Collectors.toList());
.range(0, 2)
.mapToObj(i -> lightPoints[wingLightIndex(flyerIndex, i == 1, positionIndex)])
.collect(Collectors.toList());
}
@Override
public LightSamplePointModel getFlyerLeftWingPositionIndexedLights(int flyerIndex, int positionIndex) {
return lightPoints[wingLightIndex(flyerIndex, false, positionIndex)];
}
@Override
public LightSamplePointModel getFlyerRightWingPositionIndexedLights(int flyerIndex, int positionIndex) {
return lightPoints[wingLightIndex(flyerIndex, true, positionIndex)];
}
/* ------------- one flyer, motion ------------- */
@Override
public List<WingModel> getFlyerWings(int flyerIndex) {
return IntStream
.range(flyerIndex * NUM_WINGS_PER_FLYER, flyerIndex * NUM_WINGS_PER_FLYER + NUM_WINGS_PER_FLYER)
.mapToObj(i -> wings[i])
.collect(Collectors.toList());
.range(wingIndex(flyerIndex, false), wingIndex(flyerIndex + 1, false))
.mapToObj(i -> wings[i])
.collect(Collectors.toList());
}
@Override
public WingModel getFlyerLeftWing(int flyerIndex) {
return wings[flyerIndex * NUM_WINGS_PER_FLYER];
return wings[wingIndex(flyerIndex, false)];
}
@Override
public WingModel getFlyerRightWing(int flyerIndex) {
return wings[flyerIndex * NUM_WINGS_PER_FLYER + 1];
return wings[wingIndex(flyerIndex, true)];
}
@Override
public int[] getFlyerWingsSkew(int flyerIndex) {
return IntStream
.range(flyerIndex * NUM_WINGS_PER_FLYER, flyerIndex * NUM_WINGS_PER_FLYER + NUM_WINGS_PER_FLYER)
.range(wingIndex(flyerIndex, false), wingIndex(flyerIndex + 1, false))
.map(i -> wings[i].getSkew())
.toArray();
}
@Override
public int getFlyerLeftWingSkew(int flyerIndex) {
return wings[flyerIndex * NUM_WINGS_PER_FLYER].getSkew();
return wings[wingIndex(flyerIndex, false)].getSkew();
}
@Override
public int getFlyerRightWingSkew(int flyerIndex) {
return wings[flyerIndex * NUM_WINGS_PER_FLYER + 1].getSkew();
return wings[wingIndex(flyerIndex, true)].getSkew();
}
/* ------------- config ------------- */
@Override
public FlyerModel getFlyer(int i) {
return flyers[i];
}
......@@ -294,6 +321,7 @@ class FlightModel extends LXModel implements Flight {
return flyerConfigs.toArray(new FlyerConfig[0]);
}
@Override
public List<FlyerModel> getFlyers() {
return Arrays.asList(flyers);
}
......@@ -339,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
......@@ -359,9 +387,9 @@ class FlyerModel extends LXModel implements Flyer {
this.z = z;
}
StairEdgePoint(float faction, PMatrix3D matrix) {
StairEdgePoint(float fraction, PMatrix3D matrix) {
this.fraction = fraction;
float[] origin = {1, 1, 1};
float[] newPos = new float[3];
matrix.mult(origin, newPos);
......@@ -421,7 +449,7 @@ class FlyerModel extends LXModel implements Flyer {
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),
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);
......@@ -443,7 +471,7 @@ class FlyerModel extends LXModel implements Flyer {
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),
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);
......@@ -459,7 +487,7 @@ class FlyerModel extends LXModel implements Flyer {
OUTER_STAIR_EDGE[9] = new StairEdgePoint(1.0f, matrix);
INNER_STAIR_EDGE = new StairEdgePoint[10];
}
......@@ -467,7 +495,7 @@ class FlyerModel extends LXModel implements Flyer {
private final FlyerConfig config;
private final LightSamplePointModel bodyLightPoint;
private final WingModel[] wings = new WingModel[2];
FlyerModelBuilder(FlyerConfig config) {
this.config = config;
this.wings[0] = new WingModel(config.index, false);
......@@ -500,7 +528,7 @@ class FlyerModel extends LXModel implements Flyer {
float end = OUTER_STAIR_EDGE[i].x;
float distance = end - start;
float ratio = (position - start) / distance;
float x = (ratio * end +
float x = (ratio * end +
(1f - ratio) * start);
return x;
}
......@@ -576,7 +604,7 @@ class FlyerModel extends LXModel implements Flyer {
public float getZ() {
String face = this.faceConfig.face;
if (face.equals("F")) {
return 10.0f;
return 10.0f;
} else if (face.equals("C")) {
int pipe = (int)this.faceConfig.pipe;
float startz = 12f;
......@@ -589,21 +617,21 @@ class FlyerModel extends LXModel implements Flyer {
endz = (float)(BACK_WALL_OFFSETS[1] * Math.sin(Math.PI/4f));
break;
case 2:
endz = (float)((BACK_WALL_OFFSETS[2] * 0.707f) / 2.0f);
endz = (BACK_WALL_OFFSETS[2] * 0.707f) / 2.0f;
break;
case 3:
startz = (float)(BACK_WALL_OFFSETS[1] * Math.sin(Math.PI/4f));
endz = (float)((BACK_WALL_OFFSETS[2] * 0.707f) / 2.0f);
endz = (BACK_WALL_OFFSETS[2] * 0.707f) / 2.0f;
break;
case 4:
endz = (float)(BACK_WALL_OFFSETS[2] * Math.sin(Math.PI/4f));
break;
case 5:
endz = (float)((BACK_WALL_OFFSETS[3] * 0.707f) / 2.0f);
endz = (BACK_WALL_OFFSETS[3] * 0.707f) / 2.0f;
break;
case 6:
startz = (float)(BACK_WALL_OFFSETS[2] * Math.sin(Math.PI/4f));
endz = (float)((BACK_WALL_OFFSETS[3] * 0.707f) / 2.0f);
endz = (BACK_WALL_OFFSETS[3] * 0.707f) / 2.0f;
break;
case 7:
endz =(float)(BACK_WALL_OFFSETS[3] * Math.sin(Math.PI/4f));
......@@ -671,6 +699,7 @@ class FlyerModel extends LXModel implements Flyer {
return config;
}
@Override
public String toString() {
String str = super.toString() + "\n";
str += "Flyer: " + getIndex() + "\n";
......@@ -729,10 +758,11 @@ class WingModel extends LXModel implements Wing {
}
}
@Override
public int getIndex() {
return this.index;
}
@Override
public int getFlyerIndex() {
return this.flyerIndex;
......@@ -753,6 +783,7 @@ class WingModel extends LXModel implements Wing {
return this.skew;
}
@Override
public String toString() {
String str = super.toString() + ", ";
str += "fi: " + getFlyerIndex() + ", ";
......
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