onRotationAnim method

dynamic 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

onRotationAnim(time, rotationAxis, w0) {
  if (_timeStart == -1) {
    //animation start
    _anglePrev = 0;
    _angleCurrent = 0;
    _timeStart = time;
  }

  if (_state == State2.animationRotate) {
    //w = w0 + alpha * t
    var deltaTime = (time - _timeStart) / 1000;
    var 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);
      var 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);
    }
  }
}