Problem
I'd like the following function to return to me the world coordinates of a point handled by a tap gesture. I've properly implemented it (using a few online resources) to work with the center point of the frame, but I am having trouble shifting this point around the screen.
Attempt
Here is the fully commented and working code for getScreenCoordinates
, which returns a tuple containing (0) the direction vector of the screen coordinates and (1) the position vector of the screen coordinates. The issue is having this work with a point other than the center, passed in through the screenCoord
parameter.
private func getScreenCoordinates(screenCoord:CGPoint) -> (SCNVector3, SCNVector3) { // (direction, position)
if let frame = self.canvasView.session.currentFrame {
let mat = SCNMatrix4(frame.camera.transform) // 4x4 transform matrix describing camera in world space
let direction = SCNVector3(-1 * mat.m31, -1 * mat.m32, -1 * mat.m33) // orientation of camera in world space
let position = SCNVector3(mat.m41, mat.m42, mat.m43) // location of camera in world space
return (dir, position)
}
return (SCNVector3(0, 0, -1), SCNVector3(0, 0, -0.2))
}
Desired Solution
Provide a modified getScreenCoordinates
function that returns the same data type, except instead of getting the world coordinates of the center point of the camera frame, it gets the world coordinates for screenCoord
.