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.

GvrArmModel

Standard implementation for a mathematical model to make the virtual controller approximate the physical location of the Daydream controller.

Summary

Inheritance

Inherits from: GvrBaseArmModel, IGvrControllerInputDeviceReceiver

Public attributes

armExtensionOffset = DEFAULT_ARM_EXTENSION_OFFSET
Vector3
Offset applied to the elbow position as the controller is rotated upwards.
controllerRestPosition = DEFAULT_CONTROLLER_REST_POSITION
Vector3
Position of the controller joint relative to the wrist before the arm model is applied.
elbowBendRatio = DEFAULT_ELBOW_BEND_RATIO
float
Ratio of the controller's rotation to apply to the rotation of the elbow.
elbowRestPosition = DEFAULT_ELBOW_REST_POSITION
Vector3
Position of the elbow joint relative to the head before the arm model is applied.
fadeControllerOffset = 0.0f
float
Offset in front of the controller to determine what position to use when determing if the controller should fade.
fadeDistanceFromHeadForward = 0.25f
float
Controller distance from the front/back of the head after which the controller disappears (meters).
fadeDistanceFromHeadSide = 0.15f
float
Controller distance from the left/right of the head after which the controller disappears (meters).
isLockedToNeck = false
bool
If true, the root of the pose is locked to the local position of the player's neck.
tooltipMaxAngleFromCamera = 80
int
The maximum angle in degrees between the controller and head at which to show tooltips.
tooltipMinDistanceFromFace = 0.45f
float
Controller distance from face after which the tooltips appear (meters).
wristRestPosition = DEFAULT_WRIST_REST_POSITION
Vector3
Position of the wrist joint relative to the elbow before the arm model is applied.

Protected attributes

DELTA_ALPHA = 4.0f
const float
Amount of normalized alpha transparency to change per second.
EXTENSION_WEIGHT = 0.4f
const float
Increases elbow bending as the controller moves up (unitless).
MAX_EXTENSION_ANGLE = 60.0f
const float
Maximum angle in degrees of the controller the for arm extension offset to end.
MIN_EXTENSION_ANGLE = 7.0f
const float
Minimum angle in degrees of the controller the for arm extension offset to start.
controllerPosition
Vector3
The controller position based on this arm model.
controllerRotation
Quaternion
The controller rotation based on this arm model.
elbowPosition
Vector3
The elbow position based on this arm model.
elbowRotation
Quaternion
The elbow rotation based on this arm model.
handedMultiplier
Vector3
Multiplier for handedness such that 1 = Right, 0 = Center, -1 = left.
neckPosition
Vector3
The neck position based on this arm model.
preferredAlpha
float
The preferred alpha.
tooltipAlphaValue
float
The tooltip alpha value.
torsoDirection
Vector3
Forward direction of user's torso.
torsoRotation
Quaternion
Orientation of the user's torso.
wristPosition
Vector3
The wrist position based on this arm model.
wristRotation
Quaternion
The wrist rotation based on this arm model.

Protected static attributes

NECK_OFFSET = new Vector3(0.0f, 0.075f, 0.08f)
readonly Vector3
Neck offset used to apply the inverse neck model when locked to the head.
SHOULDER_POSITION = new Vector3(0.17f, -0.2f, -0.03f)
readonly Vector3
Rest position for shoulder joint.

Properties

ControllerInputDevice
Gets or sets the controller input device.
ControllerPositionFromHead
override Vector3
ControllerRotationFromHead
override Quaternion
ElbowPosition
Vector3
Gets the elbow's position relative to the user's head.
ElbowRotation
Quaternion
Gets the elbow's rotation relative to the user's head.
NeckPosition
Vector3
Gets the neck's position relative to the user's head.
PreferredAlpha
override float
ShoulderPosition
Vector3
Gets the shoulder's position relative to the user's head.
ShoulderRotation
Quaternion
Gets the shoulder's rotation relative to the user's head.
TooltipAlphaValue
override float
WristPosition
Vector3
Gets the wrist's position relative to the user's head.
WristRotation
Quaternion
Gets the wrist's rotation relative to the user's head.

Protected functions

