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.swift
var cameraDevice:MasCameraDevice = MasCameraDevice() var sensorDevice:MasSensorDevice = MasSensorDevice() var backgroundRenderer:MasBackgroundRenderer = MasBackgroundRenderer() var trackingManager:MasTrackerManager = MasTrackerManager()
Starting / Stopping the Tracker
To start / stop Tracker, refer to the following code.
>InstantTrackerViewController.swift
@objc func pauseAR() { ... trackingManager.start(.TRACKER_TYPE_INSTANT) } @objc func resumeAR() { trackingManager.stopTracker() ... }
Using the 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() guard let backgroundTexture = backgroundRenderer.getBackgroundTexture() else { return } backgroundRenderer.begin(backgroundTexture) backgroundRenderer.renderBackgroundToTexture() backgroundRenderer.end() backgroundQuad.draw(texture: backgroundTexture, projectionMatrix: cameraDevice.getBackgroundPlaneProjectionMatrix()) 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)) }
Creating the Instant Target Data
You can create new data only when it is not in Tracking state. Refer to the following code.
>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) } }