Last active
November 13, 2018 21:43
-
-
Save aferriss/f191258ca0c0395e0f96d8cdd98fe54b to your computer and use it in GitHub Desktop.
Matrix for AR
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
projectionMatrix = arCameraData.projectionMatrix | |
viewMatrix = arCameraData.viewMatrix | |
var floorDepthMap : [Float] = [] | |
if let tempDepthMap = groundPlaneDepthMap { | |
floorDepthMap = tempDepthMap | |
} | |
if let segmentationInstance = segmentationFrameData?.instance(forPersonId: person.personId) { | |
boundingBoxBottomMidpoint = float2(x: Float(segmentationInstance.center.x), y: Float(segmentationInstance.maxY)) | |
segId = Int(segmentationInstance.segmentationId) | |
} | |
/// Sample our depth map | |
let depthMapIndex = boundingBoxBottomMidpoint.x + boundingBoxBottomMidpoint.y * Float(octi.videoSize.width) | |
if let tempDepthVal = floorDepthMap[safe: Int(depthMapIndex)] { | |
depthVal = tempDepthVal | |
} | |
let worldPos: float3 = ARFloorFinder.screenToWorld(screenPoint: CGPoint(x: CGFloat(boundingBoxBottomMidpoint.x), y: CGFloat(boundingBoxBottomMidpoint.y)), | |
zDepth: depthVal, | |
screenSize: videoSize, | |
projectionMatrix: projectionMatrix, | |
viewMatrix: viewMatrix) | |
var modelMatrix = matrix_identity_float4x4 | |
modelMatrix = modelMatrix.translatedBy(x: worldPos.x, y: worldPos.y, z: worldPos.z) | |
if billboard { | |
modelMatrix = modelMatrix.rotatedBy(rotationAngle: -arCameraData.eulerAngles.y, x: 0, y: 1, z: 0) | |
} | |
modelMatrix = modelMatrix.scaledBy(x: modelWorldSize.x, y: modelWorldSize.y, z: 1) | |
let modelViewProjectionMatrix = projectionMatrix * viewMatrix * modelMatrix |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment