I'm trying to superimpose ARFaceAnchor vertices on-screen to accomplish two scenarios 1) have a virtual face maintain is center (onscreen) position, but reflect changes in geometry.vertices 2) have the virtual face overlap the actual face (from previewlayer).
I've followed Rickster's advice here, but have only succeeded in projecting the face from certain angles onscreen (only appears lower left and rotates) . I'm not too familiar with the different purposes of each matrix, but this is where I've gotten so far. Any advice?
let modelMatrix = faceAnchor.transform
var points: [CGPoint] = []
faceAnchor.geometry.vertices.forEach {
// Convert the vertex position from model space to camera space (use the anchor’s transform)
let vertex4 = vector_float4($0.x, $0.y, $0.z, 1)
let vertexCamera = simd_mul(modelMatrix, vertex4)
// Multiply with the camera projection with that vector to get to normalized image coordinates
let normalizedImageCoordinates = simd_mul(projectionMatrix, vertexCamera)
let point = CGPoint(x: CGFloat(normalizedImageCoordinates.x), y: CGFloat(normalizedImageCoordinates.y))
points.append(point)
}