Skip to content

Commit 95adb35

Browse files
committed
aded Anchor class and removed AR API from PApplet
1 parent d471ead commit 95adb35

File tree

7 files changed

+134
-285
lines changed

7 files changed

+134
-285
lines changed

core/src/processing/core/PApplet.java

Lines changed: 0 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -9352,83 +9352,6 @@ public void printProjection() {
93529352
}
93539353

93549354

9355-
//////////////////////////////////////////////////////////////
9356-
9357-
// TENTATIVE AR API
9358-
9359-
9360-
public int trackableCount() {
9361-
return g.trackableCount();
9362-
}
9363-
9364-
public int trackableId(int i) {
9365-
return g.trackableId(i);
9366-
}
9367-
9368-
public int trackableType(int i) {
9369-
return g.trackableType(i);
9370-
}
9371-
9372-
public int trackableStatus(int i) {
9373-
return g.trackableStatus(i);
9374-
}
9375-
9376-
public boolean trackableSelected(int i, int mx, int my) {
9377-
return g.trackableSelected(i, mx, my);
9378-
}
9379-
9380-
public float[] getTrackablePolygon(int i) {
9381-
return g.getTrackablePolygon(i);
9382-
}
9383-
9384-
public float[] getTrackablePolygon(int i, float[] points) {
9385-
return g.getTrackablePolygon(i, points);
9386-
}
9387-
9388-
public PMatrix3D getTrackableMatrix(int i) {
9389-
return g.getTrackableMatrix(i);
9390-
}
9391-
9392-
public PMatrix3D getTrackableMatrix(int i, PMatrix3D target) {
9393-
return g.getTrackableMatrix(i, target);
9394-
}
9395-
9396-
public int anchorCount() {
9397-
return g.anchorCount();
9398-
}
9399-
9400-
public int anchorId(int i) {
9401-
return g.anchorId(i);
9402-
}
9403-
9404-
public int anchorStatus(int i) {
9405-
return g.anchorStatus(i);
9406-
}
9407-
9408-
public int createAnchor(int i, float x, float y, float z) {
9409-
return g.createAnchor(i, x, y, z);
9410-
}
9411-
9412-
public int createAnchor(int mx, int my) {
9413-
return g.createAnchor(mx, my);
9414-
}
9415-
9416-
public void deleteAnchor(int i) {
9417-
g.deleteAnchor(i);
9418-
}
9419-
9420-
public PMatrix3D getAnchorMatrix(int i) {
9421-
return g.getAnchorMatrix(i);
9422-
}
9423-
9424-
public PMatrix3D getAnchorMatrix(int i, PMatrix3D target) {
9425-
return g.getAnchorMatrix(i, target);
9426-
}
9427-
9428-
public void anchor(int i) {
9429-
g.anchor(i);
9430-
}
9431-
94329355
// ***********************************************************************************************
94339356

94349357

core/src/processing/core/PGraphics.java

Lines changed: 0 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -4229,105 +4229,6 @@ public void eye() {
42294229
}
42304230

42314231

4232-
//////////////////////////////////////////////////////////////
4233-
4234-
// TENTATIVE AR API
4235-
4236-
public int trackableCount() {
4237-
showMissingWarning("trackableCount");
4238-
return 0;
4239-
}
4240-
4241-
public int trackableId(int i) {
4242-
showMissingWarning("trackableId");
4243-
return 0;
4244-
}
4245-
4246-
public int trackableType(int i) {
4247-
showMissingWarning("trackableType");
4248-
return 0;
4249-
}
4250-
4251-
public int trackableStatus(int i) {
4252-
showMissingWarning("trackableStatus");
4253-
return 0;
4254-
}
4255-
4256-
public boolean trackableSelected(int i, int mx, int my) {
4257-
showMissingWarning("trackableSelected");
4258-
return false;
4259-
}
4260-
4261-
public float[] getTrackablePolygon(int i) {
4262-
showMissingWarning("getTrackablePolygon");
4263-
return null;
4264-
}
4265-
4266-
4267-
public float[] getTrackablePolygon(int i, float[] points) {
4268-
showMissingWarning("getTrackablePolygon");
4269-
return null;
4270-
}
4271-
4272-
public PMatrix3D getTrackableMatrix(int i) {
4273-
showMissingWarning("getTrackableMatrix");
4274-
return null;
4275-
}
4276-
4277-
4278-
public PMatrix3D getTrackableMatrix(int i, PMatrix3D target) {
4279-
showMissingWarning("getTrackableMatrix");
4280-
return null;
4281-
}
4282-
4283-
4284-
public int anchorCount() {
4285-
showMissingWarning("anchorCount");
4286-
return 0;
4287-
}
4288-
4289-
public int anchorId(int i) {
4290-
showMissingWarning("anchorId");
4291-
return 0;
4292-
}
4293-
4294-
public int anchorStatus(int i) {
4295-
showMissingWarning("anchorStatus");
4296-
return 0;
4297-
}
4298-
4299-
public int createAnchor(int i, float x, float y, float z) {
4300-
showMissingWarning("createAnchor");
4301-
return 0;
4302-
}
4303-
4304-
public int createAnchor(int mx, int my) {
4305-
showMissingWarning("createAnchor");
4306-
return 0;
4307-
}
4308-
4309-
public void deleteAnchor(int i) {
4310-
showMissingWarning("deleteAnchor");
4311-
}
4312-
4313-
4314-
public PMatrix3D getAnchorMatrix(int i) {
4315-
showMissingWarning("getAnchorMatrix");
4316-
return null;
4317-
}
4318-
4319-
4320-
public PMatrix3D getAnchorMatrix(int i, PMatrix3D target) {
4321-
showMissingWarning("getAnchorMatrix");
4322-
return null;
4323-
}
4324-
4325-
4326-
public void anchor(int i) {
4327-
showMethodWarning("anchor");
4328-
}
4329-
4330-
43314232
//////////////////////////////////////////////////////////////
43324233

