Exemple #1
0
        public Player(Texture2D texture, Vector2 position, Color color, int size)
        {
            this.texture = texture;
            this.position = position;
            this.color = color;
            Size = size;
            origin = new Vector2(texture.Width / 2, texture.Height / 2);

            boundingBody = new BoundingCircle(position, size);
            triggerBody = new BoundingCircle(position, size);
        }
        public bool Intersects(BoundingCircle circle)
        {
            float centerDistanceSquared = (circle.Center - center).LengthSquared();
            float totalRadiusLength = circle.Radius + radius;

            if (centerDistanceSquared < totalRadiusLength * totalRadiusLength)
            {
                return true;
            }

            return false;
        }
 public bool Intersects(BoundingCircle circle)
 {
     return circle.Intersects(this);
 }
Exemple #4
0
        public ConvexHull(Game game, Vector2[] points, Color color, Vector2 position)
        {
            this.game = game;
            this.position = position;

            int vertexCount = points.Length;
            vertices = new VertexPositionColor[vertexCount + 1];
            Vector2 center = Vector2.Zero;

            bool zeroPoint = false;

            for (int i = 0; i < vertexCount; i++)
            {
                vertices[i] = new VertexPositionColor(new Vector3(points[i], 0), color);
                center += points[i];

                if (!zeroPoint && points[i] == Vector2.Zero)
                {
                    zeroPoint = true;
                }
            }
            center /= points.Length;
            vertices[vertexCount] = new VertexPositionColor(new Vector3(center, 0), color);

            primitiveCount = points.Length;
            indices = new short[primitiveCount * 3];

            for (int i = 0; i < primitiveCount; i++)
            {
                indices[3 * i] = (short)i;
                indices[3 * i + 1] = (short)((i + 1) % vertexCount);
                indices[3 * i + 2] = (short)vertexCount;
            }
            backFacing = new bool[vertexCount];

            sphereBox = points.Length != 4 || !zeroPoint;

            if (sphereBox)
            {
                boundingSphere = new BoundingCircle();
                float boundingRadius = 0;

                foreach (Vector2 point in points)
                {
                    if ((center - point).Length() > boundingRadius)
                    {
                        boundingRadius = (center - point).Length();
                    }
                }

                boundingSphere.Center = center + position;
                boundingSphere.Radius = boundingRadius;
            }
            else
            {
                boundingBox = new BoundingRect();
                List<Vector2> realPoints = new List<Vector2>();

                foreach (Vector2 point in points)
                {
                    realPoints.Add(point + position);
                }

                boundingBox.CreateFromPoints(realPoints);
            }
        }
Exemple #5
0
 public bool Intersects(BoundingCircle intersector)
 {
     //(lightSource.Position - (center + position)).LengthSquared() > (boundingRadius + lightSource.Range) * (boundingRadius + lightSource.Range)
     if (sphereBox)
     {
         return boundingSphere.Intersects(intersector);
     }
     else
     {
         return boundingBox.Intersects(intersector);
     }
 }