mirror of
https://github.com/ppy/osu.git
synced 2024-11-09 01:37:52 +08:00
Change Implementation and name of KeepUprightAndUnstretched
This commit is contained in:
parent
dbb77705da
commit
15fb4d8dd5
@ -81,45 +81,43 @@ namespace osu.Game.Extensions
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Keeps the drawable upright and prevents it from being scaled or flipped with its Parent.
|
/// Keeps the drawable upright and prevents it from being scaled or flipped with its Parent.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="drawable">The drawable.</param>
|
/// <param name="drawable">The drawable.</param>
|
||||||
public static void KeepUprightAndUnstretched(this Drawable drawable)
|
public static void KeepUprightAndUnscaled(this Drawable drawable)
|
||||||
{
|
{
|
||||||
// Fix the rotation
|
var parentMatrix = drawable.Parent.DrawInfo.Matrix;
|
||||||
var result = drawable.Parent.DrawInfo;
|
float angle = MathF.Atan(parentMatrix.M12 / parentMatrix.M11);
|
||||||
var scale = result.Matrix.ExtractScale();
|
|
||||||
var rotation = new Matrix3(
|
|
||||||
result.Matrix.Row0 / scale.X,
|
|
||||||
result.Matrix.Row1 / scale.Y,
|
|
||||||
new Vector3(0.0f, 0.0f, 1.0f)
|
|
||||||
);
|
|
||||||
rotation.Invert();
|
|
||||||
float angle = MathF.Atan(rotation.M12 / rotation.M11);
|
|
||||||
angle *= (360 / (2 * MathF.PI));
|
angle *= (360 / (2 * MathF.PI));
|
||||||
drawable.Rotation = angle;
|
|
||||||
|
|
||||||
// Fix the scale (includes flip)
|
parentMatrix.Transpose();
|
||||||
var containerOriginToSpaceOrigin = new Matrix3(
|
parentMatrix.M13 = 0.0f;
|
||||||
new Vector3(1.0f, 0.0f, 0.0f),
|
parentMatrix.M23 = 0.0f;
|
||||||
new Vector3(0.0f, 1.0f, 0.0f),
|
|
||||||
new Vector3(drawable.DrawSize.X / 2, drawable.DrawSize.Y / 2, 1.0f)
|
|
||||||
);
|
|
||||||
var containerOriginToSpaceOriginInverse = containerOriginToSpaceOrigin;
|
|
||||||
containerOriginToSpaceOriginInverse.Invert();
|
|
||||||
Matrix3 rotatedBack = (containerOriginToSpaceOriginInverse * (rotation * (containerOriginToSpaceOrigin * result.Matrix)));
|
|
||||||
|
|
||||||
bool xFliped = rotation.M11 < 0;
|
if ((Math.Abs(Math.Abs(angle) - 90.0)) < 2.0f)
|
||||||
bool yFliped = rotation.M22 < 0;
|
{
|
||||||
|
Matrix3 m = Matrix3.CreateRotationZ(MathHelper.DegreesToRadians(40.0f));
|
||||||
var rotatedBackScale = rotatedBack.ExtractScale();
|
m.Transpose();
|
||||||
|
parentMatrix *= m;
|
||||||
drawable.Scale = new Vector2(
|
drawable.Rotation = 40.0f;
|
||||||
(xFliped ? -1 : 1) / rotatedBackScale.X,
|
|
||||||
(yFliped ? -1 : 1) / rotatedBackScale.Y
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
drawable.Rotation = 0.0f;
|
||||||
|
|
||||||
|
Matrix3 C = parentMatrix.Inverted();
|
||||||
|
|
||||||
|
float alpha, beta, sx, sy;
|
||||||
|
sy = C.M22;
|
||||||
|
alpha = C.M12 / C.M22;
|
||||||
|
|
||||||
|
beta = (C.M21 == 0.0f) ? 0.0f : 1 / ((C.M11 / C.M21) - alpha);
|
||||||
|
sx = (beta == 0.0f) ? C.M11 : C.M21 / beta;
|
||||||
|
|
||||||
|
drawable.Scale = new Vector2(sx, sy);
|
||||||
|
drawable.Shear = new Vector2(-alpha, -beta);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user