Class Shape
Defines collision geometry in local coordinates.
public abstract class Shape : IDynamicTreeProxy, IPartitionedSetIndex, IUpdatableBoundingBox, ISupportFeature, ISupportMappable, IRayCastable, IAngularSweepTestable, ISweepTestable, IDistanceTestable, IDebugDrawable
- Inheritance
-
Shape
- Implements
- Derived
- Inherited Members
Remarks
A shape has no position or orientation of its own. Shapes attached to a RigidBody use that body's transform.
Fields
ShapeId
A unique identifier for this shape.
public readonly ulong ShapeId
Field Value
Properties
Velocity
Gets the velocity of the entity, used for bounding box expansion.
[ReferenceFrame(ReferenceFrame.World)]
public abstract JVector Velocity { get; }
Property Value
WorldBoundingBox
The bounding box of the shape in world space. It is automatically updated when the position or orientation of the corresponding instance of RigidBody changes. It may include the body's predicted translation and rotation over the next step.
public JBoundingBox WorldBoundingBox { get; protected set; }
Property Value
Methods
DebugDraw(IDebugDrawer)
Draws the shape using the default visualization settings.
public void DebugDraw(IDebugDrawer drawer)
Parameters
drawerIDebugDrawer
DebugDraw(IDebugDrawer, in DebugDrawSettings)
Draws the shape as world-space triangles using the supplied settings.
public virtual void DebugDraw(IDebugDrawer drawer, in DebugDrawSettings settings)
Parameters
drawerIDebugDrawersettingsDebugDrawSettings
Remarks
Point clouds and custom shapes may use an approximate surface with gaps or overlapping faces. Higher detail settings increase the drawing cost and do not guarantee a more accurate surface.
DebugDrawLocal<TSink>(ref TSink, in DebugDrawSettings)
Draws the shape's surface as triangles in local coordinates.
protected virtual void DebugDrawLocal<TSink>(ref TSink triangleSink, in DebugDrawSettings settings) where TSink : ISink<JTriangle>
Parameters
triangleSinkTSinkThe destination for generated triangles.
settingsDebugDrawSettingsThe visualization settings.
Type Parameters
TSink
Remarks
Override to provide custom debug geometry; otherwise, the surface is approximated. Use outward-facing triangles for closed surfaces. Body and shape transforms are applied automatically.
Distance<T>(in T, in JQuaternion, in JVector, out JVector, out JVector, out JVector, out float)
Finds the closest points between this object and the query shape.
[ReferenceFrame(ReferenceFrame.World)]
public abstract bool Distance<T>(in T support, in JQuaternion orientation, in JVector position, out JVector pointA, out JVector pointB, out JVector normal, out float distance) where T : ISupportMappable
Parameters
supportTThe query shape.
orientationJQuaternionThe query shape orientation in world space.
positionJVectorThe query shape position in world space.
pointAJVectorClosest point on the query shape in world space. Undefined when the shapes overlap.
pointBJVectorClosest point on this object in world space. Undefined when the shapes overlap.
normalJVectorUnit direction from the query shape toward this object, or Zero when the shapes overlap. Do not use this to test whether a result was found.
distancefloatThe separation distance between the shapes. Zero when overlapping.
Returns
- bool
trueif the shapes are separated;falseif they overlap.
Type Parameters
TThe query support-map type.
GetCenter(out JVector)
Returns a point inside the shape. It does not need to be the center of mass.
[ReferenceFrame(ReferenceFrame.Local)]
public abstract void GetCenter(out JVector point)
Parameters
pointJVectorAn interior point in local space.
RayCast(in JVector, in JVector, out JVector, out float)
Performs a ray cast against this object.
[ReferenceFrame(ReferenceFrame.World)]
public abstract bool RayCast(in JVector origin, in JVector direction, out JVector normal, out float lambda)
Parameters
originJVectorThe starting point of the ray.
directionJVectorThe direction of the ray. Does not need to be normalized.
normalJVectorThe surface normal at the intersection point, or Zero if the ray origin is inside the object. Use the return value, not this parameter, to test whether a hit occurred.
lambdafloatThe ray parameter of the intersection:
hitPoint = origin + lambda * direction. It is a distance only ifdirectionis normalized. Zero when the ray origin is inside the object.
Returns
- bool
trueif the ray intersects with the object; otherwise,false. Also returnstruewhen the ray origin is inside the object, withlambdaset to zero andnormalset to Zero.
SupportFeature(in JVector, float, Span<JVector>)
Writes the outermost feature of the shape in the given direction.
[ReferenceFrame(ReferenceFrame.Local)]
public virtual int SupportFeature(in JVector direction, float tolerance, Span<JVector> vertices)
Parameters
directionJVectorThe direction in local space. Does not need to be normalized.
tolerancefloatThe sine of the angle within which directions share the feature.
verticesSpan<JVector>Receives the vertices in local space: one for a point, two for a segment, three or more for a convex polygon in winding order. At least MaxVertices entries long.
Returns
- int
The number of vertices written, at least one.
Remarks
The default samples the support mapping with SupportFeatureSampler. Shapes that know their features analytically should override it.
SupportMap(in JVector, out JVector)
Computes the point on the shape that is furthest in the specified direction.
[ReferenceFrame(ReferenceFrame.Local)]
public abstract void SupportMap(in JVector direction, out JVector result)
Parameters
directionJVectorThe search direction in local space. Does not need to be normalized.
resultJVectorThe point on the shape's surface furthest along
direction.
Sweep<T>(in T, in JQuaternion, in JVector, in JVector, out JVector, out JVector, out JVector, out float)
Performs a sweep test against this object.
[ReferenceFrame(ReferenceFrame.World)]
public abstract bool Sweep<T>(in T support, in JQuaternion orientation, in JVector position, in JVector sweep, out JVector pointA, out JVector pointB, out JVector normal, out float lambda) where T : ISupportMappable
Parameters
supportTThe query shape.
orientationJQuaternionThe query shape orientation in world space.
positionJVectorThe query shape position in world space.
sweepJVectorThe query shape translation in world space.
pointAJVectorCollision point on the query shape in world space at the sweep origin. Undefined when the shapes already overlap.
pointBJVectorCollision point on this object in world space at the sweep origin. Undefined when the shapes already overlap.
normalJVectorCollision normal in world space, or Zero if the shapes already overlap. Use the return value to determine whether a hit occurred; do not rely on this being non-zero.
lambdafloatThe time of impact expressed in units of
sweep. Zero if the shapes already overlap.
Returns
- bool
trueif the query shape hits or already overlaps this object; otherwise,false.
Type Parameters
TThe query support-map type.
Sweep<T>(in T, in JQuaternion, in JVector, in JVector, in JVector, float, float, out JVector, out JVector, out JVector, out float)
Finds the first impact within the specified time interval.
[ReferenceFrame(ReferenceFrame.World)]
public virtual bool Sweep<T>(in T support, in JQuaternion orientation, in JVector position, in JVector velocity, in JVector angularVelocity, float extent, float maximumTime, out JVector pointA, out JVector pointB, out JVector normal, out float lambda) where T : ISupportMappable
Parameters
supportTThe query shape.
orientationJQuaternionThe query shape's initial world-space orientation.
positionJVectorThe query shape's initial world-space position and rotation origin.
velocityJVectorThe query shape's linear velocity in world space.
angularVelocityJVectorThe query shape's angular velocity in world space, in radians per second.
extentfloatA radius enclosing the query shape about its rotation origin, including any local offset.
maximumTimefloatThe last time to search, in seconds.
pointAJVectorContact point on the query shape at its initial pose.
pointBJVectorContact point on this object in world space.
normalJVectorWorld-space normal from the query shape toward this object at impact; zero for initial overlap.
lambdafloatTime of impact in seconds; zero for initial overlap.
Returns
- bool
True if an impact is found; false if the shapes miss or the search fails.
Type Parameters
TThe query support-map type.
UpdateWorldBoundingBox(float)
Recomputes the world-space bounding box.
[ReferenceFrame(ReferenceFrame.World)]
public abstract void UpdateWorldBoundingBox(float dt = 0)
Parameters
dtfloatThe timestep for velocity-based expansion. Default is zero.