public Bitmap drawCube(Point drawOrigin, ProectionType type) { PointF[] point2D = new PointF[8]; double zoom = Screen.PrimaryScreen.Bounds.Width / 1.5; Point3D[] cubePoints = FillCubeVertices(Width, Height, Depth); Camera camera1 = new Camera(); Point3D anchorPoint = cubePoints[4]; //anchor point double cameraZ = -(((anchorPoint.X - cubeOrigin.X) * zoom) / cubeOrigin.X) + anchorPoint.Z; camera1.Position = new Point3D(cubeOrigin.X, cubeOrigin.Y, cameraZ); cubePoints = Transformation.Translate(cubePoints, cubeOrigin, new Point3D(0, 0, 0)); cubePoints = Transformation.RotateX(cubePoints, XRotation); cubePoints = Transformation.RotateY(cubePoints, YRotation); cubePoints = Transformation.RotateZ(cubePoints, ZRotation); cubePoints = Transformation.Translate(cubePoints, new Point3D(0, 0, 0), cubeOrigin); if (type == ProectionType.Perspective) { //camera1.Position = new Point3D(cubeOrigin.X, cubeOrigin.Y, 1000); PerspectiveProection(cubePoints, point2D, drawOrigin, camera1, zoom); } else { camera1.Position = new Point3D(cubeOrigin.X, cubeOrigin.Y, 1000); ParallelProection(cubePoints, point2D, drawOrigin); } var tmpBmp = draw2DCube(point2D, drawOrigin, cubePoints, camera1, type); return(tmpBmp); }
private void button2_Click(object sender, EventArgs e) { resetButton_Click(sender, e); type = ProectionType.Perspective; }
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 button1_Click(object sender, EventArgs e) { resetButton_Click(sender, e); type = ProectionType.Parallel; }