3939import java .util .ArrayList ;
4040import java .util .Collection ;
4141import java .util .HashMap ;
42- import java .util .concurrent .ArrayBlockingQueue ;
4342
4443import processing .android .AppComponent ;
4544import 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 ();
0 commit comments