November 6, 2019 update:
  • There's a new open source Cardboard SDK for iOS and Android NDK that offers a streamlined API, improved device compatibility, and built-in viewer profile QR code scanning. A corresponding Unity package (SDK) is planned for a future release. We recommend that all developers actively building for Google Cardboard migrate (iOS, Android NDK) to the new Cardboard SDK.
October 15, 2019 update:
  • The Daydream View VR headset is no longer available for purchase. However, you can continue to use the existing Google VR SDK to update and distribute your apps to the Google Play Store, and make them available to users in the Daydream app.

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.