Replace own matrix type with OpenTK.
This commit is contained in:
parent
831c93b916
commit
9b2f0859e5
@ -265,84 +265,4 @@ namespace Dashboard
|
||||
/// </summary>
|
||||
public Vector2 C;
|
||||
}
|
||||
|
||||
[DebuggerDisplay("[{M11} {M12} {M13} {M14}; {M21} {M22} {M23} {M24}; {M31} {M32} {M33} {M34}; {M41} {M42} {M43} {M44}]")]
|
||||
public struct QMat4
|
||||
{
|
||||
public float M11, M21, M31, M41;
|
||||
public float M12, M22, M32, M42;
|
||||
public float M13, M23, M33, M43;
|
||||
public float M14, M24, M34, M44;
|
||||
|
||||
public static QMat4 Identity { get; } = new QMat4()
|
||||
{
|
||||
M11 = 1.0f,
|
||||
M22 = 1.0f,
|
||||
M33 = 1.0f,
|
||||
M44 = 1.0f
|
||||
};
|
||||
|
||||
public static void Translation(out QMat4 mat, float x, float y, float z)
|
||||
{
|
||||
mat = Identity;
|
||||
mat.M14 = x;
|
||||
mat.M24 = y;
|
||||
mat.M34 = z;
|
||||
}
|
||||
|
||||
public static void Scale(out QMat4 mat, float x, float y, float z)
|
||||
{
|
||||
mat = default;
|
||||
mat.M11 = x;
|
||||
mat.M22 = y;
|
||||
mat.M33 = z;
|
||||
mat.M44 = 1.0f;
|
||||
}
|
||||
|
||||
public static void Orthographic(out QMat4 mat, QRectangle bounds, float near = 1, float far = -1)
|
||||
{
|
||||
float a, b, c;
|
||||
mat = Identity;
|
||||
|
||||
a = 1.0f/(bounds.Right - bounds.Left);
|
||||
b = 1.0f/(bounds.Top - bounds.Bottom);
|
||||
c = 1.0f/(far - near);
|
||||
|
||||
mat.M11 = 2 * a;
|
||||
mat.M22 = 2 * b;
|
||||
mat.M33 = -2 * c;
|
||||
|
||||
mat.M14 = -a * (bounds.Left + bounds.Right);
|
||||
mat.M24 = -b * (bounds.Top + bounds.Bottom);
|
||||
mat.M34 = -c * (far + near);
|
||||
mat.M44 = 1.0f;
|
||||
}
|
||||
|
||||
public static QMat4 operator *(in QMat4 a, in QMat4 b)
|
||||
{
|
||||
QMat4 mat4 = default;
|
||||
|
||||
mat4.M11 = a.M11 * b.M11 + a.M12 * b.M21 + a.M13 * b.M31 + a.M14 * b.M41;
|
||||
mat4.M12 = a.M11 * b.M12 + a.M12 * b.M22 + a.M13 * b.M32 + a.M14 * b.M42;
|
||||
mat4.M13 = a.M11 * b.M13 + a.M12 * b.M23 + a.M13 * b.M33 + a.M14 * b.M43;
|
||||
mat4.M14 = a.M11 * b.M14 + a.M12 * b.M24 + a.M13 * b.M34 + a.M14 * b.M44;
|
||||
|
||||
mat4.M21 = a.M21 * b.M11 + a.M22 * b.M21 + a.M23 * b.M31 + a.M24 * b.M41;
|
||||
mat4.M22 = a.M21 * b.M12 + a.M22 * b.M22 + a.M23 * b.M32 + a.M24 * b.M42;
|
||||
mat4.M23 = a.M21 * b.M13 + a.M22 * b.M23 + a.M23 * b.M33 + a.M24 * b.M43;
|
||||
mat4.M24 = a.M21 * b.M14 + a.M22 * b.M24 + a.M23 * b.M34 + a.M24 * b.M44;
|
||||
|
||||
mat4.M31 = a.M31 * b.M11 + a.M32 * b.M21 + a.M33 * b.M31 + a.M34 * b.M41;
|
||||
mat4.M32 = a.M31 * b.M12 + a.M32 * b.M22 + a.M33 * b.M32 + a.M34 * b.M42;
|
||||
mat4.M33 = a.M31 * b.M13 + a.M32 * b.M23 + a.M33 * b.M33 + a.M34 * b.M43;
|
||||
mat4.M34 = a.M31 * b.M14 + a.M32 * b.M24 + a.M33 * b.M34 + a.M34 * b.M44;
|
||||
|
||||
mat4.M41 = a.M41 * b.M11 + a.M42 * b.M21 + a.M43 * b.M31 + a.M44 * b.M41;
|
||||
mat4.M42 = a.M41 * b.M12 + a.M42 * b.M22 + a.M43 * b.M32 + a.M44 * b.M42;
|
||||
mat4.M43 = a.M41 * b.M13 + a.M42 * b.M23 + a.M43 * b.M33 + a.M44 * b.M43;
|
||||
mat4.M44 = a.M41 * b.M14 + a.M42 * b.M24 + a.M43 * b.M34 + a.M44 * b.M44;
|
||||
|
||||
return mat4;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using OpenTK.Mathematics;
|
||||
|
||||
namespace Dashboard.ImmediateDraw
|
||||
{
|
||||
@ -11,14 +12,14 @@ namespace Dashboard.ImmediateDraw
|
||||
|
||||
private QRectangle _viewport;
|
||||
private readonly Stack<QRectangle> _viewportStack = new Stack<QRectangle>();
|
||||
private readonly Stack<QMat4> _matrixStack = new Stack<QMat4>();
|
||||
private readonly Stack<Matrix4> _matrixStack = new Stack<Matrix4>();
|
||||
|
||||
private Command _customCommandBase = Command.CustomCommandBase;
|
||||
private readonly List<CommandHandler> _customCommands = new List<CommandHandler>();
|
||||
|
||||
public QRectangle Viewport => _viewport;
|
||||
|
||||
public QMat4 ActiveTransforms { get; }
|
||||
public Matrix4 ActiveTransforms { get; }
|
||||
|
||||
public StyleStack Style { get; } = new StyleStack(new Style());
|
||||
|
||||
@ -126,7 +127,7 @@ namespace Dashboard.ImmediateDraw
|
||||
_viewportStack.Clear();
|
||||
|
||||
_matrixStack.Clear();
|
||||
_matrixStack.Push(QMat4.Identity);
|
||||
_matrixStack.Push(Matrix4.Identity);
|
||||
}
|
||||
|
||||
private void ConditionalHandler(DrawQueue iterator)
|
||||
|
@ -102,7 +102,7 @@ namespace Dashboard.OpenGL
|
||||
|
||||
|
||||
Vector2 size = view.Size;
|
||||
QMat4.Orthographic(out QMat4 viewMatrix, view);
|
||||
Matrix4 viewMatrix = Matrix4.CreateOrthographicOffCenter(view.Left, view.Right, view.Bottom, view.Top, 1, -1);
|
||||
|
||||
GL.Viewport(0, 0, (int)view.Size.X, (int)view.Size.Y);
|
||||
GL.UseProgram(program);
|
||||
@ -122,9 +122,9 @@ namespace Dashboard.OpenGL
|
||||
(int)MathF.Round(size.Y - call.Bounds.Max.Y),
|
||||
(int)MathF.Round(call.Bounds.Size.X),
|
||||
(int)MathF.Round(call.Bounds.Size.Y));
|
||||
QMat4.Translation(out QMat4 modelMatrix, call.Bounds.Min.X, call.Bounds.Min.Y, 0);
|
||||
QMat4 modelView = viewMatrix * modelMatrix;
|
||||
GL.UniformMatrix4(m4Transforms, 1, false, ref modelView.M11);
|
||||
Matrix4 modelMatrix = Matrix4.CreateTranslation(call.Bounds.Min.X, call.Bounds.Min.Y, 0);
|
||||
Matrix4 modelView = viewMatrix * modelMatrix;
|
||||
GL.UniformMatrix4(m4Transforms, false, ref modelView);
|
||||
|
||||
GL.ActiveTexture(TextureUnit.Texture0);
|
||||
GL.BindTexture(TextureTarget.Texture2D, 0);
|
||||
|
Loading…
Reference in New Issue
Block a user