Skip to content

Commit b7844df

Browse files
committed
exprimenting with AR API
1 parent 2448050 commit b7844df

File tree

5 files changed

+90
-10
lines changed

5 files changed

+90
-10
lines changed

core/src/processing/core/PApplet.java

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

9236-
92379236
/**
92389237
* Copy the current eye matrix into the specified target.
92399238
* Pass in null to create a new matrix.
@@ -9243,6 +9242,11 @@ public PMatrix3D getEyeMatrix(PMatrix3D target) {
92439242
}
92449243

92459244

9245+
public PMatrix3D getAnchorMatrix() { return g.getAnchorMatrix(); }
9246+
9247+
9248+
public PMatrix3D getAnchorMatrix(PMatrix3D target) { return g.getAnchorMatrix(target); }
9249+
92469250
/**
92479251
* Set the current transformation matrix to the contents of another.
92489252
*/
@@ -9312,6 +9316,11 @@ public void eye() {
93129316
}
93139317

93149318

9319+
public void anchor() {
9320+
g.anchor();
9321+
}
9322+
9323+
93159324
public void ortho() {
93169325
g.ortho();
93179326
}

core/src/processing/core/PGraphics.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4151,6 +4151,26 @@ 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+
41544174
/**
41554175
* Set the current transformation matrix to the contents of another.
41564176
*/
@@ -4229,6 +4249,11 @@ public void eye() {
42294249
}
42304250

42314251

4252+
public void anchor() {
4253+
showMethodWarning("anchor");
4254+
}
4255+
4256+
42324257
//////////////////////////////////////////////////////////////
42334258

42344259
// PROJECTION

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,12 @@ public void draw() {
2121
// surface.camera.getPose();
2222
// surface.frame.getLightEstimate();
2323

24+
anchor();
25+
2426
background(0);
2527
lights();
28+
29+
2630
fill(0xFCB736);
2731
noStroke();
2832
sphere(0.10f);

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

Lines changed: 42 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626

2727
import processing.android.AppComponent;
2828
import processing.core.PGraphics;
29+
import processing.core.PMatrix3D;
2930
import processing.core.PSurface;
3031
import processing.opengl.PGL;
3132
import processing.opengl.PGLES;
@@ -117,10 +118,10 @@ protected void restoreSurface() {
117118

118119

119120
protected void updateView() {
120-
if (surfar.projmtx != null && surfar.viewmtx != null && surfar.anchorMatrix != null) {
121+
if (surfar.projmtx != null && surfar.viewmtx != null /*&& surfar.anchorMatrix != null*/) {
121122
float[] prj = surfar.projmtx;
122123
float[] view = surfar.viewmtx;
123-
float[] anchor = surfar.anchorMatrix;
124+
// float[] anchor = surfar.anchorMatrix;
124125

125126
// Fist, set all matrices to identity
126127
resetProjection();
@@ -138,11 +139,46 @@ protected void updateView() {
138139
view[2], view[6], view[10], view[14],
139140
view[3], view[7], view[11], view[15]);
140141

142+
// // now, modelview = view * anchor
143+
// applyMatrix(anchor[0], anchor[4], anchor[8], anchor[12],
144+
// anchor[1], anchor[5], anchor[9], anchor[13],
145+
// anchor[2], anchor[6], anchor[10], anchor[14],
146+
// anchor[3], anchor[7], anchor[11], anchor[15]);
147+
}
148+
}
149+
150+
@Override
151+
public PMatrix3D getAnchorMatrix() {
152+
return getAnchorMatrix(null);
153+
}
154+
155+
156+
@Override
157+
public PMatrix3D getAnchorMatrix(PMatrix3D target) {
158+
if (target == null) {
159+
target = new PMatrix3D();
160+
}
161+
float[] anchor = surfar.anchorMatrix;
162+
target.set(anchor[0], anchor[4], anchor[8], anchor[12],
163+
anchor[1], anchor[5], anchor[9], anchor[13],
164+
anchor[2], anchor[6], anchor[10], anchor[14],
165+
anchor[3], anchor[7], anchor[11], anchor[15]);
166+
return target;
167+
}
168+
169+
@Override
170+
public void anchor() {
171+
float[] anchor = surfar.anchorMatrix;
172+
141173
// now, modelview = view * anchor
142174
applyMatrix(anchor[0], anchor[4], anchor[8], anchor[12],
143-
anchor[1], anchor[5], anchor[9], anchor[13],
144-
anchor[2], anchor[6], anchor[10], anchor[14],
145-
anchor[3], anchor[7], anchor[11], anchor[15]);
146-
}
175+
anchor[1], anchor[5], anchor[9], anchor[13],
176+
anchor[2], anchor[6], anchor[10], anchor[14],
177+
anchor[3], anchor[7], anchor[11], anchor[15]);
178+
}
179+
180+
@Override
181+
public void lights() {
182+
super.lights();
147183
}
148184
}

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public class PSurfaceAR extends PSurfaceGLES {
6464
private static String C_DEVICE = "This device does not support AR";
6565

6666
// Made these public so they can be accessed from the sketch
67-
protected Session session;
67+
public Session session;
6868
public Frame frame;
6969
public Camera camera;
7070

@@ -273,6 +273,7 @@ public void onDrawFrame(GL10 gl) {
273273
return;
274274
}
275275

276+
updateTrackables();
276277
updateAnchors();
277278
updateMatrices();
278279

@@ -289,14 +290,18 @@ public void renderBackground() {
289290
backgroundRenderer.draw(frame);
290291
}
291292

293+
protected void updateTrackables() {
294+
295+
}
296+
292297
protected void updateAnchors() {
298+
293299
MotionEvent tap = queuedTaps.poll();
294300
if (tap != null && camera.getTrackingState() == TrackingState.TRACKING) {
295301
for (HitResult hit : frame.hitTest(tap)) {
296302
Trackable trackable = hit.getTrackable();
297303
if ((trackable instanceof Plane && ((Plane) trackable).isPoseInPolygon(hit.getHitPose()))
298-
|| (trackable instanceof Point
299-
&& ((Point) trackable).getOrientationMode()
304+
|| (trackable instanceof Point && ((Point) trackable).getOrientationMode()
300305
== Point.OrientationMode.ESTIMATED_SURFACE_NORMAL)) {
301306
if (anchors.size() >= 20) {
302307
anchors.get(0).detach();
@@ -307,6 +312,7 @@ protected void updateAnchors() {
307312
}
308313
}
309314
}
315+
310316
}
311317

312318
protected void updateMatrices() {

0 commit comments

Comments
 (0)