public static Bitmap Render(Octree tree, int width, int height)
        {
            buffer = new BufferPixel[width, height];
            FullRecursiveOctreeRenderer.width  = width;
            FullRecursiveOctreeRenderer.height = height;
            light = (new Vector3(1, 1, 1).Normalized());


            /*for (int i = 0; i < points.Count; i++)
             * {
             *  RenderPoint(points[i], width, height);
             * }*/



            RecDrawOctree(tree, tree.Root, new Vector3(0, 0, 0), 0);



            bmp.FastBitmap fbmp = new bmp.FastBitmap(width, height);
            for (int x = 0; x < width; x++)
            {
                for (int y = 0; y < height; y++)
                {
                    fbmp.SetPixel(x, y, buffer[x, y].depth > 0.001 ? buffer[x, y].color : Color.Red);
                }
            }
            frameCount++;
            return(fbmp.ToBitmap());
        }
Exemple #2
0
        public static Bitmap Render(Octree tree, int width, int height)
        {
            Vector3 light = (new Vector3(1, 1, .5).Normalized());

            bmp.FastBitmap fbmp = new bmp.FastBitmap(width, height);

            for (int x = 0; x < width; x++)
            {
                for (int y = 0; y < height; y++)
                {
                    Vector3 from = transform(new Vector3(0, 0, 0), false);
                    Vector3 to   = transform(new Vector3((double)x / width * 2 - 1, (double)y / height * 2 - 1, 1), false);
                    Ray     ray  = new Ray();
                    ray.Origin    = tree.WorldToOctree(from);
                    ray.Direction = (tree.WorldToOctree(to) - tree.WorldToOctree(from)).Normalized();

                    ray.CurrentParameter = 1e-10 + tree.RayParameterForBoxEntryPoint(ray, new Vector3(0, 0, 0), 1);

                    if (ray.CurrentParameter > 0)
                    {
                        tree.TraceRay(tree.Root, ray, new Vector3(0, 0, 0), 0);

                        if (ray.Result != null)
                        {
                            double dot = -Vector3.Dot(transform(light, true), ray.Result.SurfaceNormal);
                            int    col = (int)(dot * 255);
                            if (col < 0)
                            {
                                col = 0;
                            }
                            fbmp.SetPixel(x, y, Color.FromArgb(col, col, col));
                        }
                        else
                        {
                            fbmp.SetPixel(x, y, Color.Red);
                        }
                    }
                    else
                    {
                        fbmp.SetPixel(x, y, Color.Red);
                    }

                    //fbmp.SetPixel(
                }
            }
            frameCount++;


            return(fbmp.ToBitmap());
        }
        public static Bitmap Render(int width, int height)
        {
            if (file == null)
            {
                loadFile();
            }

            Vector3 light = (new Vector3(1, 1, .5).Normalized());

            bmp.FastBitmap fbmp = new bmp.FastBitmap(width, height);

            for (int x = 0; x < width; x++)
            {
                for (int y = 0; y < height; y++)
                {
                    Vector3 from = transform(new Vector3(0, 0, 0), false);
                    Vector3 to   = transform(new Vector3((double)x / width * 2 - 1, (double)y / height * 2 - 1, 1), false);
                    Ray     ray  = new Ray();
                    ray.Origin    = (from);
                    ray.Direction = ((to) - (from)).Normalized();

                    ray.CurrentParameter = epsilon + RayParameterForBoxEntryPoint(ray, new Vector3(0, 0, 0), 1);

                    if (ray.CurrentParameter > 0)
                    {
                        /*tree.TraceRay(tree.Root, ray, new Vector3(0, 0, 0), 0);
                         *
                         * if (ray.Result != null)
                         * {
                         *  double dot = -Vector3.Dot(transform(light, true), ray.Result.SurfaceNormal);
                         *  int col = (int)(dot * 255);
                         *  if (col < 0) col = 0;
                         *  fbmp.SetPixel(x, y, Color.FromArgb(col, col, col));
                         * }
                         * else*/fbmp.SetPixel(x, y, Color.Green);
                    }
                    else
                    {
                        fbmp.SetPixel(x, y, Color.Red);
                    }

                    //fbmp.SetPixel(
                }
            }
            frameCount++;


            return(fbmp.ToBitmap());
        }
Exemple #4
0
        public static Bitmap Render(List <SurfaceTangentPoint> points, int width, int height)
        {
            Vector3 light = (new Vector3(1, 1, 1).Normalized());

            BufferPixel[,] buffer = new BufferPixel[width, height];
            for (int i = 0; i < points.Count; i++)
            {
                Vector3 v = transform(points[i].Location, false);
                if (v.Z > 0.001)
                {
                    double x = v.X / v.Z;
                    double y = v.Y / v.Z;
                    if (-1 < x && x < 1 && -1 < y && y < 1)
                    {
                        int _x = (int)((x + 1) * width / 2);
                        int _y = (int)((y + 1) * height / 2);
                        if (buffer[_x, _y].depth < 0.001 || (buffer[_x, _y].depth > 0.001 && buffer[_x, _y].depth > v.Z))
                        {
                            buffer[_x, _y].depth = v.Z;
                            double dot = -Vector3.Dot(transform(points[i].SurfaceNormal, true), light);
                            int    col = (int)(dot * 255);
                            if (col < 0)
                            {
                                col = 0;
                            }
                            buffer[_x, _y].color = Color.FromArgb(col, col, col);
                        }
                    }
                }
            }
            bmp.FastBitmap fbmp = new bmp.FastBitmap(width, height);
            for (int x = 0; x < width; x++)
            {
                for (int y = 0; y < height; y++)
                {
                    fbmp.SetPixel(x, y, buffer[x, y].depth > 0.001 ? buffer[x, y].color : Color.Red);
                }
            }
            frameCount++;
            return(fbmp.ToBitmap());
        }