public static Line GetLine(Shape shape, int s, int e)
 {
     float[] start = shape.GetPoint(s);
     float[] end = shape.GetPoint(e);
     Line line = new Line(start[0], start[1], end[0], end[1]);
     return line;
 }
Example #2
0
        public override bool Intersects(Shape shape)
        {
            if (shape  is  Circle) {
                Circle other = (Circle) shape;
                float totalRad2 = GetRadius() + other.GetRadius();

                if (Math.Abs(other.GetCenterX() - GetCenterX()) > totalRad2) {
                    return false;
                }
                if (Math.Abs(other.GetCenterY() - GetCenterY()) > totalRad2) {
                    return false;
                }

                totalRad2 *= totalRad2;

                float dx = Math.Abs(other.GetCenterX() - GetCenterX());
                float dy = Math.Abs(other.GetCenterY() - GetCenterY());

                return totalRad2 >= ((dx * dx) + (dy * dy));
            } else if (shape  is  RectBox) {
                return Intersects((RectBox) shape);
            } else {
                return base.Intersects(shape);
            }
        }
 /// <summary>
 /// �ж�����Shape�Ƿ���ڰ�����ϵ
 /// </summary>
 ///
 /// <param name="s1"></param>
 /// <param name="s2"></param>
 /// <returns></returns>
 public static bool Contains(Shape s1, Shape s2)
 {
     if (s1 == null || s2 == null)
     {
         return false;
     }
     return s1.Contains(s2);
 }
Example #4
0
        public bool Contains(Shape other)
        {
            if (other.Intersects(this)) {
                return false;
            }

            for (int i = 0; i < other.GetPointCount(); i++) {
                float[] pt = other.GetPoint(i);
                if (!Contains(pt[0], pt[1])) {
                    return false;
                }
            }

            return true;
        }
Example #5
0
        public virtual bool Intersects(Shape shape)
        {
            if (shape == null) {
                return false;
            }

            CheckPoints();

            bool result = false;
            float[] points_0 = GetPoints();
            float[] thatPoints = shape.GetPoints();
            int length = points_0.Length;
            int thatLength = thatPoints.Length;
            double unknownA;
            double unknownB;

            if (!Closed()) {
                length -= 2;
            }
            if (!shape.Closed()) {
                thatLength -= 2;
            }

            for (int i = 0; i < length; i += 2) {
                int iNext = i + 2;
                if (iNext >= points_0.Length) {
                    iNext = 0;
                }

                for (int j = 0; j < thatLength; j += 2) {
                    int jNext = j + 2;
                    if (jNext >= thatPoints.Length) {
                        jNext = 0;
                    }

                    unknownA = (((points_0[iNext] - points_0[i]) * (double) (thatPoints[j + 1] - points_0[i + 1])) - ((points_0[iNext + 1] - points_0[i + 1]) * (thatPoints[j] - points_0[i])))
                            / (((points_0[iNext + 1] - points_0[i + 1]) * (thatPoints[jNext] - thatPoints[j])) - ((points_0[iNext] - points_0[i]) * (thatPoints[jNext + 1] - thatPoints[j + 1])));
                    unknownB = (((thatPoints[jNext] - thatPoints[j]) * (double) (thatPoints[j + 1] - points_0[i + 1])) - ((thatPoints[jNext + 1] - thatPoints[j + 1]) * (thatPoints[j] - points_0[i])))
                            / (((points_0[iNext + 1] - points_0[i + 1]) * (thatPoints[jNext] - thatPoints[j])) - ((points_0[iNext] - points_0[i]) * (thatPoints[jNext + 1] - thatPoints[j + 1])));

                    if (unknownA >= 0 && unknownA <= 1 && unknownB >= 0
                            && unknownB <= 1) {
                        result = true;
                        break;
                    }
                }
                if (result) {
                    break;
                }
            }

            return result;
        }
Example #6
0
 public void Fill(Shape shape)
 {
     Submit();
     GLEx gl = GLEx.Self;
     LColor old = gl.GetColor();
     gl.SetColor(m_color);
     gl.Fill(shape);
     gl.SetColor(old);
 }
Example #7
0
 public void Fill(Shape s)
 {
     shape.Fill(s, color);
 }
Example #8
0
 public void Draw(Shape shape)
 {
     if (shape == null)
     {
         return;
     }
     Submit();
     GLEx.Self.Draw(shape);
 }
Example #9
0
 /// <summary>
 /// 判断两个Shape是否相交
 /// </summary>
 ///
 /// <param name="s1"></param>
 /// <param name="s2"></param>
 /// <returns></returns>
 public static bool Intersects(Shape s1, Shape s2)
 {
     if (s1 == null || s2 == null)
     {
         return false;
     }
     return s1.Intersects(s2);
 }
