@@ -277,8 +277,11 @@ public boolean trackableSelected(int i, int mx, int my) {
277
277
Trackable tracki = trackObjects .get (i );
278
278
for (HitResult hit : surfar .frame .hitTest (mx , my )) {
279
279
Trackable trackable = hit .getTrackable ();
280
- if (tracki .equals (trackable ) && trackable .isPoseInPolygon (hit .getHitPose ())) {
281
- return true ;
280
+ if (trackable instanceof Plane ) {
281
+ Plane plane = (Plane )trackable ;
282
+ if (tracki .equals (plane ) && plane .isPoseInPolygon (hit .getHitPose ())) {
283
+ return true ;
284
+ }
282
285
}
283
286
}
284
287
return false ;
@@ -288,8 +291,11 @@ public boolean trackableSelected(int i, int mx, int my) {
288
291
protected HitResult getHitResult (int mx , int my ) {
289
292
for (HitResult hit : surfar .frame .hitTest (mx , my )) {
290
293
Trackable trackable = hit .getTrackable ();
291
- if (trackObjects .contains (trackable ) && trackable .isPoseInPolygon (hit .getHitPose ())) {
292
- return hit ;
294
+ if (trackable instanceof Plane ) {
295
+ Plane plane = (Plane )trackable ;
296
+ if (trackObjects .contains (plane ) && plane .isPoseInPolygon (hit .getHitPose ())) {
297
+ return hit ;
298
+ }
293
299
}
294
300
}
295
301
return null ;
@@ -309,27 +315,41 @@ public float[] getTrackablePolygon(int i) {
309
315
310
316
public float [] getTrackablePolygon (int i , float [] points ) {
311
317
Trackable track = trackObjects .get (i );
312
- FloatBuffer buffer = track .getPolygon ();
313
- buffer .rewind ();
314
- if (points == null || points .length < buffer .capacity ()) {
315
- points = new float [buffer .capacity ()];
318
+ if (track instanceof Plane ) {
319
+ Plane plane = (Plane )track ;
320
+ FloatBuffer buffer = plane .getPolygon ();
321
+ buffer .rewind ();
322
+ if (points == null || points .length < buffer .capacity ()) {
323
+ points = new float [buffer .capacity ()];
324
+ }
325
+ buffer .get (points , 0 , buffer .capacity ());
316
326
}
317
- buffer .get (points , 0 , buffer .capacity ());
318
327
return points ;
319
328
}
320
329
321
330
322
331
public float getTrackableExtentX (int i ) {
323
332
Trackable track = trackObjects .get (i );
324
- return track .getExtentX ();
333
+ if (track instanceof Plane ) {
334
+ return ((Plane )track ).getExtentX ();
335
+ } else if (track instanceof AugmentedImage ) {
336
+ return ((AugmentedImage )track ).getExtentX ();
337
+ }
338
+ return -1 ;
325
339
}
326
340
327
341
328
342
public float getTrackableExtentZ (int i ) {
329
343
Trackable track = trackObjects .get (i );
330
- return track .getExtentZ ();
344
+ if (track instanceof Plane ) {
345
+ return ((Plane )track ).getExtentZ ();
346
+ } else if (track instanceof AugmentedImage ) {
347
+ return ((AugmentedImage )track ).getExtentZ ();
348
+ }
349
+ return -1 ;
331
350
}
332
351
352
+
333
353
public PMatrix3D getTrackableMatrix (int i ) {
334
354
return getTrackableMatrix (i , null );
335
355
}
@@ -353,24 +373,31 @@ public PMatrix3D getTrackableMatrix(int i, PMatrix3D target) {
353
373
354
374
public int createAnchor (int i , float x , float y , float z ) {
355
375
Trackable track = trackObjects .get (i );
356
- Pose trackPose = track .getCenterPose ();
357
- pointIn [0 ] = x ;
358
- pointIn [1 ] = y ;
359
- pointIn [2 ] = z ;
360
- trackPose .transformPoint (pointIn , 0 , pointOut , 0 );
361
- Pose anchorPose = Pose .makeTranslation (pointOut );
362
- Anchor anchor = track .createAnchor (anchorPose );
363
- anchors .put (++lastAnchorId , anchor );
364
- return lastAnchorId ;
376
+ if (track instanceof Plane ) {
377
+ Plane plane = (Plane )track ;
378
+ Pose trackPose = plane .getCenterPose ();
379
+ pointIn [0 ] = x ;
380
+ pointIn [1 ] = y ;
381
+ pointIn [2 ] = z ;
382
+ trackPose .transformPoint (pointIn , 0 , pointOut , 0 );
383
+ Pose anchorPose = Pose .makeTranslation (pointOut );
384
+ Anchor anchor = plane .createAnchor (anchorPose );
385
+ anchors .put (++lastAnchorId , anchor );
386
+ return lastAnchorId ;
387
+ }
388
+ return -1 ;
365
389
}
366
390
367
391
368
392
public int createAnchor (int mx , int my ) {
369
393
for (HitResult hit : surfar .frame .hitTest (mx , my )) {
370
394
Trackable trackable = hit .getTrackable ();
371
- if (trackObjects .contains (trackable ) && trackable .isPoseInPolygon (hit .getHitPose ())) {
372
- return createAnchor (hit );
373
- }
395
+ if (trackable instanceof Plane ) {
396
+ Plane plane = (Plane )trackable ;
397
+ if (trackObjects .contains (plane ) && plane .isPoseInPolygon (hit .getHitPose ())) {
398
+ return createAnchor (hit );
399
+ }
400
+ }
374
401
}
375
402
return 0 ;
376
403
}
@@ -466,16 +493,18 @@ protected void updateTrackables() {
466
493
addNewObject (image );
467
494
}
468
495
469
-
470
496
// Remove stopped and subsummed trackables
471
497
for (int i = trackObjects .size () - 1 ; i >= 0 ; i --) {
472
498
Trackable track = trackObjects .get (i );
473
- if (track .getTrackingState () == TrackingState .STOPPED || track .getSubsumedBy () != null ) {
474
- trackObjects .remove (i );
475
- trackMatrices .remove (track );
476
- int pid = trackIds .remove (track );
477
- trackIdx .remove (pid );
478
- for (ARTracker t : trackers ) t .remove (pid );
499
+ if (track instanceof Plane ) {
500
+ Plane plane = (Plane )track ;
501
+ if (plane .getTrackingState () == TrackingState .STOPPED || plane .getSubsumedBy () != null ) {
502
+ trackObjects .remove (i );
503
+ trackMatrices .remove (plane );
504
+ int pid = trackIds .remove (plane );
505
+ trackIdx .remove (pid );
506
+ for (ARTracker t : trackers ) t .remove (pid );
507
+ }
479
508
}
480
509
}
481
510
@@ -491,7 +520,8 @@ protected void updateTrackables() {
491
520
}
492
521
493
522
protected void addNewObject (Trackable track ) {
494
- if (track .getSubsumedBy () != null ) return ;
523
+ boolean isPlane = track instanceof Plane ;
524
+ if (isPlane && ((Plane )track ).getSubsumedBy () != null ) return ;
495
525
float [] mat ;
496
526
if (trackMatrices .containsKey (track )) {
497
527
mat = trackMatrices .get (track );
@@ -502,8 +532,10 @@ protected void addNewObject(Trackable track) {
502
532
trackIds .put (track , ++lastTrackableId );
503
533
newObjects .add (track );
504
534
}
505
- Pose pose = track .getCenterPose ();
506
- pose .toMatrix (mat , 0 );
535
+ if (isPlane ) {
536
+ Pose pose = ((Plane )track ).getCenterPose ();
537
+ pose .toMatrix (mat , 0 );
538
+ }
507
539
}
508
540
509
541
0 commit comments