Skip to content

Instantly share code, notes, and snippets.

@aferriss
Last active November 13, 2018 21:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aferriss/f191258ca0c0395e0f96d8cdd98fe54b to your computer and use it in GitHub Desktop.
Save aferriss/f191258ca0c0395e0f96d8cdd98fe54b to your computer and use it in GitHub Desktop.
Matrix for AR
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