private static void CollideShapesOfDifferentTypes(Entity <Game> entity, Shape shape, ref Transform entityTransform, ref AABB shapeBB)
        {
            switch (shape.Type)
            {
            case ShapeType.Circle when _shape.Type == ShapeType.AABB:
            {
                var circle = (CircleShape)shape;

                if (Intersector.AABBIntersectsCircle(ref _shapeBB, ref entityTransform.Position, circle.Radius))
                {
                    AddCollision(entity, shape);
                }
                break;
            }

            case ShapeType.AABB when _shape.Type == ShapeType.Circle:
            {
                var circle = (CircleShape)_shape;

                if (Intersector.AABBIntersectsCircle(ref shapeBB, ref _transform.Position, circle.Radius))
                {
                    AddCollision(entity, shape);
                }
                break;
            }

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
Exemplo n.º 2
0
        private void CircleCallback(Entity <Game> entity, Shape shape)
        {
            var transform = new Transform(entity.Get <Position>().Value, entity.Get <Orientation>().Value);

            switch (shape.Type)
            {
            case ShapeType.AABB:
                var aabbShape = (AABBShape)shape;
                var aabb      = aabbShape.GetBoundingBox(ref transform);

                if (Intersector.AABBIntersectsCircle(ref aabb, ref _circlePosition, _circleRadius))
                {
                    _callback(entity, shape);
                }
                break;

            case ShapeType.Circle:
                var circleShape = (CircleShape)shape;

                if (Intersector.CirclesIntersects(ref _circlePosition, _circleRadius, ref transform.Position, circleShape.Radius))
                {
                    _callback(entity, shape);
                }
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
        private static void CollideShapesOfSameType(Entity <Game> entity, Shape shape, ref Transform entityTransform)
        {
            switch (shape.Type)
            {
            case ShapeType.AABB:
                // collision already checked - just generate collisions
                AddCollision(entity, shape);
                break;

            case ShapeType.Circle:
                var circle1 = (CircleShape)shape;
                var circle2 = (CircleShape)_shape;

                if (Intersector.CirclesIntersects(ref entityTransform.Position, circle1.Radius,
                                                  ref _transform.Position, circle2.Radius))
                {
                    AddCollision(entity, shape);
                }
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
        }