public Polygon(List <Vertex> verts) { Vertex = verts; _Normal = CrossProduct(verts[0]._Point - verts[1]._Point, verts[1]._Point - verts[2]._Point); _Normal /= _Normal.GetLength(); foreach (Vertex v in verts) { v.Polygon.Add(this); } }
protected override void OnDeviceUpdate(object s, GDIDeviceUpdateArgs e) { if (PrevApproxLevel != ApproxLevel) { ComputeObject(); PrevApproxLevel = ApproxLevel; } if (e.Heigh < e.Width) { WindowScale = (double)e.Heigh / InitialHeight; } else { WindowScale = (double)e.Width / InitialWidth; } switch (ProjMode) { case ProjectionMode.FR: rotX = Rotation.X; rotY = Rotation.Y; rotZ = Rotation.Z; break; case ProjectionMode.ISO: rotX = -35.0; rotY = -45.0; rotZ = 0.0; break; case ProjectionMode.ORT_F: rotX = 0.0; rotY = 0.0; rotZ = 0.0; break; case ProjectionMode.ORT_L: rotX = 0.0; rotY = 90.0; rotZ = 0.0; break; case ProjectionMode.ORT_T: rotX = -90.0; rotY = 0.0; rotZ = 0.0; break; } // compute transformation ( scale and rotation ) matrix DMatrix4 mat = DMatrix4.Identity; double scale = 100.0; RotateMatrix(ref mat, rotX, rotY, rotZ); ScaleMatrix(ref mat, scale * Scale.X * WindowScale, scale * Scale.Y * WindowScale, scale * Scale.Z * WindowScale); // transform verticis of object foreach (Vertex v in Vertecis) { v.Point = mat * v._Point; } Polygons.QuickSort(p => p.Vertex.Average(v => v.Point.Z)); // draw main object foreach (Polygon p in Polygons) { p.Normal = CrossProduct(p.Vertex[0].Point - p.Vertex[1].Point, p.Vertex[1].Point - p.Vertex[2].Point); p.Normal /= p.Normal.GetLength(); if (p.Normal.Z > 0) { DrawPolygonFixGaps2(p, e.Graphics, e.Width, e.Heigh); } } // some optional features foreach (Polygon p in Polygons) { if (p.Normal.Z > 0) { if (EnableNormals) { DrawNormal(p, e.Graphics, e.Width, e.Heigh); } if (EnableVertexNumbers) { DrawVertexNumbers(p, e.Graphics, e.Width, e.Heigh); } } } // Drawing axis (in the right lower corner) DVector4 ox = mat * (new DVector4(1.0, 0.0, 0.0, 0.0)); DVector4 oy = mat * (new DVector4(0.0, 1.0, 0.0, 0.0)); DVector4 oz = mat * (new DVector4(0.0, 0.0, 1.0, 0.0)); ox = ox / ox.GetLength() * 50.0 * WindowScale; oy = oy / oy.GetLength() * 50.0 * WindowScale; oz = oz / oz.GetLength() * 50.0 * WindowScale; DVector4 pos = new DVector4(e.Width - 70.0 * WindowScale, e.Heigh - 70.0 * WindowScale, 0.0, 0.0); DrawAxis(e.Graphics, ox, oy, oz, pos); }