evaluate method

void evaluate(
  1. ControllerHand hand,
  2. HandState state
)

Evaluates the current pose of state each tracking frame.

Implementation

void evaluate(ControllerHand hand, HandState state) {
  if (!state.tracked) {
    _endPinchIfNeeded(hand, state);
    _activeGesture[hand] = null;
    _pendingGesture[hand] = null;
    return;
  }

  // Pinch edges fire immediately (they are the primary click mechanism).
  if (state.isPinching) {
    if (!_pinching.contains(hand)) {
      _pinching.add(hand);
      onGesture?.call(
        HandGestureEvent(
          hand: hand,
          gesture: HandGesture.pinchStart,
          pointingRay: state.pointingRay,
        ),
      );
    }
  } else {
    _endPinchIfNeeded(hand, state);
  }

  // Level gestures (fist, flat hand, point, ...) are debounced.
  final detected = _detectGesture(state);
  final active = _activeGesture[hand];

  if (detected == active) {
    _pendingGesture[hand] = null;
    return;
  }

  if (_pendingGesture[hand] != detected) {
    _pendingGesture[hand] = detected;
    _pendingSince[hand] = DateTime.now();
    return;
  }

  final since = _pendingSince[hand]!;
  if (DateTime.now().difference(since) >= minHoldDuration) {
    _activeGesture[hand] = detected;
    _pendingGesture[hand] = null;
    if (detected != null) {
      onGesture?.call(
        HandGestureEvent(
          hand: hand,
          gesture: detected,
          pointingRay: state.pointingRay,
        ),
      );
    }
  }
}