1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
use super::*;
impl World {
/// Cast a ray and return the closest hit.
///
/// Example
/// ```no_run
/// use boxdd::{World, WorldDef, QueryFilter, Vec2};
/// let mut world = World::new(WorldDef::builder().gravity([0.0,-9.8]).build()).unwrap();
/// let hit = world.cast_ray_closest(Vec2::new(0.0, 5.0), Vec2::new(0.0, -10.0), QueryFilter::default());
/// if hit.hit { /* use hit.point / hit.normal */ }
/// ```
pub fn cast_ray_closest<VO: Into<Vec2>, VT: Into<Vec2>>(
&self,
origin: VO,
translation: VT,
filter: QueryFilter,
) -> RayResult {
cast_ray_closest_checked_impl(self.raw(), origin, translation, filter)
}
pub fn try_cast_ray_closest<VO: Into<Vec2>, VT: Into<Vec2>>(
&self,
origin: VO,
translation: VT,
filter: QueryFilter,
) -> ApiResult<RayResult> {
try_cast_ray_closest_impl(self.raw(), origin, translation, filter)
}
/// Cast a ray and collect all hits along the path.
///
/// Example
/// ```no_run
/// use boxdd::{World, WorldDef, QueryFilter, Vec2};
/// let mut world = World::new(WorldDef::builder().gravity([0.0,-9.8]).build()).unwrap();
/// let hits = world.cast_ray_all(Vec2::new(0.0, 5.0), Vec2::new(0.0, -10.0), QueryFilter::default());
/// for h in hits { let _ = (h.point, h.normal, h.fraction); }
/// ```
pub fn cast_ray_all<VO: Into<Vec2>, VT: Into<Vec2>>(
&self,
origin: VO,
translation: VT,
filter: QueryFilter,
) -> Vec<RayResult> {
cast_ray_all_checked_impl(self.raw(), origin, translation, filter)
}
/// Cast a ray and append all hits into `out`, reusing the caller-owned allocation.
pub fn cast_ray_all_into<VO: Into<Vec2>, VT: Into<Vec2>>(
&self,
origin: VO,
translation: VT,
filter: QueryFilter,
out: &mut Vec<RayResult>,
) {
cast_ray_all_into_checked_impl(self.raw(), origin, translation, filter, out);
}
pub fn try_cast_ray_all<VO: Into<Vec2>, VT: Into<Vec2>>(
&self,
origin: VO,
translation: VT,
filter: QueryFilter,
) -> ApiResult<Vec<RayResult>> {
try_cast_ray_all_impl(self.raw(), origin, translation, filter)
}
pub fn try_cast_ray_all_into<VO: Into<Vec2>, VT: Into<Vec2>>(
&self,
origin: VO,
translation: VT,
filter: QueryFilter,
out: &mut Vec<RayResult>,
) -> ApiResult<()> {
try_cast_ray_all_into_impl(self.raw(), origin, translation, filter, out)
}
}