private void Main_Load(object sender, EventArgs e)
        {
            cam = new Camera();

            voxmap = new Voxelmap(2, 2, 2);

            /*
             * voxmap[0, 0, 0] = Color.Green;
             * voxmap[0, 1, 0] = Color.Blue;
             * voxmap[1, 0, 0] = Color.Red;
             * voxmap[0, 0, 1] = Color.Red;
             * voxmap.Save(@"C:\Users\Class2018\Desktop\vox.vox");
             */

            OrthographicSizeBox.Value = (decimal)cam.OrthographicSize;
            MIPCheckBox.Checked       = cam.RenderMode == Camera.RenderModeEnum.MIP;
            RenderFrame.Image         = cam.Render(voxmap);
        }
        public Bitmap Render(Voxelmap map)
        {
            if (bitmapNeedsUpdate)
            {
                image = new Bitmap(Height, Width);
            }
            Vector3 rayStep      = Forward * RayStep;
            float   rayMaxLength = 5;//quickly set so that I can test the render;

            for (int bitmapX = 0; bitmapX < image.Width; bitmapX++)
            {
                for (int bitmapY = 0; bitmapY < image.Height; bitmapY++)
                {
                    hitVoxels.Clear();
                    Vector3 rayPoint = (bitmapX / PixelsPerUnit - OrthographicSize / 2f) * Right + (bitmapY / PixelsPerUnit - OrthographicSize / 2f) * Up + Position;
                    while ((rayPoint - Position).Magnitude < rayMaxLength)
                    {
                        int x = (int)Math.Round(rayPoint.X);
                        int y = (int)Math.Round(rayPoint.Y);
                        int z = (int)Math.Round(rayPoint.Z);
                        if (map.ContainsPoint(x, y, z))
                        {
                            Vector3I voxPoint = new Vector3I(x, y, z);
                            if (!hitVoxels.Contains(voxPoint))
                            {
                                hitVoxels.Add(voxPoint);
                            }
                        }
                        rayPoint = rayPoint + rayStep;
                    }
                    switch (RenderMode)
                    {
                    case RenderModeEnum.MIP:
                        float intensity = 0;
                        for (int i = 0; i < hitVoxels.Count; i++)
                        {
                            Color voxCol   = map[hitVoxels[i].X, hitVoxels[i].Y, hitVoxels[i].Z];
                            float voxInten = voxCol.GetBrightness();
                            if (voxInten > intensity)
                            {
                                intensity = voxInten;
                            }
                        }
                        int colorVal = (int)(255 * intensity);
                        image.SetPixel(bitmapX, bitmapY, Color.FromArgb(colorVal, colorVal, colorVal));
                        break;

                    case RenderModeEnum.Color:
                        Color col = Background;
                        for (int i = hitVoxels.Count - 1; i >= 0; i--)
                        {
                            Vector3I cords  = hitVoxels[i];
                            Color    voxCol = map[cords.X, cords.Y, cords.Z];
                            float    alpha  = voxCol.A / 255f;
                            col = Color.FromArgb(
                                (int)(col.R * (1 - alpha) + (int)(voxCol.R * alpha)),
                                (int)(col.G * (1 - alpha) + (int)(voxCol.G * alpha)),
                                (int)(col.B * (1 - alpha) + (int)(voxCol.B * alpha))
                                );
                        }
                        image.SetPixel(bitmapX, bitmapY, col);
                        break;

                    default:
                        break;
                    }
                }
            }

            return(image);
        }