Exemple #1
0
        private static void InterpolateX(
            int y,
            RasterizerPoint a, RasterizerPoint b,
            int notUsedIndex,
            out RasterizerResult result
            )
        {
            int dY     = b.Y - a.Y;
            var ratio  = (y - a.Y) / (float)(dY != 0 ? dY : 1);
            var iratio = 1 - ratio;
            var x      = ratio.Interpolate(a.X, b.X);

            switch (notUsedIndex)
            {
            case 0:
                result = new RasterizerResult(x, new Vector3(0, iratio, ratio));
                return;

            case 1:
                result = new RasterizerResult(x, new Vector3(iratio, 0, ratio));
                return;

            case 2:
                result = new RasterizerResult(x, new Vector3(iratio, ratio, 0));
                return;

            default:
                throw new Exception();
            }
        }
Exemple #2
0
        public void RasterizeTriangle(
            RasterizerPoint p0, RasterizerPoint p1, RasterizerPoint p2, T param
            )
        {
            // ReSharper disable InvocationIsSkipped
            Debug.Assert(p0.Y <= p1.Y);
            Debug.Assert(p1.Y <= p2.Y);

            if (p0.Y > ymax)
            {
                return;
            }

            var y0 = p0.Y.Clamp(ymin, ymax);
            var y1 = p1.Y;
            var y2 = p2.Y.Clamp(ymin, ymax);

            RasterizerResult r0, r1;

            for (var y = y0; y <= y2; y++)
            {
                InterpolateX(y, p0, p2, 1, out r0);
                if (y <= y1)
                {
                    InterpolateX(y, p0, p1, 2, out r1);
                }
                else
                {
                    InterpolateX(y, p1, p2, 0, out r1);
                }

                AdjustX(ref r0, ref r1);
                rowHandler(y, ref r0, ref r1, ref param);
            }
        }
Exemple #3
0
 public static void RasterizeTriangle <T>(
     RasterizerPoint p0, RasterizerPoint p1, RasterizerPoint p2,
     T param, RasterizeDelegate <T> rowHandler,
     int ymin = int.MinValue, int ymax = int.MaxValue, int xmin = int.MinValue, int xmax = int.MaxValue
     )
 {
     new TriangleRasterizer <T>(rowHandler, ymin, ymax, xmin, xmax).RasterizeTriangle(p0, p1, p2, param);
 }
Exemple #4
0
        public void RasterizeLine(
            RasterizerPoint p0, RasterizerPoint p1, T param
            )
        {
            // ReSharper disable InvocationIsSkipped
            Debug.Assert(p0.Y <= p1.Y);

            var y0 = p0.Y.Clamp(ymin, ymax);
            var y1 = p1.Y.Clamp(ymin, ymax);

            for (var y = y0; y < y1; y++)
            {
                var ratio0 = y.RatioInRange(y0, y1);
                var ratio1 = (y + 1).RatioInRange(y0, y1);
                var vx0    = ratio0.Interpolate(p0.X, p1.X);
                var vx1    = ratio1.Interpolate(p0.X, p1.X) + 1;
                var r0     = new RasterizerResult(vx0, new Vector3(ratio0));
                var r1     = new RasterizerResult(vx1, new Vector3(ratio1));
                AdjustX(ref r0, ref r1);
                rowHandler(y, ref r0, ref r1, ref param);
            }
        }