From c1570b74e1e6d1dc90b06edf92b8b6df446279ec Mon Sep 17 00:00:00 2001 From: That_One_Nerd Date: Tue, 5 Sep 2023 13:54:33 -0400 Subject: [PATCH] Isometrics work now. --- .../Mathematics/Algebra/ProjectionMatrix.cs | 22 +++++++++++++++---- Nerd_STF/Mathematics/Samples/Constants.cs | 4 ++++ 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/Nerd_STF/Mathematics/Algebra/ProjectionMatrix.cs b/Nerd_STF/Mathematics/Algebra/ProjectionMatrix.cs index b165cd1..a4a8c2c 100644 --- a/Nerd_STF/Mathematics/Algebra/ProjectionMatrix.cs +++ b/Nerd_STF/Mathematics/Algebra/ProjectionMatrix.cs @@ -40,13 +40,27 @@ public class ProjectionMatrix : Matrix3x3 public ProjectionMatrix(Fill r1, Fill r2, Fill r3) : this(r1(0), r1(1), r1(2), r2(0), r2(1), r2(2), r3(0), r3(1), r3(2)) { } - public static ProjectionMatrix SingleViewProjection(CrossSection2d section) => new(new[,] + public static ProjectionMatrix Orthographic(CrossSection2d section) => new(new[,] { { section == CrossSection2d.XY || section == CrossSection2d.ZX ? 1 : 0, 0, 0 }, { 0, section == CrossSection2d.XY || section == CrossSection2d.YZ ? 1 : 0, 0 }, { 0, 0, section == CrossSection2d.YZ || section == CrossSection2d.ZX ? 1 : 0 } }); - public static ProjectionMatrix IsometricProjection(Angle alpha, Angle beta) + + public static ProjectionMatrix Isometric() + { + const float invSqrt2 = 0.707106781187f, + invSqrt3 = 0.57735026919f, + invSqrt6 = 0.408248290464f, + invSqrt6_2 = 0.816496580928f; + return new(new[,] + { + { invSqrt2, 0, -invSqrt2 }, + { invSqrt6, invSqrt6_2, invSqrt6 }, + { 0, 0, 0 }, + }); + } + public static ProjectionMatrix Isometric(Angle alpha, Angle beta) { Matrix3x3 alphaMat = new(new[,] { @@ -66,8 +80,8 @@ public class ProjectionMatrix : Matrix3x3 { 0, 1, 0 }, { 0, 0, 0 } }); - Matrix3x3 result = alphaMat * betaMat * flatten; - return new(result.ToFill2D()); + Matrix3x3 result = (alphaMat * betaMat).Transpose() * flatten; + return new(result.Transpose().ToFill2D()); } public Fill Project(Fill toProject) => i => this * toProject(i); diff --git a/Nerd_STF/Mathematics/Samples/Constants.cs b/Nerd_STF/Mathematics/Samples/Constants.cs index 418a349..9c9f57e 100644 --- a/Nerd_STF/Mathematics/Samples/Constants.cs +++ b/Nerd_STF/Mathematics/Samples/Constants.cs @@ -67,6 +67,10 @@ public static class Constants public const float Tan60Deg = Sqrt3; public const float Tan90Deg = float.PositiveInfinity; + public static readonly Angle IsometricAngle = (35.2643896828f, Angle.Type.Degrees); + public const float IsometricCos = 0.816496580928f; + public const float IsometricSin = 0.57737026919f; + public const float AperyConstant = 1.2020569031f; public const float ArtinConstant = 0.3739558136f; public const float AsymptoticLebesgueConstant = 0.9894312738f;