Skip to content

Commit a6d740e

Browse files
committed
fixed trackable selection, examples
1 parent a974b50 commit a6d740e

File tree

3 files changed

+100
-50
lines changed

3 files changed

+100
-50
lines changed

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

Lines changed: 37 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -23,44 +23,13 @@ void draw() {
2323
lights();
2424

2525

26-
for (int i = 0; i < trackableCount(); i++) {
27-
int status = trackableStatus(i);
28-
if (status == PAR.PAUSED || status == PAR.STOPPED) continue;
29-
30-
if (status == PAR.CREATED && trackableCount() < 10) {
31-
if (trackableType(i) == PAR.PLANE_WALL) {
32-
createAnchor(i, 0.3, 0, 0);
33-
} else {
34-
createAnchor(i, 0, 0.3, 0);
35-
}
36-
}
37-
38-
points = getTrackablePolygon(i, points);
39-
40-
getTrackableMatrix(i, mat);
41-
pushMatrix();
42-
applyMatrix(mat);
43-
if (trackableSelected(i, mouseX, mouseY)) {
44-
fill(255, 0, 0, 100);
45-
} else {
46-
fill(255, 100);
47-
}
48-
49-
beginShape();
50-
for (int n = 0; n < points.length/2; n++) {
51-
float x = points[2 * n];
52-
float z = points[2 * n + 1];
53-
vertex(x, 0, z);
54-
}
55-
endShape();
56-
popMatrix();
57-
}
58-
5926
if (mousePressed) {
27+
// Create new anchor at the current touch point
6028
oldSelAnchor = selAnchor;
6129
selAnchor = createAnchor(mouseX, mouseY);
6230
}
6331

32+
// Draw objects attached to each anchor
6433
for (int i = 0; i < anchorCount(); i++) {
6534
int id = anchorId(i);
6635
if (oldSelAnchor == id) {
@@ -88,5 +57,40 @@ void draw() {
8857
popMatrix();
8958
}
9059

60+
// Draw trackable planes
61+
for (int i = 0; i < trackableCount(); i++) {
62+
int status = trackableStatus(i);
63+
if (status == PAR.PAUSED || status == PAR.STOPPED) continue;
64+
65+
if (status == PAR.CREATED && trackableCount() < 10) {
66+
// Add new anchor associated to this trackable, 0.3 meters above it
67+
if (trackableType(i) == PAR.PLANE_WALL) {
68+
createAnchor(i, 0.3, 0, 0);
69+
} else {
70+
createAnchor(i, 0, 0.3, 0);
71+
}
72+
}
73+
74+
points = getTrackablePolygon(i, points);
75+
76+
getTrackableMatrix(i, mat);
77+
pushMatrix();
78+
applyMatrix(mat);
79+
if (mousePressed && trackableSelected(i, mouseX, mouseY)) {
80+
fill(255, 0, 0, 100);
81+
} else {
82+
fill(255, 100);
83+
}
84+
85+
beginShape();
86+
for (int n = 0; n < points.length/2; n++) {
87+
float x = points[2 * n];
88+
float z = points[2 * n + 1];
89+
vertex(x, 0, z);
90+
}
91+
endShape();
92+
popMatrix();
93+
}
94+
9195
angle += 0.1;
9296
}
Lines changed: 62 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,72 @@
11
import processing.ar.*;
22

3-
float angle = 0;
3+
float angle;
4+
float[] points;
5+
PMatrix3D mat = new PMatrix3D();
46

57
void setup() {
68
fullScreen(AR);
7-
PAR.planeColor(0xB4E7FF);
9+
noStroke();
10+
mat = new PMatrix3D();
811
}
912

1013
void draw() {
11-
// At this point, there is no much AR-specific API, but you can get the AR Core session, frame,
12-
// and camera to extract more information about the AR scene.
13-
// PSurfaceAR surface = (PSurfaceAR) getSurface();
14-
// surface.camera.getPose();
15-
// surface.frame.getLightEstimate();
16-
17-
background(0);
1814
lights();
19-
fill(0xFCB736);
20-
noStroke();
21-
sphere(0.10);
22-
rotateZ(angle);
23-
translate(0, 0.3,0);
24-
sphere(0.05);
25-
angle += 0.1;
15+
16+
if (mousePressed) {
17+
// Delete the old touch anchor, if any.
18+
if (0 < anchorCount()) deleteAnchor(0);
19+
20+
// Create a new anchor at the current touch position.
21+
createAnchor(mouseX, mouseY);
22+
}
23+
24+
if (0 < anchorCount()) {
25+
pushMatrix();
26+
anchor(0);
27+
fill(217, 121, 255);
28+
sphere(0.10f);
29+
rotateY(angle);
30+
translate(0, 0, 0.3f);
31+
sphere(0.05f);
32+
angle += 0.1;
33+
popMatrix();
34+
}
35+
36+
for (int i = 0; i < trackableCount(); i++) {
37+
int status = trackableStatus(i);
38+
if (status == PAR.PAUSED || status == PAR.STOPPED) continue;
39+
points = getTrackablePolygon(i, points);
40+
41+
getTrackableMatrix(i, mat);
42+
pushMatrix();
43+
applyMatrix(mat);
44+
45+
if (mousePressed && trackableSelected(i, mouseX, mouseY)) {
46+
fill(255, 0, 0, 100);
47+
} else {
48+
fill(255, 100);
49+
}
50+
51+
float minx = +1000;
52+
float maxx = -1000;
53+
float minz = +1000;
54+
float maxz = -1000;
55+
for (int n = 0; n < points.length/2; n++) {
56+
float x = points[2 * n];
57+
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);
62+
}
63+
beginShape(QUADS);
64+
vertex(minx, 0, minz);
65+
vertex(minx, 0, maxz);
66+
vertex(maxx, 0, maxz);
67+
vertex(maxx, 0, minz);
68+
endShape();
69+
70+
popMatrix();
71+
}
2672
}

mode/libraries/ar/src/processing/ar/PGraphicsAR.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ public boolean trackableSelected(int i, int mx, int my) {
240240
Trackable trackable = hit.getTrackable();
241241
if (trackable instanceof Plane) {
242242
Plane plane = (Plane)trackable;
243-
if (planei == plane && plane.isPoseInPolygon(hit.getHitPose())) {
243+
if (planei.equals(plane) && plane.isPoseInPolygon(hit.getHitPose())) {
244244
return true;
245245
}
246246
}

0 commit comments

Comments
 (0)