updateJellies method

void updateJellies()

Implementation

void updateJellies() {
  if (_bones == null) {
    return;
  }
  ActorBone bone = parent as ActorBone;
  // We are in local bone space.
  Vec2D tipPosition = Vec2D.fromValues(bone.length, 0.0);

  if (fuzzyEquals(_cachedTip, tipPosition) &&
      fuzzyEquals(_cachedOut, _outPoint) &&
      fuzzyEquals(_cachedIn, _inPoint) &&
      _cachedScaleIn == _scaleIn &&
      _cachedScaleOut == _scaleOut) {
    return;
  }

  Vec2D.copy(_cachedTip, tipPosition);
  Vec2D.copy(_cachedOut, _outPoint);
  Vec2D.copy(_cachedIn, _inPoint);
  _cachedScaleIn = _scaleIn;
  _cachedScaleOut = _scaleOut;

  Vec2D q0 = Vec2D();
  Vec2D q1 = _inPoint;
  Vec2D q2 = _outPoint;
  Vec2D q3 = tipPosition;

  forwardDiffBezier(q0[0], q1[0], q2[0], q3[0], _jellyPoints, jellyMax, 0);
  forwardDiffBezier(q0[1], q1[1], q2[1], q3[1], _jellyPoints, jellyMax, 1);

  List<Vec2D> normalizedPoints = normalizeCurve(_jellyPoints, _bones!.length);

  Vec2D lastPoint = _jellyPoints[0];

  double scale = _scaleIn;
  double scaleInc = (_scaleOut - _scaleIn) / (_bones!.length - 1);
  for (int i = 0; i < normalizedPoints.length; i++) {
    ActorJellyBone jelly = _bones![i];
    Vec2D p = normalizedPoints[i];

    jelly.translation = lastPoint;
    jelly.length = Vec2D.distance(p, lastPoint);
    jelly.scaleY = scale;
    scale += scaleInc;

    Vec2D diff = Vec2D.subtract(Vec2D(), p, lastPoint);
    jelly.rotation = atan2(diff[1], diff[0]);
    lastPoint = p;
  }
}