示例#1
0
        public void DrawTriangle(ColorRGB color, VertexBuffer vbx, int triangleIndice)
        {
            vbx.Volume.Triangles[triangleIndice].TransformWorld(vbx);

            var surface = RendererContext.Surface;

            PainterUtils.SortTrianglePoints(vbx, surface, triangleIndice, out var v0, out var v1, out var v2);

            var p0 = v0.ScreenPoint; var p1 = v1.ScreenPoint; var p2 = v2.ScreenPoint;

            var yStart = (int)Math.Max(p0.Y, 0);
            var yEnd   = (int)Math.Min(p2.Y, surface.Height - 1);

            // Out if clipped
            if (yStart > yEnd)
            {
                return;
            }

            var yMiddle = MathUtils.Clamp((int)p1.Y, yStart, yEnd);

            // This has to move elsewhere
            var lightPos = new Vector3(0, 10, 10);

            // computing the cos of the angle between the light vector and the normal vector
            // it will return a value between 0 and 1 that will be used as the intensity of the color

            var nl0 = MathUtils.ComputeNDotL(v0.WorldPoint, v0.WorldNormal, lightPos);
            var nl1 = MathUtils.ComputeNDotL(v1.WorldPoint, v1.WorldNormal, lightPos);
            var nl2 = MathUtils.ComputeNDotL(v2.WorldPoint, v2.WorldNormal, lightPos);

            if (PainterUtils.Cross2D(p0, p1, p2) > 0)
            {
                // P0
                //   P1
                // P2
                paintHalfTriangle(yStart, (int)yMiddle - 1, color, p0, p2, p0, p1, nl0, nl2, nl0, nl1);
                paintHalfTriangle((int)yMiddle, yEnd, color, p0, p2, p1, p2, nl0, nl2, nl1, nl2);
            }
            else
            {
                //   P0
                // P1
                //   P2
                paintHalfTriangle(yStart, (int)yMiddle - 1, color, p0, p1, p0, p2, nl0, nl1, nl0, nl2);
                paintHalfTriangle((int)yMiddle, yEnd, color, p1, p2, p0, p2, nl1, nl2, nl0, nl2);
            }
        }
示例#2
0
        public void DrawTriangle(ColorRGB color, VertexBuffer vbx, int triangleIndice)
        {
            vbx.Volume.Triangles[triangleIndice].TransformWorld(vbx);

            var surface = RendererContext.Surface;

            PainterUtils.SortTrianglePoints(vbx, surface, triangleIndice, out var v0, out var v1, out var v2);

            var p0 = v0.ScreenPoint; var p1 = v1.ScreenPoint; var p2 = v2.ScreenPoint;

            var yStart = (int)Math.Max(p0.Y, 0);
            var yEnd   = (int)Math.Min(p2.Y, surface.Height - 1);

            // Out if clipped
            if (yStart > yEnd)
            {
                return;
            }

            var yMiddle = MathUtils.Clamp((int)p1.Y, yStart, yEnd);

            var lightPos     = new Vector3(0, 10, 10);
            var vertexNormal = (v0.WorldNormal + v1.WorldNormal + v2.WorldNormal) / 3;
            var vertexCenter = (v0.WorldPoint + v1.WorldPoint + v2.WorldPoint) / 3;

            color = MathUtils.ComputeNDotL(vertexCenter, vertexNormal, lightPos) * color;

            if (PainterUtils.Cross2D(p0, p1, p2) > 0)
            {
                // P0
                //   P1
                // P2
                paintHalfTriangle(yStart, (int)yMiddle - 1, color, p0, p2, p0, p1);
                paintHalfTriangle((int)yMiddle, yEnd, color, p0, p2, p1, p2);
            }
            else
            {
                //   P0
                // P1
                //   P2
                paintHalfTriangle(yStart, (int)yMiddle - 1, color, p0, p1, p0, p2);
                paintHalfTriangle((int)yMiddle, yEnd, color, p1, p2, p0, p2);
            }
        }
示例#3
0
        public void DrawTriangle(ColorRGB color, VertexBuffer vbx, int triangleIndice)
        {
            var surface = RendererContext.Surface;

            PainterUtils.SortTrianglePoints(vbx, surface, triangleIndice, out var v0, out var v1, out var v2);

            var p0 = v0.ScreenPoint; var p1 = v1.ScreenPoint; var p2 = v2.ScreenPoint;

            var yStart = (int)Math.Max(p0.Y, 0);
            var yEnd   = (int)Math.Min(p2.Y, surface.Height - 1);

            // Out if clipped
            if (yStart > yEnd)
            {
                return;
            }

            var yMiddle = MathUtils.Clamp((int)p1.Y, yStart, yEnd);

            if (PainterUtils.Cross2D(p0, p1, p2) > 0)
            {
                // P0
                //   P1
                // P2
                paintHalfTriangle(yStart, (int)yMiddle - 1, color, p0, p2, p0, p1);
                paintHalfTriangle((int)yMiddle, yEnd, color, p0, p2, p1, p2);
            }
            else
            {
                //   P0
                // P1
                //   P2
                paintHalfTriangle(yStart, (int)yMiddle - 1, color, p0, p1, p0, p2);
                paintHalfTriangle((int)yMiddle, yEnd, color, p1, p2, p0, p2);
            }
        }