Skip to content

Commit eeaad35

Browse files
committed
workong on the AR API
1 parent 79121cc commit eeaad35

File tree

6 files changed

+532
-90
lines changed

6 files changed

+532
-90
lines changed

core/src/processing/core/PApplet.java

Lines changed: 89 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9233,6 +9233,7 @@ public PMatrix3D getEyeMatrix() {
92339233
return g.getEyeMatrix();
92349234
}
92359235

9236+
92369237
/**
92379238
* Copy the current eye matrix into the specified target.
92389239
* Pass in null to create a new matrix.
@@ -9242,11 +9243,6 @@ public PMatrix3D getEyeMatrix(PMatrix3D target) {
92429243
}
92439244

92449245

9245-
public PMatrix3D getAnchorMatrix() { return g.getAnchorMatrix(); }
9246-
9247-
9248-
public PMatrix3D getAnchorMatrix(PMatrix3D target) { return g.getAnchorMatrix(target); }
9249-
92509246
/**
92519247
* Set the current transformation matrix to the contents of another.
92529248
*/
@@ -9316,11 +9312,6 @@ public void eye() {
93169312
}
93179313

93189314

9319-
public void anchor() {
9320-
g.anchor();
9321-
}
9322-
9323-
93249315
public void ortho() {
93259316
g.ortho();
93269317
}
@@ -9361,6 +9352,94 @@ public void printProjection() {
93619352
}
93629353

93639354

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) {
9377+
return g.trackableSelected(i);
9378+
}
9379+
9380+
public float trackableExtentX(int i) {
9381+
return g.trackableExtentX(i);
9382+
}
9383+
9384+
public float trackableExtentZ(int i) {
9385+
return g.trackableExtentZ(i);
9386+
}
9387+
9388+
public float[] getTrackablePolygon(int i) {
9389+
return g.getTrackablePolygon(i);
9390+
}
9391+
9392+
public float[] getTrackablePolygon(int i, float[] points) {
9393+
return g.getTrackablePolygon(i, points);
9394+
}
9395+
9396+
public PMatrix3D getTrackableMatrix(int i) {
9397+
return g.getTrackableMatrix(i);
9398+
}
9399+
9400+
public PMatrix3D getTrackableMatrix(int i, PMatrix3D target) {
9401+
return g.getTrackableMatrix(i, target);
9402+
}
9403+
9404+
public int anchorCount() {
9405+
return g.anchorCount();
9406+
}
9407+
9408+
public int anchorId(int i) {
9409+
return g.anchorId(i);
9410+
}
9411+
9412+
public int anchorStatus(int id) {
9413+
return g.anchorStatus(id);
9414+
}
9415+
9416+
public int createAnchor() {
9417+
return g.createAnchor();
9418+
}
9419+
9420+
public int createAnchor(int trackId, float x, float y, float z) {
9421+
return g.createAnchor(trackId, x, y, z);
9422+
}
9423+
9424+
public void deleteAnchor(int id) {
9425+
g.deleteAnchor(id);
9426+
}
9427+
9428+
public PMatrix3D getAnchorMatrix(int id) {
9429+
return g.getAnchorMatrix(id);
9430+
}
9431+
9432+
public PMatrix3D getAnchorMatrix(int id, PMatrix3D target) {
9433+
return g.getAnchorMatrix(id, target);
9434+
}
9435+
9436+
public void anchor(int id) {
9437+
g.anchor(id);
9438+
}
9439+
9440+
// ***********************************************************************************************
9441+
9442+
93649443
/**
93659444
* Given an x and y coordinate, returns the x position of where
93669445
* that point would be placed on screen, once affected by translate(),

core/src/processing/core/PGraphics.java

Lines changed: 107 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4151,26 +4151,6 @@ public PMatrix3D getEyeMatrix(PMatrix3D target) {
41514151
}
41524152

41534153

4154-
/**
4155-
* Returns a copy of the current eye matrix.
4156-
* Pass in null to create a new matrix.
4157-
*/
4158-
public PMatrix3D getAnchorMatrix() {
4159-
showMissingWarning("getAnchorMatrix");
4160-
return null;
4161-
}
4162-
4163-
4164-
/**
4165-
* Copy the current eye matrix into the specified target.
4166-
* Pass in null to create a new matrix.
4167-
*/
4168-
public PMatrix3D getAnchorMatrix(PMatrix3D target) {
4169-
showMissingWarning("getAnchorMatrix");
4170-
return null;
4171-
}
4172-
4173-
41744154
/**
41754155
* Set the current transformation matrix to the contents of another.
41764156
*/
@@ -4249,7 +4229,113 @@ public void eye() {
42494229
}
42504230

42514231

