Exemplo n.º 1
0
        private RTCf.Canvas GenerateProjectile(int width, int height)
        {
            var canvas = new RTCf.Canvas(width, height, black);

            var m   = double.Parse(Magnetude.Text);
            var vel = new Tuple <double, double, double>(
                double.Parse(VelocityX.Text),
                double.Parse(VelocityY.Text),
                double.Parse(VelocityZ.Text));

            var proj = new obj.Projectile(
                RTCf.PointType.Point(0, 1, 0),
                RTCf.PointType.Vector(vel.Item1, vel.Item2, vel.Item3).Normalize() * m);
            var env = new obj.Environment(
                RTCf.PointType.Vector(0, -0.1, 0),
                RTCf.PointType.Vector(-0.01, 0, 0));

            canvas.WritePixel((int)proj.Position.X, (height - 1) - (int)proj.Position.Y, red);

            foreach (var coord in obj.Projectile.GetTick(env, proj))
            {
                canvas.WritePixel((int)coord.X, (height - 1) - (int)coord.Y, red);
            }

            return(canvas);
        }
Exemplo n.º 2
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);
        }
Exemplo n.º 3
0
        public void ConstructPPMPixelData()
        {
            var expected = "255 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n" +
                           "0 0 0 0 0 0 0 128 0 0 0 0 0 0 0\n" +
                           "0 0 0 0 0 0 0 0 0 0 0 0 0 0 255";

            var c  = new RTF.Canvas(5, 3);
            var c1 = new RTF.Color(1.5, 0, 0);
            var c2 = new RTF.Color(0, 0.5, 0);
            var c3 = new RTF.Color(-0.5, 0, 1);

            c.WritePixel(0, 0, c1);
            c.WritePixel(2, 1, c2);
            c.WritePixel(4, 2, c3);

            Assert.Equal(expected, string.Join("\n", c.CreatePPMCanvas()));
        }
Exemplo n.º 4
0
        public void WritingPixelToCanvas()
        {
            var c   = new RTF.Canvas(10, 20);
            var red = new RTF.Color(1, 0, 0);

            c.WritePixel(2, 3, red);

            Assert.Equal(red, c.PixelAt(2, 3));
        }
Exemplo n.º 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);
        }
Exemplo n.º 6
0
        public RTF.Canvas ConvertPointsToCanvas(List <RTF.PointType> points, int width, int height)
        {
            RTF.Canvas c      = new RTF.Canvas(width, height, new RTF.Color(0, 0, 0));
            var        radius = (3d / 8d) * width;

            var color = new RTF.Color(255, 255, 255);

            foreach (var point in points)
            {
                int x = (int)((radius * point.X) + width / 2);
                int y = (int)((radius * point.Z) + height / 2);

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

            return(c);
        }