Instant Tracker

The Instant Tracker instantly scans the planar surface in the camera frame and recognizes the space with sensors. You can find the rendered 3D object on the space.

Create Instants
Starting / Stopping the Tracker
Using the Tracking Information
Creating the Instant Target Data

Create Instants

>InstantTrackerViewController.mm

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

Starting / Stopping the Tracker

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

>InstantTrackerViewController.mm

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

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

Using the 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];
    
    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:panTranslateX y:panTranslateY z:-0.05f];
        [texturedCube setScale:0.3f + pinchScale y:0.3f + pinchScale z:0.01f];
        [texturedCube draw];
    }
    ...
}

Creating the Instant Target Data

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

>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];
    }
}