update method
void
update({})
Writes the estimated world-space hand position into out.
Implementation
void update({
required CameraRig cameraRig,
required Quaternion controllerOrientation,
required double dt,
required Vector3 out,
}) {
if (!dt.isFinite || dt < 0) {
throw ArgumentError.value(dt, 'dt', 'Must be finite and non-negative.');
}
cameraRig.headTransform.copyForwardTo(_headForward);
cameraRig.headTransform.copyRightTo(_headRight);
cameraRig.headTransform.copyUpTo(_headUp);
_rotateControllerForward(controllerOrientation);
final horizontal = _controllerForward.dot(_headRight).clamp(-1.0, 1.0);
final vertical = _controllerForward.dot(_headUp).clamp(-1.0, 1.0);
final alignment = _controllerForward.dot(_headForward).clamp(-1.0, 1.0);
final targetX = restOffset.x + horizontal * horizontalReach;
final targetY = restOffset.y + vertical * verticalReach;
final targetZ = restOffset.z - (1 - alignment) * 0.5 * depthReach;
if (!_initialized || dt == 0) {
_localX = targetX;
_localY = targetY;
_localZ = targetZ;
_initialized = true;
} else {
final alpha = 1 - math.exp(-responsiveness * dt);
_localX += (targetX - _localX) * alpha;
_localY += (targetY - _localY) * alpha;
_localZ += (targetZ - _localZ) * alpha;
}
final head = cameraRig.position;
out.setValues(
head.x +
_headRight.x * _localX +
_headUp.x * _localY +
_headForward.x * _localZ,
head.y +
_headRight.y * _localX +
_headUp.y * _localY +
_headForward.y * _localZ,
head.z +
_headRight.z * _localX +
_headUp.z * _localY +
_headForward.z * _localZ,
);
}