private void RasterizeEdges() { List <Vertex>[] edges = new List <Vertex> [yMax - yMin + 1]; for (int i = 0; i < edges.Length; i++) { edges[i] = new List <Vertex>(); } RasterizeExtremums(ref edges); for (int i = Triangle3D.V1_INDEX; i <= Triangle3D.V3_INDEX; i++) { int y1 = Maths.Round(_Triangle[i].Position.Y); int y2 = Maths.Round(_Triangle[i + 1].Position.Y); if (y1 == y2) { continue; } RasterizeEdge(ref edges, _Triangle[i], _Triangle[i + 1]); } for (int i = 0; i < edges.Length; i++) { _Lines[i] = new Triangle3DLine(new Vertex(edges[i][0]), new Vertex(edges[i][1])); } for (int i = 0; i < edges.Length; i++) { edges[i].Clear(); } }
// Не обрабатывает вырожденные случаи. public void RasterizeLine(Triangle3DLine line) { int x1 = Maths.Round(line.V1.Position.X); int x2 = Maths.Round(line.V2.Position.X); double y = line.V1.Position.Y; double z1 = line.V1.Position.Z; double z2 = line.V2.Position.Z; double dx = x2 - x1; double dz = z2 - z1; for (int x = x1 + 1; x < x2; x++) { double z = ((x - x1) / dx) * dz + z1; line[x - x1] = new Vertex(x, y, z); } }