Math library changes and fixes.
This commit is contained in:
parent
9c9efc6eeb
commit
4dff6eba91
@ -87,6 +87,11 @@ namespace Quik
|
||||
{
|
||||
return a.X * b.X + a.Y * b.Y;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return $"({X}; {Y})";
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -335,16 +340,16 @@ namespace Quik
|
||||
/// <summary>
|
||||
/// A rectangle.
|
||||
/// </summary>
|
||||
[DebuggerDisplay("({Right}, {Top}, {Left}, {Bottom})")]
|
||||
[DebuggerDisplay("({Left}, {Top}, {Right}, {Bottom})")]
|
||||
public struct QRectangle
|
||||
{
|
||||
/// <summary>
|
||||
/// Rectangle maximum point.
|
||||
/// Position maximum point.
|
||||
/// </summary>
|
||||
public QVec2 Max;
|
||||
|
||||
/// <summary>
|
||||
/// Rectangle minimum point.
|
||||
/// Position minimum point.
|
||||
/// </summary>
|
||||
public QVec2 Min;
|
||||
|
||||
@ -362,14 +367,14 @@ namespace Quik
|
||||
|
||||
public float Top
|
||||
{
|
||||
get => Max.Y;
|
||||
set => Max.Y = value;
|
||||
get => Min.Y;
|
||||
set => Min.Y = value;
|
||||
}
|
||||
|
||||
public float Bottom
|
||||
{
|
||||
get => Min.Y;
|
||||
set => Min.Y = value;
|
||||
get => Max.Y;
|
||||
set => Max.Y = value;
|
||||
}
|
||||
|
||||
public QVec2 Size
|
||||
@ -384,10 +389,10 @@ namespace Quik
|
||||
Min = min;
|
||||
}
|
||||
|
||||
public QRectangle(float r, float t, float l, float b)
|
||||
public QRectangle(float r, float b, float l, float t)
|
||||
{
|
||||
Max = new QVec2() {X = r, Y = t};
|
||||
Min = new QVec2() {X = l, Y = b};
|
||||
Max = new QVec2() {X = r, Y = b};
|
||||
Min = new QVec2() {X = l, Y = t};
|
||||
}
|
||||
|
||||
public bool Contains(QVec2 point)
|
||||
@ -405,11 +410,11 @@ namespace Quik
|
||||
|
||||
public static QRectangle Intersect(in QRectangle a, in QRectangle b) =>
|
||||
new QRectangle(
|
||||
Math.Min(a.Right, b.Right),
|
||||
Math.Min(a.Top, b.Top),
|
||||
Math.Max(a.Left, b.Left),
|
||||
Math.Max(a.Right, b.Right),
|
||||
Math.Max(a.Bottom, b.Bottom)
|
||||
);
|
||||
,
|
||||
Math.Min(a.Left, b.Left),
|
||||
Math.Min(a.Top, b.Top));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -493,19 +498,19 @@ namespace Quik
|
||||
public static void Orthographic(out QMat4 mat, QRectangle bounds, float near = 1, float far = -1)
|
||||
{
|
||||
float a, b, c;
|
||||
mat = default;
|
||||
mat = Identity;
|
||||
|
||||
a = 1.0f/(bounds.Right - bounds.Left);
|
||||
b = 1.0f/(bounds.Top - bounds.Bottom);
|
||||
c = 1.0f/(near - far);
|
||||
c = 1.0f/(far - near);
|
||||
|
||||
mat.M11 = 2 * a;
|
||||
mat.M22 = 2 * b;
|
||||
mat.M33 = 2 * c;
|
||||
mat.M33 = -2 * c;
|
||||
|
||||
mat.M41 = -a * (bounds.Left + bounds.Right);
|
||||
mat.M42 = -b * (bounds.Top + bounds.Bottom);
|
||||
mat.M43 = -c * (near + far);
|
||||
mat.M14 = -a * (bounds.Left + bounds.Right);
|
||||
mat.M24 = -b * (bounds.Top + bounds.Bottom);
|
||||
mat.M34 = -c * (far + near);
|
||||
mat.M44 = 1.0f;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user