Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question about the coordinates mapping #6

Closed
StephenGuanqi opened this issue Jun 23, 2017 · 1 comment
Closed

Question about the coordinates mapping #6

StephenGuanqi opened this issue Jun 23, 2017 · 1 comment

Comments

@StephenGuanqi
Copy link

Hi, this project is really awesome! I just want to ask one question about coordinates mapping:

 let mat = SCNMatrix4FromMat4(currentFrame.camera.transform)
        let dir = SCNVector3(-1 * mat.m31, -1 * mat.m32, -1 * mat.m33)
        let currentPosition = pointOfView.position + (dir * 0.1)

Could you please explain what does these code do?
What's the meaning of sceneView.pointOfView and its difference between currentFrame?

And , I also wondered to calculate the current position of line point to start drawing, why can't I use the following code?

func getCameraCoordinate(sceneView: ARSCNView) -> SCNVector3 {
        let cameraTransform = sceneView.session.currentFrame?.camera.transform
        let cameraCoordinates = MDLTransform(matrix: cameraTransform!)
        return SCNVector3(x: cameraCoordinates.translation.x, y: cameraCoordinates.translation.y, z: cameraCoordinates.translation.z)
    }

Thank you very much.

@lapfelix
Copy link
Owner

sceneView.pointOfView is the current ARKit point of view in the scene. The position of the currentFrame.camera and the position of the sceneView.pointOfView should be the same.

Now regarding the code that gets the orientation of the camera, that was actually done by someone else in this pull request: #2

let mat = SCNMatrix4FromMat4(currentFrame.camera.transform)
// here we get the 4x4 transform matrix from the current frame's camera
        let dir = SCNVector3(-1 * mat.m31, -1 * mat.m32, -1 * mat.m33)
        // .m31, .m32 and .m33 stand for the x, y and z components of the out vector of the matrix
        // which has a magnitude of 1 and is parallel to the user's point of view (going outwards I think)
        let currentPosition = pointOfView.position + (dir * 0.1)
        // and here we multiply the camera's "out" vector by 0.1 (for 10 cm) and then add that to the
        // camera's position to get the position of a point that's exactly 10 cm in front of the camera

You can read up on that output vector here: https://www.fastgraph.com/makegames/3drotation/

Also yes, it does look like your code would work (also could be simplified to simply return sceneView.pointOfView.position) but it would "only" return the position of the camera, not 10 cm in front of it. I'm not an expert at 3D programming at all so that was my first approach too, to simply draw where the camera is positioned ! 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants