Skip to content

Commit 4c584b3

Browse files
committed
more selection tweaks
1 parent 8233296 commit 4c584b3

File tree

5 files changed

+27
-40
lines changed

5 files changed

+27
-40
lines changed

core/src/processing/core/PApplet.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9373,8 +9373,8 @@ public int trackableStatus(int i) {
93739373
return g.trackableStatus(i);
93749374
}
93759375

9376-
public boolean trackableSelected(int i) {
9377-
return g.trackableSelected(i);
9376+
public boolean trackableSelected(int i, int mx, int my) {
9377+
return g.trackableSelected(i, mx, my);
93789378
}
93799379

93809380
public float[] getTrackablePolygon(int i) {

core/src/processing/core/PGraphics.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4253,7 +4253,7 @@ public int trackableStatus(int i) {
42534253
return 0;
42544254
}
42554255

4256-
public boolean trackableSelected(int i) {
4256+
public boolean trackableSelected(int i, int mx, int my) {
42574257
showMissingWarning("trackableSelected");
42584258
return false;
42594259
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public void draw() {
4646
getTrackableMatrix(i, mat);
4747
pushMatrix();
4848
applyMatrix(mat);
49-
if (trackableSelected(i)) {
49+
if (trackableSelected(i, mouseX, mouseY)) {
5050
fill(255, 0, 0, 100);
5151
} else {
5252
fill(255, 100);
@@ -74,6 +74,7 @@ public void draw() {
7474
deleteAnchor(i);
7575
continue;
7676
}
77+
7778
int status = anchorStatus(i);
7879
if (status == PAR.PAUSED || status == PAR.STOPPED) {
7980
if (status == PAR.PAUSED) System.out.println("-------------> PAUSED ANCHOR " + i);

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

Lines changed: 19 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
import java.util.ArrayList;
4040
import java.util.Collection;
4141
import java.util.HashMap;
42-
import java.util.concurrent.ArrayBlockingQueue;
4342

4443
import processing.android.AppComponent;
4544
import processing.core.PGraphics;
@@ -62,7 +61,6 @@ public class PGraphicsAR extends PGraphics3D {
6261
protected float[] anchorMatrix = new float[16];
6362

6463
protected ArrayList<Plane> trackPlanes = new ArrayList<Plane>();
65-
protected ArrayList<Plane> selectedPlanes = new ArrayList<Plane>();
6664
protected HashMap<Plane, float[]> trackMatrices = new HashMap<Plane, float[]>();
6765

6866
protected ArrayList<Plane> newPlanes = new ArrayList<Plane>();
@@ -217,8 +215,18 @@ public int trackableStatus(int i) {
217215

218216

219217
@Override
220-
public boolean trackableSelected(int i) {
221-
return selectedPlanes.contains(trackPlanes.get(i));
218+
public boolean trackableSelected(int i, int mx, int my) {
219+
Plane planei = trackPlanes.get(i);
220+
for (HitResult hit : surfar.frame.hitTest(mx, my)) {
221+
Trackable trackable = hit.getTrackable();
222+
if (trackable instanceof Plane) {
223+
Plane plane = (Plane)trackable;
224+
if (planei == plane && plane.isPoseInPolygon(hit.getHitPose())) {
225+
return true;
226+
}
227+
}
228+
}
229+
return false;
222230
}
223231

224232

@@ -372,20 +380,18 @@ protected void createBackgroundRenderer() {
372380
backgroundRenderer = new BackgroundRenderer(surfar.getActivity());
373381
}
374382

375-
protected void setCameraTexture(Session session) {
376-
session.setCameraTextureName(backgroundRenderer.getTextureId());
383+
protected void setCameraTexture() {
384+
surfar.session.setCameraTextureName(backgroundRenderer.getTextureId());
377385
}
378386

379-
protected void updateMatrices(Camera camera) {
380-
camera.getProjectionMatrix(projMatrix, 0, 0.1f, 100.0f);
381-
camera.getViewMatrix(viewMatrix, 0);
387+
protected void updateMatrices() {
388+
surfar.camera.getProjectionMatrix(projMatrix, 0, 0.1f, 100.0f);
389+
surfar.camera.getViewMatrix(viewMatrix, 0);
382390
}
383391

384392

385-
protected void updateTrackables(Frame frame, ArrayBlockingQueue<MotionEvent> taps) {
386-
387-
Collection<Plane> planes = frame.getUpdatedTrackables(Plane.class);
388-
393+
protected void updateTrackables() {
394+
Collection<Plane> planes = surfar.frame.getUpdatedTrackables(Plane.class);
389395
for (Plane plane: planes) {
390396
if (plane.getSubsumedBy() != null) continue;
391397
float[] mat;
@@ -412,27 +418,12 @@ protected void updateTrackables(Frame frame, ArrayBlockingQueue<MotionEvent> tap
412418
System.out.println("-------------> REMOVED TRACKING PLANE " + plane.hashCode());
413419
}
414420
}
415-
416-
// Determine selected planes using the touches array
417-
TouchEvent.Pointer[] touches = parent.touches;
418-
for (int i = 0; i < touches.length; i++) {
419-
for (HitResult hit : frame.hitTest(touches[i].x, touches[i].y)) {
420-
Trackable trackable = hit.getTrackable();
421-
if (trackable instanceof Plane) {
422-
Plane plane = (Plane)trackable;
423-
if (trackPlanes.contains(plane) && plane.isPoseInPolygon(hit.getHitPose())) {
424-
selectedPlanes.add(plane);
425-
}
426-
}
427-
}
428-
}
429421
}
430422

431423

432424
protected void cleanup() {
433425
updatedPlanes.clear();
434426
newPlanes.clear();
435-
selectedPlanes.clear();
436427

437428
for (Anchor anchor: delAnchors) {
438429
anchor.detach();

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

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,6 @@
4848

4949
import java.io.File;
5050
import java.io.InputStream;
51-
import java.util.ArrayList;
52-
import java.util.Collection;
53-
import java.util.HashMap;
54-
import java.util.concurrent.ArrayBlockingQueue;
5551

5652
public class PSurfaceAR extends PSurfaceGLES {
5753
private static String T_ALERT_MESSAGE = "ALERT";
@@ -72,7 +68,6 @@ public class PSurfaceAR extends PSurfaceGLES {
7268
protected AndroidARRenderer renderer;
7369
protected PGraphicsAR par;
7470

75-
protected ArrayBlockingQueue<MotionEvent> queuedTaps = new ArrayBlockingQueue<>(16);
7671
protected RotationHandler displayRotationHelper;
7772

7873
public PSurfaceAR(PGraphics graphics, AppComponent appComponent, SurfaceHolder surfaceHolder) {
@@ -232,12 +227,12 @@ public void onDrawFrame(GL10 gl) {
232227
displayRotationHelper.updateSessionIfNeeded(session);
233228
try {
234229

235-
par.setCameraTexture(session);
230+
par.setCameraTexture();
236231
frame = session.update();
237232
camera = frame.getCamera();
238233

239-
if (camera.getTrackingState() == TrackingState.TRACKING) par.updateTrackables(frame, queuedTaps);
240-
par.updateMatrices(camera);
234+
if (camera.getTrackingState() == TrackingState.TRACKING) par.updateTrackables();
235+
par.updateMatrices();
241236

242237
sketch.calculate();
243238
sketch.handleDraw();

0 commit comments

Comments
 (0)