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.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 after loading the map, refer to the following code.
>ObjectTrackerViewController.swift
@objc func resumeAR() { ... trackingManager.start(.TRACKER_TYPE_OBJECT) } @objc func pauseAR() { trackingManager.stopTracker() ... }
Using the Tracking Information
To use the Tracking information, refer to the following code.
>ObjectTrackerViewController.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: 0.0, y: 0.0, z: -0.05) textureCube.setScale(x: 0.3, y: 0.3, z: 0.01) textureCube.draw() } glDisable(GLenum(GL_DEPTH_TEST)) }
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.swift
func startEngin() { ... trackingManager.addTrackerData(objectTrackerMapPath) trackingManager.loadTrackerData() }
Adding / Replacing a Map
Create a map file refer to Documentation > Map Manager.
Copy the received map file to the desired path.
If you have an existing map file, call function 'addTrackerData' and function 'loadTrackerData' after calling trackingManager.removeTrackerData()