Example #10
0
        public void Draw(Shape shape, Color c)
        {
            if (shape == null)
            {
                return;
            }
            if (glType == GL.GL_LINE_STRIP || shape is Path)
            {

                xnaPolygon.ClearPoints();
                float[] points = shape.GetPoints();
                if (points == null)
                {
                    return;
                }
                if (points.Length == 0)
                {
                    return;
                }
                float x = points[0];
                float y = points[1];
                if (batch == null)
                {
                    batch = new SpriteBatch(GLEx.Device);
                }
                batch.Begin(SpriteSortMode.Deferred, c.A == 255 ? BlendState.AlphaBlend : BlendState.Additive, null, null, GLEx.Device.RasterizerState, null, GLEx.cemera.viewMatrix);
                for (int i = 0; i < points.Length; i += 2)
                {
                    DrawLine(batch, new Vector2(x, y), new Vector2(points[i], points[i + 1]), GLEx.WhitePixel, c);
                    x = points[i];
                    y = points[i + 1];
                }
                batch.End();
            }
            else
            {

                if (LineWidth == 0)
                {
                    float[] points = shape.GetPoints();
                    if (points.Length == 0)
                    {
                        return;
                    }
                    GLBegin(GL_LINES);
                    for (int i = 0; i < points.Length; i += 2)
                    {
                        GLVertex2f(points[i], points[i + 1]);
                    }
                    if (shape.Closed())
                    {
                        GLVertex2f(points[0], points[1]);
                    }
                    GLEnd(c);
                }
                else
                {

                    xnaPolygon.ClearPoints();
                    float[] points = shape.GetPoints();
                    if (points == null)
                    {
                        return;
                    }
                    if (points.Length == 0)
                    {
                        return;
                    }

                    for (int i = 0; i < points.Length; i += 2)
                    {
                        xnaPolygon.AddPoint(new Vector2(points[i], points[i + 1]));
                    }
                    if (shape.Closed())
                    {
                        xnaPolygon.AddPoint(new Vector2(points[0], points[1]));
                    }
                    xnaPolygon.Stroke = c;
                    xnaPolygon.StrokeWidth = LineWidth;
                    if (batch == null)
                    {
                        batch = new SpriteBatch(GLEx.Device);
                    }
                    batch.Begin(SpriteSortMode.Deferred, c.A == 255 ? BlendState.AlphaBlend : BlendState.Additive, null, null, GLEx.Device.RasterizerState, null, GLEx.cemera.viewMatrix);
                    xnaPolygon.Draw(batch);
                    batch.End();

                }
            }
        }
Example #11
0
 public Shape GetShape()
 {
     if (shapeCache != null)
     {
         return shapeCache;
     }
     LImage shapeImage = GetImage();
     if (shapeImage != null)
     {
         Polygon polygon = CollisionMask.MakePolygon(shapeImage);
         if (shapeImage != null)
         {
             shapeImage.Dispose();
             shapeImage = null;
         }
         return (shapeCache = polygon);
     }
     throw new RuntimeException("Create texture for shape fail !");
 }
Example #12
0
 public void Draw(Shape s, Color c)
 {
     shape.Draw(s, c);
 }
Example #13
0
 public void Draw(Shape s, LColor c)
 {
     Draw(s, c.Color);
 }
Example #14
0
 public void Draw(Shape s)
 {
     shape.Draw(s, color);
 }
Example #15
0
 public void Fill(Shape s, Color c)
 {
     shape.Fill(s, c);
 }
Example #16
0
 public void Fill(Shape s, LColor c)
 {
     Fill(s, c.Color);
 }
Example #17
0
 public Bind(Object o)
 {
     if (o is Actor)
     {
         type = 1;
         actorObject = (Actor)o;
         this.isBindPos = true;
         this.isBindGetPos = true;
         this.isBindRotation = true;
         this.isBindGetRotation = true;
         this.isBindUpdate = true;
         this.isBindScale = true;
         this.isBindSize = true;
     }
     else if (o is Shape)
     {
         type = 2;
         shapeObject = (Shape)o;
         this.isBindPos = true;
         this.isBindGetPos = true;
         this.isBindRotation = true;
         this.isBindGetRotation = true;
         this.isBindUpdate = false;
         this.isBindScale = true;
         this.isBindSize = true;
     }
     else if (o is LComponent)
     {
         type = 3;
         compObject = (LComponent)o;
         this.isBindPos = true;
         this.isBindGetPos = true;
         this.isBindRotation = false;
         this.isBindGetRotation = false;
         this.isBindUpdate = true;
         this.isBindScale = false;
         this.isBindSize = true;
     }
     else if (o is LObject)
     {
         type = 4;
         lObject = (LObject)o;
         this.isBindPos = true;
         this.isBindGetPos = true;
         this.isBindRotation = true;
         this.isBindGetRotation = true;
         this.isBindUpdate = true;
         this.isBindScale = false;
         this.isBindSize = true;
     }
     else
     {
         type = 0;
         Bind.BindObject obj0 = BindClass(this.obj = o);
         this.methods = obj0.methods;
         this.isBindPos = obj0.bindPos;
         this.isBindGetPos = obj0.bindGetPos;
         this.isBindRotation = obj0.bindRotation;
         this.isBindGetRotation = obj0.bindGetRotation;
         this.isBindUpdate = obj0.bindUpdate;
         this.isBindScale = obj0.bindScale;
         this.isBindSize = obj0.bindSize;
     }
 }