4252-
public void anchor() {
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) {
4257+
showMissingWarning("trackableSelected");
4258+
return false;
4259+
}
4260+
4261+
public float trackableExtentX(int i) {
4262+
showMissingWarning("trackableExtentX");
4263+
return 0;
4264+
}
4265+
4266+
public float trackableExtentZ(int i) {
4267+
showMissingWarning("trackableExtentZ");
4268+
return 0;
4269+
}
4270+
4271+
4272+
public float[] getTrackablePolygon(int i) {
4273+
showMissingWarning("getTrackablePolygon");
4274+
return null;
4275+
}
4276+
4277+
4278+
public float[] getTrackablePolygon(int i, float[] points) {
4279+
showMissingWarning("getTrackablePolygon");
4280+
return null;
4281+
}
4282+
4283+
public PMatrix3D getTrackableMatrix(int i) {
4284+
showMissingWarning("getTrackableMatrix");
4285+
return null;
4286+
}
4287+
4288+
4289+
public PMatrix3D getTrackableMatrix(int i, PMatrix3D target) {
4290+
showMissingWarning("getTrackableMatrix");
4291+
return null;
4292+
}
4293+
4294+
4295+
public int anchorCount() {
4296+
showMissingWarning("anchorCount");
4297+
return 0;
4298+
}
4299+
4300+
public int anchorId(int i) {
4301+
showMissingWarning("anchorId");
4302+
return 0;
4303+
}
4304+
4305+
public int anchorStatus(int id) {
4306+
showMissingWarning("anchorStatus");
4307+
return 0;
4308+
}
4309+
4310+
public int createAnchor() {
4311+
showMissingWarning("createAnchor");
4312+
return 0;
4313+
}
4314+
4315+
public int createAnchor(int trackId, float x, float y, float z) {
4316+
showMissingWarning("createAnchor");
4317+
return 0;
4318+
}
4319+
4320+
4321+
public void deleteAnchor(int id) {
4322+
showMissingWarning("deleteAnchor");
4323+
}
4324+
4325+
4326+
public PMatrix3D getAnchorMatrix(int id) {
4327+
showMissingWarning("getAnchorMatrix");
4328+
return null;
4329+
}
4330+
4331+
4332+
public PMatrix3D getAnchorMatrix(int id, PMatrix3D target) {
4333+
showMissingWarning("getAnchorMatrix");
4334+
return null;
4335+
}
4336+
4337+
4338+
public void anchor(int id) {
42534339
showMethodWarning("anchor");
42544340
}
42554341

debug/apps/arscene/src/main/java/arscene/Sketch.java

Lines changed: 48 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,20 @@
22

33
import processing.ar.*;
44
import processing.core.PApplet;
5+
import processing.core.PMatrix3D;
56

67
public class Sketch extends PApplet {
78
float angle = 0;
9+
float[] points;
10+
PMatrix3D mat = new PMatrix3D();
11+
int anchorId;
812

913
public void settings() {
1014
fullScreen(AR);
1115
}
1216

1317
public void setup() {
14-
PAR.planeColor(0xB4E7FF);
18+
1519
}
1620

1721
public void draw() {
@@ -21,18 +25,52 @@ public void draw() {
2125
// surface.camera.getPose();
2226
// surface.frame.getLightEstimate();
2327

24-
anchor();
25-
2628
background(0);
2729
lights();
2830

2931

30-
fill(0xFCB736);
31-
noStroke();
32-
sphere(0.10f);
33-
rotateZ(angle);
34-
translate(0, 0.3f,0);
35-
sphere(0.05f);
36-
angle += 0.1;
32+
for (int i = 0; i < trackableCount(); i++) {
33+
int status = trackableStatus(i);
34+
if (status == PAR.PAUSED || status == PAR.STOPPED) continue;
35+
if (!trackableSelected(i)) continue;
36+
37+
if (status == PAR.CREATED) {
38+
anchorId = createAnchor(trackableId(i), 0, 0.3f, 0);
39+
}
40+
41+
float lenx = trackableExtentX(i);
42+
float lenz = trackableExtentZ(i);
43+
points = getTrackablePolygon(i, points);
44+
45+
getTrackableMatrix(i, mat);
46+
pushMatrix();
47+
applyMatrix(mat);
48+
fill(255, 0, 0, 100);
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+
56+
// vertex(-lenx/2, 0, -lenz/2);
57+
// vertex(+lenx/2, 0, -lenz/2);
58+
// vertex(+lenx/2, 0, +lenz/2);
59+
// vertex(-lenx/2, 0, +lenz/2);
60+
endShape();
61+
popMatrix();
62+
}
63+
64+
65+
if (0 < anchorCount()) {
66+
anchor(anchorId);
67+
fill(0xFCB736);
68+
noStroke();
69+
sphere(0.10f);
70+
rotateZ(angle);
71+
translate(0, 0.3f, 0);
72+
sphere(0.05f);
73+
angle += 0.1;
74+
}
3775
}
3876
}
Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,19 @@
11
package processing.ar;
22

3-
public class PAR {
4-
static public void planeColor(int color) {
5-
ARPlane.setPlaneColor(color);
6-
}
3+
import com.google.ar.core.Plane;
4+
5+
public interface PAR {
6+
static final int UNKNOWN = -1;
7+
static final int PLANE_FLOOR = 0;
8+
static final int PLANE_CEILING = 1;
9+
static final int PLANE_WALL = 2;
10+
static final int POINT = 3;
11+
12+
static final int CREATED = 1 << 0;
13+
static final int UPDATED = 1 << 1;
14+
static final int TRACKING = 1 << 2;
15+
static final int PAUSED = 1 << 3;
16+
static final int STOPPED = 1 << 4;
17+
18+
719
}

0 commit comments

Comments
 (0)