Skip to main content

Auki::ConjureKit::Manna::DefaultTextureToNDCMatrices

Provides utility methods for calculating the texture-to-NDC (normalized coordinates) matrix in various screen orientations. This functionality is provided for each use case supported in Unity.

Public Functions

Name
Matrix4x4ARFoundationDefaultMatrix(int textureWidth, int textureHeight, int screenWidth, int screenHeight, ScreenOrientation screenOrientation)
Computes a projectedToTextureCoordinatesMatrix that is suited for a texture created via the Manna ARFoundation code samples. See Manna.ProcessVideoFrameTexture for more details on creating a custom textureToProjectedCoordinatesMatrix.
Matrix4x4GenericMatrix(TextureCorner, as in most systems. Note that normalized device coordinates go from -1 to 1 left-to-right and bottom-to-top across the screen and that only the ratio screenWidth / screenHeight matters to the resulting matrix, and not the actual values of screenWidth and screenHeight.
Matrix4x4AddCrop(Matrix4x4 textureToProjectedCoordinatesMatrix, int cropWindowMinX, int cropWindowMinY)
Computes a textureToProjectedCoordinatesMatrix that converts cropped texture pixel coordinates to projected coordinates.
Matrix4x4ARFoundationDefaultMatrix(Texture texture)
Computes a projectedToTextureCoordinatesMatrix that is suited for a texture created via the Manna ARFoundation code samples. See Manna.ProcessVideoFrameTexture for more details on creating a custom textureToProjectedCoordinatesMatrix.
Matrix4x4ScreenToNDCMatrix(int screenWidth, int screenHeight)
Creates a screen to NDC transformation matrix.

Public Functions Documentation

function ARFoundationDefaultMatrix

static Matrix4x4 ARFoundationDefaultMatrix(
int textureWidth,
int textureHeight,
int screenWidth,
int screenHeight,
ScreenOrientation screenOrientation
)

Computes a projectedToTextureCoordinatesMatrix that is suited for a texture created via the Manna ARFoundation code samples. See Manna.ProcessVideoFrameTexture for more details on creating a custom textureToProjectedCoordinatesMatrix.

Parameters:

  • textureWidth Pixel width of the texture (texture.width)
  • textureHeight Pixel height of the texture (texture.height)
  • screenWidth Pixel screen width, typically Screen.width
  • screenHeight Pixel screen height, typically Screen.height
  • screenOrientation The current potrait or landscape mode, typically Screen.orientation

function GenericMatrix

static Matrix4x4 GenericMatrix(
TextureCorner originOfTextureInPortraitMode,
bool widthIsHorizontalInPortraitMode,
bool insensitiveToLandscapeMode,
int textureWidth,
int textureHeight,
int screenWidth,
int screenHeight,
ScreenOrientation screenOrientation
)

Generic option-based constructor for a textureToProjectedCoordinatesMatrix when the projected coordinates are NDC (Normalized Device Coordinates), as in most systems. Note that normalized device coordinates go from -1 to 1 left-to-right and bottom-to-top across the screen and that only the ratio screenWidth / screenHeight matters to the resulting matrix, and not the actual values of screenWidth and screenHeight.

Parameters:

  • originOfTextureInPortraitMode TextureCorner enum value
  • widthIsHorizontalInPortraitMode Set this bool to true if the texture coordinate ranging from 0 to texture.width is a horizontal coordinate in portrait mode
  • insensitiveToLandscapeMode Set this bool to true if the texture coordinate system does not change when the device passes from portrait mode to landscape mode (e.g., texture.width and texture.height do not switch)
  • textureWidth Pixel width of the texture (texture.width)
  • textureHeight Pixel height of the texture (texture.height)
  • screenWidth Pixel screen width, typically Screen.width
  • screenHeight Pixel screen height, typically Screen.height
  • screenOrientation The current potrait or landscape mode, typically Screen.orientation

function AddCrop

static Matrix4x4 AddCrop(
Matrix4x4 textureToProjectedCoordinatesMatrix,
int cropWindowMinX,
int cropWindowMinY
)

Computes a textureToProjectedCoordinatesMatrix that converts cropped texture pixel coordinates to projected coordinates.

Parameters:

  • textureToProjectedCoordinatesMatrix Non-cropped texture to projected coordinates matrix
  • cropWindowMinX X-index of first pixel inside the crop (i.e., 0 for no crop)
  • cropWindowMinY Y-index of first pixel inside the crop (i.e., 0 for no crop)

Return: A matrix that converts cropped pixel coordinates to projected coordinates

function ARFoundationDefaultMatrix

static Matrix4x4 ARFoundationDefaultMatrix(
Texture texture
)

Computes a projectedToTextureCoordinatesMatrix that is suited for a texture created via the Manna ARFoundation code samples. See Manna.ProcessVideoFrameTexture for more details on creating a custom textureToProjectedCoordinatesMatrix.

Parameters:

  • texture Texture for which the matrix is to be constructed.

function ScreenToNDCMatrix

static Matrix4x4 ScreenToNDCMatrix(
int screenWidth,
int screenHeight
)

Creates a screen to NDC transformation matrix.

Parameters:

  • screenWidth Width of screen in pixels
  • screenHeight Height of screen in pixels