Instant Tracker iOS Tutorial

1. Overview
2. iOS Development
2.1 Create Instants
2.2 Start / Stop Tracker
2.3 Use Tracking Information
2.4 Create Instant Target Data
3. Reference
3.1 API Reference
3.2 Sample


1. Overview

Start developing MAXST ARSDK Instant Tracker on iOS Platform. Refer to Instant Tracker Introduction for detailed information.

Refer to Tracker Coordinate System to better understand 3D coordinate system of Instant Tracker.

Prerequisites
Instant Tracker Introduction
Tracker Coordinate System


2. iOS Development

Start developing on xCode using Objective-C. Refer to Requirements & Supports to find out which devices are supported.

ARSDK has to properly integrate on iOS UIViewController. Refer to Life Cycle documents for detail.


2.1 Create Instants

InstantTrackerViewController.mm

- (void)viewDidLoad
{
    ...
    trackingManager = [[MasTrackerManager alloc] init];
    cameraDevice = [[MasCameraDevice alloc] init];
    sensorDevice = [[MasSensorDevice alloc] init];
}

2.2 Start / Stop Tracker

To start / stop the tracker, refer to the following code.

※ To change the tracker, destroyTracker() should be called before

InstantTrackerViewController.mm

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

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

2.3 Use Tracking Information

To augment an object using tracking results, refer to the following code.

InstantTrackerViewController.mm

- (void)glkView:(GLKView *)view drawInRect:(CGRect)rect
{
    ...
    MasTrackingState *trackingState = [trackingManager updateTrackingState];
    MasTrackingResult *result = [trackingState getTrackingResult];
    
    MasTrackedImage *trackedImage = [trackingState getImage];
    [backgroundCameraQuad draw:trackedImage 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:panTranslateX y:panTranslateY z:-0.05f];
        [texturedCube setScale:0.3f + pinchScale y:0.3f + pinchScale z:0.01f];
        [texturedCube draw];
    }
    ...
}

2.4 Create Instant Target Data

You can create new data only when it is not in tracking state. Refer to the following code.

※ startTracker() should be called before

InstantTrackerViewController.mm

- (IBAction)doTrackingState:(id)sender {
    UIButton **button = (UIButton**)sender;
    
    if([[[button titleLabel] text]  isEqual: @"Start Tracking"])
    {
        beforeTranslateX = 0.0f;
        beforeTranslateY = 0.0f;
        panTranslateX = 0.0f;
        panTranslateY = 0.0f;
        pinchScale = 0.0f;
        rotateValue = 0.0f;
        
        [trackingManager findSurface];
        [button setTitle:@"Stop Tracking" forState:UIControlStateNormal];
    }
    else if([[[button titleLabel] text]  isEqual: @"Stop Tracking"])
    {
        [trackingManager quitFindingSurface];
        [button setTitle:@"Start Tracking" forState:UIControlStateNormal];
    }
}

3. References

These are additional references to develop Instant Tracker


3.1 API Reference

Following documents explain classes and functions used to run Instant Tracker.

MaxstAR Class

TrackerManager Class

CameraDevice Class


3.2 Sample

For information regarding sample build and run of Instant Tracker, refer to Sample

InstantTrackerViewController.mm