Exemplo n.º 1
0
        public void AddTriangle(DestroyableVector2Operator a, DestroyableVector2Operator b, DestroyableVector2Operator c)
        {
            if (a.Y != b.Y || a.Y != c.Y)
            {
                //var z = (a.V + b.V + c.V) / 3.0f;
                //var z1 = Vector3.MoveTowards(a.V, z, 1.0f);
                //var z2 = Vector3.MoveTowards(b.V, z, 1.0f);
                //var z3 = Vector3.MoveTowards(c.V, z, 1.0f);

                //Debug.DrawLine(z1, z2, Color.red, 10.0f);
                //Debug.DrawLine(z2, z3, Color.red, 10.0f);
                //Debug.DrawLine(z3, z1, Color.red, 10.0f);


                if (b.Y > a.Y)
                {
                    DestroyableHelper.Swap(ref a, ref b);
                }
                if (c.Y > a.Y)
                {
                    DestroyableHelper.Swap(ref c, ref a);
                }
                if (c.Y > b.Y)
                {
                    DestroyableHelper.Swap(ref b, ref c);
                }

                var fth = a.Y - c.Y;
                var tth = a.Y - b.Y;
                var bth = b.Y - c.Y;

                var inx = c.X + (a.X - c.X) * DestroyableHelper.Divide(bth, fth);
                var d   = new DestroyableVector2Operator((int)inx, b.Y);

                var abs = DestroyableHelper.Divide(a.X - b.X, tth);
                var ads = DestroyableHelper.Divide(a.X - d.X, tth);

                AddTriangle(b.X, d.X, abs, ads, b.Y, 1, tth);

                var cbs = DestroyableHelper.Divide(c.X - b.X, bth);
                var cds = DestroyableHelper.Divide(c.X - d.X, bth);

                AddTriangle(b.X, d.X, cbs, cds, b.Y, -1, bth);
            }
        }
Exemplo n.º 2
0
        public void AddTriangle(float l, float r, float ls, float rs, int y, int s, int c)
        {
            if (l > r)
            {
                DestroyableHelper.Swap(ref l, ref r);
                DestroyableHelper.Swap(ref ls, ref rs);
            }

            for (var i = 0; i < c; i++)
            {
                var il = Mathf.FloorToInt(l);
                var ir = Mathf.CeilToInt(r);

                for (var x = il; x < ir; x++)
                {
                    AddPixel(x, y);
                }

                y += s;
                l += ls;
                r += rs;
            }
        }