gazesim/code/recording/util/SingleMarkerVisualizer/SingleMarkerVisualizer.pde

177 lines
4.2 KiB
Plaintext

Marker marker;
CalibrationBoard gc, gc_test;
String status = "not started";
int mark_pause_start = -1;
int curr_mark = 0;
boolean pause = true;
boolean finished = false;
boolean display_marks = true;
boolean calibration_mode = true;
boolean display_stats = true;
float start_delay = 3;
int count_down_begin;
void setup() {
fullScreen();
//size(640, 480);
frameRate(60);
screen_border_width = 0;
mark_pause = 2.0; // in seconds
marker_stroke_weight = 4;
marker_stroke_width = 13;
marker_move_step = 7;
PImage img = loadImage("1023.png");
marker_image_width = img.width;
marker = new Marker(img);
gc = new CalibrationBoard(1, 5, 0, 0, -1, -1); // means 5-point grid
gc_test = new CalibrationBoard(1, 4, (gc.xgap + marker_image_width)/2., (gc.ygap + marker_image_width)/2., gc.xgap, gc.ygap);
resetMarker();
}
void reset() {
mark_pause_start = -1;
curr_mark = 0;
pause = true;
finished = false;
display_marks = true;
calibration_mode = true;
gc = new CalibrationBoard(1, 5, 0, 0, -1, -1); // means 5-point grid
gc_test = new CalibrationBoard(1, 4, (gc.xgap + marker_image_width)/2., (gc.ygap + marker_image_width)/2., gc.xgap, gc.ygap);
resetMarker();
}
void resetMarker() {
float x, y;
if (calibration_mode) {
x = gc.marks[curr_mark].x - marker_image_width/2.;
y = gc.marks[curr_mark].y - marker_image_width/2.;
} else {
x = gc_test.marks[curr_mark].x - marker_image_width/2.;
y = gc_test.marks[curr_mark].y - marker_image_width/2.;
}
marker.dest = new PVector(x, y);
marker.setX(x);
marker.setY(y);
}
void draw() {
background(255);
if (!finished) {
marker.draw();
marker.update();
}
if (!pause) {
if (frameCount - count_down_begin > start_delay * frameRate) {
status = "started";
if (marker.onDest) {
if (mark_pause_start < 0) {
mark_pause_start = frameCount;
} else {
status = ((frameCount - mark_pause_start) / frameRate) + "";
if (frameCount - mark_pause_start > mark_pause * frameRate) {
if ((calibration_mode && curr_mark < gc.inds.length-1) || (!calibration_mode && curr_mark < gc_test.inds.length-1)) {
PVector destC;
if (calibration_mode) {
destC = gc.marks[++curr_mark];
} else {
destC = gc_test.marks[++curr_mark];
}
marker.dest = new PVector(destC.x - marker_image_width/2., destC.y - marker_image_width/2.);
} else {
status = "finished";
finished = true;
}
}
}
} else {
status = "moving";
mark_pause_start = -1;
}
} else {
text(((frameCount - count_down_begin)/frameRate) + "/" + start_delay, width/2, height-7);
}
} else {
status = "paused";
}
if (display_marks) {
gc.drawMarks();
gc_test.drawMarks();
}
//fill(255, 0, 0);
//noStroke();
//ellipse(marker.dest.x, marker.dest.y, 5, 5);
//fill(0, 0, 255);
//for (PVector m: gc.marks) {
// ellipse(m.x - marker_image_width/2., m.y - marker_image_width/2., 5, 5);
//}
if (finished) {
fill(255, 0, 0);
} else if (pause) {
fill(0);
} else {
fill(0, 0, 255);
}
if (display_stats) {
text("status: " + status, 3, 13);
String progress;
if (calibration_mode) {
progress = (curr_mark+1) + "/" + gc.inds.length;
} else {
progress = (curr_mark+1) + "/" + gc_test.inds.length;
}
text(progress, 3, height-7);
}
}
void keyPressed() {
println(keyCode);
switch (keyCode) {
case 32: // Space Button
pause = !pause;
display_marks = false;
if (!pause)
count_down_begin = frameCount;
break;
case 77: // M key
display_marks = !display_marks;
break;
case 67: // C key
curr_mark = 0;
calibration_mode = true;
println("calibration mode");
resetMarker();
break;
case 84: // T key
curr_mark = 0;
calibration_mode = false;
println("test mode");
resetMarker();
break;
case 82: // R key
reset();
break;
case 83: // S key
saveFrame("screenshot_###.png");
break;
case 72: // H key
display_stats = !display_stats;
break;
default:
break;
}
}