Object Tracker

The Object Tracker loads the map file and renders 3D object on it.

Create Instants
Starting / Stopping the Tracker
Using the Tracking Information
Setting a Map
Adding / Replacing a Map

Create Instants

>ObjectTrackerViewController.mm

- (void)viewDidLoad
{
    ...
    trackingManager = [[MasTrackerManager alloc] init];
    cameraDevice = [[MasCameraDevice alloc] init];
    backgroundRenderer = [[MasBackgroundRenderer alloc] init];
    [MasMaxstAR onSurfaceCreated];
}

Starting / Stopping the Tracker

To start / stop Tracker after loading the map, refer to the following code.

>ObjectTrackerViewController.mm

- (void)resumeAR
{
    ...
    [trackingManager startTracker:TRACKER_TYPE_OBJECT];
}

- (void)pauseAR
{
    [trackingManager stopTracker];
    ...
}

Using the Tracking Information

To use the Tracking information, refer to the following code.

>ObjectTrackerViewController.mm

- (void)glkView:(GLKView *)view drawInRect:(CGRect)rect
{
    ...
    MasTrackingState *trackingState = [trackingManager updateTrackingState];
    MasTrackingResult *result = [trackingState getTrackingResult];
    
    MasBackgroundTexture *backgroundTexture = [backgroundRenderer getBackgroundTexture];
    [backgroundRenderer begin:backgroundTexture];
    [backgroundRenderer renderBackgroundToTexture];
    [backgroundRenderer end];
    
    [backgroundQuad draw:backgroundTexture projectionMatrix:[cameraDevice getBackgroundPlaneProjectionMatrix]];
    
    glEnable(GL_DEPTH_TEST);
    matrix_float4x4 projectionMatrix = [cameraDevice getProjectionMatrix];
    
    for (int i = 0; i < [result getCount]; i++)
    {
        MasTrackable *trackable = [result getTrackable:i];
        
        [texturedCube setProjectionMatrix:projectionMatrix];
        [texturedCube setPoseMatrix:[trackable getPose]];
        [texturedCube setTranslation:0.0f y:0.0f z:-0.0005f];
        [texturedCube setScale:0.4f y:0.4f z:0.001f];
        [texturedCube draw];
    }
    ...
}

Setting a Map

By calling function addTrackerData to register the map file and calling function loadTrackerData, Space can be tracked. To set a map, refer to the following code.

>ObjectTrackerViewController.mm

- (void)startEngine
{
    ...
    [trackingManager addTrackerData:objectTrackerMapPath];
    [trackingManager loadTrackerData];
}

Adding / Replacing a Map

  1. Create a map file refer to Documentation > Map Manager.

  2. Copy the received map file to the desired path.

  3. Set a map.

  4. If you have an existing map file, call function 'addTrackerData' and function 'loadTrackerData' after calling [trackingManager removeTrackerData]