You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
98 lines
2.2 KiB
Java
98 lines
2.2 KiB
Java
import processing.core.PApplet;
|
|
import java.util.ArrayList;
|
|
|
|
class ProjectorApplet extends PApplet {
|
|
final int projectorScreenNumber = 2;
|
|
|
|
final static int centerX = 860;
|
|
final static int centerY = 540;
|
|
|
|
int bgColor = color(0, 0, 0);
|
|
|
|
EuglenaApplet parent;
|
|
Calibrator calibrator;
|
|
|
|
ArrayList<ProjectorCommand> commandQueue;
|
|
|
|
ProjectorApplet(EuglenaApplet parent) {
|
|
this.parent = parent;
|
|
calibrator = new Calibrator(this);
|
|
commandQueue = new ArrayList<>();
|
|
}
|
|
|
|
public void settings() {
|
|
fullScreen(P2D, this.projectorScreenNumber);
|
|
}
|
|
|
|
@Override
|
|
public void setup() {
|
|
clear();
|
|
// smooth(); // Smooth might create artefacts when animating?
|
|
}
|
|
|
|
@Override
|
|
public void draw() {
|
|
ArrayList<Integer> entriesToRemove = new ArrayList<>();
|
|
try {
|
|
for (int i = 0; i < commandQueue.size(); i++) {
|
|
|
|
boolean done = commandQueue.get(i).run(this);
|
|
if (done) {
|
|
entriesToRemove.add(i);
|
|
}
|
|
|
|
}
|
|
} catch (ProjectorCommandException e) {
|
|
// Do nothing
|
|
}
|
|
|
|
// Remove entries (have to do it in reverse order to preserve indices)
|
|
for (int i = entriesToRemove.size() - 1; i >= 0; i--) {
|
|
commandQueue.remove(i);
|
|
}
|
|
|
|
|
|
calibrator.draw(parent);
|
|
}
|
|
|
|
public void reset() {
|
|
commandQueue.clear();
|
|
this.clear();
|
|
}
|
|
|
|
public void clear() {
|
|
fill(bgColor);
|
|
noStroke();
|
|
rectMode(CORNER);
|
|
rect(0, 0, width * 4, height * 4);
|
|
}
|
|
|
|
public void setBgColor(int c) {
|
|
bgColor = c;
|
|
}
|
|
|
|
public void setBgColor(int r, int b, int g) {
|
|
bgColor = color(r, g, b);
|
|
}
|
|
|
|
public int getBgColor() {
|
|
return bgColor;
|
|
}
|
|
|
|
public float convertXCoord(float x) {
|
|
return (x / calibrator.magx + width * calibrator.offsetx);
|
|
}
|
|
|
|
public float convertYCoord(float y) {
|
|
return (y / calibrator.magy + height * calibrator.offsety);
|
|
}
|
|
|
|
public float convertXDistance(float dx) {
|
|
return (dx / calibrator.magx);
|
|
}
|
|
|
|
public float convertYDistance(float dy) {
|
|
return (dy / calibrator.magy);
|
|
}
|
|
}
|