applyAbsoluteWorld method
void
applyAbsoluteWorld()
Implementation
void applyAbsoluteWorld() {
final double rotateMix = this.rotateMix,
translateMix = this.translateMix,
scaleMix = this.scaleMix,
shearMix = this.shearMix;
final Bone target = this.target!;
final double ta = target.a, tb = target.b, tc = target.c, td = target.d;
final double degRadReflect =
ta * td - tb * tc > 0 ? MathUtils.degRad : -MathUtils.degRad;
final double offsetRotation = data.offsetRotation * degRadReflect;
final double offsetShearY = data.offsetShearY * degRadReflect;
final List<Bone> bones = this.bones;
final int n = bones.length;
for (int i = 0; i < n; i++) {
final Bone bone = bones[i];
bool modified = false;
if (rotateMix != 0) {
final double a = bone.a, b = bone.b, c = bone.c, d = bone.d;
double r = math.atan2(tc, ta) - math.atan2(c, a) + offsetRotation;
if (r > math.pi) {
r -= math.pi * 2;
} else if (r < -math.pi) {
r += math.pi * 2;
}
r *= rotateMix;
final double cos = math.cos(r), sin = math.sin(r);
bone
..a = cos * a - sin * c
..b = cos * b - sin * d
..c = sin * a + cos * c
..d = sin * b + cos * d;
modified = true;
}
if (translateMix != 0) {
final Vector2 temp = this.temp..set(data.offsetX, data.offsetY);
target.localToWorld(temp);
bone
..worldX += (temp.x - bone.worldX) * translateMix
..worldY += (temp.y - bone.worldY) * translateMix;
modified = true;
}
if (scaleMix > 0) {
double s = math.sqrt(bone.a * bone.a + bone.c * bone.c);
double ts = math.sqrt(ta * ta + tc * tc);
if (s > 0.00001) s = (s + (ts - s + data.offsetScaleX) * scaleMix) / s;
bone
..a *= s
..c *= s;
s = math.sqrt(bone.b * bone.b + bone.d * bone.d);
ts = math.sqrt(tb * tb + td * td);
if (s > 0.00001) s = (s + (ts - s + data.offsetScaleY) * scaleMix) / s;
bone
..b *= s
..d *= s;
modified = true;
}
if (shearMix > 0) {
final double b = bone.b, d = bone.d;
final double by = math.atan2(d, b);
double r = math.atan2(td, tb) -
math.atan2(tc, ta) -
(by - math.atan2(bone.c, bone.a));
if (r > math.pi) {
r -= math.pi * 2;
} else if (r < -math.pi) {
r += math.pi * 2;
}
r = by + (r + offsetShearY) * shearMix;
final double s = math.sqrt(b * b + d * d);
bone
..b = math.cos(r) * s
..d = math.sin(r) * s;
modified = true;
}
if (modified) bone.appliedValid = false;
}
}