1

I have started a new Augmented Reality Project using Xcode's default template.

I have made arView.session.delegate = self

override func viewDidLoad() {
    super.viewDidLoad()

    // Load the "Box" scene from the "Experience" Reality File
    let boxAnchor = try! Experience.loadBox()

    // Add the box anchor to the scene
    arView.scene.anchors.append(boxAnchor)

    arView.session.delegate = self
}

and added this delegate method where I am printing the camera transform

func session(_ session: ARSession, didUpdate frame: ARFrame) {
    print(frame.camera.transform)
}

The printing is like this:

simd_float4x4([[-0.99477124, -0.02513871, 0.09898488, 0.0], 
               [0.04075573, -0.98642635, 0.15906614, 0.0], 
               [0.09364258, 0.16226865, 0.9822931, 0.0], 
               [-0.031830817, -0.025311433, 0.007536184, 1.0]])

This printing is listing the columns, right? and the column order is x, y, z, and w, right?

If so, the last line of that matrix is always 0 0 0 1.

Why? What is this line representing?

Andy Jazz
  • 49,178
  • 17
  • 136
  • 220
Duck
  • 34,902
  • 47
  • 248
  • 470

1 Answers1

2

simd_float4x4 structure represents four columns with the following indices: 0, 1, 2, and 3. The last column with index 3 holds translation values for x, y and z. The fourth element in the last column is not like w in quaternions, it stands for homogeneous coordinates. Three diagonal 1 values are scale for x, y, and z axis.

┌               ┐
|  1  0  0  tx  |
|  0  1  0  ty  |
|  0  0  1  tz  |
|  0  0  0  1   |
└               ┘

If you need a more detailed info on 4x4 matrices, read this post.

First three values in the lowest row are for projection purposes.

Andy Jazz
  • 49,178
  • 17
  • 136
  • 220