Commit 4ca1ceac authored by Ashley Chen's avatar Ashley Chen
Browse files

modifying LXModel construction, added Pattern class

parent cbf36878
......@@ -13,24 +13,25 @@ abstract interface Flight extends GeometryConstants {
* pattern getters for all flyers
*/
/* ------------- all flyers, motion ------------- */
List<Wing> getAllWings();
List<Wing> getAllLeftWings();
List<Wing> getAllRightWings();
List<? extends Wing> getAllWings();
List<? extends Wing> getAllLeftWings();
List<? extends Wing> getAllRightWings();
int[] getAllWingsSkew();
/* ------------- all flyers, lights ------------- */
List<LightSamplePoint> getAllLights();
List<? extends LightSamplePoint> getAllLights();
List<LightSamplePoint> getAllBodyLights();
List<LightSamplePoint> getAllWingsLights();
List<LightSamplePoint> getAllWingsPositionIndexedLights(int positionIndex); // head
List<? extends LightSamplePoint> getAllBodyLights();
List<? extends LightSamplePoint> getAllWingsLights();
List<? extends LightSamplePoint> getAllWingsPositionIndexedLights(int positionIndex); // head
// left wings
List<LightSamplePoint> getAllLeftWingLights();
List<LightSamplePoint> getAllLeftWingPositionIndexedLights(int positionIndex);
List<? extends LightSamplePoint> getAllLeftWingLights();
List<? extends LightSamplePoint> getAllLeftWingPositionIndexedLights(int positionIndex);
// right wings
List<LightSamplePoint> getAllRightWingLights();
List<LightSamplePoint> getAllRightWingPositionIndexedLights(int positionIndex);
List<? extends LightSamplePoint> getAllRightWingLights();
List<? extends LightSamplePoint> getAllRightWingPositionIndexedLights(int positionIndex);
/**
......@@ -39,19 +40,19 @@ abstract interface Flight extends GeometryConstants {
/* ------------- one flyer, motion ------------- */
Wing getFlyerLeftWing(int flyerIndex);
Wing getFlyerRightWing(int flyerIndex);
List<Wing> getFlyerWings(int flyerIndex);
List<? extends Wing> getFlyerWings(int flyerIndex);
/* ------------- one flyer, lights ------------- */
List<LightSamplePoint> getFlyerLights(int flyerIndex);
List<? extends LightSamplePoint> getFlyerLights(int flyerIndex);
LightSamplePoint getFlyerBodyLight(int flyerIndex);
List<LightSamplePoint> getFlyerWingsLights(int flyerIndex);
List<LightSamplePoint> getFlyerWingsPositionIndexedLights(int flyerIndex, int positionIndex);
List<? extends LightSamplePoint> getFlyerWingsLights(int flyerIndex);
List<? extends LightSamplePoint> getFlyerWingsPositionIndexedLights(int flyerIndex, int positionIndex);
List<LightSamplePoint> getFlyerLeftWingLights(int flyerIndex);
List<? extends LightSamplePoint> getFlyerLeftWingLights(int flyerIndex);
LightSamplePoint getFlyerLeftWingPositionIndexedLights(int flyerIndex, int positionIndex);
List<LightSamplePoint> getFlyerRightWingLights(int flyerIndex);
List<? extends LightSamplePoint> getFlyerRightWingLights(int flyerIndex);
LightSamplePoint getFlyerRightWingPositionIndexedLights(int flyerIndex, int positionIndex);
......@@ -68,5 +69,5 @@ abstract interface Flight extends GeometryConstants {
*/
FlyerConfig[] getFlyerConfigs();
List<Flyer> getFlyers();
List<? extends Flyer> getFlyers();
}
\ No newline at end of file
import java.util.List;
import heronarts.lx.model.LXModel;
import heronarts.lx.model.LXPoint;
......@@ -27,7 +25,7 @@ abstract interface Flyer extends GeometryConstants {
LXPoint getBodyLightPoint();
List<? extends LXPoint> getLightPoints();
// List<? extends LXPoint> getLightPoints();
FlyerConfig getConfig();
......
......@@ -2,7 +2,7 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import heronarts.lx.model.LXPoint;
import heronarts.lx.transform.LXVector;
import heronarts.lx.color.LXColor;
interface GeometryConstants {
......@@ -100,76 +100,39 @@ interface GeometryConstants {
//// 3.974 0.005
// ));
// float wingVertices[] = {
// 3.480f, 0.152f, 0f,
// 0.005f, 6.297f, 0f,
// 0.148f, 6.542f, 0f,
// 20.841f, 6.539f, 0f,
// 20.919f, 6.179f, 0f,
// 3.974f, 0.005f, 0f
//};
// float leftWingLightVertices[] = {
// 0f, 20.88f, 0f, // head
// -6.42f, 16.49f, 0f, // side
// 0f, 0f, 0f // tail
// };
//
// LXMatrix leftWingLightMatrix = new LXMatrix(leftWingLightVertices);
//
// LXTransform transformToRightWingLightMatrix = new LXTransform(leftWingLightMatrix);
//
//
//
// float rightWingLightVerticesTransform[] = {
// -1f, 0f, 0f, // head
// -1f, 0f, 0f, // side
// -1f, 0f, 0f // tail
// };
// LXMatrix rightWingLightTransform = new LXMatrix(rightWingLightVerticesTransform);
//
// LXMatrix rightWingLightMatrix = leftWingLightMatrix.multiply(rightWingLightTransform);
// LXModel wing = new LXModel(wingPoints);
// List<LXPoint> wingLightPoints = new ArrayList<LXPoint>(Arrays.asList(
// new LXPoint(-1, 20.88, 0), // left head
// new LXPoint(-7.42, 16.49, 0), // left side
// new LXPoint(-1, 0, 0), // left tail
// new LXPoint(1, 20.88, 0), // right head
// new LXPoint(7.42, 16.49, 0), // right side
// new LXPoint(1, 0, 0), // right tail
// new LXPoint(0, 16.49, 0) // body
// ));
List<LXPoint> lightGeometryPoints = new ArrayList<LXPoint>(Arrays.asList(
new LXPoint(4.011, -4.967, 0), // left head
new LXPoint(9.116, -11.173, 0), // left side
new LXPoint(26.741, -0.987, 0), // left tail
new LXPoint(4.011, 4.967, 0), // right head
new LXPoint(9.116, 11.173, 0), // right side
new LXPoint(26.741, 0.987, 0), // right tail
new LXPoint(5.288, 0, 0) // body
// REVIEW(mcslee): changed to LXVector... if you're just storing geometry
// here that is fine to use, but keep in mind these are a static global
// instance because this is an interface. If these are going to be used
// in the model objects, copies will need to be made.
// LXModel wing = new LXModel(wingPoints);
List<LXVector> lightGeometryPoints = new ArrayList<LXVector>(Arrays.asList(
new LXVector(4.011f, -4.967f, 0f), // left head
new LXVector(9.116f, -11.173f, 0f), // left side
new LXVector(26.741f, -0.987f, 0f), // left tail
new LXVector(4.011f, 4.967f, 0f), // right head
new LXVector(9.116f, 11.173f, 0f), // right side
new LXVector(26.741f, 0.987f, 0f), // right tail
new LXVector(5.288f, 0f, 0f) // body
));
List<LXPoint> bodyGeometryPoints = new ArrayList<LXPoint>(Arrays.asList(
new LXPoint(0, 0, 0), // head
new LXPoint(3.333, 4.040, 0), // right side
new LXPoint(3.333, -4.040, 0), // left side
new LXPoint(26.259, 0, 0), // tail
new LXPoint(5.288, 0, -4.394) // body tip
List<LXVector> bodyGeometryPoints = new ArrayList<LXVector>(Arrays.asList(
new LXVector(0f, 0f, 0f), // head
new LXVector(3.333f, 4.040f, 0f), // right side
new LXVector(3.333f, -4.040f, 0f), // left side
new LXVector(26.259f, 0f, 0f), // tail
new LXVector(5.288f, 0f, -4.394f) // body tip
));
// LXModelBuilder wingModelBuilder = new LXModelBuilder();
// LXModel wingLights = new LXModel(wingLightPoints);
// REVIEW(mcslee): note that these need to be constructed for each wing instance,
// if a static array is used then you'll end up pointing at the same underlying
// point instances
// LXModel wingLights = new LXModel(wingLightPoints);
public default List<LXVector> buildLights() {
return new ArrayList<LXVector>(lightGeometryPoints);
}
}
import heronarts.lx.model.LXPoint;
abstract interface LightSamplePoint extends GeometryConstants {
enum LightCorners {
......@@ -22,34 +22,35 @@ abstract interface LightSamplePoint extends GeometryConstants {
Integer getWingIndex();
int getBodyIndex();
LightCorners getLocation();
int getIndex();
/**
* Index of this lightPoint in color buffer, colors[lightPoint.getIndex()]
*/
// TODO (achen) make this cleaner
default int getIndex() {
Integer wingIndex = getWingIndex();
if (wingIndex != null) {
return getBodyIndex() * NUM_LIGHT_POINTS_PER_FLYER +
(wingIndex % NUM_WINGS_PER_FLYER) * NUM_LIGHT_POINTS_PER_WING +
getLocation().position;
}
return getBodyIndex() * NUM_LIGHT_POINTS_PER_FLYER + getLocation().position;
}
// /**
// * Index of this lightPoint in color buffer, colors[lightPoint.getIndex()]
// */
// // TODO (achen) make this cleaner
// default int getIndex() {
// Integer wingIndex = getWingIndex();
// if (wingIndex != null) {
// return getBodyIndex() * NUM_LIGHT_POINTS_PER_FLYER +
// (wingIndex % NUM_WINGS_PER_FLYER) * NUM_LIGHT_POINTS_PER_WING +
// getLocation().position;
// }
// return getBodyIndex() * NUM_LIGHT_POINTS_PER_FLYER + getLocation().position;
// }
default LXPoint getXYZ() {
Integer wingIndex = getWingIndex();
if (wingIndex != null) {
return lightGeometryPoints.get((wingIndex % NUM_WINGS_PER_FLYER) * NUM_LIGHT_POINTS_PER_WING + getLocation().position);
}
return lightGeometryPoints.get(getLocation().position);
}
// default LXVector getXYZ() {
// Integer wingIndex = getWingIndex();
// if (wingIndex != null) {
// return lightGeometryPoints.get((wingIndex % NUM_WINGS_PER_FLYER) * NUM_LIGHT_POINTS_PER_WING + getLocation().position);
// }
// return lightGeometryPoints.get(getLocation().position);
// }
// Uses the color representation of LXStudio
void setColor(int color);
int getColor();
// What range is this value? -pal
// TODO (achen) define brightness range. Very likely 0 - 100
void setBrightness(int brightness);
// void setColor(int color);
// int getColor();
// // What range is this value? -pal
// // TODO (achen) define brightness range. Very likely 0 - 100
// void setBrightness(int brightness);
}
This diff is collapsed.
import heronarts.lx.LX;
import heronarts.lx.pattern.LXModelPattern;
import heronarts.lx.model.LXPoint;
abstract class Pattern extends LXModelPattern<FlightModel> {
protected int[] skews = null;
Pattern(LX lx) {
super(lx);
// this.addLayer(new LXLayer(lx, new LXDeviceComponent(lx, "skew")));
skews = ((FlightModel) lx.getModel()).getAllWingsSkew();
}
/**
* Get the current color at this point
*
* @param p Point
* @return Current color of this point
*/
public int getColor(LXPoint p) {
return this.colors[p.index];
}
/**
* Update the color for the given point
*
* @param p Point
* @param color The color to set for this point
*/
public void setColor(LXPoint p, int color) {
this.colors[p.index] = color;
}
/**
* Get the current angle for this wing
*
* @param wing WingModel
* @return Current angle of this wing
*/
public int getSkew(WingModel wing) {
return this.skews[wing.index];
}
/**
* Update the angle for the given wing
*
* @param wing WingModel
* @param skew The angle to set for this point
*/
public void setSkew(WingModel wing, int skew) {
this.skews[wing.index] = skew;
}
// // REVIEW(mcslee): I would suggest collapsing your distinction between
// // the interface and class, then these metohds will just work without
// // an extra layer of method call abstraction around LXPoint, the above
// // methods should be sufficient
// public int getColor(LightSamplePoint p) {
// return this.colors[p.getIndex()];
// }
//
// public void setColor(LightSamplePoint p, int color) {
// this.colors[p.getIndex()] = color;
// }
}
\ No newline at end of file
......@@ -2,40 +2,37 @@ import java.util.List;
import heronarts.lx.LX;
import heronarts.lx.modulator.SinLFO;
import heronarts.lx.pattern.LXPattern;
import heronarts.lx.parameter.BoundedParameter;
// array of wing positions akin to colors[]
class FadeTest extends LXPattern {
class FadeTest extends Pattern {
final BoundedParameter speed = new BoundedParameter("SPEE", 11000, 100000, 1000);
final SinLFO color = new SinLFO(0, 360, speed);
protected final Flight model;
FadeTest(LX lx) {
super(lx);
model = (Flight)lx.getModel();
addParameter(speed);
addModulator(color).start();
}
@Override
public void run(double deltaMs) {
for (LightSamplePoint bodyPoint : model.getAllBodyLights()) {
bodyPoint.setColor(lx.hsb(0, 0, 20));
for (LightSamplePointModel bodyPoint : model.getAllBodyLights()) {
setColor(bodyPoint, LX.hsb(0, 0, 20));
}
for (LightSamplePoint wingPoint : model.getAllWingsLights()) {
for (LightSamplePointModel wingPoint : model.getAllWingsLights()) {
float hue = color.getValuef();
wingPoint.setColor(lx.hsb(hue, 100, 100));
setColor(wingPoint, LX.hsb(hue, 100, 100));
}
}
}
class BlackPinkTest extends LXPattern {
class BlackPinkTest extends Pattern {
int FLYER_MOD = 75;
......@@ -43,11 +40,8 @@ class BlackPinkTest extends LXPattern {
final SinLFO flyerIndex = new SinLFO(0, FLYER_MOD, period);
protected final Flight model;
BlackPinkTest(LX lx) {
super(lx);
model = (Flight)lx.getModel();
addParameter(period);
addModulator(flyerIndex).start();
}
......@@ -55,22 +49,22 @@ class BlackPinkTest extends LXPattern {
@Override
public void run(double deltaMs) {
List<LightSamplePoint> allLights = model.getAllLights();
List<LightSamplePointModel> allLights = model.getAllLights();
for (LightSamplePoint lightPoint : allLights) {
for (LightSamplePointModel lightPoint : allLights) {
if (lightPoint.getBodyIndex() == (int) flyerIndex.getValue()) {
lightPoint.setColor(lx.hsb(330, 70, 70));
setColor(lightPoint, LX.hsb(330, 70, 70));
} else {
lightPoint.setColor(lx.hsb(0, 0, 20));
setColor(lightPoint, LX.hsb(0, 0, 20));
}
}
for (Wing wing : model.getAllWings()) {
for (WingModel wing : model.getAllWings()) {
if (wing.getFlyerIndex() == (int) flyerIndex.getValue()) {
wing.setSkew(180);
setSkew(wing, 180);
} else {
wing.setSkew(0);
setSkew(wing, 0);
}
}
......
import java.util.List;
import heronarts.lx.model.LXPoint;
abstract interface Wing extends GeometryConstants {
......@@ -10,7 +8,7 @@ abstract interface Wing extends GeometryConstants {
int getFlyerIndex();
boolean getIsRight();
List<? extends LXPoint> getLightPoints();
// List<? extends LXPoint> getLightPoints();
static int getIndex(int flyerIndex, boolean isRight) {
return flyerIndex * NUM_WINGS_PER_FLYER + isRightAsInt(isRight);
......
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