1
1
import processing.ar.* ;
2
2
3
3
ARTracker tracker;
4
- ARAnchor touchAnchor;
5
4
ArrayList<ARAnchor > trackAnchors = new ArrayList<ARAnchor > ();
5
+ ARAnchor touchAnchor;
6
6
PShape obj;
7
7
8
8
void setup () {
9
9
fullScreen(AR );
10
10
obj = loadShape (" model.obj" );
11
-
12
11
tracker = new ARTracker (this );
13
12
tracker. start();
14
- noStroke ();
13
+ noStroke ();
15
14
}
16
15
17
16
void draw () {
18
17
lights ();
19
-
20
18
drawObject(touchAnchor);
21
- for (ARAnchor anchor : trackAnchors) {
22
- if (anchor. isTracking()) drawSphere(anchor);
23
- if (anchor. isStopped()) anchor. dispose();
24
- }
25
- tracker. clearAnchors(trackAnchors);
26
-
19
+ drawAnchors();
27
20
drawTrackables();
28
21
}
29
22
@@ -40,42 +33,51 @@ void trackableEvent(ARTrackable t) {
40
33
}
41
34
}
42
35
43
- void drawObject (ARAnchor anchor ) {
44
- if (anchor != null ) {
45
- anchor. attach();
46
- shape (obj);
47
- anchor. detach();
36
+ void drawAnchors () {
37
+ for (ARAnchor anchor : trackAnchors) {
38
+ if (anchor. isTracking()) drawSphere(anchor, 0.05 );
39
+ if (anchor. isStopped()) anchor. dispose();
48
40
}
49
- }
50
-
51
- void drawSphere (ARAnchor anchor ) {
52
- anchor. attach();
53
- fill (#CF79F5 );
54
- sphere (0.05 );
55
- anchor. detach();
41
+ tracker. clearAnchors(trackAnchors);
56
42
}
57
43
58
44
void drawTrackables () {
59
45
for (int i = 0 ; i < tracker. count(); i++ ) {
60
- ARTrackable trackable = tracker. get(i);
61
- if (! trackable. isTracking()) continue ;
62
-
46
+ ARTrackable t = tracker. get(i);
63
47
pushMatrix ();
64
- trackable. transform();
65
- if (mousePressed && trackable. isSelected(mouseX , mouseY )) {
48
+ t. transform();
49
+ float lx = t. lengthX();
50
+ float lz = t. lengthZ();
51
+ if (mousePressed && t. isSelected(mouseX , mouseY )) {
66
52
fill (255 , 0 , 0 , 100 );
67
53
} else {
68
54
fill (255 , 100 );
69
55
}
70
-
71
- beginShape (QUADS );
72
- float lx = trackable. lengthX();
73
- float lz = trackable. lengthZ();
74
- vertex (- lx/ 2 , 0 , - lz/ 2 );
75
- vertex (- lx/ 2 , 0 , + lz/ 2 );
76
- vertex (+ lx/ 2 , 0 , + lz/ 2 );
77
- vertex (+ lx/ 2 , 0 , - lz/ 2 );
78
- endShape ();
79
- popMatrix ();
56
+ drawPlane(lx, lz);
57
+ popMatrix ();
80
58
}
81
59
}
60
+
61
+ void drawSphere (ARAnchor anchor , float r ) {
62
+ anchor. attach();
63
+ fill (#CF79F5 );
64
+ sphere (r);
65
+ anchor. detach();
66
+ }
67
+
68
+ void drawPlane (float lx , float lz ) {
69
+ beginShape (QUADS );
70
+ vertex (- lx/ 2 , 0 , - lz/ 2 );
71
+ vertex (- lx/ 2 , 0 , + lz/ 2 );
72
+ vertex (+ lx/ 2 , 0 , + lz/ 2 );
73
+ vertex (+ lx/ 2 , 0 , - lz/ 2 );
74
+ endShape ();
75
+ }
76
+
77
+ void drawObject (ARAnchor anchor ) {
78
+ if (anchor != null ) {
79
+ anchor. attach();
80
+ shape (obj);
81
+ anchor. detach();
82
+ }
83
+ }
0 commit comments