Skip to content

Commit 61a9935

Browse files
committed
updated examples
1 parent 95adb35 commit 61a9935

File tree

3 files changed

+43
-45
lines changed

3 files changed

+43
-45
lines changed

mode/libraries/ar/examples/Cubes/Cubes.pde

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -42,19 +42,11 @@ void draw() {
4242
continue;
4343
}
4444

45-
anchor.attach();
46-
fill(255);
47-
rotateY(angle);
48-
box(0.15);
49-
anchor.detach();
45+
drawBox(anchor, 255, 255, 255);
5046
}
5147

5248
if (selAnchor != null) {
53-
selAnchor.attach();
54-
fill(255, 0, 0);
55-
rotateY(angle);
56-
box(0.15);
57-
selAnchor.detach();
49+
drawBox(selAnchor, 255, 0, 0);
5850
}
5951

6052

@@ -96,5 +88,13 @@ void draw() {
9688
popMatrix();
9789
}
9890

99-
angle += 0.1;
91+
angle += 0.1;
92+
}
93+
94+
void drawBox(Anchor anchor, int r, int g, int b) {
95+
anchor.attach();
96+
fill(r, g, b);
97+
rotateY(angle);
98+
box(0.15);
99+
anchor.detach();
100100
}
Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,31 @@
11
import processing.ar.*;
22

3+
Tracker tracker;
4+
Anchor anchor;
35
PShape arObj;
46

57
void setup() {
68
fullScreen(AR);
79
arObj = loadShape("model.obj");
10+
11+
tracker = new Tracker(this);
12+
tracker.start();
813
}
914

1015
void draw() {
1116
lights();
1217

1318
if (mousePressed) {
1419
// Delete the old touch anchor, if any.
15-
if (0 < anchorCount()) deleteAnchor(0);
20+
if (anchor != null) anchor.dispose();
1621

1722
// Create a new anchor at the current touch position.
18-
createAnchor(mouseX, mouseY);
23+
anchor = new Anchor(tracker, mouseX, mouseY);
1924
}
2025

21-
if (0 < anchorCount()) {
22-
anchor(0);
26+
if (anchor != null) {
27+
anchor.attach();
2328
shape(arObj);
29+
anchor.detach();
2430
}
2531
}
Lines changed: 22 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,72 +1,64 @@
11
import processing.ar.*;
22

3+
Tracker tracker;
4+
Anchor anchor;
35
float angle;
4-
float[] points;
5-
PMatrix3D mat = new PMatrix3D();
66

77
void setup() {
88
fullScreen(AR);
99
noStroke();
10-
mat = new PMatrix3D();
10+
11+
tracker = new Tracker(this);
12+
tracker.start();
1113
}
1214

1315
void draw() {
1416
lights();
1517

1618
if (mousePressed) {
1719
// Delete the old touch anchor, if any.
18-
if (0 < anchorCount()) deleteAnchor(0);
20+
if (anchor != null) anchor.dispose();
1921

2022
// Create a new anchor at the current touch position.
21-
createAnchor(mouseX, mouseY);
23+
anchor = new Anchor(tracker, mouseX, mouseY);
2224
}
2325

24-
if (0 < anchorCount()) {
25-
pushMatrix();
26-
anchor(0);
26+
if (anchor != null) {
27+
anchor.attach();
2728
fill(217, 121, 255);
2829
sphere(0.10f);
2930
rotateY(angle);
3031
translate(0, 0, 0.3f);
3132
sphere(0.05f);
3233
angle += 0.1;
33-
popMatrix();
34+
anchor.detach();
3435
}
3536

36-
for (int i = 0; i < trackableCount(); i++) {
37-
int status = trackableStatus(i);
37+
// Draw trackable planes
38+
for (int i = 0; i < tracker.count(); i++) {
39+
Trackable trackable = tracker.get(i);
40+
41+
int status = trackable.status();
3842
if (status == PAR.PAUSED || status == PAR.STOPPED) continue;
39-
points = getTrackablePolygon(i, points);
4043

41-
getTrackableMatrix(i, mat);
42-
pushMatrix();
43-
applyMatrix(mat);
4444

45-
if (mousePressed && trackableSelected(i, mouseX, mouseY)) {
45+
float[] points = trackable.getPolygon();
46+
47+
pushMatrix();
48+
trackable.transform();
49+
if (mousePressed && trackable.selected(mouseX, mouseY)) {
4650
fill(255, 0, 0, 100);
4751
} else {
4852
fill(255, 100);
4953
}
5054

51-
float minx = +1000;
52-
float maxx = -1000;
53-
float minz = +1000;
54-
float maxz = -1000;
55+
beginShape();
5556
for (int n = 0; n < points.length/2; n++) {
5657
float x = points[2 * n];
5758
float z = points[2 * n + 1];
58-
minx = min(minx, x);
59-
maxx = max(maxx, x);
60-
minz = min(minz, z);
61-
maxz = max(maxz, z);
59+
vertex(x, 0, z);
6260
}
63-
beginShape(QUADS);
64-
vertex(minx, 0, minz);
65-
vertex(minx, 0, maxz);
66-
vertex(maxx, 0, maxz);
67-
vertex(maxx, 0, minz);
6861
endShape();
69-
7062
popMatrix();
7163
}
7264
}

0 commit comments

Comments
 (0)