Example #18
0
 public override bool Intersects(Shape shape)
 {
     if (shape  is  Circle) {
         return shape.Intersects(this);
     }
     return base.Intersects(shape);
 }
Example #19
0
 public void Fill(Shape shape, Color c)
 {
     float[] points = shape.GetPoints();
     if (points.Length == 0)
     {
         return;
     }
     GLBegin(GL_QUADS);
     for (int i = 0; i < points.Length; i += 2)
     {
         GLVertex2f(points[i], points[i + 1]);
     }
     if (shape.Closed())
     {
         GLVertex2f(points[0], points[1]);
     }
     GLEnd(c);
 }
Example #20
0
 public void Fill(Shape shape)
 {
     if (isClose)
     {
         return;
     }
     if (shape == null)
     {
         return;
     }
     Triangle tris = shape.GetTriangles();
     if (tris.GetTriangleCount() == 0)
     {
         return;
     }
     GLBegin(GL.GL_TRIANGLES);
     for (int i = 0; i < tris.GetTriangleCount(); i++)
     {
         for (int p = 0; p < 3; p++)
         {
             float[] pt = tris.GetTrianglePoint(i, p);
             GLVertex2f(pt[0], pt[1]);
         }
     }
     GLEnd();
 }
Example #21
0
 public static Line GetLine(Shape shape, float sx, float sy, int e)
 {
     float[] end = shape.GetPoint(e);
     Line line = new Line(sx, sy, end[0], end[1]);
     return line;
 }
Example #22
0
        public void Draw(Shape shape)
        {
            if (isClose)
            {
                return;
            }
            if (lineWidth <= 1)
            {
                float[] points = shape.GetPoints();
                if (points.Length == 0)
                {
                    return;
                }
                GLBegin(GL.GL_LINE_STRIP);
                for (int i = 0; i < points.Length; i += 2)
                {
                    GLVertex2f(points[i], points[i + 1]);
                }
                if (shape.Closed())
                {
                    GLVertex2f(points[0], points[1]);
                }
                GLEnd();
            }
            else
            {
                float[] points = shape.GetPoints();
                if (points == null)
                {
                    return;
                }
                if (points.Length == 0)
                {
                    return;
                }
                if (shape is Path)
                {
                    float x = points[0];
                    float y = points[1];

                    for (int i = 0; i < points.Length; i += 2)
                    {
                        DrawLine(x, y, points[i], points[i + 1]);
                        x = points[i];
                        y = points[i + 1];
                    }
                }
                else
                {
                    int hashCode = 1;
                    for (int i = 0; i < points.Length; i++)
                    {
                        hashCode = LSystem.Unite(hashCode, points[i]);
                    }
                    XNAPolygon xnaPolygon = (XNAPolygon)CollectionUtils.Get(lazyXnaPolygon, hashCode);
                    if (xnaPolygon == null)
                    {
                        xnaPolygon = new XNAPolygon(GL.device);
                        xnaPolygon.StrokeWidth = lineWidth;
                        for (int i = 0; i < points.Length; i += 2)
                        {
                            xnaPolygon.AddPoint(new Vector2(points[i], points[i + 1]));
                        }
                        if (shape.Closed())
                        {
                            xnaPolygon.AddPoint(new Vector2(points[0], points[1]));
                        }
                        CollectionUtils.Put(lazyXnaPolygon, hashCode, xnaPolygon);
                    }
                    xnaPolygon.Stroke = color;
                    XnaBatchBegin(color);
                    xnaPolygon.Draw(xnaBatch);
                    XnaBatchEnd();
                }
            }
        }
Example #23
0
 public void Fill(Shape shape)
 {
     if (shape == null)
     {
         return;
     }
     Submit();
     GLEx.Self.Fill(shape);
 }
Example #24
0
 public void FreeCache()
 {
     if (shapeCache != null)
     {
         shapeCache = null;
     }
     if (maskCache != null)
     {
         maskCache.Dispose();
         maskCache = null;
     }
 }