コード例 #1
0
        public RTF.Canvas DrawRedCircle(RTF.Shapes.Sphere s)
        {
            var    rayOrigin   = RTF.PointType.Point(0, 0, -5);
            double wallZ       = 10;
            double wallSize    = 7;
            var    canvasPixel = 100;
            double pixelSize   = (double)wallSize / (double)canvasPixel;
            double half        = wallSize / 2;

            var canvas = new RTF.Canvas(canvasPixel, canvasPixel, new RTF.Color(0, 0, 0));
            var color  = new RTF.Color(255, 0, 0);
            var shape  = s;

            for (int y = 0; y < canvasPixel; y++)
            {
                var worldY = half - pixelSize * y;
                for (int x = 0; x < canvasPixel; x++)
                {
                    var worldX   = -half + pixelSize * x;
                    var position = RTF.PointType.Point(worldX, worldY, wallZ);

                    var r  = new RTF.Ray(rayOrigin, (position - rayOrigin).Normalize());
                    var xs = shape.Intersect(r);

                    var hit = RTF.Intersection.Hit(xs);

                    if (hit != null)
                    {
                        canvas.WritePixel(x, y, color);
                    }
                }
            }

            return(canvas);
        }
コード例 #2
0
        private void RotationScalingButton_Click(object sender, RoutedEventArgs e)
        {
            var s = new RTF.Shapes.Sphere
            {
                Transform = RTH.Transformations.Scaling(0.5, 1, 1) * RTH.Transformations.RotationZ(Math.PI / 4)
            };
            var canvas = CreateCircle(s);

            canvas.SaveAsPPMFile(FolderPath.Text + "\\Light[Rotation Scaling].ppm");
        }
コード例 #3
0
        private void ScalingYButton_Click(object sender, RoutedEventArgs e)
        {
            var s = new RTF.Shapes.Sphere
            {
                Transform = RTH.Transformations.Scaling(1, 0.5, 1)
            };
            var canvas = CreateCircle(s);

            canvas.SaveAsPPMFile(FolderPath.Text + "\\Light[Scaling Y].ppm");
        }
コード例 #4
0
        private void ScalingXButton_Click(object sender, RoutedEventArgs e)
        {
            var s = new RTF.Shapes.Sphere
            {
                Transform = RTH.Transformations.Scaling(0.5, 1, 1)
            };
            var canvas = DrawRedCircle(s);

            canvas.SaveAsPPMFile(FolderPath.Text + "\\RaySphereIntersections[Scaling X].ppm");
        }
コード例 #5
0
        public RTF.Canvas CreateCircle(RTF.Shapes.Sphere s)
        {
            var lightPos = RTF.PointType.Point(-10, 10, -10);
            var light    = new RTF.Light(lightPos, RTF.Color.White);

            var    rayOrigin   = RTF.PointType.Point(0, 0, -5);
            double wallZ       = 10;
            double wallSize    = 7;
            var    canvasPixel = 100;
            double pixelSize   = wallSize / canvasPixel;
            double half        = wallSize / 2;

            var canvas = new RTF.Canvas(canvasPixel, canvasPixel, RTF.Color.Black);

            var shape = s;

            shape.Material.Color = RTF.Color.Magenta;

            for (int y = 0; y < canvasPixel; y++)
            {
                var worldY = half - pixelSize * y;
                for (int x = 0; x < canvasPixel; x++)
                {
                    var worldX   = -half + pixelSize * x;
                    var position = RTF.PointType.Point(worldX, worldY, wallZ);

                    var r  = new RTF.Ray(rayOrigin, (position - rayOrigin).Normalize());
                    var xs = shape.Intersect(r);

                    var hit = RTF.Intersection.Hit(xs);

                    if (hit != null)
                    {
                        var point  = RTH.Transformations.Position(r, hit.T);
                        var normal = hit.Object.NormalAt(point);
                        var eye    = -r.Direction;

                        var color = RTF.Light.Lighting(
                            (hit.Object as RTF.Shapes.Sphere).Material,
                            hit.Object,
                            light,
                            point,
                            eye,
                            normal,
                            false);

                        canvas.WritePixel(x, y, color);
                    }
                }
            }

            return(canvas);
        }
