1

I stumbled upon this while applying rotation from the camera onto an entity in RealityKit. I thought I have to do some matrix math to gain the euler angles from arView.session.currentFrame.camera.transform matrix, but retrieving the rotation from arview.cameraTransform.rotation did the trick (found here).

So: What is the difference of both matrices and when should be used which?

wider-spider
  • 465
  • 4
  • 12

1 Answers1

1

Your first sample is the transform matrix that defines the camera’s rotation/translation in world coordinates.

open var transform: simd_float4x4 { get }

Your second sample is a specialized type of the transform matrix.

public var cameraTransform: Transform { get }

// or

@MainActor var cameraTransform: Transform { get }

Apple's definition:

Note that Transform is a specialized type that does not support all transformations that can be represented by a general 4x4 matrix. Setting the Transform from a 4x4 matrix is a lossy operation. It may result in certain transformations (such as shearing) being dropped!

However, in some situations cameraTransform is a more convenient property than transform.

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