update method

  1. @override
void update(
  1. int dirt
)
override

Implementation

@override
void update(int dirt) {
  ActorBone bone = parent as ActorBone;
  ActorNode? parentBone = bone.parent;
  JellyComponent? parentBoneJelly;
  if (parentBone is ActorBone) {
    parentBoneJelly = parentBone.jelly;
  }

  Mat2D inverseWorld = Mat2D();
  if (!Mat2D.invert(inverseWorld, bone.worldTransform)) {
    return;
  }

  if (_inTarget != null) {
    Vec2D translation = _inTarget!.getWorldTranslation(Vec2D());
    Vec2D.transformMat2D(_inPoint, translation, inverseWorld);
    Vec2D.normalize(_inDirection, _inPoint);
  } else if (parentBone != null) {
    ActorBone? firstBone;
    if (parentBone is ActorBone) {
      firstBone = parentBone.firstBone;
    } else if (parentBone is ActorRootBone) {
      firstBone = parentBone.firstBone;
    }
    if (firstBone == bone &&
        parentBoneJelly != null &&
        parentBoneJelly._outTarget != null) {
      Vec2D translation =
          parentBoneJelly._outTarget!.getWorldTranslation(Vec2D());
      Vec2D localParentOut =
          Vec2D.transformMat2D(Vec2D(), translation, inverseWorld);
      Vec2D.normalize(localParentOut, localParentOut);
      Vec2D.negate(_inDirection, localParentOut);
    } else {
      Vec2D d1 = Vec2D.fromValues(1.0, 0.0);
      Vec2D d2 = Vec2D.fromValues(1.0, 0.0);

      Vec2D.transformMat2(d1, d1, parentBone.worldTransform);
      Vec2D.transformMat2(d2, d2, bone.worldTransform);

      Vec2D sum = Vec2D.add(Vec2D(), d1, d2);
      Vec2D.transformMat2(_inDirection, sum, inverseWorld);
      Vec2D.normalize(_inDirection, _inDirection);
    }
    _inPoint[0] = _inDirection[0] * _easeIn * bone.length * curveConstant;
    _inPoint[1] = _inDirection[1] * _easeIn * bone.length * curveConstant;
  } else {
    _inDirection[0] = 1.0;
    _inDirection[1] = 0.0;
    _inPoint[0] = _inDirection[0] * _easeIn * bone.length * curveConstant;
  }

  if (_outTarget != null) {
    Vec2D translation = _outTarget!.getWorldTranslation(Vec2D());
    Vec2D.transformMat2D(_outPoint, translation, inverseWorld);
    Vec2D tip = Vec2D.fromValues(bone.length, 0.0);
    Vec2D.subtract(_outDirection, _outPoint, tip);
    Vec2D.normalize(_outDirection, _outDirection);
  } else if (bone.firstBone != null) {
    ActorBone firstBone = bone.firstBone!;
    JellyComponent? firstBoneJelly = firstBone.jelly;
    if (firstBoneJelly != null && firstBoneJelly._inTarget != null) {
      Vec2D translation =
          firstBoneJelly._inTarget!.getWorldTranslation(Vec2D());
      Vec2D worldChildInDir = Vec2D.subtract(
          Vec2D(), firstBone.getWorldTranslation(Vec2D()), translation);
      Vec2D.transformMat2(_outDirection, worldChildInDir, inverseWorld);
    } else {
      Vec2D d1 = Vec2D.fromValues(1.0, 0.0);
      Vec2D d2 = Vec2D.fromValues(1.0, 0.0);

      Vec2D.transformMat2(d1, d1, firstBone.worldTransform);
      Vec2D.transformMat2(d2, d2, bone.worldTransform);

      Vec2D sum = Vec2D.add(Vec2D(), d1, d2);
      Vec2D negativeSum = Vec2D.negate(Vec2D(), sum);
      Vec2D.transformMat2(_outDirection, negativeSum, inverseWorld);
      Vec2D.normalize(_outDirection, _outDirection);
    }
    Vec2D.normalize(_outDirection, _outDirection);
    Vec2D scaledOut = Vec2D.scale(
        Vec2D(), _outDirection, _easeOut * bone.length * curveConstant);
    _outPoint[0] = bone.length;
    _outPoint[1] = 0.0;
    Vec2D.add(_outPoint, _outPoint, scaledOut);
  } else {
    _outDirection[0] = -1.0;
    _outDirection[1] = 0.0;

    Vec2D scaledOut = Vec2D.scale(
        Vec2D(), _outDirection, _easeOut * bone.length * curveConstant);
    _outPoint[0] = bone.length;
    _outPoint[1] = 0.0;
    Vec2D.add(_outPoint, _outPoint, scaledOut);
  }

  updateJellies();
}