Esempio n. 1
0
 public void DrawShape(IReadOnlyCircle boundingCircle)
 {
     GL.Color3(Color.LightSlateGray);
     DrawObstacle(boundingCircle);
     GL.Color3(Color.White);
     DrawCollisionOutline(boundingCircle);
 }
Esempio n. 2
0
        /// <summary>
        /// Test for intersection of the specified box and circle (excluding borders).
        /// </summary>
        /// <param name="box">The box.</param>
        /// <param name="circle">The circle.</param>
        /// <returns>True if the two objects overlap.</returns>
        public static bool Intersects(this IReadOnlyBox2D box, IReadOnlyCircle circle)
        {
            float AxisDeltaDelta(float min, float max, float center)
            {
                var diffMin = min - center;

                if (0 < diffMin) //left case
                {
                    return(diffMin * diffMin);
                }
                else
                {
                    var diffMax = center - max;
                    if (0 < diffMax) //right case
                    {
                        return(diffMax * diffMax);
                    }
                }
                return(0f);
            }

            float d = 0f;

            d += AxisDeltaDelta(box.MinX, box.MaxX, circle.CenterX);
            d += AxisDeltaDelta(box.MinY, box.MaxY, circle.CenterY);
            return(d < circle.Radius * circle.Radius);
        }
Esempio n. 3
0
        /// <summary>
        /// Test the specified circles for intersection.
        /// </summary>
        /// <param name="circleA">The first circle.</param>
        /// <param name="circleB">The second circle.</param>
        /// <returns><c>true</c> if the circles overlap; otherwise, <c>false</c></returns>
        public static bool Intersects(this IReadOnlyCircle circleA, IReadOnlyCircle circleB)
        {
            var rSum = circleB.Radius + circleA.Radius;
            var diff = circleB.Center - circleA.Center;

            return(rSum * rSum > diff.LengthSquared());
        }
Esempio n. 4
0
 private void DrawBullet(IReadOnlyCircle bullet, uint type)
 {
     GL.BindTexture(TextureTarget.Texture2D, tileSet.Handle);
     GL.BlendFunc(BlendingFactor.SrcAlpha, BlendingFactor.OneMinusSrcAlpha);
     GL.Enable(EnableCap.Blend);
     DrawTile(bullet.Center.X, bullet.Center.Y, 0.25f, 0.75f, 25 + (type * 5));
     GL.Disable(EnableCap.Blend);
 }
Esempio n. 5
0
        /// <summary>
        /// Creates a <seealso cref="Box2D"/> from a circle.
        /// </summary>
        /// <param name="circle">The circle.</param>
        /// <returns>A new Box2D instance</returns>
        public static Box2D CreateFromCircle(IReadOnlyCircle circle)
        {
            var rectangle = new Box2D(0, 0, 2f * circle.Radius, 2f * circle.Radius)
            {
                CenterX = circle.CenterX,
                CenterY = circle.CenterY
            };

            return(rectangle);
        }
Esempio n. 6
0
        /// <summary>
        /// Undoes the overlap.
        /// </summary>
        /// <param name="a">a.</param>
        /// <param name="b">The b.</param>
        public static void UndoOverlap(this Circle a, IReadOnlyCircle b)
        {
            Vector2 cB   = new Vector2(b.CenterX, b.CenterY);
            Vector2 diff = new Vector2(a.CenterX, a.CenterY);

            diff -= cB;
            diff /= diff.Length();
            diff *= a.Radius + b.Radius;
            var newA = cB + diff;

            a.CenterX = newA.X;
            a.CenterY = newA.Y;
        }
Esempio n. 7
0
 private static void DrawCircleTexture(IReadOnlyCircle circle, IReadOnlyRectangle texCoords)
 {
     GL.Enable(EnableCap.Texture2D);
     GL.Enable(EnableCap.Blend);
     GL.Begin(PrimitiveType.Quads);
     GL.BlendFunc(BlendingFactor.SrcAlpha, BlendingFactor.OneMinusSrcAlpha);
     GL.TexCoord2(texCoords.MinX, texCoords.MinY);
     GL.Vertex2(circle.Center.X - circle.Radius, circle.Center.Y - circle.Radius);
     GL.TexCoord2(texCoords.MaxX, texCoords.MinY);
     GL.Vertex2(circle.Center.X + circle.Radius, circle.Center.Y - circle.Radius);
     GL.TexCoord2(texCoords.MaxX, texCoords.MaxY);
     GL.Vertex2(circle.Center.X + circle.Radius, circle.Center.Y + circle.Radius);
     GL.TexCoord2(texCoords.MinX, texCoords.MaxY);
     GL.Vertex2(circle.Center.X - circle.Radius, circle.Center.Y + circle.Radius);
     GL.End();
     GL.Disable(EnableCap.Blend);
     GL.Disable(EnableCap.Texture2D);
 }
Esempio n. 8
0
 private void DrawObstacle(IReadOnlyCircle boundingCircle)
 {
     GL.PushMatrix();
     {
         // we use only one instance of asteroid vertices, so we have to
         // move those to the position and scale those to the size of each asteroid
         // and we want each asteroid to rotate around its center
         GL.Translate(boundingCircle.CenterX, boundingCircle.CenterY, 0f);
         GL.Scale(2f * boundingCircle.Radius, 2f * boundingCircle.Radius, 1f);
         GL.Rotate(time.AbsoluteTime * 70, 0, 0, 1);
         GL.Begin(PrimitiveType.Polygon);
         foreach (var p in asteroid)
         {
             GL.Vertex2(p);
         }
         GL.End();
     }
     GL.PopMatrix();
 }
Esempio n. 9
0
 public bool Intersects(IReadOnlyCircle obj)
 {
     //circlecollider
     if (obj != null)
     {
         float radius   = Radius + obj.Radius;
         float deltaX   = Center.X - obj.Center.X;
         float deltaY   = Center.Y - obj.Center.Y;
         float distance = (float)Math.Sqrt((deltaX * deltaX) + (deltaY * deltaY));
         if (distance < radius)
         {
             return(true);
         }
         else
         {
             return(false);
         }
     }
     else
     {
         return(false);
     }
 }
Esempio n. 10
0
 private static void DrawCollisionOutline(IReadOnlyCircle boundingCircle)
 {
     DrawTools.DrawCircle(boundingCircle.CenterX, boundingCircle.CenterY, boundingCircle.Radius, 20, false);
 }
Esempio n. 11
0
        /// <summary>
        /// Determines whether the circle contains the specified point.
        /// </summary>
        /// <param name="circle">The circle to test.</param>
        /// <param name="point">The point to test.</param>
        /// <returns>
        ///   <c>true</c> if the circle contains the specified point; otherwise, <c>false</c>.
        /// </returns>
        public static bool Contains(this IReadOnlyCircle circle, Vector2 point)
        {
            var diff = point - circle.Center;

            return(circle.Radius * circle.Radius > diff.LengthSquared());
        }
Esempio n. 12
0
 public void DrawCircle(IReadOnlyCircle circle)
 {
     DrawTools.DrawCircle(circle.CenterX, circle.CenterY, circle.Radius, 32, false);
 }