Esempio n. 1
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();
            }
        }