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