constrain method

  1. @override
void constrain(
  1. ActorNode node
)
override

Implementation

@override
void constrain(ActorNode node) {
  ActorNode? t = target as ActorNode?;
  if (t == null) {
    return;
  }

  ActorNode parent = this.parent!;

  Mat2D transformA = parent.worldTransform;
  Mat2D transformB = Mat2D.clone(t.worldTransform);
  if (_sourceSpace == TransformSpace.local) {
    ActorNode? grandParent = target!.parent;
    if (grandParent != null) {
      Mat2D inverse = Mat2D();
      Mat2D.invert(inverse, grandParent.worldTransform);
      Mat2D.multiply(transformB, inverse, transformB);
    }
  }
  if (_destSpace == TransformSpace.local) {
    ActorNode? grandParent = parent.parent;
    if (grandParent != null) {
      Mat2D.multiply(transformB, grandParent.worldTransform, transformB);
    }
  }
  Mat2D.decompose(transformA, _componentsA);
  Mat2D.decompose(transformB, _componentsB);

  double angleA = _componentsA[4] % pi2;
  double angleB = _componentsB[4] % pi2;
  double diff = angleB - angleA;
  if (diff > pi) {
    diff -= pi2;
  } else if (diff < -pi) {
    diff += pi2;
  }

  double ti = 1.0 - strength;

  _componentsB[4] = angleA + diff * strength;
  _componentsB[0] = _componentsA[0] * ti + _componentsB[0] * strength;
  _componentsB[1] = _componentsA[1] * ti + _componentsB[1] * strength;
  _componentsB[2] = _componentsA[2] * ti + _componentsB[2] * strength;
  _componentsB[3] = _componentsA[3] * ti + _componentsB[3] * strength;
  _componentsB[5] = _componentsA[5] * ti + _componentsB[5] * strength;

  Mat2D.compose(parent.worldTransform, _componentsB);
}