internal void Disegnati(Bitmap bmp, double[,] zBuffer, Camera camera) { if (Vertici.All(v => v.z < 0) || Vertici.Any(v => v == null) || !FacciaRivoltaATelecamera()) { return; } GraphicsUnit u = GraphicsUnit.Pixel; Point min = new Point(LimitaAViewport(camera, Vertici.Min(v => v.x)), LimitaAViewport(camera, Vertici.Min(v => v.y))); Point max = new Point(LimitaAViewport(camera, Vertici.Max(v => v.x)), LimitaAViewport(camera, Vertici.Max(v => v.y))); for (double x = min.X; x <= max.X; x++) { for (double y = min.Y; y <= max.Y; y++) { var p = new Point(x, y); if (puntoInTriangolo(p)) { int Xi = (int)Math.Round(p.X + (camera.Rx / 2.0)); int Yi = (int)Math.Round(-p.Y + (camera.Ry / 2.0)); if (bmp.GetBounds(ref u).Contains(Xi, Yi)) { var z = CalcolaZ(p); if (z > 0.1 && z < zBuffer[Xi, Yi]) { bmp.SetPixel(Xi, Yi, colore); zBuffer[Xi, Yi] = z; } } } } } }
double CalcolaZ(Point p) { int i = 0; return(1 / Vertici.Sum(v => 1 / v.z * λ(i++, p))); }