Skip to content

Class PhysicsShape

Namespace: Apogee.Physics
Assembly: Apogee.Physics.dll

A collision shape: an immutable thing a body (or another shape) is made of, in the body's local space. Made with the static functions, given to , and shared freely: many bodies can use one. Jolt counts references, so a shape that a script lets go of lives on in the bodies that use it.

public sealed class PhysicsShape : EngineObject

Inheritance

object ← EngineObject ← PhysicsShape

Inherited Members

EngineObject.IsAdopted, EngineObject.Handle, EngineObject.IsDestroyed, EngineObject.Class, EngineObject.Adopt(), EngineObject.TryGet(SlotHandle, out EngineObject), EngineObject.Destroy(), object.Equals(object?), object.Equals(object?, object?), object.GetHashCode(), object.GetType(), object.ReferenceEquals(object?, object?), object.ToString()

Properties

CenterOfMass

The shape's center of mass, in its local space.

public Vector3 CenterOfMass { get; }

Property Value

Vector3

Class

What the registry knows about this object's class.

public override ClassInfo Class { get; }

Property Value

ClassInfo

Kind

What it is: box, sphere, capsule, cylinder, convex_hull, mesh, height_field, compound, offset or scaled.

public string Kind { get; }

Property Value

string

Volume

The volume in cubic meters, which with the density gives a dynamic body its mass.

public float Volume { get; }

Property Value

float

Methods

Box(Vector3, float)

A box of these half extents, centered on the origin. The edges are rounded by convexRadius (Jolt's default, 5 cm, is shrunk for small boxes).

public static PhysicsShape Box(Vector3 halfExtents, float convexRadius = 0.05)

Parameters

halfExtents Vector3

convexRadius float

Returns

PhysicsShape

Capsule(float, float)

A capsule along Y: a cylinder of halfHeight (without the caps) with a hemisphere of radius on each end.

public static PhysicsShape Capsule(float halfHeight, float radius)

Parameters

halfHeight float

radius float

Returns

PhysicsShape

Compound(PhysicsShape[], Vector3[], Quaternion[])

Several shapes at fixed places in one: the child i at positions[i] turned by rotations[i] (identity when the list is shorter).

public static PhysicsShape Compound(PhysicsShape[] children, Vector3[] positions, Quaternion[] rotations)

Parameters

children PhysicsShape[]

positions Vector3[]

rotations Quaternion[]

Returns

PhysicsShape

ConvexHull(Vector3[])

The convex hull of these points (at least four, not in one plane).

public static PhysicsShape ConvexHull(Vector3[] points)

Parameters

points Vector3[]

Returns

PhysicsShape

Cylinder(float, float)

A cylinder along Y (wheels, barrels, posts).

public static PhysicsShape Cylinder(float halfHeight, float radius)

Parameters

halfHeight float

radius float

Returns

PhysicsShape

HeightField(float[], int, Vector3, Vector3)

A grid of heights (terrain): heights is size by size samples row by row (a power of two plus one works best, at least 2), at offset from the origin with the grid spaced by scale in x and z and heights multiplied by its y. A height of at least 1e30 is a hole.

public static PhysicsShape HeightField(float[] heights, int size, Vector3 offset, Vector3 scale)

Parameters

heights float[]

size int

offset Vector3

scale Vector3

Returns

PhysicsShape

IsValidScale(Vector3)

Whether the shape can be scaled by this much (a sphere only evenly, a mesh by anything).

public bool IsValidScale(Vector3 scale)

Parameters

scale Vector3

Returns

bool

Mesh(Vector3[], int[])

A static triangle mesh (terrain, buildings): indices are three per triangle. Meshes are only for static and kinematic bodies.

public static PhysicsShape Mesh(Vector3[] vertices, int[] indices)

Parameters

vertices Vector3[]

indices int[]

Returns

PhysicsShape

Offset(PhysicsShape, Vector3, Quaternion)

The shape moved and turned inside its own space, which moves the body's origin relative to it (a box standing on the origin instead of centered on it).

public static PhysicsShape Offset(PhysicsShape shape, Vector3 position, Quaternion rotation)

Parameters

shape PhysicsShape

position Vector3

rotation Quaternion

Returns

PhysicsShape

OnDestroyed()

protected override void OnDestroyed()

Scaled(PhysicsShape, Vector3)

The shape stretched by scale; fails when the shape cannot be scaled so ().

public static PhysicsShape Scaled(PhysicsShape shape, Vector3 scale)

Parameters

shape PhysicsShape

scale Vector3

Returns

PhysicsShape

Sphere(float)

public static PhysicsShape Sphere(float radius)

Parameters

radius float

Returns

PhysicsShape