ApplyArmModel()
virtual void
Applies the arm model parameters to update the orientation and position.
ApplyExtensionOffset(float extensionRatio)
virtual void
Offset the elbow by the extension offset.
ApplyInverseNeckModel(Vector3 headPosition)
virtual Vector3
Transform the head position into an approximate neck position.
ApplyRotationToJoints()
virtual void
Apply the joint rotations to the positions of the joints to determine the final pose.
CalculateExtensionRatio(float xAngle)
virtual float
Calculate the extension ratio based on the angle of the controller along the x axis.
CalculateFinalJointRotations(Quaternion controllerOrientation, Quaternion xyRotation, Quaternion lerpRotation)
virtual void
Determine the final joint rotations relative to the head.
CalculateLerpRotation(Quaternion xyRotation, float extensionRatio)
virtual Quaternion
Calculate the lerp rotation, which is used to control how much the rotation of the controller impacts each joint.
GetControllerRotation(out Quaternion rotation, out Quaternion xyRotation, out float xAngle)
void
Get the controller's orientation.
SetUntransformedJointPositions()
virtual void
Set the starting positions of the joints before they are transformed by the arm model.
UpdateHandedness()
virtual void
Updates the arm model handedness.
UpdateNeckPosition()
virtual void
Updates the neck position in the arm model.
UpdateTorsoDirection(bool forceImmediate)
virtual void
Updates the arm model torso direction.
UpdateTransparency()
virtual void
Controls the transparency of the controller to prevent the controller from clipping through the user's head.

Public attributes

armExtensionOffset

Vector3 armExtensionOffset = DEFAULT_ARM_EXTENSION_OFFSET

Offset applied to the elbow position as the controller is rotated upwards.

controllerRestPosition

Vector3 controllerRestPosition = DEFAULT_CONTROLLER_REST_POSITION

Position of the controller joint relative to the wrist before the arm model is applied.

elbowBendRatio

float elbowBendRatio = DEFAULT_ELBOW_BEND_RATIO

Ratio of the controller's rotation to apply to the rotation of the elbow.

The remaining rotation is applied to the wrist's rotation.

elbowRestPosition

Vector3 elbowRestPosition = DEFAULT_ELBOW_REST_POSITION

Position of the elbow joint relative to the head before the arm model is applied.

fadeControllerOffset

float fadeControllerOffset = 0.0f

Offset in front of the controller to determine what position to use when determing if the controller should fade.

This is useful when objects are attached to the controller.

fadeDistanceFromHeadForward

float fadeDistanceFromHeadForward = 0.25f

Controller distance from the front/back of the head after which the controller disappears (meters).

fadeDistanceFromHeadSide

float fadeDistanceFromHeadSide = 0.15f

Controller distance from the left/right of the head after which the controller disappears (meters).

isLockedToNeck

bool isLockedToNeck = false

If true, the root of the pose is locked to the local position of the player's neck.

tooltipMaxAngleFromCamera

int tooltipMaxAngleFromCamera = 80

The maximum angle in degrees between the controller and head at which to show tooltips.

When the angle between the controller and the head is larger than this value, the tooltips disappear. If the value is 180, then the tooltips are always shown. If the value is 90, the tooltips are only shown when they are facing the camera.

tooltipMinDistanceFromFace

float tooltipMinDistanceFromFace = 0.45f

Controller distance from face after which the tooltips appear (meters).

wristRestPosition

Vector3 wristRestPosition = DEFAULT_WRIST_REST_POSITION

Position of the wrist joint relative to the elbow before the arm model is applied.

Protected attributes

DELTA_ALPHA

const float DELTA_ALPHA = 4.0f

Amount of normalized alpha transparency to change per second.

EXTENSION_WEIGHT

const float EXTENSION_WEIGHT = 0.4f

Increases elbow bending as the controller moves up (unitless).

MAX_EXTENSION_ANGLE

const float MAX_EXTENSION_ANGLE = 60.0f

Maximum angle in degrees of the controller the for arm extension offset to end.

This is the range of controller X-axis values in which the modeled arm rotates with the controller, outside of which the modeled arm doesn't rotate with the controller, only the controller rotates. Above this value, the wrist is primarily responsible for controller rotation, not the arm.

MIN_EXTENSION_ANGLE

const float MIN_EXTENSION_ANGLE = 7.0f

Minimum angle in degrees of the controller the for arm extension offset to start.

This is the range of controller X-axis values in which the modeled arm rotates with the controller, outside of which the modeled arm doesn't rotate with the controller, only the controller rotates. Below this value, the wrist is primarily responsible for controller rotation, not the arm.

controllerPosition

Vector3 controllerPosition

The controller position based on this arm model.

controllerRotation

Quaternion controllerRotation

The controller rotation based on this arm model.

elbowPosition

Vector3 elbowPosition

The elbow position based on this arm model.

elbowRotation

Quaternion elbowRotation

The elbow rotation based on this arm model.

handedMultiplier

Vector3 handedMultiplier

Multiplier for handedness such that 1 = Right, 0 = Center, -1 = left.

neckPosition

Vector3 neckPosition

The neck position based on this arm model.

preferredAlpha

float preferredAlpha

The preferred alpha.

tooltipAlphaValue

float tooltipAlphaValue

The tooltip alpha value.

torsoDirection

Vector3 torsoDirection

Forward direction of user's torso.

torsoRotation

Quaternion torsoRotation

Orientation of the user's torso.

wristPosition

Vector3 wristPosition

The wrist position based on this arm model.

