pub struct BasicCollisionSystem<P, T, D, B, Y = ()>{ /* private fields */ }
Expand description
Collision detection system for use with
specs
.
Has support for both broad phase and narrow phase collision detection. Will only do narrow phase if both broad and narrow phase is activated.
Can handle any transform component type, as long as the type implements
Transform
, and as long as the
storage is wrapped in a
FlaggedStorage
.
§Type parameters:
P
: Shape primitiveT
: TransformD
: Data accepted by broad phaseB
: Bounding volumeY
: Shape type, seeCollider
§System Function:
fn(Entities, T, NextFrame<T>, CollisionShape) -> (CollisionShape, EventChannel<ContactEvent>)
Implementations§
Source§impl<P, T, D, B, Y> BasicCollisionSystem<P, T, D, B, Y>where
P: Primitive + ComputeBound<B> + Send + Sync + 'static,
P::Point: Debug + Send + Sync + 'static,
<P::Point as EuclideanSpace>::Scalar: Send + Sync + 'static,
<P::Point as EuclideanSpace>::Diff: Debug + Send + Sync + 'static,
T: Component + Transform<P::Point> + Send + Sync + Clone + 'static,
Y: Default + Send + Sync + 'static,
B: Bound<Point = P::Point> + Send + Sync + 'static + Union<B, Output = B> + Clone,
D: HasBound<Bound = B> + From<(Entity, B)> + GetId<Entity>,
impl<P, T, D, B, Y> BasicCollisionSystem<P, T, D, B, Y>where
P: Primitive + ComputeBound<B> + Send + Sync + 'static,
P::Point: Debug + Send + Sync + 'static,
<P::Point as EuclideanSpace>::Scalar: Send + Sync + 'static,
<P::Point as EuclideanSpace>::Diff: Debug + Send + Sync + 'static,
T: Component + Transform<P::Point> + Send + Sync + Clone + 'static,
Y: Default + Send + Sync + 'static,
B: Bound<Point = P::Point> + Send + Sync + 'static + Union<B, Output = B> + Clone,
D: HasBound<Bound = B> + From<(Entity, B)> + GetId<Entity>,
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a new collision detection system, with no broad or narrow phase activated.
Examples found in repository?
examples/basic2d.rs (line 20)
17pub fn main() {
18 let mut world = World::new();
19
20 let mut system = BasicCollisionSystem2::<f32, BodyPose2<f32>, ()>::new()
21 .with_broad_phase(BroadBruteForce2::default())
22 .with_narrow_phase(GJK2::new());
23 system.setup(&mut world.res);
24
25 let mut reader_1 = world
26 .write_resource::<EventChannel<ContactEvent2<f32>>>()
27 .register_reader();
28
29 world
30 .create_entity()
31 .with(CollisionShape2::<f32, BodyPose2<f32>, ()>::new_simple(
32 CollisionStrategy::FullResolution,
33 CollisionMode::Discrete,
34 Rectangle::new(10., 10.).into(),
35 )).with(BodyPose2::<f32>::one())
36 .build();
37
38 world
39 .create_entity()
40 .with(CollisionShape2::<f32, BodyPose2<f32>, ()>::new_simple(
41 CollisionStrategy::FullResolution,
42 CollisionMode::Discrete,
43 Rectangle::new(10., 10.).into(),
44 )).with(BodyPose2::<f32>::new(
45 Point2::new(3., 2.),
46 Rotation2::from_angle(Rad(0.)),
47 )).build();
48
49 system.run_now(&world.res);
50 println!(
51 "Contacts: {:?}",
52 world
53 .read_resource::<EventChannel<ContactEvent2<f32>>>()
54 .read(&mut reader_1)
55 .collect::<Vec<_>>()
56 );
57}
More examples
examples/basic3d.rs (line 19)
17pub fn main() {
18 let mut world = World::new();
19 let mut system = BasicCollisionSystem3::<f32, BodyPose3<f32>, ()>::new()
20 .with_broad_phase(BroadBruteForce3::default())
21 .with_narrow_phase(GJK3::new());
22 system.setup(&mut world.res);
23
24 let mut reader_1 = world
25 .write_resource::<EventChannel<ContactEvent3<f32>>>()
26 .register_reader();
27
28 world
29 .create_entity()
30 .with(CollisionShape3::<f32, BodyPose3<f32>, ()>::new_simple(
31 CollisionStrategy::FullResolution,
32 CollisionMode::Discrete,
33 Cuboid::new(10., 10., 10.).into(),
34 )).with(BodyPose3::<f32>::one())
35 .build();
36
37 world
38 .create_entity()
39 .with(CollisionShape3::<f32, BodyPose3<f32>, ()>::new_simple(
40 CollisionStrategy::FullResolution,
41 CollisionMode::Discrete,
42 Cuboid::new(10., 10., 10.).into(),
43 )).with(BodyPose3::<f32>::new(
44 Point3::new(3., 2., 0.),
45 Quaternion::from_angle_z(Rad(0.)),
46 )).build();
47
48 system.run_now(&world.res);
49 println!(
50 "Contacts: {:?}",
51 world
52 .read_resource::<EventChannel<ContactEvent3<f32>>>()
53 .read(&mut reader_1)
54 .collect::<Vec<_>>()
55 );
56}
Sourcepub fn with_narrow_phase<N: NarrowPhase<P, T, B, Y> + 'static>(
self,
narrow: N,
) -> Self
pub fn with_narrow_phase<N: NarrowPhase<P, T, B, Y> + 'static>( self, narrow: N, ) -> Self
Specify what narrow phase algorithm to use
Examples found in repository?
examples/basic2d.rs (line 22)
17pub fn main() {
18 let mut world = World::new();
19
20 let mut system = BasicCollisionSystem2::<f32, BodyPose2<f32>, ()>::new()
21 .with_broad_phase(BroadBruteForce2::default())
22 .with_narrow_phase(GJK2::new());
23 system.setup(&mut world.res);
24
25 let mut reader_1 = world
26 .write_resource::<EventChannel<ContactEvent2<f32>>>()
27 .register_reader();
28
29 world
30 .create_entity()
31 .with(CollisionShape2::<f32, BodyPose2<f32>, ()>::new_simple(
32 CollisionStrategy::FullResolution,
33 CollisionMode::Discrete,
34 Rectangle::new(10., 10.).into(),
35 )).with(BodyPose2::<f32>::one())
36 .build();
37
38 world
39 .create_entity()
40 .with(CollisionShape2::<f32, BodyPose2<f32>, ()>::new_simple(
41 CollisionStrategy::FullResolution,
42 CollisionMode::Discrete,
43 Rectangle::new(10., 10.).into(),
44 )).with(BodyPose2::<f32>::new(
45 Point2::new(3., 2.),
46 Rotation2::from_angle(Rad(0.)),
47 )).build();
48
49 system.run_now(&world.res);
50 println!(
51 "Contacts: {:?}",
52 world
53 .read_resource::<EventChannel<ContactEvent2<f32>>>()
54 .read(&mut reader_1)
55 .collect::<Vec<_>>()
56 );
57}
More examples
examples/basic3d.rs (line 21)
17pub fn main() {
18 let mut world = World::new();
19 let mut system = BasicCollisionSystem3::<f32, BodyPose3<f32>, ()>::new()
20 .with_broad_phase(BroadBruteForce3::default())
21 .with_narrow_phase(GJK3::new());
22 system.setup(&mut world.res);
23
24 let mut reader_1 = world
25 .write_resource::<EventChannel<ContactEvent3<f32>>>()
26 .register_reader();
27
28 world
29 .create_entity()
30 .with(CollisionShape3::<f32, BodyPose3<f32>, ()>::new_simple(
31 CollisionStrategy::FullResolution,
32 CollisionMode::Discrete,
33 Cuboid::new(10., 10., 10.).into(),
34 )).with(BodyPose3::<f32>::one())
35 .build();
36
37 world
38 .create_entity()
39 .with(CollisionShape3::<f32, BodyPose3<f32>, ()>::new_simple(
40 CollisionStrategy::FullResolution,
41 CollisionMode::Discrete,
42 Cuboid::new(10., 10., 10.).into(),
43 )).with(BodyPose3::<f32>::new(
44 Point3::new(3., 2., 0.),
45 Quaternion::from_angle_z(Rad(0.)),
46 )).build();
47
48 system.run_now(&world.res);
49 println!(
50 "Contacts: {:?}",
51 world
52 .read_resource::<EventChannel<ContactEvent3<f32>>>()
53 .read(&mut reader_1)
54 .collect::<Vec<_>>()
55 );
56}
Sourcepub fn with_broad_phase<V: BroadPhase<D> + 'static>(self, broad: V) -> Self
pub fn with_broad_phase<V: BroadPhase<D> + 'static>(self, broad: V) -> Self
Specify what broad phase algorithm to use
Examples found in repository?
examples/basic2d.rs (line 21)
17pub fn main() {
18 let mut world = World::new();
19
20 let mut system = BasicCollisionSystem2::<f32, BodyPose2<f32>, ()>::new()
21 .with_broad_phase(BroadBruteForce2::default())
22 .with_narrow_phase(GJK2::new());
23 system.setup(&mut world.res);
24
25 let mut reader_1 = world
26 .write_resource::<EventChannel<ContactEvent2<f32>>>()
27 .register_reader();
28
29 world
30 .create_entity()
31 .with(CollisionShape2::<f32, BodyPose2<f32>, ()>::new_simple(
32 CollisionStrategy::FullResolution,
33 CollisionMode::Discrete,
34 Rectangle::new(10., 10.).into(),
35 )).with(BodyPose2::<f32>::one())
36 .build();
37
38 world
39 .create_entity()
40 .with(CollisionShape2::<f32, BodyPose2<f32>, ()>::new_simple(
41 CollisionStrategy::FullResolution,
42 CollisionMode::Discrete,
43 Rectangle::new(10., 10.).into(),
44 )).with(BodyPose2::<f32>::new(
45 Point2::new(3., 2.),
46 Rotation2::from_angle(Rad(0.)),
47 )).build();
48
49 system.run_now(&world.res);
50 println!(
51 "Contacts: {:?}",
52 world
53 .read_resource::<EventChannel<ContactEvent2<f32>>>()
54 .read(&mut reader_1)
55 .collect::<Vec<_>>()
56 );
57}
More examples
examples/basic3d.rs (line 20)
17pub fn main() {
18 let mut world = World::new();
19 let mut system = BasicCollisionSystem3::<f32, BodyPose3<f32>, ()>::new()
20 .with_broad_phase(BroadBruteForce3::default())
21 .with_narrow_phase(GJK3::new());
22 system.setup(&mut world.res);
23
24 let mut reader_1 = world
25 .write_resource::<EventChannel<ContactEvent3<f32>>>()
26 .register_reader();
27
28 world
29 .create_entity()
30 .with(CollisionShape3::<f32, BodyPose3<f32>, ()>::new_simple(
31 CollisionStrategy::FullResolution,
32 CollisionMode::Discrete,
33 Cuboid::new(10., 10., 10.).into(),
34 )).with(BodyPose3::<f32>::one())
35 .build();
36
37 world
38 .create_entity()
39 .with(CollisionShape3::<f32, BodyPose3<f32>, ()>::new_simple(
40 CollisionStrategy::FullResolution,
41 CollisionMode::Discrete,
42 Cuboid::new(10., 10., 10.).into(),
43 )).with(BodyPose3::<f32>::new(
44 Point3::new(3., 2., 0.),
45 Quaternion::from_angle_z(Rad(0.)),
46 )).build();
47
48 system.run_now(&world.res);
49 println!(
50 "Contacts: {:?}",
51 world
52 .read_resource::<EventChannel<ContactEvent3<f32>>>()
53 .read(&mut reader_1)
54 .collect::<Vec<_>>()
55 );
56}
Trait Implementations§
Source§impl<'a, P, T, Y, D, B> System<'a> for BasicCollisionSystem<P, T, D, B, Y>where
P: Primitive + ComputeBound<B> + Send + Sync + 'static,
P::Point: Debug + Send + Sync + 'static,
<P::Point as EuclideanSpace>::Scalar: Send + Sync + 'static,
<P::Point as EuclideanSpace>::Diff: Debug + Send + Sync + 'static,
T: Component + Transform<P::Point> + Send + Sync + Clone + 'static,
Y: Default + Send + Sync + 'static,
B: Bound<Point = P::Point> + Send + Sync + 'static + Union<B, Output = B> + Clone,
D: HasBound<Bound = B> + From<(Entity, B)> + GetId<Entity>,
impl<'a, P, T, Y, D, B> System<'a> for BasicCollisionSystem<P, T, D, B, Y>where
P: Primitive + ComputeBound<B> + Send + Sync + 'static,
P::Point: Debug + Send + Sync + 'static,
<P::Point as EuclideanSpace>::Scalar: Send + Sync + 'static,
<P::Point as EuclideanSpace>::Diff: Debug + Send + Sync + 'static,
T: Component + Transform<P::Point> + Send + Sync + Clone + 'static,
Y: Default + Send + Sync + 'static,
B: Bound<Point = P::Point> + Send + Sync + 'static + Union<B, Output = B> + Clone,
D: HasBound<Bound = B> + From<(Entity, B)> + GetId<Entity>,
Source§type SystemData = (Read<'a, EntitiesRes>, Storage<'a, T, Fetch<'a, MaskedStorage<T>>>, Storage<'a, NextFrame<T>, Fetch<'a, MaskedStorage<NextFrame<T>>>>, Storage<'a, CollisionShape<P, T, B, Y>, FetchMut<'a, MaskedStorage<CollisionShape<P, T, B, Y>>>>, Write<'a, EventChannel<ContactEvent<Entity, <P as Primitive>::Point>>>)
type SystemData = (Read<'a, EntitiesRes>, Storage<'a, T, Fetch<'a, MaskedStorage<T>>>, Storage<'a, NextFrame<T>, Fetch<'a, MaskedStorage<NextFrame<T>>>>, Storage<'a, CollisionShape<P, T, B, Y>, FetchMut<'a, MaskedStorage<CollisionShape<P, T, B, Y>>>>, Write<'a, EventChannel<ContactEvent<Entity, <P as Primitive>::Point>>>)
The resource bundle required to execute this system. Read more
Source§fn run(&mut self, system_data: Self::SystemData)
fn run(&mut self, system_data: Self::SystemData)
Executes the system with the required system
data.
Source§fn running_time(&self) -> RunningTime
fn running_time(&self) -> RunningTime
Returns a hint how long the system needs for running.
This is used to optimize the way they’re executed (might
allow more parallelization). Read more
Source§fn accessor<'b>(&'b self) -> AccessorCow<'a, 'b, Self>
fn accessor<'b>(&'b self) -> AccessorCow<'a, 'b, Self>
Return the accessor from the
SystemData
.Auto Trait Implementations§
impl<P, T, D, B, Y> Freeze for BasicCollisionSystem<P, T, D, B, Y>
impl<P, T, D, B, Y = ()> !RefUnwindSafe for BasicCollisionSystem<P, T, D, B, Y>
impl<P, T, D, B, Y> Send for BasicCollisionSystem<P, T, D, B, Y>
impl<P, T, D, B, Y = ()> !Sync for BasicCollisionSystem<P, T, D, B, Y>
impl<P, T, D, B, Y> Unpin for BasicCollisionSystem<P, T, D, B, Y>
impl<P, T, D, B, Y = ()> !UnwindSafe for BasicCollisionSystem<P, T, D, B, Y>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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 moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<'a, T> RunWithPool<'a> for Twhere
T: System<'a>,
impl<'a, T> RunWithPool<'a> for Twhere
T: System<'a>,
Source§fn run(&mut self, res: &'a Resources, _: &ThreadPool)
fn run(&mut self, res: &'a Resources, _: &ThreadPool)
Runs the system/group of systems. Possibly in parallel depending
on how the structure is set up. Read more
Source§fn reads(&self, reads: &mut Vec<ResourceId>)
fn reads(&self, reads: &mut Vec<ResourceId>)
Accumulates the necessary read/shared resources from the
systems in this group.
Source§fn writes(&self, writes: &mut Vec<ResourceId>)
fn writes(&self, writes: &mut Vec<ResourceId>)
Accumulates the necessary write/exclusive resources from the
systems in this group.