bevy_rapier2d::geometry

Struct Collider

Source
pub struct Collider {
    pub raw: SharedShape,
    /* private fields */
}
Expand description

A geometric entity that can be attached to a RigidBody so it can be affected by contacts and intersection queries.

Related components:

Fields§

§raw: SharedShape

The raw shape from Rapier.

Implementations§

Source§

impl Collider

Source

pub fn scale(&self) -> Vect

The scaling factor that was applied to this collider.

Source

pub fn promote_scaled_shape(&mut self)

This replaces the unscaled version of this collider by its scaled version, and resets self.scale() to 1.0.

Source

pub fn compound(shapes: Vec<(Vect, Rot, Collider)>) -> Self

Initialize a new collider with a compound shape.

Source

pub fn ball(radius: Real) -> Self

Initialize a new collider with a ball shape defined by its radius.

Source

pub fn halfspace(outward_normal: Vect) -> Option<Self>

Initialize a new collider build with a half-space shape defined by the outward normal of its planar boundary.

Source

pub fn cuboid(half_x: Real, half_y: Real) -> Self

Initialize a new collider with a cuboid shape defined by its half-extents.

Source

pub fn round_cuboid(half_x: Real, half_y: Real, border_radius: Real) -> Self

Initialize a new collider with a round cuboid shape defined by its half-extents and border radius.

Source

pub fn capsule(start: Vect, end: Vect, radius: Real) -> Self

Initialize a new collider with a capsule shape.

Source

pub fn capsule_x(half_height: Real, radius: Real) -> Self

Initialize a new collider with a capsule shape aligned with the x axis.

Source

pub fn capsule_y(half_height: Real, radius: Real) -> Self

Initialize a new collider with a capsule shape aligned with the y axis.

Source

pub fn segment(a: Vect, b: Vect) -> Self

Initializes a collider with a segment shape.

Source

pub fn triangle(a: Vect, b: Vect, c: Vect) -> Self

Initializes a collider with a triangle shape.

Source

pub fn round_triangle(a: Vect, b: Vect, c: Vect, border_radius: Real) -> Self

Initializes a collider with a triangle shape with round corners.

Source

pub fn polyline(vertices: Vec<Vect>, indices: Option<Vec<[u32; 2]>>) -> Self

Initializes a collider with a polyline shape defined by its vertex and index buffers.

Source

pub fn trimesh( vertices: Vec<Vect>, indices: Vec<[u32; 3]>, ) -> Result<Self, TriMeshBuilderError>

Initializes a collider with a triangle mesh shape defined by its vertex and index buffers.

Source

pub fn trimesh_with_flags( vertices: Vec<Vect>, indices: Vec<[u32; 3]>, flags: TriMeshFlags, ) -> Result<Self, TriMeshBuilderError>

Initializes a collider with a triangle mesh shape defined by its vertex and index buffers, and flags controlling its pre-processing.

Source

pub fn convex_decomposition(vertices: &[Vect], indices: &[[u32; 2]]) -> Self

Initializes a collider with a compound shape obtained from the decomposition of the given trimesh (in 3D) or polyline (in 2D) into convex parts.

Source

pub fn round_convex_decomposition( vertices: &[Vect], indices: &[[u32; 2]], border_radius: Real, ) -> Self

Initializes a collider with a compound shape obtained from the decomposition of the given trimesh (in 3D) or polyline (in 2D) into convex parts dilated with round corners.

Source

pub fn convex_decomposition_with_params( vertices: &[Vect], indices: &[[u32; 2]], params: &VHACDParameters, ) -> Self

Initializes a collider with a compound shape obtained from the decomposition of the given trimesh (in 3D) or polyline (in 2D) into convex parts.

Source

pub fn round_convex_decomposition_with_params( vertices: &[Vect], indices: &[[u32; 2]], params: &VHACDParameters, border_radius: Real, ) -> Self

Initializes a collider with a compound shape obtained from the decomposition of the given trimesh (in 3D) or polyline (in 2D) into convex parts dilated with round corners.

Source

pub fn convex_hull(points: &[Vect]) -> Option<Self>

Initializes a new collider with a 2D convex polygon or 3D convex polyhedron obtained after computing the convex-hull of the given points.

Source

pub fn round_convex_hull(points: &[Vect], border_radius: Real) -> Option<Self>

Initializes a new collider with a round 2D convex polygon or 3D convex polyhedron obtained after computing the convex-hull of the given points. The shape is dilated by a sphere of radius border_radius.

Source

pub fn convex_polyline(points: Vec<Vect>) -> Option<Self>

Creates a new collider that is a convex polygon formed by the given polyline assumed to be convex (no convex-hull will be automatically computed).

Source

pub fn round_convex_polyline( points: Vec<Vect>, border_radius: Real, ) -> Option<Self>

Creates a new collider that is a round convex polygon formed by the given polyline assumed to be convex (no convex-hull will be automatically computed). The polygon shape is dilated by a sphere of radius border_radius.

Source

