diff --git a/Tetrahedrons/MVec4D.cs b/Tetrahedrons/MVec4D.cs index ddc59be..eb9bdd5 100644 --- a/Tetrahedrons/MVec4D.cs +++ b/Tetrahedrons/MVec4D.cs @@ -61,6 +61,9 @@ namespace Tetrahedrons } } + public Vector4d V4 => new Vector4d(X, Y, Z, W); + public Vector3d V3 => new Vector3d(X, Y, Z); + #region Swizzle public double Yx diff --git a/Tetrahedrons/TetrahedronWindow.cs b/Tetrahedrons/TetrahedronWindow.cs index 0e26716..b95f896 100644 --- a/Tetrahedrons/TetrahedronWindow.cs +++ b/Tetrahedrons/TetrahedronWindow.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Drawing; +using System.Drawing.Printing; using System.Net.Mail; using System.Security; using OpenTK; @@ -15,8 +16,10 @@ namespace Tetrahedrons private Matrix4 _proj3d; private Matrix4 _view; - Vector3d a = Vector3d.UnitX; - Vector3d b = Vector3d.UnitY; + MVec4D a = MVec4D.UnitX; + MVec4D b = MVec4D.UnitY; + MVec4D v = MVec4D.Vec1(1, 1, 0, -1); + MVec4D t = MVec4D.Vec1(0, 0, 0, 1); protected override void OnLoad(EventArgs e) { @@ -25,7 +28,8 @@ namespace Tetrahedrons X = (DisplayDevice.Default.Width - Width) / 2; Y = (DisplayDevice.Default.Height - Height) / 2; - _view = Matrix4.LookAt(Vector3.Zero, -new Vector3(1, .6f, 1f), Vector3.UnitZ); + _view = Matrix4.LookAt(Vector3.Zero, -new Vector3(1, 1, 1), Vector3.UnitZ); + } protected override void OnRenderFrame(FrameEventArgs e) @@ -35,7 +39,9 @@ namespace Tetrahedrons GL.Viewport(ClientRectangle); GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); + GL.Enable(EnableCap.DepthTest); GL.PointSize(10f); + GL.LineWidth(3f); GL.PushMatrix(); @@ -44,11 +50,41 @@ namespace Tetrahedrons GL.MatrixMode(MatrixMode.Modelview); GL.LoadMatrix(ref _view); + GL.Disable(EnableCap.DepthTest); GL.Begin(PrimitiveType.TriangleStrip); - GL.Vertex3(-a - b); - GL.Vertex3(-a + b); - GL.Vertex3(a - b); - GL.Vertex3(a + b); + GL.Color3(1d, 1, 1); + GL.Vertex3((-a - b).V3); + GL.Vertex3((-a + b).V3); + GL.Vertex3((a - b).V3); + GL.Vertex3((a + b).V3); + GL.End(); + GL.Enable(EnableCap.DepthTest); + + GL.Begin(PrimitiveType.Lines); + GL.Color3(1d,0,0); GL.Vertex3(0,0,0); GL.Vertex3(1,0,0); + GL.Color3(0,1d,0); GL.Vertex3(0,0,0); GL.Vertex3(0,1,0); + GL.Color3(0,0,1d); GL.Vertex3(0,0,0); GL.Vertex3(0,0,1); + GL.End(); + + var B = MVec4D.UnitXyz; + var bt = B ^ t; + var bv = B ^ v; + var alph = bt / bv ?? MVec4D.Zero; + var dt = alph * v; + var p = t - dt; + + Console.Out.WriteLine("p = {0}", p); + + GL.Begin(PrimitiveType.Lines); + GL.Color3(.5 + t.W/4, 0, .5 - t.W/4); + GL.Vertex3(t.V3); + GL.Color3(.5 + (t + v).W/4, 0, .5 - (t + v).W/4); + GL.Vertex3((t + v).V3); + GL.End(); + + GL.Begin(PrimitiveType.Points); + GL.Color3(0d, 0, 1); + GL.Vertex3(p.V3); GL.End(); SwapBuffers(); @@ -59,6 +95,12 @@ namespace Tetrahedrons base.OnUpdateFrame(e); _proj3d = Matrix4.CreateOrthographic(6, 6f * Height / Width, -2, 2); + + var rv = MVec4D.Rotor(e.Time, MVec4D.UnitXy); + v = rv * v * !rv; + + var rt = MVec4D.Rotor(e.Time / 4, MVec4D.UnitZw); + t = rt * t * !rt; } } } \ No newline at end of file