Skip to content

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.

C#
public readonly struct ShapeDescription : IEquatable<ShapeDescription>

Implements

IEquatable<ShapeDescription>

Properties

Category

The layers the shape is in (CollisionLayers); Default by default.

C#
public ulong Category { get; init; }

Property Value

ulong

Density

Density; null for the backend’s default. A value needs MassProperties.

C#
public float? Density { get; init; }

Property Value

float?

Friction

Friction; null for the backend’s default. A value needs FrictionRestitution.

C#
public float? Friction { get; init; }

Property Value

float?

IsSensor

A sensor: it never blocks and is never blocked; it reports the shapes that enter and leave it as SensorEvents.

C#
public bool IsSensor { get; init; }

Property Value

bool

Kind

The geometry.

C#
public ShapeKind Kind { get; init; }

Property Value

ShapeKind

Mask

The layers it collides with; All by default.

C#
public ulong Mask { get; init; }

Property Value

ulong

Offset

The shape’s centre relative to its body’s origin.

C#
public Vector2 Offset { get; init; }

Property Value

Vector2

OneWay

A one-way platform (needs OneWayPlatforms): it stops only bodies coming down onto its up-facing side.

C#
public bool OneWay { get; init; }

Property Value

bool

Radius

The radius of a circle or a capsule’s ends.

C#
public float Radius { get; init; }

Property Value

float

RequiredCapabilities

The capabilities this description needs beyond the common contract.

C#
public PhysicsCapabilities RequiredCapabilities { get; }

Property Value

PhysicsCapabilities

Restitution

Restitution (bounciness); null for the backend’s default. A value needs FrictionRestitution.

C#
public float? Restitution { get; init; }

Property Value

float?

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.

C#
public bool SensorEvents { get; init; }

Property Value

bool

Size

A box’s full width and height, in world units; both positive. Unused by circles.

C#
public Vector2 Size { get; init; }

Property Value

Vector2

Vertices

The convex polygon’s vertices, relative to Offset, counter-clockwise.

C#
public ReadOnlyMemory<Vector2> Vertices { get; init; }

Property Value

ReadOnlyMemory<Vector2>

Methods

Box(Vector2, Vector2)

An axis-aligned box of size centred at offset from its body’s origin, in the default layers.

C#
public static ShapeDescription Box(Vector2 size, Vector2 offset = default)

Parameters

size Vector2

offset Vector2

Returns

ShapeDescription

Capsule(float, float, Vector2)

A vertical capsule height tall overall with ends of radius (needs Capsules).

C#
public static ShapeDescription Capsule(float radius, float height, Vector2 offset = default)

Parameters

radius float

height float

offset Vector2

Returns

ShapeDescription

Circle(float, Vector2)

A circle (needs Circles).

C#
public static ShapeDescription Circle(float radius, Vector2 offset = default)

Parameters

radius float

offset Vector2

Returns

ShapeDescription

Equals(object)

C#
public override bool Equals(object obj)

Parameters

obj object

Returns

bool

Equals(ShapeDescription)

C#
public bool Equals(ShapeDescription other)

Parameters

other ShapeDescription

Returns

bool

GetHashCode()

C#
public override int GetHashCode()

Returns

int

InLayers(ulong, ulong)

The same shape in other layers.

C#
public ShapeDescription InLayers(ulong category, ulong mask)

Parameters

category ulong

mask ulong

Returns

ShapeDescription

Polygon(ReadOnlyMemory<Vector2>, Vector2)

A convex polygon (needs Polygons).

C#
public static ShapeDescription Polygon(ReadOnlyMemory<Vector2> vertices, Vector2 offset = default)

Parameters

vertices ReadOnlyMemory<Vector2>

offset Vector2

Returns

ShapeDescription

Sensor(Vector2, Vector2)

A box sensor of size centred at offset.

C#
public static ShapeDescription Sensor(Vector2 size, Vector2 offset = default)

Parameters

size Vector2

offset Vector2

Returns

ShapeDescription

ToString()

C#
public override string ToString()

Returns

string

Validate()

Throws when the description is invalid whatever the backend declares.

C#
public void Validate()

Exceptions

ArgumentOutOfRangeException

The kind is undefined, a size, radius or offset is not positive or not finite, or a box’s size is not positive.

ArgumentException

A sensor is also one-way.

Operators

operator ==(ShapeDescription, ShapeDescription)

C#
public static bool operator ==(ShapeDescription left, ShapeDescription right)

Parameters

left ShapeDescription

right ShapeDescription

Returns

bool

operator !=(ShapeDescription, ShapeDescription)

C#
public static bool operator !=(ShapeDescription left, ShapeDescription right)

Parameters

left ShapeDescription

right ShapeDescription

Returns

bool