コード例 #1
0
        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();
            }
        }
コード例 #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();
            }
        }