コード例 #6
0
        public RTF.Canvas CreateCircle()
        {
            var ceilling = new RTF.Shapes.Plane()
            {
                Material = new RTF.Material()
                {
                    Color    = new RTF.Color(1, 0.9, 0.9),
                    Specular = 0
                }
            };

            var middle = new RTF.Shapes.Sphere()
            {
                Transform = transform.Translation(-0.5, 1, 0.5),
                Material  = new RTF.Material(RTF.Color.Purple, 0.7, 0.3)
            };
            var right = new RTF.Shapes.Sphere()
            {
                Transform = transform.Translation(1.5, 0.5, -0.5) * transform.Scaling(0.5, 0.5, 0.5),
                Material  = new RTF.Material(RTF.Color.Lime, 0.7, 0.3)
            };
            var left = new RTF.Shapes.Sphere()
            {
                Transform = transform.Translation(-1.5, 0.33, -0.75) * transform.Scaling(0.33, 0.33, 0.33),
                Material  = new RTF.Material(RTF.Color.Cyan, 0.7, 0.3)
            };

            var world = new RTF.World
            {
                Lights = new List <RTF.Light>()
                {
                    new RTF.Light(point.Point(-10, 10, -10), RTF.Color.White)
                },
                Objects = new List <RTF.Shapes.Shape>()
                {
                    ceilling, right, middle, right, left
                }
            };

            var camera = new RTF.Camera(200, 100, Math.PI / 3)
            {
                Transform = transform.ViewTransform(
                    point.Point(0, 1.5, -5),
                    point.Point(0, 1, 0),
                    point.Vector(0, 1, 0))
            };

            return(RTF.Canvas.Render(camera, world));
        }
コード例 #7
0
        public RTF.Canvas CreatingPerturbedSphere()
        {
            var p_ceiling = new RTF.Patterns.Checker(RTF.Color.Black, RTF.Color.White);

            var ceilling = new RTF.Shapes.Plane()
            {
                Material = new RTF.Material()
                {
                    Pattern  = new RTF.Patterns.Perturbed(p_ceiling),
                    Color    = RTF.Color.Black,
                    Specular = 0
                }
            };

            var p_sphere = new RTF.Patterns.Ring(RTF.Color.Purple, RTF.Color.Pink);
            var middle   = new RTF.Shapes.Sphere()
            {
                Transform = transform.Translation(-0.5, 1, 0.5),
                Material  = new RTF.Material()
                {
                    Pattern  = new RTF.Patterns.Perturbed(p_sphere),
                    Color    = RTF.Color.Black,
                    Specular = 0
                }
            };

            var world = new RTF.World
            {
                Lights = new List <RTF.Light>()
                {
                    new RTF.Light(point.Point(-10, 10, -10), RTF.Color.White)
                },
                Objects = new List <RTF.Shapes.Shape>()
                {
                    ceilling, middle
                }
            };

            var camera = new RTF.Camera(400, 200, Math.PI / 3)
            {
                Transform = transform.ViewTransform(
                    point.Point(0, 1.5, -5),
                    point.Point(0, 1, 0),
                    point.Vector(0, 1, 0))
            };

            return(RTF.Canvas.Render(camera, world));
        }
コード例 #8
0
        public RTF.Canvas CreateWorld()
        {
            var ceilling = new RTF.Shapes.Plane()
            {
                Material = new RTF.Material()
                {
                    Color    = new RTF.Color(1, 0.9, 0.9),
                    Specular = 0
                }
            };

            var middle = new RTF.Shapes.Sphere()
            {
                Transform = transform.Translation(-0.5, 1, 0.5),
                Material  = new RTF.Material()
                {
                    Color        = RTF.Color.Green,
                    Diffuse      = 0.1,
                    Specular     = 1,
                    Transparency = 1,
                    Shininess    = 300,
                    Reflective   = 0.9
                }
            };

            var world = new RTF.World
            {
                Lights = new List <RTF.Light>()
                {
                    new RTF.Light(point.Point(-10, 10, -10), RTF.Color.White)
                },
                Objects = new List <RTF.Shapes.Shape>()
                {
                    ceilling, middle
                }
            };

            var camera = new RTF.Camera(200, 100, Math.PI / 3)
            {
                Transform = transform.ViewTransform(
                    point.Point(0, 1.5, -5),
                    point.Point(0, 1, 0),
                    point.Vector(0, 1, 0))
            };

            return(RTF.Canvas.Render(camera, world));
        }