Ejemplo n.º 1
0
            public override void Render()
            {
                arg12CommonArea.Clear();
                arg2Area.Clear();
                for (int i = 0; i < 4; i++)
                {
                    arg12CommonArea.Add(rect[i] * Arg1Transform);
                    arg2Area.Add(rect[i] * Arg2Transform);
                }
                arg1RemainedAreaCount = 0;
                var clockwiseOrder = AreVectorsClockwiseOrdered(arg2Area[0], arg2Area[1], arg2Area[2]);

                for (int i = 0; i < 4; i++)
                {
                    int j  = (i < 3) ? i + 1 : 0;
                    var v1 = clockwiseOrder ? arg2Area[j] : arg2Area[i];
                    var v2 = clockwiseOrder ? arg2Area[i] : arg2Area[j];
                    if (Operation == ImageCombinerOperation.Multiply)
                    {
                        SplitPolygon(arg12CommonArea, splitResult1, splitResult2, v1, v2);
                        Toolbox.Swap(ref arg12CommonArea, ref splitResult1);
                    }
                    else if (Operation == ImageCombinerOperation.CutOut)
                    {
                        SplitPolygon(arg12CommonArea, splitResult1, splitResult2, v1, v2);
                        Toolbox.Swap(ref arg12CommonArea, ref splitResult1);
                        if (splitResult2.Count > 0)
                        {
                            Toolbox.Swap(ref splitResult2, ref arg1RemainedAreas[arg1RemainedAreaCount++]);
                            if (splitResult2 == null)
                            {
                                splitResult2 = new Polygon();
                            }
                        }
                    }
                    else
                    {
                        throw new InvalidOperationException();
                    }
                }
                // Following matrices transform vertices into texture coordinates.
                var uvTransform1 = Arg1Transform.CalcInversed() * Arg1UVTransform;
                var uvTransform2 = Arg2Transform.CalcInversed() * Arg2UVTransform;

                Renderer.Transform1 = LocalToWorldTransform;
                if (Operation == ImageCombinerOperation.Multiply)
                {
                    PrepareVertices(arg12CommonArea);
                    Renderer.DrawTriangleFan(Arg1Texture, Arg2Texture, Arg12CommonMaterial, vertices, arg12CommonArea.Count);
                }
                else
                {
                    for (int i = 0; i < arg1RemainedAreaCount; i++)
                    {
                        PrepareVertices(arg1RemainedAreas[i]);
                        Renderer.DrawTriangleFan(Arg1Texture, null, Arg1Material, vertices, arg1RemainedAreas[i].Count);
                    }
                    PrepareVertices(arg12CommonArea);
                    Renderer.DrawTriangleFan(Arg1Texture, Arg2Texture, Arg12CommonMaterial, vertices, arg12CommonArea.Count);
                }

                void PrepareVertices(Polygon polygon)
                {
                    for (int i = 0; i < polygon.Count; i++)
                    {
                        vertices[i].Pos   = polygon[i];
                        vertices[i].Color = Color;
                        var uv1 = polygon[i] * uvTransform1;
                        var uv2 = polygon[i] * uvTransform2;
                        vertices[i].UV1 = uv1;
                        vertices[i].UV2 = uv2;
                    }
                }
            }