pub fn heightfield(heights: Vec<Real>, scale: Vect) -> Self

Initializes a collider with a heightfield shape defined by its set of height and a scale factor along each coordinate axis.

Source

pub fn as_typed_shape(&self) -> ColliderView<'_>

Takes a strongly typed reference of this collider.

Source

pub fn as_unscaled_typed_shape(&self) -> ColliderView<'_>

Takes a strongly typed reference of the unscaled version of this collider.

Source

pub fn as_ball(&self) -> Option<BallView<'_>>

Downcast this collider to a ball, if it is one.

Source

pub fn as_cuboid(&self) -> Option<CuboidView<'_>>

Downcast this collider to a cuboid, if it is one.

Source

pub fn as_capsule(&self) -> Option<CapsuleView<'_>>

Downcast this collider to a capsule, if it is one.

Source

pub fn as_segment(&self) -> Option<SegmentView<'_>>

Downcast this collider to a segment, if it is one.

Source

pub fn as_triangle(&self) -> Option<TriangleView<'_>>

Downcast this collider to a triangle, if it is one.

Source

pub fn as_trimesh(&self) -> Option<TriMeshView<'_>>

Downcast this collider to a triangle mesh, if it is one.

Source

pub fn as_polyline(&self) -> Option<PolylineView<'_>>

Downcast this collider to a polyline, if it is one.

Source

pub fn as_halfspace(&self) -> Option<HalfSpaceView<'_>>

Downcast this collider to a half-space, if it is one.

Source

pub fn as_heightfield(&self) -> Option<HeightFieldView<'_>>

Downcast this collider to a heightfield, if it is one.

Source

pub fn as_compound(&self) -> Option<CompoundView<'_>>

Downcast this collider to a compound shape, if it is one.

Source

pub fn as_convex_polygon(&self) -> Option<ConvexPolygonView<'_>>

Downcast this collider to a convex polygon, if it is one.

Source

pub fn as_ball_mut(&mut self) -> Option<BallViewMut<'_>>

Downcast this collider to a mutable ball, if it is one.

Source

pub fn as_cuboid_mut(&mut self) -> Option<CuboidViewMut<'_>>

Downcast this collider to a mutable cuboid, if it is one.

Source

pub fn as_capsule_mut(&mut self) -> Option<CapsuleViewMut<'_>>

Downcast this collider to a mutable capsule, if it is one.

Source

pub fn as_segment_mut(&mut self) -> Option<SegmentViewMut<'_>>

Downcast this collider to a mutable segment, if it is one.

Source

pub fn as_triangle_mut(&mut self) -> Option<TriangleViewMut<'_>>

Downcast this collider to a mutable triangle, if it is one.

Source

pub fn as_trimesh_mut(&mut self) -> Option<TriMeshViewMut<'_>>

Downcast this collider to a mutable triangle mesh, if it is one.

Source

pub fn as_polyline_mut(&mut self) -> Option<PolylineViewMut<'_>>

Downcast this collider to a mutable polyline, if it is one.

Source

pub fn as_halfspace_mut(&mut self) -> Option<HalfSpaceViewMut<'_>>

Downcast this collider to a mutable half-space, if it is one.

Source

pub fn as_heightfield_mut(&mut self) -> Option<HeightFieldViewMut<'_>>

Downcast this collider to a mutable heightfield, if it is one.

Source

pub fn set_scale(&mut self, scale: Vect, num_subdivisions: u32)

Set the scaling factor of this shape.

If the scaling factor is non-uniform, and the scaled shape can’t be represented as a supported smooth shape (for example scalling a Ball with a non-uniform scale results in an ellipse which isn’t supported), the shape is approximated by a convex polygon/convex polyhedron using num_subdivisions subdivisions.

Source

pub fn project_local_point_with_max_dist( &self, point: Vect, solid: bool, max_dist: Real, ) -> Option<PointProjection>

Projects a point on self, unless the projection lies further than the given max distance.

The point is assumed to be expressed in the local-space of self.

Source

pub fn project_point_with_max_dist( &self, translation: Vect, rotation: Rot, point: Vect, solid: bool, max_dist: Real, ) -> Option<PointProjection>

Projects a point on self transformed by m, unless the projection lies further than the given max distance.

Source

pub fn project_local_point(&self, point: Vect, solid: bool) -> PointProjection

Projects a point on self.

The point is assumed to be expressed in the local-space of self.

Source

pub fn project_local_point_and_get_feature( &self, point: Vect, ) -> (PointProjection, FeatureId)

Projects a point on the boundary of self and returns the id of the feature the point was projected on.

Source

pub fn distance_to_local_point(&self, point: Vect, solid: bool) -> Real

Computes the minimal distance between a point and self.

Source

pub fn contains_local_point(&self, point: Vect) -> bool

Tests if the given point is inside of self.

Source

pub fn project_point( &self, translation: Vect, rotation: Rot, point: Vect, solid: bool, ) -> PointProjection

Projects a point on self transformed by m.

