applyRelativeWorld method
void
applyRelativeWorld()
Implementation
void applyRelativeWorld() {
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,
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) + 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 * translateMix
..worldY += temp.y * translateMix;
modified = true;
}
if (scaleMix > 0) {
double s =
(math.sqrt(ta * ta + tc * tc) - 1 + data.offsetScaleX) * scaleMix +
1;
bone
..a *= s
..c *= s;
s = (math.sqrt(tb * tb + td * td) - 1 + data.offsetScaleY) * scaleMix +
1;
bone
..b *= s
..d *= s;
modified = true;
}
if (shearMix > 0) {
double r = math.atan2(td, tb) - math.atan2(tc, ta);
if (r > math.pi) {
r -= math.pi * 2;
} else if (r < -math.pi) {
r += math.pi * 2;
}
final double b = bone.b, d = bone.d;
r = math.atan2(d, b) + (r - math.pi / 2 + 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;
}
}