Struct ncollide2d::pipeline::object::CollisionGroups
source · [−]pub struct CollisionGroups { /* private fields */ }
Expand description
Groups of collision used to filter which object interact with which other one.
There are at most 30 groups indexed from 0 to 29 (included). This identifies collidable entities by combining three attributes:
- A set of group this structure is member of.
- A collision group whitelist.
- A collision group blacklist.
For two entities to interact, they must be member of at least one group part of each-other’s whitelists, and must not be part of any blacklisted group. The blacklist always has priority on the whitelist.
Example
For example if the object A is such that:
- It is part of the groups 1, 3, and 6.
- It whitelists the groups 6 and 7.
- It blacklists the group 1.
Let there be an object B such that:
- It is part of the groups 1, 3, and 7.
- It whitelists the groups 3 and 7.
- It does not blacklist anything.
and an object C such that:
- It is part of the groups 6 and 9.
- It whitelists the groups 3 and 7.
- It does not blacklist anything.
Then we have:
- A and C can interact because A whitelists the group 6 (which C is part of), and, reciprocally, C whitelists the group 3 (which A is part of).
- A and B will not interact because B is part of the group 1 which is blacklisted by A.
- Finally, B and C will not interact either because, even if C whitelists the group 3 (which B is part of), B does not whitelists the groups 6 nor 9 (which B is part of).
Implementations
sourceimpl CollisionGroups
impl CollisionGroups
sourcepub fn new() -> CollisionGroups
pub fn new() -> CollisionGroups
Creates a new CollisionGroups
that enables interactions with everything except
self-interaction.
sourcepub fn empty() -> CollisionGroups
pub fn empty() -> CollisionGroups
Creates a new CollisionGroups
that disables interactions with everything.
sourcepub fn with_membership(self, groups: &[usize]) -> CollisionGroups
pub fn with_membership(self, groups: &[usize]) -> CollisionGroups
Returns a copy of this object, updated with a new set of membership groups.
Examples
const GROUP_A: usize = 0;
const GROUP_B: usize = 29;
let groups = CollisionGroups::new().with_membership(&[GROUP_A, GROUP_B]);
assert!(groups.is_member_of(GROUP_A));
assert!(groups.is_member_of(GROUP_B));
sourcepub fn with_whitelist(self, groups: &[usize]) -> CollisionGroups
pub fn with_whitelist(self, groups: &[usize]) -> CollisionGroups
Returns a copy of this object, updated with a new set of whitelisted groups.
Examples
const GROUP_A: usize = 0;
const GROUP_B: usize = 29;
let group_a = CollisionGroups::new().with_whitelist(&[GROUP_B]);
assert!(!group_a.is_group_whitelisted(GROUP_A));
assert!(group_a.is_group_whitelisted(GROUP_B));
sourcepub fn with_blacklist(self, groups: &[usize]) -> CollisionGroups
pub fn with_blacklist(self, groups: &[usize]) -> CollisionGroups
Returns a copy of this object, updated with a new set of blacklisted groups.
Examples
const GROUP_A: usize = 0;
const GROUP_B: usize = 29;
let group_a = CollisionGroups::new().with_blacklist(&[GROUP_B]);
assert!(!group_a.is_group_blacklisted(GROUP_A));
assert!(group_a.is_group_blacklisted(GROUP_B));
sourcepub fn max_group_id() -> usize
pub fn max_group_id() -> usize
The maximum allowed group identifier.
sourcepub fn add_membership_by_mask(self, group_mask: u32) -> CollisionGroups
pub fn add_membership_by_mask(self, group_mask: u32) -> CollisionGroups
adds this entity to the given group by a mask of bits where each bit index represent a group
sourcepub fn remove_membership_by_mask(self, group_mask: u32) -> CollisionGroups
pub fn remove_membership_by_mask(self, group_mask: u32) -> CollisionGroups
removes this entity from the given group by a mask of bits where each bit index represent a group
sourcepub fn with_membership_by_mask(self, group_mask: u32) -> CollisionGroups
pub fn with_membership_by_mask(self, group_mask: u32) -> CollisionGroups
Replaces the membership with a mask of bits where each bit index represent a group
sourcepub fn add_whitelist_by_mask(self, group_mask: u32) -> CollisionGroups
pub fn add_whitelist_by_mask(self, group_mask: u32) -> CollisionGroups
adds this entity to this entity whitelist by a mask of bits where each bit index represent a group
sourcepub fn remove_whitelist_by_mask(self, group_mask: u32) -> CollisionGroups
pub fn remove_whitelist_by_mask(self, group_mask: u32) -> CollisionGroups
remove this entity from this entity whitelist by a mask of bits where each bit index represent a group
sourcepub fn with_whitelist_by_mask(self, group_mask: u32) -> CollisionGroups
pub fn with_whitelist_by_mask(self, group_mask: u32) -> CollisionGroups
Replaces the whitelist with a mask of bits where each bit index represent a group
sourcepub fn add_blacklist_by_mask(self, group_mask: u32) -> CollisionGroups
pub fn add_blacklist_by_mask(self, group_mask: u32) -> CollisionGroups
adds this entity to this entity blacklist by a mask of bits where each bit index represent a group
sourcepub fn remove_blacklist_by_mask(self, group_mask: u32) -> CollisionGroups
pub fn remove_blacklist_by_mask(self, group_mask: u32) -> CollisionGroups
remove this entity from this entity blacklist by a mask of bits where each bit index represent a group
sourcepub fn with_blacklist_by_mask(self, group_mask: u32) -> CollisionGroups
pub fn with_blacklist_by_mask(self, group_mask: u32) -> CollisionGroups
Replaces the blacklist with a mask of bits where each bit index represent a group
sourcepub fn modify_membership(&mut self, group_id: usize, add: bool)
pub fn modify_membership(&mut self, group_id: usize, add: bool)
Adds or removes this entity from the given group.
sourcepub fn modify_whitelist(&mut self, group_id: usize, add: bool)
pub fn modify_whitelist(&mut self, group_id: usize, add: bool)
Adds or removes the given group from this entity whitelist.
sourcepub fn modify_blacklist(&mut self, group_id: usize, add: bool)
pub fn modify_blacklist(&mut self, group_id: usize, add: bool)
Adds or removes this entity from the given group.
sourcepub fn set_membership(&mut self, groups: &[usize])
pub fn set_membership(&mut self, groups: &[usize])
Make this object member of the given groups only.
sourcepub fn set_whitelist(&mut self, groups: &[usize])
pub fn set_whitelist(&mut self, groups: &[usize])
Whitelists the given groups only (others will be un-whitelisted).
sourcepub fn set_blacklist(&mut self, groups: &[usize])
pub fn set_blacklist(&mut self, groups: &[usize])
Blacklists the given groups only (others will be un-blacklisted).
sourcepub fn copy_membership(&mut self, other: &CollisionGroups)
pub fn copy_membership(&mut self, other: &CollisionGroups)
Copies the membership of another collision groups.
sourcepub fn copy_whitelist(&mut self, other: &CollisionGroups)
pub fn copy_whitelist(&mut self, other: &CollisionGroups)
Copies the whitelist of another collision groups.
sourcepub fn copy_blacklist(&mut self, other: &CollisionGroups)
pub fn copy_blacklist(&mut self, other: &CollisionGroups)
Copies the blacklist of another collision groups.
sourcepub fn enable_self_interaction(&mut self)
pub fn enable_self_interaction(&mut self)
Allows the object to interact with itself.
sourcepub fn disable_self_interaction(&mut self)
pub fn disable_self_interaction(&mut self)
Prevents the object from interacting with itself.
sourcepub fn is_member_of(&self, group_id: usize) -> bool
pub fn is_member_of(&self, group_id: usize) -> bool
Tests if this entity is part of the given group.
sourcepub fn is_group_whitelisted(&self, group_id: usize) -> bool
pub fn is_group_whitelisted(&self, group_id: usize) -> bool
Tests if the given group is whitelisted.
sourcepub fn is_group_blacklisted(&self, group_id: usize) -> bool
pub fn is_group_blacklisted(&self, group_id: usize) -> bool
Tests if the given group is blacklisted.
sourcepub fn can_interact_with(&self, group_id: usize) -> bool
pub fn can_interact_with(&self, group_id: usize) -> bool
Tests whether interactions with a given group is possible.
Collision is possible if group_id
is whitelisted but not blacklisted.
sourcepub fn can_interact_with_groups(&self, other: &CollisionGroups) -> bool
pub fn can_interact_with_groups(&self, other: &CollisionGroups) -> bool
Tests whether two collision groups have at least one group in common.
sourcepub fn can_interact_with_self(&self) -> bool
pub fn can_interact_with_self(&self) -> bool
Tests whether self-interaction is enabled.
Trait Implementations
sourceimpl Clone for CollisionGroups
impl Clone for CollisionGroups
sourcefn clone(&self) -> CollisionGroups
fn clone(&self) -> CollisionGroups
Returns a copy of the value. Read more
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
sourceimpl Debug for CollisionGroups
impl Debug for CollisionGroups
sourceimpl Default for CollisionGroups
impl Default for CollisionGroups
impl Copy for CollisionGroups
Auto Trait Implementations
impl RefUnwindSafe for CollisionGroups
impl Send for CollisionGroups
impl Sync for CollisionGroups
impl Unpin for CollisionGroups
impl UnwindSafe for CollisionGroups
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> CheckedAs for T
impl<T> CheckedAs for T
sourcefn checked_as<Dst>(self) -> Option<Dst> where
T: CheckedCast<Dst>,
fn checked_as<Dst>(self) -> Option<Dst> where
T: CheckedCast<Dst>,
Casts the value.
sourceimpl<Src, Dst> CheckedCastFrom<Src> for Dst where
Src: CheckedCast<Dst>,
impl<Src, Dst> CheckedCastFrom<Src> for Dst where
Src: CheckedCast<Dst>,
sourcefn checked_cast_from(src: Src) -> Option<Dst>
fn checked_cast_from(src: Src) -> Option<Dst>
Casts the value.
sourceimpl<T> Downcast for T where
T: Any,
impl<T> Downcast for T where
T: Any,
sourcefn into_any(self: Box<T, Global>) -> Box<dyn Any + 'static, Global>
fn into_any(self: Box<T, Global>) -> Box<dyn Any + 'static, Global>
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
. Read more
sourcefn into_any_rc(self: Rc<T>) -> Rc<dyn Any + 'static>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any + 'static>
Convert Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
. Rc<Any>
can then be
further downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
. Read more
sourcefn as_any(&self) -> &(dyn Any + 'static)
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. Read more
sourcefn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
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. Read more
sourceimpl<T> DowncastSync for T where
T: Any + Send + Sync,
impl<T> DowncastSync for T where
T: Any + Send + Sync,
sourceimpl<Src, Dst> LosslessTryInto<Dst> for Src where
Dst: LosslessTryFrom<Src>,
impl<Src, Dst> LosslessTryInto<Dst> for Src where
Dst: LosslessTryFrom<Src>,
sourcefn lossless_try_into(self) -> Option<Dst>
fn lossless_try_into(self) -> Option<Dst>
Performs the conversion.
sourceimpl<Src, Dst> LossyInto<Dst> for Src where
Dst: LossyFrom<Src>,
impl<Src, Dst> LossyInto<Dst> for Src where
Dst: LossyFrom<Src>,
sourcefn lossy_into(self) -> Dst
fn lossy_into(self) -> Dst
Performs the conversion.
sourceimpl<T> OverflowingAs for T
impl<T> OverflowingAs for T
sourcefn overflowing_as<Dst>(self) -> (Dst, bool) where
T: OverflowingCast<Dst>,
fn overflowing_as<Dst>(self) -> (Dst, bool) where
T: OverflowingCast<Dst>,
Casts the value.
sourceimpl<Src, Dst> OverflowingCastFrom<Src> for Dst where
Src: OverflowingCast<Dst>,
impl<Src, Dst> OverflowingCastFrom<Src> for Dst where
Src: OverflowingCast<Dst>,
sourcefn overflowing_cast_from(src: Src) -> (Dst, bool)
fn overflowing_cast_from(src: Src) -> (Dst, bool)
OverflowingCasts the value.
sourceimpl<T> SaturatingAs for T
impl<T> SaturatingAs for T
sourcefn saturating_as<Dst>(self) -> Dst where
T: SaturatingCast<Dst>,
fn saturating_as<Dst>(self) -> Dst where
T: SaturatingCast<Dst>,
Casts the value.
sourceimpl<Src, Dst> SaturatingCastFrom<Src> for Dst where
Src: SaturatingCast<Dst>,
impl<Src, Dst> SaturatingCastFrom<Src> for Dst where
Src: SaturatingCast<Dst>,
sourcefn saturating_cast_from(src: Src) -> Dst
fn saturating_cast_from(src: Src) -> Dst
Casts the value.
sourceimpl<SS, SP> SupersetOf<SS> for SP where
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SP where
SS: SubsetOf<SP>,
sourcefn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
The inverse inclusion map: attempts to construct self
from the equivalent element of its
superset. Read more
sourcefn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
Checks if self
is actually part of its subset T
(and can be converted to it).
sourcefn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
Use with care! Same as self.to_subset
but without any property checks. Always succeeds.
sourcefn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
The inclusion map: converts self
to the equivalent element of its superset.
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more
sourceimpl<T> UnwrappedAs for T
impl<T> UnwrappedAs for T
sourcefn unwrapped_as<Dst>(self) -> Dst where
T: UnwrappedCast<Dst>,
fn unwrapped_as<Dst>(self) -> Dst where
T: UnwrappedCast<Dst>,
Casts the value.
sourceimpl<Src, Dst> UnwrappedCastFrom<Src> for Dst where
Src: UnwrappedCast<Dst>,
impl<Src, Dst> UnwrappedCastFrom<Src> for Dst where
Src: UnwrappedCast<Dst>,
sourcefn unwrapped_cast_from(src: Src) -> Dst
fn unwrapped_cast_from(src: Src) -> Dst
UnwrappedCasts the value.
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
fn vzip(self) -> V
sourceimpl<T> WrappingAs for T
impl<T> WrappingAs for T
sourcefn wrapping_as<Dst>(self) -> Dst where
T: WrappingCast<Dst>,
fn wrapping_as<Dst>(self) -> Dst where
T: WrappingCast<Dst>,
Casts the value.
sourceimpl<Src, Dst> WrappingCastFrom<Src> for Dst where
Src: WrappingCast<Dst>,
impl<Src, Dst> WrappingCastFrom<Src> for Dst where
Src: WrappingCast<Dst>,
sourcefn wrapping_cast_from(src: Src) -> Dst
fn wrapping_cast_from(src: Src) -> Dst
WrappingCasts the value.