Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also .

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also .
...
  • 2 commits
  • 2 files changed
  • 0 commit comments
  • 2 contributors
Commits on Apr 12, 2012
Lon Riesberg
Added Controls Class to map key bindings to optional GUI controls.
Current release consists of a vertical slider for zoom control.  The
slider can be toggled on/off by pressing the 'c' key.

Slide out controls that map to the other key bindings is currently
being implemented and will be released soon.
Merge pull request #2 from ravenwing/master
Added Controls Class to map key bindings to optional GUI controls.
Showing with 145 additions and 7 deletions.
  1. +95 −0 Kepler2012/Controls.pde
  2. +50 −7 Kepler2012/Kepler2012.pde
View
@@ -0,0 +1,95 @@
+/*
+
+ Kepler Visualization - Controls
+
+ GUI controls added by Lon Riesberg, Laboratory for Atmospheric and Space Physics
+ lon@ieee.org
+
+ April, 2012
+
+ Current release consists of a vertical slider for zoom control. The slider can be toggled
+ on/off by pressing the 'c' key.
+
+ Slide out controls that map to the other key bindings is currently being implemented and
+ will be released soon.
+
+*/
+
+class Controls {
+
+ int barWidth;
+ int barX; // x-coordinate of zoom control
+ int minY, maxY; // y-coordinate range of zoom control
+ float minZoomValue, maxZoomValue; // values that map onto zoom control
+ float valuePerY; // zoom value of each y-pixel
+ int sliderY; // y-coordinate of current slider position
+ float sliderValue; // value that corresponds to y-coordinate of slider
+ int sliderWidth, sliderHeight;
+ int sliderX; // x-coordinate of left-side slider edge
+
+ Controls () {
+
+ barX = 40;
+ barWidth = 15;
+
+ minY = 40;
+ maxY = minY + height/3 - sliderHeight/2;
+
+ minZoomValue = 0.0;
+ maxZoomValue = 3.0; // 300 percent
+ valuePerY = (maxZoomValue - minZoomValue) / (maxY - minY);
+
+ sliderWidth = 25;
+ sliderHeight = 10;
+ sliderX = (barX + (barWidth/2)) - (sliderWidth/2);
+ sliderValue = minZoomValue;
+ sliderY = minY;
+ }
+
+
+ void render() {
+
+ strokeWeight(0.5);
+ stroke(105, 105, 105);
+
+ // zoom control bar
+ fill(0, 0, 0, 0);
+ rect(barX, minY, barWidth, maxY-minY);
+
+ // slider
+ fill(105, 105, 105);
+ rect(sliderX, sliderY, sliderWidth, sliderHeight);
+ }
+
+
+ float getZoomValue(int y) {
+ if ((y >= minY) && (y <= (maxY - sliderHeight/2))) {
+ sliderY = (int) (y - (sliderHeight/2));
+ if (sliderY < minY) {
+ sliderY = minY;
+ }
+ sliderValue = (y - minY) * valuePerY + minZoomValue;
+ }
+ return sliderValue;
+ }
+
+
+ void updateZoomSlider(float value) {
+ int tempY = (int) (value / valuePerY) + minY;
+ if ((tempY >= minY) && (tempY <= (maxY-sliderHeight))) {
+ sliderValue = value;
+ sliderY = tempY;
+ }
+ }
+
+
+ boolean isZoomSliderEvent(int x, int y) {
+ int slop = 50; // number of pixels above or below slider that's acceptable. provided for ease of use.
+ int sliderTop = (int) (sliderY - (sliderHeight/2)) - slop;
+ int sliderBottom = sliderY + sliderHeight + slop;
+ return ((x >= sliderX) && (x <= (sliderX + sliderWidth)) && (y >= sliderTop) && (y <= sliderBottom));
+ }
+}
+
+
+
View
@@ -46,6 +46,11 @@ float tzoom = 0.3;
float flatness = 0;
float tflatness = 0;
+// add controls (e.g. zoom, sort selection)
+Controls controls;
+int showControls;
+boolean draggingZoomSlider = false;
+
void setup() {
size(screenWidth, screenHeight, OPENGL);
background(0);
@@ -62,6 +67,10 @@ void setup() {
println(planets.size());
addMarkerPlanets();
updatePlanetColors();
+
+ controls = new Controls();
+ showControls = 1;
+
}
void getPlanets(String url, boolean is2012) {
@@ -163,23 +172,44 @@ void addMarkerPlanets() {
void draw() {
// Ease rotation vectors, zoom
-
- zoom += (tzoom - zoom) * 0.01;
+ zoom += (tzoom - zoom) * 0.01;
+ if (zoom < 0) {
+ zoom = 0;
+ } else if (zoom > 3.0) {
+ zoom = 3.0;
+ }
+ controls.updateZoomSlider(zoom);
rot.x += (trot.x - rot.x) * 0.1;
rot.y += (trot.y - rot.y) * 0.1;
rot.z += (trot.z - rot.z) * 0.1;
// Ease the flatness weight
flatness += (tflatness - flatness) * 0.1;
- // MousePress Rotation Adjustment
+ // MousePress - Controls Handling
if (mousePressed) {
- trot.x += (pmouseY - mouseY) * 0.01;
- trot.z += (pmouseX - mouseX) * 0.01;
+ if((showControls == 1) && controls.isZoomSliderEvent(mouseX, mouseY)) {
+ draggingZoomSlider = true;
+ zoom = controls.getZoomValue(mouseY);
+ tzoom = zoom;
+ }
+
+ // MousePress - Rotation Adjustment
+ else if (!draggingZoomSlider) {
+ trot.x += (pmouseY - mouseY) * 0.01;
+ trot.z += (pmouseX - mouseX) * 0.01;
+ }
}
+
+
background(10);
+ // show controls
+ if (showControls == 1) {
+ controls.render();
+ }
+
// We want the center to be in the middle and slightly down when flat, and to the left and down when raised
translate(width/2 - (width * flatness * 0.4), height/2 + (160 * rot.x));
rotateX(rot.x);
@@ -260,7 +290,12 @@ void draw() {
p.update();
p.render();
}
- }
+ }
+
+
+
+
+
}
void sortBySize() {
@@ -288,7 +323,9 @@ void keyPressed() {
String timeStamp = hour() + "_" + minute() + "_" + second();
if (key == 's') {
save("out/Kepler" + timeStamp + ".png");
- }
+ } else if (key == 'c'){
+ showControls = -1 * showControls;
+ }
if (keyCode == UP) {
tzoom += 0.025;
@@ -340,3 +377,9 @@ void toggleFlatness(float f) {
}
}
+void mouseReleased() {
+ draggingZoomSlider = false;
+}
+
+
+

No commit comments for this range