public static double GetVerticeIntence(Point3D camera, Point3D light, Point3D normal, Point3D vertice) { double Kd = 0.5, Ks = 0.7, Ka = 0.4; int p = 3; double Ia = 0.7, I = 0.7; return(Ia * Ka + I / (Methods2D.DistanceFromPointToCamera(vertice, camera)) * (Ks * Math.Pow(CosA(light, camera, normal, vertice), 30) + Kd * CosQ(light, normal, vertice))); }
private Bitmap draw2DCube(PointF[] point2D, Point drawOrigin, Point3D[] cubePoints, Camera camera1, ProectionType type) { Rectangle bounds = getBounds(point2D); bounds.Width += drawOrigin.X; bounds.Height += drawOrigin.Y; Camera light = new Camera(); light.Position = new Point3D(Width / 2, Height / 2 + 175, Depth / 2); Bitmap tmpBmp = new Bitmap(bounds.Width, bounds.Height); Point light2D = new Point(); ParallelPointProection(light.Position, ref light2D, drawOrigin); tmpBmp.SetPixel(light2D.X, light2D.Y, Color.OrangeRed); tmpBmp.SetPixel(light2D.X + 1, light2D.Y, Color.OrangeRed); tmpBmp.SetPixel(light2D.X - 1, light2D.Y, Color.OrangeRed); tmpBmp.SetPixel(light2D.X + 1, light2D.Y + 1, Color.OrangeRed); tmpBmp.SetPixel(light2D.X + 1, light2D.Y - 1, Color.OrangeRed); tmpBmp.SetPixel(light2D.X - 1, light2D.Y - 1, Color.OrangeRed); tmpBmp.SetPixel(light2D.X - 1, light2D.Y + 1, Color.OrangeRed); tmpBmp.SetPixel(light2D.X, light2D.Y + 1, Color.OrangeRed); tmpBmp.SetPixel(light2D.X, light2D.Y - 1, Color.OrangeRed); Color[] verticeColor = Methods2D.GetIntence(cubePoints, light); /*GetGuroColors(cubePoints, camera1.Position, * new Point3D(camera1.Position.X, camera1.Position.Y, camera1.Position.Z), Color.White);*/ DrawGuro(tmpBmp, point2D, verticeColor, cubePoints); /*//Back Face * Methods2D.DrawLine(tmpBmp, point2D[0], point2D[1], verticeColor[0], verticeColor[1]); * Methods2D.DrawLine(tmpBmp, point2D[1], point2D[5], verticeColor[1], verticeColor[5]); * Methods2D.DrawLine(tmpBmp, point2D[5], point2D[4], verticeColor[5], verticeColor[4]); * Methods2D.DrawLine(tmpBmp, point2D[4], point2D[0], verticeColor[4], verticeColor[0]); * * //Front Face * Methods2D.DrawLine(tmpBmp, point2D[3], point2D[2], verticeColor[3], verticeColor[2]); * Methods2D.DrawLine(tmpBmp, point2D[2], point2D[6], verticeColor[2], verticeColor[6]); * Methods2D.DrawLine(tmpBmp, point2D[6], point2D[7], verticeColor[6], verticeColor[7]); * Methods2D.DrawLine(tmpBmp, point2D[7], point2D[3], verticeColor[7], verticeColor[3]); * * //Right Face * Methods2D.DrawLine(tmpBmp, point2D[7], point2D[4], verticeColor[7], verticeColor[4]); * Methods2D.DrawLine(tmpBmp, point2D[3], point2D[0], verticeColor[3], verticeColor[0]); * * //Left Face * Methods2D.DrawLine(tmpBmp, point2D[6], point2D[5], verticeColor[6], verticeColor[5]); * Methods2D.DrawLine(tmpBmp, point2D[2], point2D[1], verticeColor[2], verticeColor[1]);*/ return(tmpBmp); }
private void timer1_Tick(object sender, EventArgs e) { Random rnd = new Random(); bitmap = new Bitmap(pictureBox1.Width, pictureBox1.Height); List <Pixel> angles = new List <Pixel>(); int angleCount = rnd.Next(2, 6); List <int> xs = new List <int>(); for (int i = 0; i < angleCount; i++) { xs.Add(rnd.Next(0, pictureBox1.Width - 1) / 2); } xs = xs.OrderBy(x => x).ToList(); int firstX = xs[0]; int firstY = rnd.Next(0, pictureBox1.Height - 1); int previousX = firstX; int previousY = firstY; var color = GetRandomColor(); angles.Add(new Pixel(firstX, firstY, color)); for (int i = 1; i < xs.Count; i++) { int y = rnd.Next(0, firstY); angles.Add(new Pixel(xs[i], y, GetRandomColor())); previousX = xs[i]; previousY = y; } for (int i = xs.Count - 1; i > 0; i--) { int y = rnd.Next(firstY, pictureBox1.Height - 1); angles.Add(new Pixel(xs[i], y, GetRandomColor())); previousX = xs[i]; previousY = y; } angles.Add(new Pixel(firstX, firstY, color)); /*List<Pixel> angles = new List<Pixel>(); * angles.Add(new Pixel(20, 20, Color.Red)); * angles.Add(new Pixel(300, 100, Color.Purple)); * angles.Add(new Pixel(400, 400, Color.Blue)); * angles.Add(new Pixel(200, 450, Color.Green)); * angles.Add(new Pixel(20, 20, Color.Red));*/ Random random = new Random(); Methods2D.FillPolygon(bitmap, angles); pictureBox1.Image = bitmap; }
public void DrawWatchablePolygons(Bitmap tmpBmp, Point3D normal, List <PointF> points, List <Color> colors) { var cos = normal.Z / Math.Sqrt(Math.Pow(normal.X, 2) + Math.Pow(normal.Y, 2) + Math.Pow(normal.Z, 2)); if (cos >= 0 && cos <= 1) { List <Pixel> pixels = new List <Pixel>(); for (int i = 0; i < points.Count; i++) { pixels.Add(new Pixel((int)points[i].X, (int)points[i].Y, colors[i])); } Methods2D.FillPolygon(tmpBmp, pixels); } }