Skip to content

Commit b3b83c1

Browse files
committed
center shape to raycast
1 parent 69ba771 commit b3b83c1

File tree

1 file changed

+17
-14
lines changed

1 file changed

+17
-14
lines changed

crates/parry2d/examples/debug_shape_cast2d.rs

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ mod common_macroquad2d;
22

33
use common_macroquad2d::draw_point;
44
use macroquad::prelude::*;
5-
use nalgebra::{Isometry2, Point2, Vector2};
5+
use nalgebra::{Isometry2, Point2};
66
use parry2d::math::Isometry;
77
use parry2d::query::{self, Ray, ShapeCastOptions};
88
use parry2d::shape::{Ball, ConvexPolygon, Shape};
@@ -15,15 +15,14 @@ async fn main() {
1515
for _i in 1.. {
1616
clear_background(BLACK);
1717

18-
let screen_shift =
19-
Point2::new(screen_width() / 2.0, screen_height() / 2.0) + Vector2::new(-500.0, -200.0);
18+
let screen_shift = Point2::new(screen_width() / 2.0, screen_height() / 2.0);
2019

2120
let to_cast_against = ConvexPolygon::from_convex_polyline(
2221
[
23-
[600.0, 288.0].into(),
24-
[576.0, 312.0].into(),
25-
[552.0, 288.0].into(),
26-
[576.0, 264.0].into(),
22+
[-24.0, 0.0].into(),
23+
[0.0, 24.0].into(),
24+
[24.0, 0.0].into(),
25+
[0.0, -24.0].into(),
2726
]
2827
.into(),
2928
)
@@ -33,31 +32,35 @@ async fn main() {
3332
let mouse_pos = mouse_position();
3433
let mouse_position_world =
3534
(Point2::<f32>::new(mouse_pos.0, mouse_pos.1) - screen_shift.coords) / RENDER_SCALE;
36-
let target_pos: Point2<f32> = [264.0, 440.0].into();
35+
let target_pos: Point2<f32> = [-312.0, 152.0].into();
36+
37+
// Those 2 fail with `min_bound >= _eps_tol`, fixed with a tolerance * 100
3738
shape_cast_debug(
3839
screen_shift,
40+
[99.0, -33.0].into(),
3941
target_pos,
40-
mouse_position_world,
4142
to_cast_against.clone(),
4243
);
43-
// Those 2 fail with `min_bound >= _eps_tol`, fixed with a tolerance * 100
4444
shape_cast_debug(
4545
screen_shift,
46-
[675.0, 255.0].into(),
46+
[98.0, -31.0].into(),
4747
target_pos,
4848
to_cast_against.clone(),
4949
);
50+
// This fails with `niter == 100` (and `niter == 100_000`), fixed with a tolerance * 10_000
5051
shape_cast_debug(
5152
screen_shift,
52-
[674.0, 257.0].into(),
53+
[47.0, -32.0].into(),
5354
target_pos,
5455
to_cast_against.clone(),
5556
);
56-
// This fails with `niter == 100` (and `niter == 100_000`), fixed with a tolerance * 10_000
57+
58+
// For debug purposes, raycast to mouse position.
59+
// Rendered last to be on top of the other raycasts
5760
shape_cast_debug(
5861
screen_shift,
59-
[623.0, 256.0].into(),
6062
target_pos,
63+
mouse_position_world,
6164
to_cast_against.clone(),
6265
);
6366

0 commit comments

Comments
 (0)