Exemplo n.º 1
0
        public RigidBodyWithColliderBuilder SetBoxCollider(FixedPointVector2 size, FixedPointVector2?centre = null)
        {
            _boxColliderSize   = size;
            _boxColliderCentre = centre ?? FixedPointVector2.Zero;
            _colliderType      = ColliderType.Box;

            return(this);
        }
Exemplo n.º 2
0
        public static CollisionManifold?CalculateManifold(AABB a, AABB b)
        {
            // First, calculate the Minkowski difference. a maps to red, and b maps to blue from our example (though it doesn't matter!)
            var top    = a.Max.Y - b.Min.Y;
            var bottom = a.Min.Y - b.Max.Y;
            var left   = a.Min.X - b.Max.X;
            var right  = a.Max.X - b.Min.X;

            // If the Minkowski difference intersects the origin, there's a collision
            if (right < FixedPoint.Zero || left > FixedPoint.Zero || top < FixedPoint.Zero || bottom > FixedPoint.Zero)
            {
                return(null);
            }

            // The pen vector is the shortest vector from the origin of the MD to an edge.
            // You know this has to be a vertical or horizontal line from the origin (these are by def. the shortest)
            var min = FixedPoint.MaxValue;
            FixedPointVector2?penetration = null;

            if (MathFixedPoint.Abs(left) < min)
            {
                min         = MathFixedPoint.Abs(left);
                penetration = FixedPointVector2.From(left, FixedPoint.Zero);
            }

            if (MathFixedPoint.Abs(right) < min)
            {
                min         = MathFixedPoint.Abs(right);
                penetration = FixedPointVector2.From(right, FixedPoint.Zero);
            }

            if (MathFixedPoint.Abs(top) < min)
            {
                min         = MathFixedPoint.Abs(top);
                penetration = FixedPointVector2.From(FixedPoint.Zero, top);
            }

            if (MathFixedPoint.Abs(bottom) < min)
            {
                min         = MathFixedPoint.Abs(bottom);
                penetration = FixedPointVector2.From(FixedPoint.Zero, bottom);
            }

            if (penetration.HasValue)
            {
                return(new CollisionManifold(min, penetration.Value.Normalize()));
            }

            return(null);
        }
Exemplo n.º 3
0
 public CircleColliderEntityComponent(FixedPoint radius, FixedPointVector2 center)
 {
     Radius = radius;
     Center = center;
 }
Exemplo n.º 4
0
 public CollisionManifold(FixedPoint penetration, FixedPointVector2 normal)
 {
     Penetration = penetration;
     Normal      = normal;
 }
Exemplo n.º 5
0
 public AABB(FixedPointVector2 min, FixedPointVector2 max)
 {
     Min = min;
     Max = max;
 }
Exemplo n.º 6
0
 public RigidBodyWithColliderBuilder SetPosition(FixedPointVector2 value)
 {
     _position = value;
     return(this);
 }