Commit 07489be6 authored by Philip Levis's avatar Philip Levis
Browse files

Starting to comment and document Processing code.

parent 3164f629
/**
* The FLIGHT GUI window that draws the stairwell of the Packard
* building at Stanford with FLIGHT's Fractal Flyers. The Fractal
* Flyers visualize light colors and wing position.
*
* @author Philip Levis <pal@cs.stanford.edu>
*/
class UIFlightDrawer extends UI3dComponent implements GeometryConstants {
final float[] VBAR_OFFSETS;
final float[] HBAR_OFFSETS;
final float[] BACK_WALL_OFFSETS;
// These variables are all derived from constants in GeometryConstants -pal
// The X offset of the vertical bars on the front window. These are
// used as reference points for drawing the overhead pipes as well
// as the front window bars.
private final float[] VBAR_OFFSETS;
// The Y offset of the horizontal bars on the front window. These are
// used as reference points for drawing the front window as well as
// drawing Fractal Flyers that are hanging off the front window.
private final float[] HBAR_OFFSETS;
// The X and Z offset of reference points on the back wall. These
// correspond to a subset of the VBAR_OFFSETS, but rotated -P/4 along
// the Y axis.
private final float[] BACK_WALL_OFFSETS;
FlightModel model;
......@@ -34,16 +54,15 @@ class UIFlightDrawer extends UI3dComponent implements GeometryConstants {
protected void onDraw(UI ui, PGraphics pg) {
pg.pushMatrix();
// I'd like the bottom left corner of the stairwell to be 0, 0, 0
// and then just set the camera to a good spot, but this does not
// seem to work with the preview window. So, instead, translate
// the whole model so that 0, 0, 0 is at a good spot.
drawBuilding(pg);
drawFlyers(pg);
pg.popMatrix();
}
/**
* Draw all of the Fractal Flyers.
*
*/
private void drawFlyers(PGraphics pg) {
computeFlyerLightsAndWings();
// We draw each flyer by first computing a geometric
......@@ -51,27 +70,31 @@ class UIFlightDrawer extends UI3dComponent implements GeometryConstants {
// drawing it, then popping the tranformation. This allows the
// draw code to just operate in a normalized coordinate space. -pal
for (Flyer flyer : model.getFlyers()) {
try {
pg.pushMatrix();
float x = flyer.getX();
float y = flyer.getY();
float z = flyer.getZ();
pg.translate(x, y, z);
rotateY(-flyer.getRotation() * (float)Math.PI / 180);
rotateZ(-flyer.getTilt() * (float)Math.PI / 180);
pg.rotateY(-flyer.getRotation() * (float)Math.PI / 180);
pg.rotateZ(-flyer.getTilt() * (float)Math.PI / 180);
drawFlyer(pg, flyer);
pg.popMatrix();
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
}
/**
* Draw one Fractal Flyer at (0,0,0). its long dimension
* along the X axis, its narrow dimension along the Z axis,
* and its body hanging down in the Y axis.
*/
private void drawFlyer(PGraphics pg, Flyer flyer) {
// All of these values are in inches, taken from
// FRACTAL_FLYER/drawings/body-dimensions-for-ui-graphics.pdf
pg.translate(-10f, 0, 0);
pg.pushMatrix();
// (0, 0, 0) should be at the hanging point, so transate forward
// to that point
pg.translate(FLYER_HANGING_OFFSET, 0, 0);
pg.noStroke();
// top plate
pg.fill(#a0a0a0);
......@@ -141,30 +164,38 @@ class UIFlightDrawer extends UI3dComponent implements GeometryConstants {
pg.vertex(3.33f, 0, -4.04f);
pg.vertex(5.29f, -4.39f, 0);
pg.endShape(CLOSE);
pg.popMatrix();
}
/**
* A hook for UI-specific additions to the visualization of the Fractal
* Flyers. Used, for example, to allow the UI to highlight a Fractal
* Flyer that has been selected in the physical layout tool.
*/
private void computeFlyerLightsAndWings() {
for (LXAbstractChannel channel: pengine.getChannels()) {
/* if (channel.hasLights()) {
channel.getFaderTransition().blend(lights, channel.getLights(), 1);
} */
// Motion is just last writer wins.
/*
if (channel.hasMotion()) {
channel.setWings(wings);
}
*/
}
flyerHighlighter.highlight();
}
/** Draws the Packard stairwell: the walls, the ceiling pipes, and
* the stairs themselves. Assumes that (0, 0, 0) is the narrow
* corner (left, if facing it from the outside), the front window
* runs along the X axis, and -Z is in front of the building.
*/
private void drawBuilding(PGraphics pg) {
drawWalls(pg);
drawCeiling(pg);
drawStairs(pg);
}
/**
* Draws a cylinder of radius r and height h, with one end
* centered at (0, 0, 0) and the other at (0, 0, h). If you want
* to move the cylinder, call this method having set up a matrix
* so these coordinates are at your desired position. Used to draw
* pipes in the ceiling of the stairwell. Uses whatever fill color
* was specified before calling.
*/
private void drawCylinder(PGraphics pg, float r, float h) {
int sides = 36;
float angle = 360 / sides;
......@@ -195,6 +226,10 @@ class UIFlightDrawer extends UI3dComponent implements GeometryConstants {
endShape(CLOSE);
}
/** Draw a ceiling pipe from (x0, z0) to (x1, z1). Y is constant,
* at GeometryConstants.FRONT_WINDOW_NADIR_HEIGHT (the height of
* the pipe superstructure).
*/+
private void drawCeilingPipe(PGraphics pg, float x0, float z0, float x1, float z1) {
pg.noStroke();
pg.fill(#c0c0c0);
......@@ -212,7 +247,13 @@ class UIFlightDrawer extends UI3dComponent implements GeometryConstants {
drawCylinder(pg, 0.5f * GeometryConstants.FEET, length);
pg.popMatrix();
}
/**
* Draw all of the ceiling pipes. Their placement is based on the
* prow architectural drawing in the project repository. Four pipes
* stretch from the front window to the back wall, while four other
* pipes join with these to form two internal triangles.
*/
private void drawCeiling(PGraphics pg) {
// Because the back wall is at a 45 degree angle to the front window,
// the X and Z displacement is the same. -pal
......@@ -244,6 +285,11 @@ class UIFlightDrawer extends UI3dComponent implements GeometryConstants {
}
/** Draw a flight of up or down stairs at a given yOffset (floor
* height). Facing the stairs from the back wall, up stairs are
* on the left (-x) while down stairs are on the right (+x). It
* also draws half of the corner platform.
*/
private void drawStairFlight(PGraphics pg, float yOffset, boolean up) {
pg.fill(#202020);
pg.pushMatrix();
......@@ -284,6 +330,12 @@ class UIFlightDrawer extends UI3dComponent implements GeometryConstants {
pg.popMatrix();
}
/** Draw a platform against the interior wall at a given yOffset;
* this is the platform that the doors from the interior of
* the building open on to, so you can take stairs up and down.
* Constants taken from the DWG model of the stairwell in the
* repository.
*/
private void drawPlatform(PGraphics pg, float yOffset) {
pg.fill(#202020);
pg.pushMatrix();
......@@ -318,6 +370,10 @@ class UIFlightDrawer extends UI3dComponent implements GeometryConstants {
pg.popMatrix();
}
/**
* Draw all of the stairs: the platforms on the ground floor, floor 2,
* and floor 3 as well as the stairs that connec them.
*/
private void drawStairs(PGraphics pg) {
pg.pushMatrix();
// Translate to the midpoint of the center wall that
......@@ -341,6 +397,10 @@ class UIFlightDrawer extends UI3dComponent implements GeometryConstants {
pg.popMatrix();
}
/**
* Draw the back wall in white and the latticework on the front
* window.
*/
private void drawWalls(PGraphics pg) {
pg.fill(#c0c0c0);
pg.stroke(#202020);
......
import java.util.List;
/**
* The FLIGHT GUI window that lets you move where a Fractal Flyer is
* physically placed and save the current physical configuration.
*
* The configuration is saved to and loaded from a JSON file whose
* name is defined by Config.FLYER_CONFIG_FILE. When the file is
* saved, the previous one is saved as a backup.
*
* Physical placement is first determined which "face" the flyer is
* placed on: C is hanging from the ceiling pipes, F is along the
* front window, E is the external edge of the central stair, and I is
* the internal edge of the central stair. Depending on which face the
* flyer is placed on, different parameters are available for
* placement. For example, if you are hanging a flyer from the
* ceiling, you specify which pipe; if you are hanging it off the from
* window, you specify which vertical bar.
*
*
* @author Philip Levis <pal@cs.stanford.edu>
*
*/
class UIFlyerConfiguration extends UIWindow {
final static int WIDTH = 140;
final static int HEIGHT = 420;
......
......@@ -95,7 +95,11 @@ interface GeometryConstants {
final static String LIGHT_PATTERN = "lightning";
final static String MOVEMENT_PATTERN = "gentle_flap";
/**
* Physical constants of a Fractal Flyer.
*/
// How far from the wide tip the center of mass/hanging point is
public final static float FLYER_HANGING_OFFSET = 10 * INCHES;
/**
......
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