2222
2323package processing .ar ;
2424
25- import android .view .MotionEvent ;
2625import android .view .SurfaceHolder ;
2726
2827import com .google .ar .core .Anchor ;
29- import com .google .ar .core .Camera ;
30- import com .google .ar .core .Frame ;
3128import com .google .ar .core .HitResult ;
3229import com .google .ar .core .Plane ;
3330import com .google .ar .core .Pose ;
34- import com .google .ar .core .Session ;
3531import com .google .ar .core .Trackable ;
3632import com .google .ar .core .TrackingState ;
3733
4541import processing .core .PGraphics ;
4642import processing .core .PMatrix3D ;
4743import processing .core .PSurface ;
48- import processing .event .TouchEvent ;
4944import processing .opengl .PGL ;
5045import processing .opengl .PGLES ;
5146import processing .opengl .PGraphics3D ;
@@ -63,9 +58,11 @@ public class PGraphicsAR extends PGraphics3D {
6358 protected float [] anchorMatrix = new float [16 ];
6459 protected float [] colorCorrection = new float [4 ];
6560
61+ protected ArrayList <Tracker > trackers = new ArrayList <Tracker >();
6662 protected ArrayList <Plane > trackPlanes = new ArrayList <Plane >();
6763 protected HashMap <Plane , float []> trackMatrices = new HashMap <Plane , float []>();
6864 protected HashMap <Plane , Integer > trackIds = new HashMap <Plane , Integer >();
65+ protected HashMap <Integer , Integer > trackIdx = new HashMap <Integer , Integer >();
6966
7067 protected ArrayList <Plane > newPlanes = new ArrayList <Plane >();
7168 protected ArrayList <Plane > updatedPlanes = new ArrayList <Plane >();
@@ -96,6 +93,10 @@ public PGraphicsAR() {
9693 }
9794
9895
96+ static processing .ar .Trackable [] getTrackables () {
97+ return null ;
98+ }
99+
99100 @ Override
100101 public PSurface createSurface (AppComponent appComponent , SurfaceHolder surfaceHolder , boolean reset ) {
101102 if (reset ) pgl .resetFBOLayer ();
@@ -189,6 +190,15 @@ protected void updateView() {
189190 }
190191
191192
193+ public void addTracker (Tracker tracker ) {
194+ trackers .add (tracker );
195+ }
196+
197+
198+ public void removeTracker (Tracker tracker ) {
199+ trackers .remove (tracker );
200+ }
201+
192202 @ Override
193203 public int trackableCount () {
194204 return trackPlanes .size ();
@@ -201,6 +211,11 @@ public int trackableId(int i) {
201211 }
202212
203213
214+ public int trackableIndex (int id ) {
215+ return trackIdx .get (id );
216+ }
217+
218+
204219 @ Override
205220 public int trackableType (int i ) {
206221 Plane plane = trackPlanes .get (i );
@@ -425,13 +440,18 @@ protected void updateTrackables() {
425440 updatedPlanes .add (plane );
426441 }
427442
428- // Remove stopped and subsummed trackables
443+ // Remove stopped and subsummed trackables, and update indices.
429444 for (int i = trackPlanes .size () - 1 ; i >= 0 ; i --) {
430445 Plane plane = trackPlanes .get (i );
431446 if (plane .getTrackingState () == TrackingState .STOPPED || plane .getSubsumedBy () != null ) {
432447 trackPlanes .remove (i );
433448 trackMatrices .remove (plane );
434- trackIds .remove (plane );
449+ int pid = trackIds .remove (plane );
450+ trackIdx .remove (pid );
451+ for (Tracker t : trackers ) t .remove (pid );
452+ } else {
453+ int pid = trackIds .get (plane );
454+ trackIdx .put (pid , i );
435455 }
436456 }
437457 }
0 commit comments