Try MAXST AR Fusion Tracker Now ✨

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 Swift. 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.swift

var cameraDevice:MasCameraDevice = MasCameraDevice()
var sensorDevice:MasSensorDevice = MasSensorDevice()
var trackingManager:MasTrackerManager = MasTrackerManager()

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.swift

@objc func pauseAR()
{
    ...
    trackingManager.start(.TRACKER_TYPE_INSTANT)
}

@objc func resumeAR()
{
    trackingManager.stopTracker()
    ...
}

2.3 Use Tracking Information

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

InstantTrackerViewController.swift

override func glkView(_ view: GLKView, drawIn rect: CGRect) {
    
    ...
    
    let trackingState:MasTrackingState = trackingManager.updateTrackingState()
    let result:MasTrackingResult = trackingState.getTrackingResult()
    
    let backgroundImage:MasTrackedImage = trackingState.getImage()
        let backgroundProjectionMatrix:matrix_float4x4 = cameraDevice.getBackgroundPlaneProjectionMatrix()
 
        if let cameraQuad = backgroundCameraQuad {
            cameraQuad.draw(image:backgroundImage, projectionMatrix: backgroundProjectionMatrix)
       }
    
    glEnable(GLenum(GL_DEPTH_TEST))
    
    let projectionMatrix:matrix_float4x4 = cameraDevice.getProjectionMatrix()

    let trackingCount:Int32 = result.getCount()

    for i in stride(from: 0, to: trackingCount, by: 1) {
        let trackable:MasTrackable = result.getTrackable(i)
        textureCube.setProjectionMatrix(projectionMatrix: projectionMatrix)
        textureCube.setPoseMatrix(poseMatrix: trackable.getPose())
        textureCube.setTranslation(x: panTranslateX, y: panTranslateY, z: -0.05)
        textureCube.setScale(x: 0.3 + pinchScale, y: 0.3 + pinchScale, z: 0.01)
        textureCube.draw()
    }
    
    glDisable(GLenum(GL_DEPTH_TEST))
}

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.swift

@IBAction func doTrackingState(_ sender: Any) {
    let button:UIButton = sender as! UIButton
    
    if button.titleLabel?.text == "Start Tracking" {
        beforeTranslateX = 0.0
        beforeTranslateY = 0.0
        panTranslateX = 0.0
        panTranslateY = 0.0
        pinchScale = 0.0
        rotateValue = 0.0
        
        trackingManager.findSurface()
        button.setTitle("Stop Tracking", for: .normal)
    } else if button.titleLabel?.text == "Stop Tracking" {
        trackingManager.quitFindingSurface()
        button.setTitle("Start Tracking", for: .normal)
    }
}

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.swift