43334234
// PROJECTION
Lines changed: 39 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
import processing.ar.*;
22

3-
float[] points;
4-
PMatrix3D mat;
53
float angle;
6-
int oldSelAnchor;
7-
int selAnchor;
4+
Anchor selAnchor;
5+
ArrayList<Anchor> regAnchors;
6+
7+
Tracker tracker;
88

99
void setup() {
1010
fullScreen(AR);
1111
mat = new PMatrix3D();
12+
13+
tracker = new Tracker(this);
14+
tracker.start();
15+
regAnchors = new ArrayList<Anchor>();
1216
}
1317

1418
void draw() {
@@ -25,58 +29,58 @@ void draw() {
2529

2630
if (mousePressed) {
2731
// Create new anchor at the current touch point
28-
oldSelAnchor = selAnchor;
29-
selAnchor = createAnchor(mouseX, mouseY);
32+
if (selAnchor != null) selAnchor.dispose();
33+
selAnchor = new Anchor(tracker, mouseX, mouseY);
3034
}
3135

3236
// Draw objects attached to each anchor
33-
for (int i = 0; i < anchorCount(); i++) {
34-
int id = anchorId(i);
35-
if (oldSelAnchor == id) {
36-
deleteAnchor(i);
37-
continue;
38-
}
37+
for (Anchor anchor: regAnchors) {
3938

40-
int status = anchorStatus(i);
39+
int status = anchor.status(i);
4140
if (status == PAR.PAUSED || status == PAR.STOPPED) {
42-
if (status == PAR.STOPPED) deleteAnchor(i);
41+
if (status == PAR.STOPPED) anchor.dispose();
4342
continue;
4443
}
4544

46-
pushMatrix();
47-
anchor(i);
48-
49-
if (selAnchor == id) {
50-
fill(255, 0, 0);
51-
} else {
52-
fill(255);
53-
}
45+
anchor.attach();
46+
fill(255);
47+
rotateY(angle);
48+
box(0.15);
49+
anchor.detach();
50+
}
5451

52+
if (selAnchor != null) {
53+
selAnchor.attach();
54+
fill(255, 0, 0);
5555
rotateY(angle);
5656
box(0.15);
57-
popMatrix();
57+
selAnchor.detach();
5858
}
59+
5960

6061
// Draw trackable planes
61-
for (int i = 0; i < trackableCount(); i++) {
62-
int status = trackableStatus(i);
62+
for (int i = 0; i < tracker.count(); i++) {
63+
Trackable trackable = tracker.get(i);
64+
65+
int status = trackable.status();
6366
if (status == PAR.PAUSED || status == PAR.STOPPED) continue;
6467

65-
if (status == PAR.CREATED && trackableCount() < 10) {
68+
if (status == PAR.CREATED && regAnchor.size() < 10) {
6669
// 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);
70+
Anchor anchor;
71+
if (trackable.type() == PAR.PLANE_WALL) {
72+
anchor = new Anchor(trackable, 0.3, 0, 0);
6973
} else {
70-
createAnchor(i, 0, 0.3, 0);
74+
anchor = new Anchor(trackable, 0, 0.3, 0);
7175
}
76+
regAnchors.add(anchor);
7277
}
7378

74-
points = getTrackablePolygon(i, points);
75-
76-
getTrackableMatrix(i, mat);
79+
float[] points = trackable.getPolygon();
80+
7781
pushMatrix();
78-
applyMatrix(mat);
79-
if (mousePressed && trackableSelected(i, mouseX, mouseY)) {
82+
trackable.transform();
83+
if (mousePressed && trackable.selected(mouseX, mouseY)) {
8084
fill(255, 0, 0, 100);
8185
} else {
8286
fill(255, 100);
@@ -93,4 +97,4 @@ void draw() {
9397
}
9498

9599
angle += 0.1;
96-
}
100+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package processing.ar;
2+
3+
import processing.core.PMatrix3D;
4+
5+
public class Anchor implements PAR {
6+
protected PGraphicsAR g;
7+
8+
private int id;
9+
private PMatrix3D m;
10+
11+
public Anchor(Trackable trackable, float x, float y, float z) {
12+
this.g = trackable.g;
13+
14+
int idx = g.trackableIndex(Integer.parseInt(trackable.id()));
15+
id = g.createAnchor(idx, x, y, z);
16+
}
17+
18+
public Anchor(Tracker tracker, int mx, int my) {
19+
this.g = tracker.g;
20+
id = g.createAnchor(mx, my);
21+
}
22+
23+
public void dispose() {
24+
g.deleteAnchor(id);
25+
}
26+
27+
public String id() {
28+
return String.valueOf(id);
29+
}
30+
31+
public int status() {
32+
return g.anchorStatus(id);
33+
}
34+
35+
public PMatrix3D matrix() {
36+
return m;
37+
}
38+
39+
public void attach() {
40+
g.pushMatrix();
41+
g.applyMatrix(matrix());
42+
}
43+
44+
public void detach() {
45+
g.popMatrix();
46+
}
47+
}

0 commit comments

Comments
 (0)