Permalink
Browse files

First stabs at an adjustable scale; the functionality is there, but I…

…'m really not sure about that accuracy. Some measurements seem dead on, some seem off by quite a lot. Math: apparently it's important.
  • Loading branch information...
1 parent ad94502 commit ab79499094338b5442357dceab54b2117c66c026 @mezzoblue committed Nov 9, 2009
Showing with 118 additions and 6 deletions.
  1. +12 −3 Elevation.pde
  2. +1 −1 tracks.pde
  3. +105 −2 ui.pde
View
@@ -25,7 +25,8 @@ int numTracks;
// scene-related objects
uiPanel UI;
Scene scene;
-Crosshairs crosshair;
+uiCrosshairs crosshair;
+uiScale mapScale;
uiButton[] buttons;
uiCheckbox[] checkboxes;
uiSwitch[] switches;
@@ -118,11 +119,12 @@ void setup() {
691, scene.canvasHeight - 82, 40, 28,
"UI-Switch-4", "nada", "");
+ // drop in the compass
compass = new uiCompass(
scene.canvasWidth / 2, scene.canvasHeight - 50, 31, 31);
// create the crosshairs object
- crosshair = new Crosshairs();
+ crosshair = new uiCrosshairs();
// get the map data XML files
filenames = listFileNames(dataPath("") + "/xml/");
@@ -142,6 +144,9 @@ void setup() {
tracklist[i].createLimits();
};
+ // create the map scale object once the map data is loaded
+ mapScale = new uiScale(scene.canvasWidth / 2, scene.canvasHeight - 101, scene.canvasWidth, 5);
+
// diagnostics
println("Number of Tracks: " + numTracks);
println("minX: " + scene.minX);
@@ -153,7 +158,7 @@ void setup() {
println("minSpeed: " + scene.minSpeed);
println("maxSpeed: " + scene.maxSpeed);
- // set the viewRedraw flag coming out of setup so that we get the initial draw
+ // set the viewRedraw flag coming out of setup() so that we get the initial draw
scene.viewRedraw = true;
};
@@ -252,8 +257,12 @@ void draw() {
switches[i].render();
}
+ // draw the map scale
+ mapScale.render(scene.palette[1]);
+
// draw mini-compass
compass.translateThenRender();
+
};
// reset the viewRedraw switch for each loop so we don't peg the CPU
View
@@ -17,7 +17,7 @@ class Tracks {
// constructor
Tracks(int num) {
pointCount = num;
- X = new float[pointCount];
+ X = new float[point];
Y = new float[pointCount];
Z = new float[pointCount];
speed = new float[pointCount];
View
@@ -169,6 +169,7 @@ class uiButton extends uiElement {
};
+
// basic checkbox
class uiCheckbox extends uiElement {
@@ -291,6 +292,7 @@ class uiCompass extends uiElement {
rotateX(scene.rotationX + PI / 2);
rotateZ(-scene.rotationY - PI / 2);
// north is light blue
+ noStroke();
fill(#616c7c);
quad(0,-16,4,-5,0,0,-4,-5);
// all other arms are darker blue
@@ -304,12 +306,112 @@ class uiCompass extends uiElement {
+// map scale indicator
+class uiScale {
+
+ Boolean toggle;
+
+ // position
+ int x, y;
+ // dimensions
+ int wide, high;
+ // kilometer markers
+ float kmInterval, kmScale;
+
+ uiScale(int newX, int newY, int newWide, int newHigh) {
+ toggle = true;
+ x = newX;
+ y = newY;
+ wide = newWide;
+ high = newHigh;
+ };
+
+ void render(color col) {
+ if (toggle) {
+
+ // distance between kilometers, based on variable drawingScale value
+ kmInterval = scene.drawingScale * (scene.maxX - scene.minX);
+
+ // how many kilometers wide the base scale is, based on scene width
+ kmScale = round((scene.maxX - scene.minX));
+
+ float kmCurrent = kmScale / kmInterval;
+
+ // 13.682
+ println(kmCurrent);
+ // 1000
+ println(kmInterval);
+
+ println(scene.maxX - scene.minX);
+
+ pushMatrix();
+ strokeWeight(1);
+ translate(x, y);
+
+ // draw the 100k markers
+ if (kmInterval < 75) {
+ for (int i = 0; i <= round(kmCurrent) / 100; i++) {
+ stroke(col, 160);
+ strokeWeight(3);
+ float thisKm = (i * kmInterval * 10) - wide / 2;
+ line(thisKm, -24, thisKm, 0);
+ };
+ };
+
+
+ // draw the 10k markers
+ if (kmInterval < 3000) {
+ for (int i = 0; i <= round(kmCurrent) / 10; i++) {
+ stroke(col, 120);
+ strokeWeight(2);
+ float thisKm = (i * kmInterval) - wide / 2;
+ line(thisKm, -16, thisKm, 0);
+ };
+ };
+
+
+ // draw the kilometer markers
+ if (kmInterval > 40) {
+ for (int i = 0; i <= round(kmCurrent); i++) {
+ stroke(col, 80);
+ float thisKm = (i * kmInterval / 10) - wide / 2;
+ line(thisKm, -8, thisKm, 0);
+ };
+ };
+
+ // draw the hundred meter markers
+ if (kmInterval > 400) {
+ for (int i = 0; i <= round(kmCurrent) * 10; i++) {
+ stroke(col, 40);
+ float thisM = (kmInterval / 100) * i - wide / 2;
+ line(thisM, -4, thisM, 0);
+ };
+ };
+
+ if (kmInterval > 3000) {
+ // draw the ten meter markers
+ for (int i = 0; i <= round(kmCurrent) * 100; i++) {
+ stroke(col, 40);
+ float thisM = (kmInterval / 1000) * i - wide / 2;
+ line(thisM, -2, thisM, 0);
+ };
+ };
+
+ popMatrix();
+
+ };
+ };
+
+};
+
+
+
// main crosshairs
-class Crosshairs {
+class uiCrosshairs {
Boolean toggle;
- Crosshairs() {
+ uiCrosshairs() {
toggle = true;
}
@@ -422,6 +524,7 @@ void keyPressed() {
};
+
int determineOffset() {
try {
if (keyEvent.isControlDown()) {

0 comments on commit ab79499

Please sign in to comment.