wristRotation

Quaternion wristRotation

The wrist rotation based on this arm model.

Protected static attributes

NECK_OFFSET

readonly Vector3 NECK_OFFSET = new Vector3(0.0f, 0.075f, 0.08f)

Neck offset used to apply the inverse neck model when locked to the head.

SHOULDER_POSITION

readonly Vector3 SHOULDER_POSITION = new Vector3(0.17f, -0.2f, -0.03f)

Rest position for shoulder joint.

Properties

ControllerInputDevice

GvrControllerInputDevice ControllerInputDevice

Gets or sets the controller input device.

The controller input device.

ControllerPositionFromHead

override Vector3 ControllerPositionFromHead

ControllerRotationFromHead

override Quaternion ControllerRotationFromHead

ElbowPosition

Vector3 ElbowPosition

Gets the elbow's position relative to the user's head.

The elbow position.

ElbowRotation

Quaternion ElbowRotation

Gets the elbow's rotation relative to the user's head.

The elbow rotation.

NeckPosition

Vector3 NeckPosition

Gets the neck's position relative to the user's head.

If isLockedToNeck is true, this will be the input tracking position of the head node modified by an inverse neck model to approximate the neck position. Otherwise, it is always zero.

The neck position.

PreferredAlpha

override float PreferredAlpha

ShoulderPosition

Vector3 ShoulderPosition

Gets the shoulder's position relative to the user's head.

This is not actually used as part of the arm model calculations, and exists for debugging.

The shoulder position.

ShoulderRotation

Quaternion ShoulderRotation

Gets the shoulder's rotation relative to the user's head.

This is not actually used as part of the arm model calculations, and exists for debugging.

The shoulder rotation.

TooltipAlphaValue

override float TooltipAlphaValue

WristPosition

Vector3 WristPosition

Gets the wrist's position relative to the user's head.

The wrist position.

WristRotation

Quaternion WristRotation

Gets the wrist's rotation relative to the user's head.

The wrist rotation.

Protected functions

ApplyArmModel

virtual void ApplyArmModel()

Applies the arm model parameters to update the orientation and position.

ApplyExtensionOffset

virtual void ApplyExtensionOffset(
  float extensionRatio
)

Offset the elbow by the extension offset.

Details
Parameters
extensionRatio
The extension ratio of the elbow to apply.

ApplyInverseNeckModel

virtual Vector3 ApplyInverseNeckModel(
  Vector3 headPosition
)

Transform the head position into an approximate neck position.

Details
Parameters
headPosition
Head position.
Returns
The inverse neck model.

ApplyRotationToJoints

virtual void ApplyRotationToJoints()

Apply the joint rotations to the positions of the joints to determine the final pose.

CalculateExtensionRatio

virtual float CalculateExtensionRatio(
  float xAngle
)

Calculate the extension ratio based on the angle of the controller along the x axis.

Details
Parameters
xAngle
The X angle of the controller along the x axis.
Returns
The extension ratio of the elbow.

CalculateFinalJointRotations

virtual void CalculateFinalJointRotations(
  Quaternion controllerOrientation,
  Quaternion xyRotation,
  Quaternion lerpRotation
)

Determine the final joint rotations relative to the head.

Details
Parameters
controllerOrientation
Controller orientation.
xyRotation
The xy rotation of the controller.
lerpRotation
Lerp rotation.

CalculateLerpRotation

virtual Quaternion CalculateLerpRotation(
  Quaternion xyRotation,
  float extensionRatio
)

Calculate the lerp rotation, which is used to control how much the rotation of the controller impacts each joint.

Details
Parameters
xyRotation
The xy rotation of the controller.
extensionRatio
The extension ratio of the elbow.
Returns
The lerp rotation.

GetControllerRotation

void GetControllerRotation(
  out Quaternion rotation,
  out Quaternion xyRotation,
  out float xAngle
)

Get the controller's orientation.

Details
Parameters
rotation
The output rotation which will be written to.
xyRotation
The output xy-only rotation.
xAngle
The output angle from the X axis.

SetUntransformedJointPositions

virtual void SetUntransformedJointPositions()

Set the starting positions of the joints before they are transformed by the arm model.

UpdateHandedness

virtual void UpdateHandedness()

Updates the arm model handedness.

UpdateNeckPosition

virtual void UpdateNeckPosition()

Updates the neck position in the arm model.

UpdateTorsoDirection

virtual void UpdateTorsoDirection(
  bool forceImmediate
)

Updates the arm model torso direction.

Details
Parameters
forceImmediate
If true, uses the gaze direction, otherwise uses slerp to update the direction smoothly.

UpdateTransparency

virtual void UpdateTransparency()

Controls the transparency of the controller to prevent the controller from clipping through the user's head.

Also controls the transparency of the tooltips so they are only visible when the controller is held up.