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

69 lines
1.3 KiB
Plaintext

int marker_stroke_weight;
int marker_stroke_width;
float marker_move_step;
class Marker {
PVector p, c;
float w, h;
PImage image;
PVector dest;
boolean onDest;
public Marker(PImage img) {
this.image = img;
this.w = img.width;
this.h = img.height;
this.c = new PVector(width/2., height/2.);
this.p = new PVector(c.x - w/2., c.y - h/2.);
this.dest = this.p;
this.onDest = true;
}
public void draw() {
image(image, p.x, p.y);
stroke(255, 0, 0);
strokeWeight(marker_stroke_weight);
line(c.x - marker_stroke_width, c.y, c.x + marker_stroke_width, c.y);
line(c.x, c.y - marker_stroke_width, c.x, c.y + marker_stroke_width);
}
public void update() {
if (p.x != dest.x || p.y != dest.y) {
onDest = false;
PVector diff = dest.get();
diff.sub(p);
if (diff.mag() > marker_move_step) {
diff.normalize();
moveX(diff.x * marker_move_step);
moveY(diff.y * marker_move_step);
} else {
setX(dest.x);
setY(dest.y);
}
} else {
onDest = true;
}
}
public void moveX(float step) {
this.p.x += step;
this.c.x += step;
}
public void moveY(float step) {
this.p.y += step;
this.c.y += step;
}
public void setX(float x) {
this.p.x = x;
this.c.x = x + w/2.;
}
public void setY(float y) {
this.p.y = y;
this.c.y = y + h/2.;
}
}