update method

CameraShakeOffset update(
  1. double deltaSeconds
)

Advances the shake simulation by deltaSeconds and returns the offset.

Implementation

CameraShakeOffset update(double deltaSeconds) {
  if (deltaSeconds <= 0.0 || trauma <= 0.0) {
    return CameraShakeOffset.zero;
  }

  _time += deltaSeconds * frequency;
  final shakePower = trauma * trauma;

  final tx = _noise.getNoise2(_time, 0.0) * maxTranslation.x * shakePower;
  final ty = _noise.getNoise2(_time, 100.0) * maxTranslation.y * shakePower;
  final tz = _noise.getNoise2(_time, 200.0) * maxTranslation.z * shakePower;

  final rx = _noise.getNoise2(_time, 300.0) * maxRotation.x * shakePower;
  final ry = _noise.getNoise2(_time, 400.0) * maxRotation.y * shakePower;
  final rz = _noise.getNoise2(_time, 500.0) * maxRotation.z * shakePower;

  trauma = math.max(0.0, trauma - decayRate * deltaSeconds);

  return CameraShakeOffset(
    translation: vm.Vector3(tx, ty, tz),
    rotationEuler: vm.Vector3(rx, ry, rz),
  );
}