Instant Tracker
Related documentations |
---|
Tracker Coordinate System |
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
Start / Stop Tracker
Use Tracking Information
Create Instant Target Data
Create Instants
>GameViewController.swift
var cameraDevice:MasCameraDevice = MasCameraDevice() var sensorDevice:MasSensorDevice = MasSensorDevice() var trackingManager:MasTrackerManager = MasTrackerManager()
Start / Stop Tracker
To start / stop Tracker, refer to the following code.
>GameViewController.swift
@objc func pauseAR() { ... trackingManager.start(.TRACKER_TYPE_INSTANT) } @objc func resumeAR() { trackingManager.stopTracker() ... }
Use Tracking Information
To augment an object using Tracking results, refer to the following code.
You must use Convert Matrix for Metal.('metalConverter')
>GameViewController.swift
func renderer(_ renderer: SCNSceneRenderer, willRenderScene scene: SCNScene, atTime time: TimeInterval) { if backgroundCameraQuad == nil { backgroundCameraQuad = BackgroundCameraQuad(device: renderer.device, pixelFormat: renderer.colorPixelFormat) } let commandEncoder:MTLRenderCommandEncoder = renderer.currentRenderCommandEncoder! let trackingState:MasTrackingState = trackingManager.updateTrackingState() let result:MasTrackingResult = trackingState.getTrackingResult() let backgroundImage:MasTrackedImage = trackingState.getImage() var backgroundProjectionMatrix:matrix_float4x4 = cameraDevice.getBackgroundPlaneProjectionMatrix() backgroundProjectionMatrix = backgroundProjectionMatrix * metalConverter let projectionMatrix:matrix_float4x4 = cameraDevice.getProjectionMatrix() if let cameraQuad = backgroundCameraQuad { if(backgroundImage.getData() != nil) { cameraQuad.setProjectionMatrix(projectionMatrix: backgroundProjectionMatrix) cameraQuad.draw(commandEncoder: commandEncoder, image: backgroundImage) } } let trackingCount:Int32 = result.getCount() if trackingCount > 0 { for i in stride(from: 0, to: trackingCount, by: 1) { let trackable:MasTrackable = result.getTrackable(i) let projectionSCNMatrix4 = SCNMatrix4.init(projectionMatrix) let poseSCNMatrix4 = SCNMatrix4.init(trackable.getPose()) cameraNode.camera?.projectionTransform = projectionSCNMatrix4 foxNode.transform = SCNMatrix4Mult(foxTransform, poseSCNMatrix4) } } else { foxNode.scale = SCNVector3Make(0.0, 0.0, 0.0) } }
Create Instant Target Data
You can create new data only when it is not in Tracking state. Refer to the following code.
>GameViewController.swift
@IBAction func clickStartButton(_ sender: Any) { let button:UIButton = sender as! UIButton if button.titleLabel?.text == "START" { trackingManager.findSurface() button.setTitle("STOP", for: .normal) } else if button.titleLabel?.text == "STOP"{ trackingManager.quitFindingSurface() button.setTitle("START", for: .normal) } }