Ejemplo n.º 1
0
        public static void RenderGeometry(DrawingContext2D drawingContext, AptContext context,
                                          Geometry shape, ItemTransform transform)
        {
            var matrix = transform.GeometryRotation;

            matrix.Translation = transform.GeometryTranslation;

            foreach (var e in shape.Entries)
            {
                switch (e)
                {
                case GeometryLines l:
                {
                    var color = l.Color.ToColorRgbaF() * transform.ColorTransform;
                    foreach (var line in l.Lines)
                    {
                        drawingContext.DrawLine(
                            Line2D.Transform(line, matrix),
                            l.Thickness,
                            color);
                    }
                    break;
                }

                case GeometrySolidTriangles st:
                {
                    var color = st.Color.ToColorRgbaF() * transform.ColorTransform;
                    foreach (var tri in st.Triangles)
                    {
                        drawingContext.FillTriangle(
                            Triangle2D.Transform(tri, matrix),
                            color);
                    }
                    break;
                }

                case GeometryTexturedTriangles tt:
                {
                    var coordinatesTransform = new Matrix3x2
                    {
                        M11 = tt.RotScale.M11,
                        M12 = tt.RotScale.M12,
                        M21 = tt.RotScale.M21,
                        M22 = tt.RotScale.M22,
                        M31 = tt.Translation.X,
                        M32 = tt.Translation.Y
                    };

                    foreach (var tri in tt.Triangles)
                    {
                        //if (assignment is RectangleAssignment)
                        //    throw new NotImplementedException();

                        var tex = context.GetTexture(tt.Image, shape);

                        drawingContext.FillTriangle(
                            tex,
                            Triangle2D.Transform(tri, coordinatesTransform),
                            Triangle2D.Transform(tri, matrix),
                            transform.ColorTransform);
                    }
                    break;
                }
                }
            }
        }
Ejemplo n.º 2
0
        public void RenderGeometry(DrawingContext2D drawingContext, AptContext context,
                                   Geometry shape, ItemTransform transform, Texture solidTexture)
        {
            CalculateTransform(ref transform, context);
            var matrix = transform.GeometryRotation;

            foreach (var e in shape.Entries)
            {
                switch (e)
                {
                case GeometryLines l:
                {
                    var color = l.Color.ToColorRgbaF() * transform.ColorTransform;
                    foreach (var line in l.Lines)
                    {
                        drawingContext.DrawLine(
                            Line2D.Transform(line, matrix),
                            l.Thickness,
                            color);
                    }
                    break;
                }

                case GeometrySolidTriangles st:
                {
                    var color = st.Color.ToColorRgbaF() * transform.ColorTransform;
                    foreach (var tri in st.Triangles)
                    {
                        if (solidTexture == null)
                        {
                            drawingContext.FillTriangle(
                                Triangle2D.Transform(tri, matrix),
                                color);
                        }
                        else
                        {
                            var destTri  = Triangle2D.Transform(tri, matrix);
                            var coordTri = new Triangle2D(new Vector2(tri.V0.X / 100.0f * solidTexture.Width,
                                                                      tri.V0.Y / 100.0f * solidTexture.Height),
                                                          new Vector2(tri.V1.X / 100.0f * solidTexture.Width,
                                                                      tri.V1.Y / 100.0f * solidTexture.Height),
                                                          new Vector2(tri.V2.X / 100.0f * solidTexture.Width,
                                                                      tri.V2.Y / 100.0f * solidTexture.Height));

                            drawingContext.FillTriangle(
                                solidTexture,
                                coordTri,
                                destTri,
                                new ColorRgbaF(1.0f, 1.0f, 1.0f, color.A));
                        }
                    }
                    break;
                }

                case GeometryTexturedTriangles tt:
                {
                    var coordinatesTransform = new Matrix3x2
                    {
                        M11 = tt.RotScale.M11,
                        M12 = tt.RotScale.M12,
                        M21 = tt.RotScale.M21,
                        M22 = tt.RotScale.M22,
                        M31 = tt.Translation.X,
                        M32 = tt.Translation.Y
                    };

                    foreach (var tri in tt.Triangles)
                    {
                        //if (assignment is RectangleAssignment)
                        //    throw new NotImplementedException();

                        var tex = context.GetTexture(tt.Image, shape);

                        drawingContext.FillTriangle(
                            tex,
                            Triangle2D.Transform(tri, coordinatesTransform),
                            Triangle2D.Transform(tri, matrix),
                            transform.ColorTransform);
                    }
                    break;
                }
                }
            }
        }