In visionOS, I need to convert a SIM3D<Float> from world space to screen space

Generated on 9/17/2024

1 search

To convert a SIM3D<Float> from world space to screen space in visionOS, you need to transform your content through a series of coordinate spaces. This involves using a projection view matrix, which is a combination of the projection matrix and the view matrix. Here's a brief overview of the process:

  1. Projection View Matrix: This matrix is used to transform content from 3D world space to normalized device coordinate space. It is composed of the projection matrix and the view matrix.

  2. View Matrix: The view matrix can be broken down into two transforms:

    • Device from Origin: Transforms the origin space to the device space.
    • View from Device: Transforms the device space to the view space. This can be acquired by calling CpView get transform in the compositor services API.
  3. Projection Matrix: This matrix is used to project the 3D coordinates onto a 2D plane.

  4. Scene Aware Projection Matrix: For better positioning of rendered content with real-world objects, you can use a scene aware projection matrix, which combines camera intrinsics and real-time scene understanding factors.

To implement this in code, you would typically:

  • Acquire the necessary transforms using ARKit and compositor services APIs.
  • Compose the view matrix by combining the device from origin and view from device transforms.
  • Compute the projection matrix for the given view.
  • Finally, compose the projection view matrix by multiplying the projection matrix with the view matrix.

For more detailed guidance, you can refer to the session Render Metal with passthrough in visionOS (09:20) which covers positioning render content.