GvrMathHelpers

Helper functions to perform common math operations for Gvr.

Summary

Public static functions

ConvertFloatArrayToMatrix(float[] floatArray)
Matrix4x4
Converts a float array of length 16 into a column-major 4x4 matrix.
EaseOutCubic(float min, float max, float value)
float
A cubic easing function (https://easings.net/#easeOutCubic).
GetIntersectionPosition(Camera cam, RaycastResult raycastResult)
Vector3
Gets the intersection position of the camera and the raycast result.
GvrMatrixToUnitySpace(Matrix4x4 gvrMatrix, out Vector3 position, out Quaternion orientation)
void
Converts matrix from Google VR convention to Unity convention.
NormalizedCartesianToSpherical(Vector3 cartCoords)
Vector2
Normalizes a 3D Cartesian direction to a 2D spherical direction.

Public static functions

ConvertFloatArrayToMatrix

Matrix4x4 ConvertFloatArrayToMatrix(
  float[] floatArray
)

Converts a float array of length 16 into a column-major 4x4 matrix.

Details
Parameters
floatArray
The array to convert to a matrix.
Returns
A column-major 4x4 matrix.

EaseOutCubic

float EaseOutCubic(
  float min,
  float max,
  float value
)

A cubic easing function (https://easings.net/#easeOutCubic).

Details
Parameters
min
The minimum output value.
max
The maximum output value.
value
The input to the easing function between 0 and 1.
Returns
The output of the easing function between (min) and (max).

GetIntersectionPosition

Vector3 GetIntersectionPosition(
  Camera cam,
  RaycastResult raycastResult
)

Gets the intersection position of the camera and the raycast result.

Details
Parameters
cam
The camera to use.
raycastResult
The result of the raycast to intersect with the camera.
Returns
The position of the intersection.

GvrMatrixToUnitySpace

void GvrMatrixToUnitySpace(
  Matrix4x4 gvrMatrix,
  out Vector3 position,
  out Quaternion orientation
)

Converts matrix from Google VR convention to Unity convention.

Google VR is row-major, RHS coordinates, and Unity is column-major, LHS.

Details
Parameters
gvrMatrix
The Google VR matrix data.
position
The position in Unity space based on the Google VR matrix.
orientation
The orientation in Unity space.

NormalizedCartesianToSpherical

Vector2 NormalizedCartesianToSpherical(
  Vector3 cartCoords
)

Normalizes a 3D Cartesian direction to a 2D spherical direction.

Details
Parameters
cartCoords
The coordinates to normalize.
Returns
The spherical coordinates.