onRotationAnim method

void onRotationAnim(
  1. dynamic time,
  2. dynamic rotationAxis,
  3. dynamic w0
)
  • Perform animation for rotation operation
  • @param {Number} time Instant in which this function is called as performance.now()
  • @param {Vector3} rotationAxis Rotation axis
  • @param {number} w0 Initial angular velocity

Implementation

/// * Perform animation for rotation operation
	/// * @param {Number} time Instant in which this function is called as performance.now()
	/// * @param {Vector3} rotationAxis Rotation axis
	/// * @param {number} w0 Initial angular velocity
	/// *
void onRotationAnim(time, rotationAxis, w0) {
  if (_timeStart == -1) {
    //animation start
    _anglePrev = 0;
    _angleCurrent = 0;
    _timeStart = time;
  }

  if (_state == State2.animationRotate) {
    //w = w0 + alpha * t
    final deltaTime = (time - _timeStart) / 1000;
    final w = w0 + ((-dampingFactor) * deltaTime);

    if (w > 0) {
      //tetha = 0.5 * alpha * t^2 + w0 * t + tetha0
      _angleCurrent =
          0.5 * (-dampingFactor) * math.pow(deltaTime, 2) +
              w0 * deltaTime +
              0;
      applyTransformMatrix(rotate(rotationAxis, _angleCurrent));
      dispatchEvent(_changeEvent);
      final self = this;
      _animationId = requestAnimationFrame((t) {
        self.onRotationAnim(t, rotationAxis, w0);
      });
    } else {
      _animationId = -1;
      _timeStart = -1;

      updateTbState(State2.idle, false);
      activateGizmos(false);

      dispatchEvent(_changeEvent);
    }
  } else {
    //interrupt animation

    _animationId = -1;
    _timeStart = -1;

    if (_state != State2.rotate) {
      activateGizmos(false);
      dispatchEvent(_changeEvent);
    }
  }
}