Skip to content

Commit 0f5b4a4

Browse files
feat: changed some QueryPipeline API to be more library friendly (#863)
1 parent 6265129 commit 0f5b4a4

File tree

6 files changed

+22
-25
lines changed

6 files changed

+22
-25
lines changed

examples2d/debug_intersection2.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ pub fn init_world(testbed: &mut Testbed) {
5353
);
5454

5555
for intersection in query_pipeline.intersect_shape(
56-
&Isometry::translation(slow_time.cos() * 10.0, slow_time.sin() * 10.0),
56+
Isometry::translation(slow_time.cos() * 10.0, slow_time.sin() * 10.0),
5757
&Ball::new(rad / 2.0),
5858
) {
5959
if let Some(graphics) = graphics.as_deref_mut() {

examples2d/utils/character.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ fn update_kinematic_controller(
140140
let Some(broad_phase) = phx.broad_phase.downcast_ref::<BroadPhaseBvh>() else {
141141
return;
142142
};
143-
let query_pipeline = broad_phase.as_query_pipeline_mut(
143+
let mut query_pipeline = broad_phase.as_query_pipeline_mut(
144144
phx.narrow_phase.query_dispatcher(),
145145
&mut phx.bodies,
146146
&mut phx.colliders,
@@ -165,7 +165,7 @@ fn update_kinematic_controller(
165165

166166
controller.solve_character_collision_impulses(
167167
phx.integration_parameters.dt,
168-
query_pipeline,
168+
&mut query_pipeline,
169169
&*character_shape,
170170
character_mass,
171171
&*collisions,

examples3d/utils/character.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ fn update_kinematic_controller(
150150
let Some(broad_phase) = phx.broad_phase.downcast_ref::<BroadPhaseBvh>() else {
151151
return;
152152
};
153-
let query_pipeline = broad_phase.as_query_pipeline_mut(
153+
let mut query_pipeline = broad_phase.as_query_pipeline_mut(
154154
phx.narrow_phase.query_dispatcher(),
155155
&mut phx.bodies,
156156
&mut phx.colliders,
@@ -175,7 +175,7 @@ fn update_kinematic_controller(
175175

176176
controller.solve_character_collision_impulses(
177177
phx.integration_parameters.dt,
178-
query_pipeline,
178+
&mut query_pipeline,
179179
&*character_shape,
180180
character_mass,
181181
&*collisions,

src/control/character_controller.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,7 @@ impl KinematicCharacterController {
423423

424424
let mut grounded = false;
425425

426-
'outer: for (_, collider) in queries.intersect_aabb_conservative(&character_aabb) {
426+
'outer: for (_, collider) in queries.intersect_aabb_conservative(character_aabb) {
427427
manifolds.clear();
428428
let pos12 = character_pos.inv_mul(collider.position());
429429
let _ = dispatcher.contact_manifolds(
@@ -770,15 +770,15 @@ impl KinematicCharacterController {
770770
pub fn solve_character_collision_impulses<'a>(
771771
&self,
772772
dt: Real,
773-
mut queries: QueryPipelineMut,
773+
queries: &mut QueryPipelineMut,
774774
character_shape: &dyn Shape,
775775
character_mass: Real,
776776
collisions: impl IntoIterator<Item = &'a CharacterCollision>,
777777
) {
778778
for collision in collisions {
779779
self.solve_single_character_collision_impulse(
780780
dt,
781-
&mut queries,
781+
queries,
782782
character_shape,
783783
character_mass,
784784
collision,
@@ -813,10 +813,7 @@ impl KinematicCharacterController {
813813
.compute_aabb(&collision.character_pos)
814814
.loosened(prediction);
815815

816-
for (_, collider) in queries
817-
.as_ref()
818-
.intersect_aabb_conservative(&character_aabb)
819-
{
816+
for (_, collider) in queries.as_ref().intersect_aabb_conservative(character_aabb) {
820817
if let Some(parent) = collider.parent {
821818
if let Some(body) = queries.bodies.get(parent.handle) {
822819
if body.is_dynamic() {

src/dynamics/ccd/ccd_solver.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ impl CCDSolver {
168168
.shape
169169
.compute_swept_aabb(&co1.pos, &predicted_collider_pos1);
170170

171-
for (ch2, _) in query_pipeline.intersect_aabb_conservative(&aabb1) {
171+
for (ch2, _) in query_pipeline.intersect_aabb_conservative(aabb1) {
172172
if *ch1 == ch2 {
173173
// Ignore self-intersection.
174174
continue;
@@ -301,7 +301,7 @@ impl CCDSolver {
301301
.shape
302302
.compute_swept_aabb(&co1.pos, &predicted_collider_pos1);
303303

304-
for (ch2, _) in query_pipeline.intersect_aabb_conservative(&aabb1) {
304+
for (ch2, _) in query_pipeline.intersect_aabb_conservative(aabb1) {
305305
if *ch1 == ch2 {
306306
// Ignore self-intersection.
307307
continue;
@@ -433,7 +433,7 @@ impl CCDSolver {
433433
let co_next_pos1 = rb1.pos.next_position * co1_parent.pos_wrt_parent;
434434
let aabb = co1.shape.compute_swept_aabb(&co1.pos, &co_next_pos1);
435435

436-
for (ch2, _) in query_pipeline.intersect_aabb_conservative(&aabb) {
436+
for (ch2, _) in query_pipeline.intersect_aabb_conservative(aabb) {
437437
let co2 = &colliders[ch2];
438438

439439
let bh1 = co1.parent.map(|p| p.handle);

src/pipeline/query_pipeline.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -211,19 +211,19 @@ impl<'a> QueryPipeline<'a> {
211211
#[profiling::function]
212212
pub fn intersect_ray(
213213
&'a self,
214-
ray: &'a Ray,
214+
ray: Ray,
215215
max_toi: Real,
216216
solid: bool,
217217
) -> impl Iterator<Item = (ColliderHandle, &'a Collider, RayIntersection)> + 'a {
218218
// TODO: add this to CompositeShapeRef?
219219
self.bvh
220-
.leaves(move |node: &BvhNode| node.aabb().intersects_local_ray(ray, max_toi))
220+
.leaves(move |node: &BvhNode| node.aabb().intersects_local_ray(&ray, max_toi))
221221
.filter_map(move |leaf| {
222222
let (co, co_handle) = self.colliders.get_unknown_gen(leaf)?;
223223
if self.filter.test(self.bodies, co_handle, co) {
224224
if let Some(intersection) =
225225
co.shape
226-
.cast_ray_and_get_normal(co.position(), ray, max_toi, solid)
226+
.cast_ray_and_get_normal(co.position(), &ray, max_toi, solid)
227227
{
228228
return Some((co_handle, co, intersection));
229229
}
@@ -259,15 +259,15 @@ impl<'a> QueryPipeline<'a> {
259259
#[profiling::function]
260260
pub fn intersect_point(
261261
&'a self,
262-
point: &'a Point<Real>,
262+
point: Point<Real>,
263263
) -> impl Iterator<Item = (ColliderHandle, &'a Collider)> + 'a {
264264
// TODO: add to CompositeShapeRef?
265265
self.bvh
266-
.leaves(move |node: &BvhNode| node.aabb().contains_local_point(point))
266+
.leaves(move |node: &BvhNode| node.aabb().contains_local_point(&point))
267267
.filter_map(move |leaf| {
268268
let (co, co_handle) = self.colliders.get_unknown_gen(leaf)?;
269269
if self.filter.test(self.bodies, co_handle, co)
270-
&& co.shape.contains_point(co.position(), point)
270+
&& co.shape.contains_point(co.position(), &point)
271271
{
272272
return Some((co_handle, co));
273273
}
@@ -299,11 +299,11 @@ impl<'a> QueryPipeline<'a> {
299299
#[profiling::function]
300300
pub fn intersect_aabb_conservative(
301301
&'a self,
302-
aabb: &'a Aabb,
302+
aabb: Aabb,
303303
) -> impl Iterator<Item = (ColliderHandle, &'a Collider)> + 'a {
304304
// TODO: add to ColliderRef?
305305
self.bvh
306-
.leaves(move |node: &BvhNode| node.aabb().intersects(aabb))
306+
.leaves(move |node: &BvhNode| node.aabb().intersects(&aabb))
307307
.filter_map(move |leaf| {
308308
let (co, co_handle) = self.colliders.get_unknown_gen(leaf)?;
309309
// NOTE: do **not** recompute and check the latest collider AABB.
@@ -388,11 +388,11 @@ impl<'a> QueryPipeline<'a> {
388388
#[profiling::function]
389389
pub fn intersect_shape(
390390
&'a self,
391-
shape_pos: &'a Isometry<Real>,
391+
shape_pos: Isometry<Real>,
392392
shape: &'a dyn Shape,
393393
) -> impl Iterator<Item = (ColliderHandle, &'a Collider)> + 'a {
394394
// TODO: add this to CompositeShapeRef?
395-
let shape_aabb = shape.compute_aabb(shape_pos);
395+
let shape_aabb = shape.compute_aabb(&shape_pos);
396396
self.bvh
397397
.leaves(move |node: &BvhNode| node.aabb().intersects(&shape_aabb))
398398
.filter_map(move |leaf| {

0 commit comments

Comments
 (0)