Ejemplo n.º 1
0
void ChannelBase<Vector2f>::set(Vector2f newValue) {
  if (isDigital) {
    newValue.x = newValue.x >= actPoint ? 1.0f : 0.0f;
    newValue.y = newValue.y >= actPoint ? 1.0f : 0.0f;
  } else {
    float length = newValue.length();
    if (deadZone > 0) {
      if (length <= deadZone) {
        newValue = Vector2f::ZERO;
      } else {
        newValue *= (length - deadZone) / (length * (1 - deadZone));
      }
    }
    if (hasBound) {
      newValue.x = newValue.x >= bound ? 1.0f : newValue.x;
      newValue.y = newValue.y >= bound ? 1.0f : newValue.y;

      newValue.x = newValue.x <= -bound ? -1.0f : newValue.x;
      newValue.y = newValue.y <= -bound ? -1.0f : newValue.y;
    }

    newValue *= sensitivity;
  }

  if (alwaysNotifyListener or !newValue.fuzzyEqual(value, 0.0001)) {
    value = newValue;

    if (not listeners.empty()) {
      notifyListeners();
    }
  } else {
    return;
  }

  if (false) {
    value = Vector2f(0.0f);
  }
}