pub trait AnyCollider: Component<Mutability = Mutable> + ComputeMassProperties {
type Context: for<'w, 's> ReadOnlySystemParam<Item<'w, 's>: Send + Sync>;
// Required methods
fn aabb_with_context(
&self,
position: RVector,
rotation: impl Into<Quat>,
margin: f32,
context: ColliderContext<'_, '_, '_, Self::Context>,
) -> ColliderAabb;
fn contact_manifolds_with_context(
&self,
other: &Self,
position1: RVector,
rotation1: impl Into<Quat>,
position2: RVector,
rotation2: impl Into<Quat>,
prediction_distance: f32,
manifolds: &mut Vec<ContactManifold>,
context: ColliderPairContext<'_, '_, '_, Self::Context>,
);
// Provided methods
fn swept_aabb_with_context(
&self,
start_position: RVector,
start_rotation: impl Into<Quat>,
end_position: RVector,
end_rotation: impl Into<Quat>,
margin: f32,
context: ColliderContext<'_, '_, '_, Self::Context>,
) -> ColliderAabb { ... }
fn ccd_thickness_with_context(
&self,
context: ColliderContext<'_, '_, '_, Self::Context>,
) -> f32 { ... }
fn max_distance_to_point_with_context(
&self,
point: RVector,
context: ColliderContext<'_, '_, '_, Self::Context>,
) -> f32 { ... }
fn bounding_radius_with_context(
&self,
context: ColliderContext<'_, '_, '_, Self::Context>,
) -> f32 { ... }
}Expand description
A trait that generalizes over colliders. Implementing this trait allows colliders to be used with the physics engine.
Required Associated Types§
Sourcetype Context: for<'w, 's> ReadOnlySystemParam<Item<'w, 's>: Send + Sync>
type Context: for<'w, 's> ReadOnlySystemParam<Item<'w, 's>: Send + Sync>
A type providing additional context for collider operations.
Context allows you to access an arbitrary ReadOnlySystemParam on
the world, for context-sensitive behavior in collider operations. You
can use this to query components on the collider entity, or get any
other necessary context from the world.
§Example
#[derive(Component)]
pub struct VoxelCollider;
#[derive(Component)]
pub struct VoxelData {
// collider voxel data...
}
impl AnyCollider for VoxelCollider {
type Context = (
// you can query extra components here
SQuery<&'static VoxelData>,
// or put any other read-only system param here
SRes<Time>,
);
fn contact_manifolds_with_context(
&self,
other: &Self,
position1: RVector,
rotation1: impl Into<Quat>,
position2: RVector,
rotation2: impl Into<Quat>,
prediction_distance: f32,
manifolds: &mut Vec<ContactManifold>,
context: ColliderPairContext<Self::Context>,
) {
let [voxels1, voxels2] = context.0.get_many([context.collider1, context.collider2])
.expect("our own `VoxelCollider` entities should have `VoxelData`");
let elapsed = context.1.elapsed();
// do some computation...
}
}Required Methods§
Sourcefn aabb_with_context(
&self,
position: RVector,
rotation: impl Into<Quat>,
margin: f32,
context: ColliderContext<'_, '_, '_, Self::Context>,
) -> ColliderAabb
fn aabb_with_context( &self, position: RVector, rotation: impl Into<Quat>, margin: f32, context: ColliderContext<'_, '_, '_, Self::Context>, ) -> ColliderAabb
Computes the Axis-Aligned Bounding Box of the collider with the given position and rotation, grown by the given margin.
See SimpleCollider::aabb for collider types with an empty AnyCollider::Context.
Sourcefn contact_manifolds_with_context(
&self,
other: &Self,
position1: RVector,
rotation1: impl Into<Quat>,
position2: RVector,
rotation2: impl Into<Quat>,
prediction_distance: f32,
manifolds: &mut Vec<ContactManifold>,
context: ColliderPairContext<'_, '_, '_, Self::Context>,
)
fn contact_manifolds_with_context( &self, other: &Self, position1: RVector, rotation1: impl Into<Quat>, position2: RVector, rotation2: impl Into<Quat>, prediction_distance: f32, manifolds: &mut Vec<ContactManifold>, context: ColliderPairContext<'_, '_, '_, Self::Context>, )
Computes all ContactManifolds between two colliders.
Returns an empty vector if the colliders are separated by a distance greater than prediction_distance
or if the given shapes are invalid.
See SimpleCollider::contact_manifolds for collider types with an empty AnyCollider::Context.
Provided Methods§
Sourcefn swept_aabb_with_context(
&self,
start_position: RVector,
start_rotation: impl Into<Quat>,
end_position: RVector,
end_rotation: impl Into<Quat>,
margin: f32,
context: ColliderContext<'_, '_, '_, Self::Context>,
) -> ColliderAabb
fn swept_aabb_with_context( &self, start_position: RVector, start_rotation: impl Into<Quat>, end_position: RVector, end_rotation: impl Into<Quat>, margin: f32, context: ColliderContext<'_, '_, '_, Self::Context>, ) -> ColliderAabb
Computes the swept Axis-Aligned Bounding Box of the collider, grown by the given margin. This corresponds to the space the shape would occupy if it moved from the given start position to the given end position.
See SimpleCollider::swept_aabb for collider types with an empty AnyCollider::Context.
Sourcefn ccd_thickness_with_context(
&self,
context: ColliderContext<'_, '_, '_, Self::Context>,
) -> f32
fn ccd_thickness_with_context( &self, context: ColliderContext<'_, '_, '_, Self::Context>, ) -> f32
Returns a conservative minimum thickness used by Continuous Collision Detection (CCD) to determine when the collider might tunnel through other geometry.
Typically corresponds to the minimum distance from the centroid of any given shape to its surface.
Sourcefn max_distance_to_point_with_context(
&self,
point: RVector,
context: ColliderContext<'_, '_, '_, Self::Context>,
) -> f32
fn max_distance_to_point_with_context( &self, point: RVector, context: ColliderContext<'_, '_, '_, Self::Context>, ) -> f32
Returns the maximum distance from the collider to the given point.
Sourcefn bounding_radius_with_context(
&self,
context: ColliderContext<'_, '_, '_, Self::Context>,
) -> f32
fn bounding_radius_with_context( &self, context: ColliderContext<'_, '_, '_, Self::Context>, ) -> f32
Returns the radius of the bounding sphere of the collider.
This is used to compute a size-relative ColliderAabbMargin for the collider.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".