Source

pub fn distance_to_point( &self, translation: Vect, rotation: Rot, point: Vect, solid: bool, ) -> Real

Computes the minimal distance between a point and self transformed by m.

Source

pub fn project_point_and_get_feature( &self, translation: Vect, rotation: Rot, point: Vect, ) -> (PointProjection, FeatureId)

Projects a point on the boundary of self transformed by m and returns the id of the feature the point was projected on.

Source

pub fn contains_point( &self, translation: Vect, rotation: Rot, point: Vect, ) -> bool

Tests if the given point is inside of self transformed by m.

Source

pub fn cast_local_ray( &self, ray_origin: Vect, ray_dir: Vect, max_time_of_impact: Real, solid: bool, ) -> Option<Real>

Computes the time of impact between this transform shape and a ray.

Source

pub fn cast_local_ray_and_get_normal( &self, ray_origin: Vect, ray_dir: Vect, max_time_of_impact: Real, solid: bool, ) -> Option<RayIntersection>

Computes the time of impact, and normal between this transformed shape and a ray.

Source

pub fn intersects_local_ray( &self, ray_origin: Vect, ray_dir: Vect, max_time_of_impact: Real, ) -> bool

Tests whether a ray intersects this transformed shape.

Source

pub fn cast_ray( &self, translation: Vect, rotation: Rot, ray_origin: Vect, ray_dir: Vect, max_time_of_impact: Real, solid: bool, ) -> Option<Real>

Computes the time of impact between this transform shape and a ray.

Source

pub fn cast_ray_and_get_normal( &self, translation: Vect, rotation: Rot, ray_origin: Vect, ray_dir: Vect, max_time_of_impact: Real, solid: bool, ) -> Option<RayIntersection>

Computes the time of impact, and normal between this transformed shape and a ray.

Source

pub fn intersects_ray( &self, translation: Vect, rotation: Rot, ray_origin: Vect, ray_dir: Vect, max_time_of_impact: Real, ) -> bool

Tests whether a ray intersects this transformed shape.

Trait Implementations§

Source§

impl Clone for Collider

Source§

fn clone(&self) -> Collider

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Component for Collider
where Self: Send + Sync + 'static,

Source§

const STORAGE_TYPE: StorageType = bevy::ecs::component::StorageType::Table

A constant indicating the storage type used for this component.
Source§

fn register_required_components( requiree: ComponentId, components: &mut Components, storages: &mut Storages, required_components: &mut RequiredComponents, inheritance_depth: u16, )

Registers required components.
Source§

fn register_component_hooks(hooks: &mut ComponentHooks)

Called when registering this component, allowing mutable access to its ComponentHooks.
Source§

impl Debug for Collider

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Collider

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<'a> From<&'a Collider> for &'a dyn Shape

Source§

fn from(collider: &'a Collider) -> &'a dyn Shape

Converts to this type from the input type.
Source§

impl From<SharedShape> for Collider

Source§

fn from(shared_shape: SharedShape) -> Collider

Converts to this type from the input type.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T, U> AsBindGroupShaderType<U> for T
where U: ShaderType, &'a T: for<'a> Into<U>,

Source§

fn as_bind_group_shader_type(&self, _images: &RenderAssets<GpuImage>) -> U

Return the T ShaderType for self. When used in AsBindGroup derives, it is safe to assume that all images in self exist.
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<C> Bundle for C
where C: Component,

Source§

fn component_ids( components: &mut Components, storages: &mut Storages, ids: &mut impl FnMut(ComponentId), )

Source§

unsafe fn from_components<T, F>(ctx: &mut T, func: &mut F) -> C
where F: for<'a> FnMut(&'a mut T) -> OwningPtr<'a>,

Source§

fn register_required_components( components: &mut Components, storages: &mut Storages, required_components: &mut RequiredComponents, )

Registers components that are required by the components in this Bundle.
Source§

fn get_component_ids( components: &Components, ids: &mut impl FnMut(Option<ComponentId>), )

Gets this Bundle’s component ids. This will be None if the component has not been registered.
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
Source§

impl<T> Downcast<T> for T

Source§

fn downcast(&self) -> &T

Source§

impl<T> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
Source§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Send + Sync>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Source§

impl<C> DynamicBundle for C
where C: Component,

Source§

fn get_components(self, func: &mut impl FnMut(StorageType, OwningPtr<'_>))

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FromWorld for T
where T: Default,

Source§

fn from_world(_world: &mut World) -> T

Creates Self using default().

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
Source§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> TypeData for T
where T: 'static + Send + Sync + Clone,

Source§

impl<T> Upcast<T> for T

Source§

fn upcast(&self) -> Option<&T>

Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> ConditionalSend for T
where T: Send,

Source§

impl<T> Settings for T
where T: 'static + Send + Sync,

Source§

impl<T> WasmNotSend for T
where T: Send,

Source§

impl<T> WasmNotSendSync for T

Source§

impl<T> WasmNotSync for T
where T: Sync,