Search Unity

Difference between Camera.main.transform and cameraToWorldMatrix

Discussion in 'VR' started by cpiber, Sep 20, 2018.

  1. cpiber

    cpiber

    Joined:
    Sep 4, 2018
    Posts:
    1
    Hello,

    can someone please explain the difference between cameraToWorldMatrix and Camera.main.transform?
    For my understanding it should be the same, because in Unity we start with the camera at the world origin, and as the HoloLens moves around the transform of the MainCamera is updated.

    Then, when I capture frames with photoCapture and query TryGetCameraToWorldMatrix(), the resulting cameraToWorld position (= cameraToWorldMatrix.GetColumn(3)) should be Camera.main.transform.position, shouldn't it?

    In the Poster Calibration example of the companion kit (https://github.com/Microsoft/MixedRealityCompanionKit/tree/master/PosterCalibrationSample), I saw that the camera position is computed like this:

    Code (CSharp):
    1. frame.TryGetCameraToWorldMatrix(out cameraToWorld);
    2. cameraToWorld = cameraToWorld * Matrix4x4.Scale(new Vector3(1,1,-1));
    3. cameraPos = cameraToWorld.MultiplyPoint(Vector3.zero);
    But why is all this necessary just to get the camera position?

    I am really confused when to use the cameraToWorld matrix for positioning holograms and when to use Camera.main.transform. If they are not equal, what is their relation?

    Thank you!
    - Chris
     
    frothe likes this.