public RigidBodyWithColliderBuilder SetBoxCollider(FixedPointVector2 size, FixedPointVector2?centre = null) { _boxColliderSize = size; _boxColliderCentre = centre ?? FixedPointVector2.Zero; _colliderType = ColliderType.Box; return(this); }
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); }
public CircleColliderEntityComponent(FixedPoint radius, FixedPointVector2 center) { Radius = radius; Center = center; }
public CollisionManifold(FixedPoint penetration, FixedPointVector2 normal) { Penetration = penetration; Normal = normal; }
public AABB(FixedPointVector2 min, FixedPointVector2 max) { Min = min; Max = max; }
public RigidBodyWithColliderBuilder SetPosition(FixedPointVector2 value) { _position = value; return(this); }