Skip to content

Commit

Permalink
Cleaning up, fixing a new TCX format bug
Browse files Browse the repository at this point in the history
  • Loading branch information
Dave Shea authored and Dave Shea committed Dec 6, 2009
1 parent 35d2a43 commit 78cd21d
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 67 deletions.
48 changes: 13 additions & 35 deletions Elevation.pde
Expand Up @@ -13,17 +13,16 @@ import java.util.Date;
import java.text.SimpleDateFormat;
import processing.opengl.*;


// for file data
ArrayList filenames;

// for track data
Scene scene;
Tracks[] tracklist;
int numTracks;

// scene-related objects
// GUI objects
uiPanel UI;
Scene scene;
uiCrosshairs crosshair;
uiScale mapScale;
uiButton[] buttons;
Expand All @@ -33,7 +32,6 @@ uiCompass compass;




void setup() {
frameRate(30);

Expand All @@ -59,7 +57,6 @@ void setup() {
"Panel");

buttons = new uiButton[8];

// arrow buttons
buttons[0] = new uiButton(
44, scene.canvasHeight - 90, 35, 40, 119, 87,
Expand All @@ -73,15 +70,13 @@ void setup() {
buttons[3] = new uiButton(
61, scene.canvasHeight - 67, 45, 30, 100, 68,
"UI-DPad-right", "offsetZ--");

// ^ / v buttons
buttons[4] = new uiButton(
216, scene.canvasHeight - 82, 52, 30, 93, 125,
"UI-Button-up", "offsetY++");
buttons[5] = new uiButton(
266, scene.canvasHeight - 82, 52, 30, 91, 123,
"UI-Button-down", "offsetY--");

// + / - buttons
buttons[6] = new uiButton(
331, scene.canvasHeight - 82, 52, 30, 43, 61,
Expand All @@ -90,8 +85,6 @@ void setup() {
381, scene.canvasHeight - 82, 52, 30, 45, 95,
"UI-Button-minus", "drawingScale--");



// checkboxes
checkboxes = new uiCheckbox[5];
checkboxes[0] = new uiCheckbox(
Expand All @@ -106,13 +99,9 @@ void setup() {
checkboxes[3] = new uiCheckbox(
951, scene.canvasHeight - 46, 19, 18, 122, 90,
"UI-Checkbox", "scene.toggleDimension", "checked");

// hidden checkboxes
// toggle true elevation
checkboxes[4] = new uiCheckbox(
1500, 1, 1, 1, 54, 94,
"", "scene.toggleElevation", "unchecked");

checkboxes[4] = new uiCheckbox(1500, 1, 1, 1, 54, 94,
"", "scene.toggleElevation", "unchecked"); // toggle true elevation

// switches
switches = new uiSwitch[5];
Expand All @@ -128,13 +117,9 @@ void setup() {
switches[3] = new uiSwitch(
691, scene.canvasHeight - 82, 40, 28, 52, 1,
"UI-Switch-4", "nada", "");

// hidden switches
// toggle mode 5
switches[4] = new uiSwitch(
1500, 1, 1, 1, 53, 1,
"", "nada", "");

switches[4] = new uiSwitch(1500, 1, 1, 1, 53, 1,
"", "nada", ""); // toggle mode 5

// drop in the compass
compass = new uiCompass(
Expand All @@ -156,7 +141,6 @@ void setup() {
tracklist = new Tracks[numTracks];
for (int i = 0; i < numTracks; i++) {
tracklist[i] = parseXML((String) filenames.get(i));

// pull out the track dimensions
tracklist[i].getDimensions();
};
Expand Down Expand Up @@ -200,23 +184,21 @@ void draw() {
if(mousePressed) {

// any mouse action should probably toggle a re-draw
scene.viewRedraw = true;
scene.viewRedraw = true;

if (!(
if (!(
(mouseX > UI.x && mouseX < (UI.x + UI.wide)) &&
(mouseY > UI.y && mouseY < (UI.y + UI.high))
)) {
// use a cursor image while rotating the scene
// use a cursor image while rotating the scene (I suspect this was causing crashes in OS X, removed for now)
// cursor(scene.cursorHand, scene.cursorHand.width / 2, scene.cursorHand.height / 2);
// (I suspect this was causing crashes in OS X, removed for now)
scene.rotationY += ((float) (mouseX - pmouseX) / 180);
if (scene.viewDimension == "3D") {
scene.rotationX += ((float) (mouseY - pmouseY) / 180);
}
}
}
}


// check the UI components; render needed?
for (int i = 0; i < buttons.length; i++) {
buttons[i].check();
Expand All @@ -228,10 +210,8 @@ void draw() {
checkboxes[i].check();
}


// if we're going to redraw, let's go for it
if (scene.viewRedraw == true) {

if (scene.viewRedraw == true) {
background(scene.palette[0]);
stroke(scene.palette[1]);
noFill();
Expand All @@ -257,9 +237,8 @@ void draw() {
for (int i = 0; i < numTracks; i++) {
tracklist[i].render();
}


// disable deth ordering for the sake of drawing 2D controls over top of the 3D scene

// disable depth ordering for the sake of drawing 2D controls over top of the 3D scene
hint(DISABLE_DEPTH_TEST);
// reset the camera view for 2D drawing
camera();
Expand All @@ -281,7 +260,6 @@ void draw() {

// draw mini-compass
compass.translateThenRender();

};

// reset the viewRedraw switch for each loop so we don't peg the CPU
Expand Down
6 changes: 5 additions & 1 deletion fileParsing.pde
Expand Up @@ -76,9 +76,9 @@ Tracks parseXML(String file) {
*/
int degreeLength = 111000;
scene.averageParallel(Float.parseFloat(coordinates[i][0]));

if (coordinates[i][0] != null) {
scene.averageParallel(Float.parseFloat(coordinates[i][0]));
// pull out the raw latitude coordinates
float phi = radians(Float.parseFloat(coordinates[i][0]));
float adjustedPhi = degrees(0.5 * log((1 + sin(phi)) / (1 - sin(phi))));
Expand Down Expand Up @@ -110,7 +110,11 @@ Tracks parseXML(String file) {
} else {
// only do it if we have more than one point to compare
if (i > 0) {

// result will be in milliseconds, ie. 5 seconds = 1000
long timeDifference = getTimeDifference(obj.time[i], obj.time[i - 1]);
// so let's step it down to seconds
timeDifference *= 0.001;

if (timeDifference > 0) {
// speed = distance / time
Expand Down
39 changes: 8 additions & 31 deletions tracks.pde
Expand Up @@ -91,14 +91,14 @@ class Tracks {
noStroke();
noFill();

color strokeColor = color(0, 0, 0, 0);
if (speed[i] > (0.4 * speedLimit)) {strokeColor = color(0, 0, 255);} // blue
if (speed[i] > (0.8 * speedLimit)) {strokeColor = color(0, 255, 0);} // green
if (speed[i] > (1.6 * speedLimit)) {strokeColor = color(255, 255, 0);} // yellow
if (speed[i] > (2.0 * speedLimit)) {strokeColor = color(255, 192, 0);} // yellow orange
if (speed[i] > (2.4 * speedLimit)) {strokeColor = color(255, 128, 0);} // orange
if (speed[i] > (2.8 * speedLimit)) {strokeColor = color(255, 64, 0);} // orange red
if (speed[i] > (3.2 * speedLimit)) {strokeColor = color(255, 0, 0);} // red
color strokeColor = color(0, 0, 255);
// if (speed[i] > (0.4 * speedLimit)) {strokeColor = color(0, 0, 255);} // blue
// if (speed[i] > (0.8 * speedLimit)) {strokeColor = color(0, 255, 0);} // green
// if (speed[i] > (1.6 * speedLimit)) {strokeColor = color(255, 255, 0);} // yellow
// if (speed[i] > (2.0 * speedLimit)) {strokeColor = color(255, 192, 0);} // yellow orange
// if (speed[i] > (2.4 * speedLimit)) {strokeColor = color(255, 128, 0);} // orange
// if (speed[i] > (2.8 * speedLimit)) {strokeColor = color(255, 64, 0);} // orange red
// if (speed[i] > (3.2 * speedLimit)) {strokeColor = color(255, 0, 0);} // red

// create the fadeout trails
for (int j = 0; j < 64; j++) {
Expand Down Expand Up @@ -126,29 +126,6 @@ class Tracks {



// quad fills
// don't work at the moment because something strange is happening with the rotation.
// only works for X, need to rotate on Y. strange.
case 5:
noStroke();
fill(scene.palette[1], 64);
if (X[i - 1] != 0) {
pushMatrix();
translate(0, 0, Z[i]);
// rotateY(-PI * 0.25);
quad(
X[i], scene.minY,
X[i], Y[i] * scene.elevationExaggeration,
X[i - 1], Y[i - 1] * scene.elevationExaggeration,
X[i - 1], scene.minY
);
popMatrix();
}
break;




}; // end switch
}; //end if
}; // end for
Expand Down

0 comments on commit 78cd21d

Please sign in to comment.