Merge branch 'MathLib' of https://github.com/NoriteSC/FlaxEngineFork into NoriteSC-MathLib
This commit is contained in:
@@ -890,6 +890,17 @@ namespace Math
|
||||
{
|
||||
return Lerp<T>(a, b, alpha < 0.5f ? InterpCircularIn(0.f, 1.f, alpha * 2.f) * 0.5f : InterpCircularOut(0.f, 1.f, alpha * 2.f - 1.f) * 0.5f + 0.5f);
|
||||
}
|
||||
/// <summary>
|
||||
/// PingPongs the value <paramref name="t"/>, so that it is never larger than <paramref name="length"/> and never smaller than 0.
|
||||
/// </summary>
|
||||
/// <param name="t"></param>
|
||||
/// <param name="length"></param>
|
||||
/// <returns></returns>
|
||||
template<class T>
|
||||
static FORCE_INLINE T PingPong(const T& t, T length)
|
||||
{
|
||||
return length - Abs(Repeat(t, length * 2.0f) - length);
|
||||
}
|
||||
|
||||
// Rotates position about the given axis by the given angle, in radians, and returns the offset to position
|
||||
Vector3 FLAXENGINE_API RotateAboutAxis(const Vector3& normalizedRotationAxis, float angle, const Vector3& positionOnAxis, const Vector3& position);
|
||||
|
||||
@@ -487,9 +487,12 @@ namespace FlaxEngine.GUI
|
||||
public void UpdateTransform()
|
||||
{
|
||||
// Actual pivot and negative pivot
|
||||
Float2.Multiply(ref _pivot, ref _bounds.Size, out var v1);
|
||||
Float2.Negate(ref v1, out var v2);
|
||||
Float2.Add(ref v1, ref _bounds.Location, out v1);
|
||||
//Float2.Multiply(ref _pivot, ref _bounds.Size, out var v1);
|
||||
//Float2.Negate(ref v1, out var v2);
|
||||
//Float2.Add(ref v1, ref _bounds.Location, out v1);
|
||||
var v1 = _pivot * _bounds.Size;
|
||||
var v2 = -v1;
|
||||
v1 += _bounds.Location;
|
||||
|
||||
// ------ Matrix3x3 based version:
|
||||
|
||||
@@ -518,18 +521,42 @@ namespace FlaxEngine.GUI
|
||||
// ------ Matrix2x2 based version:
|
||||
|
||||
// 2D transformation
|
||||
Matrix2x2.Scale(ref _scale, out Matrix2x2 m1);
|
||||
Matrix2x2.Shear(ref _shear, out Matrix2x2 m2);
|
||||
Matrix2x2.Multiply(ref m1, ref m2, out m1);
|
||||
Matrix2x2.Rotation(Mathf.DegreesToRadians * _rotation, out m2);
|
||||
Matrix2x2.Multiply(ref m1, ref m2, out m1);
|
||||
|
||||
//Matrix2x2.Scale(ref _scale, out Matrix2x2 m1);
|
||||
//Matrix2x2.Shear(ref _shear, out Matrix2x2 m2);
|
||||
//Matrix2x2.Multiply(ref m1, ref m2, out m1);
|
||||
|
||||
// Scale and Shear
|
||||
Matrix3x3 m1 = new Matrix3x3
|
||||
(
|
||||
_scale.X,
|
||||
_scale.X * (_shear.Y == 0 ? 0 : (1.0f / Mathf.Tan(Mathf.DegreesToRadians * (90 - Mathf.Clamp(_shear.Y, -89.0f, 89.0f))))),
|
||||
0,
|
||||
_scale.Y * (_shear.X == 0 ? 0 : (1.0f / Mathf.Tan(Mathf.DegreesToRadians * (90 - Mathf.Clamp(_shear.X, -89.0f, 89.0f))))),
|
||||
_scale.Y,
|
||||
0, 0, 0, 1
|
||||
);
|
||||
|
||||
|
||||
//Matrix2x2.Rotation(Mathf.DegreesToRadians * _rotation, out m2);
|
||||
float sin = Mathf.Sin(Mathf.DegreesToRadians * _rotation);
|
||||
float cos = Mathf.Cos(Mathf.DegreesToRadians * _rotation);
|
||||
|
||||
//Matrix2x2.Multiply(ref m1, ref m2, out m1);
|
||||
m1.M11 = (_scale.X * cos) + (m1.M12 * -sin);
|
||||
m1.M12 = (_scale.X * sin) + (m1.M12 * cos);
|
||||
float m21 = (m1.M21 * cos) + (_scale.Y * -sin);
|
||||
m1.M22 = (m1.M21 * sin) + (_scale.Y * cos);
|
||||
m1.M21 = m21;
|
||||
// Mix all the stuff
|
||||
Matrix3x3.Translation2D(ref v2, out Matrix3x3 m3);
|
||||
Matrix3x3 m4 = (Matrix3x3)m1;
|
||||
Matrix3x3.Multiply(ref m3, ref m4, out m3);
|
||||
Matrix3x3.Translation2D(ref v1, out m4);
|
||||
Matrix3x3.Multiply(ref m3, ref m4, out _cachedTransform);
|
||||
//Matrix3x3.Translation2D(ref v2, out Matrix3x3 m3);
|
||||
//Matrix3x3 m4 = (Matrix3x3)m1;
|
||||
//Matrix3x3.Multiply(ref m3, ref m4, out m3);
|
||||
//Matrix3x3.Translation2D(ref v1, out m4);
|
||||
//Matrix3x3.Multiply(ref m3, ref m4, out _cachedTransform);
|
||||
m1.M31 = (v2.X * m1.M11) + (v2.Y * m1.M21) + v1.X;
|
||||
m1.M32 = (v2.X * m1.M12) + (v2.Y * m1.M22) + v1.Y;
|
||||
_cachedTransform = m1;
|
||||
|
||||
// Cache inverted transform
|
||||
Matrix3x3.Invert(ref _cachedTransform, out _cachedTransformInv);
|
||||
|
||||
Reference in New Issue
Block a user