PhysicsAPI reference
Struct ShapeDescription
Namespace: MicroEngine.Physics
Assembly: MicroEngine.Physics.dll
Guide: Physics worlds
What AddShape attaches to a body. Build one with Box (common) or a capability’s factory.
public readonly struct ShapeDescription : IEquatable<ShapeDescription>Implements
Properties
Category
The layers the shape is in (CollisionLayers); Default by default.
public ulong Category { get; init; }Property Value
Density
Density; null for the backend’s default. A value needs MassProperties.
public float? Density { get; init; }Property Value
Friction
Friction; null for the backend’s default. A value needs FrictionRestitution.
public float? Friction { get; init; }Property Value
IsSensor
A sensor: it never blocks and is never blocked; it reports the shapes that enter and leave it as SensorEvents.
public bool IsSensor { get; init; }Property Value
Kind
The geometry.
public ShapeKind Kind { get; init; }Property Value
Mask
The layers it collides with; All by default.
public ulong Mask { get; init; }Property Value
Offset
The shape’s centre relative to its body’s origin.
public Vector2 Offset { get; init; }Property Value
OneWay
A one-way platform (needs OneWayPlatforms): it stops only bodies coming down onto its up-facing side.
public bool OneWay { get; init; }Property Value
Radius
The radius of a circle or a capsule’s ends.
public float Radius { get; init; }Property Value
RequiredCapabilities
The capabilities this description needs beyond the common contract.
public PhysicsCapabilities RequiredCapabilities { get; }Property Value
Restitution
Restitution (bounciness); null for the backend’s default. A value needs FrictionRestitution.
public float? Restitution { get; init; }Property Value
SensorEvents
Whether sensors see this shape (true by default). Sensor events need it on the visiting shape as well as a sensor that accepts its layers; the backend enables whatever it needs from this flag.
public bool SensorEvents { get; init; }Property Value
Size
A box’s full width and height, in world units; both positive. Unused by circles.
public Vector2 Size { get; init; }Property Value
Vertices
The convex polygon’s vertices, relative to Offset, counter-clockwise.
public ReadOnlyMemory<Vector2> Vertices { get; init; }Property Value
Methods
Box(Vector2, Vector2)
An axis-aligned box of size centred at offset from its body’s origin, in the default layers.
public static ShapeDescription Box(Vector2 size, Vector2 offset = default)Parameters
size Vector2
offset Vector2
Returns
Capsule(float, float, Vector2)
A vertical capsule height tall overall with ends of radius (needs Capsules).
public static ShapeDescription Capsule(float radius, float height, Vector2 offset = default)Parameters
radius float
height float
offset Vector2
Returns
Circle(float, Vector2)
A circle (needs Circles).
public static ShapeDescription Circle(float radius, Vector2 offset = default)Parameters
radius float
offset Vector2
Returns
Equals(object)
public override bool Equals(object obj)Parameters
obj object
Returns
Equals(ShapeDescription)
public bool Equals(ShapeDescription other)Parameters
other ShapeDescription
Returns
GetHashCode()
public override int GetHashCode()Returns
InLayers(ulong, ulong)
The same shape in other layers.
public ShapeDescription InLayers(ulong category, ulong mask)Parameters
category ulong
mask ulong
Returns
Polygon(ReadOnlyMemory<Vector2>, Vector2)
A convex polygon (needs Polygons).
public static ShapeDescription Polygon(ReadOnlyMemory<Vector2> vertices, Vector2 offset = default)Parameters
vertices ReadOnlyMemory<Vector2>
offset Vector2
Returns
Sensor(Vector2, Vector2)
A box sensor of size centred at offset.
public static ShapeDescription Sensor(Vector2 size, Vector2 offset = default)Parameters
size Vector2
offset Vector2
Returns
ToString()
public override string ToString()Returns
Validate()
Throws when the description is invalid whatever the backend declares.
public void Validate()Exceptions
The kind is undefined, a size, radius or offset is not positive or not finite, or a box’s size is not positive.
A sensor is also one-way.
Operators
operator ==(ShapeDescription, ShapeDescription)
public static bool operator ==(ShapeDescription left, ShapeDescription right)Parameters
left ShapeDescription
right ShapeDescription
Returns
operator !=(ShapeDescription, ShapeDescription)
public static bool operator !=(ShapeDescription left, ShapeDescription right)Parameters
left ShapeDescription
right ShapeDescription