updateCameras method

void updateCameras(
  1. GamepadState state
)

Updates variables for both cameras' servos.

Implementation

void updateCameras(GamepadState state) {
  // Update only ONE camera. Go left to right.
  final newFrontSwivel = state.normalDpadX;
  final newFrontTilt = state.normalDpadY;
  final newRearSwivel = state.normalRightX;
  final newRearTilt = state.normalRightJoystickY;
  if (newFrontSwivel.abs() >= 0.05 || newFrontTilt.abs() >= 0.05) {
    // Update the front camera. Now, choose which axis
    if (newFrontSwivel.abs() > newFrontTilt.abs()) {
      frontSwivel += newFrontSwivel * cameraSwivelIncrement;
    } else {
      frontTilt += newFrontTilt * cameraTiltIncrement;
    }
  } else if (newRearSwivel.abs() >= 0.05 || newRearTilt.abs() >= 0.05) {
    if (newRearSwivel.abs() > newRearTilt.abs()) {
      rearSwivel += newRearSwivel * cameraSwivelIncrement;
    } else {
      rearTilt += newRearTilt * cameraTiltIncrement * -1;
    }
  }
  // Clamp cameras
  frontSwivel = frontSwivel.clamp(0, 180);
  frontTilt = frontTilt.clamp(0, 180);
  rearSwivel = rearSwivel.clamp(0, 180);
  rearTilt = rearTilt.clamp(0, 180);
}