How to use Vuforia Tracked Events


Story by Abhilash on Vuforia

Share   

Vuforia is one of the widely used augmented reality SDK for mobile devices that enables the creation of augmented reality applications. This blog post is all about the best way to write your custom logic on object recognitions that is scalable and maintainable.

The DefaultTrackableEventHandler is the script the deals with all kind of event registrations for your target like OnTrackingFound (what to do on successful tracking), OnTrackingLost (what to do when tracking is lost). There is a good chance that devs will inject code into DefaultTrackableEventHandler to intercept and write their own custom logic.

Assume that you want to playback an audio when an object is tracked and stop playback of audio when object lost its tracking. Below is a typical messy code.

vuforia-wha-everyone-does

Over a period of time, this looks messy and expands to large if-else ladder to accommodate various scenarios.

But, how can you add custom logic that is maintainable and scalable? Here is what you need to do.

  1. Inherit the DefaultTrackableEventHandler
  2. Override OnTrackingFound() and OnTrackingLost()
  3. Remove DefaultTrackableEventHandler component from your Vuforia Target element and add your inherited class.

As sample code snippet is below:

vuforia-suggested-approach

With this, you are creating new classes that just deals with what it is supposed to do.

Hope this helps.






comments powered by Disqus

Related Story   →

Woohoo!!! I am featured for Mixed Reality

I have been featured for AR/VR/MR in Malayala Manorama daily newspaper.