rscenes_raylib_connector/
rmodels_collisions.rs

1use raylib_ffi::*;
2use std::fmt::Debug;
3
4#[derive(Clone, Copy, Debug, Default)]
5pub(crate) struct RmodelsCollisionsImpl;
6
7/// Crate only methods
8impl RmodelsCollisionsImpl {
9    // Collision detection methods
10
11    pub fn __check_collision_spheres(
12        center1: Vector3,
13        radius1: f32,
14        center2: Vector3,
15        radius2: f32,
16    ) -> bool {
17        unsafe { CheckCollisionSpheres(center1, radius1, center2, radius2) }
18    }
19
20    pub fn __check_collision_boxes(box1: BoundingBox, box2: BoundingBox) -> bool {
21        unsafe { CheckCollisionBoxes(box1, box2) }
22    }
23
24    pub fn __check_collision_box_sphere(box_: BoundingBox, center: Vector3, radius: f32) -> bool {
25        unsafe { CheckCollisionBoxSphere(box_, center, radius) }
26    }
27
28    pub fn __get_raycollision_sphere(ray: Ray, center: Vector3, radius: f32) -> RayCollision {
29        unsafe { GetRayCollisionSphere(ray, center, radius) }
30    }
31
32    pub fn __get_raycollision_box(ray: Ray, box_: BoundingBox) -> RayCollision {
33        unsafe { GetRayCollisionBox(ray, box_) }
34    }
35
36    pub fn __get_raycollision_mesh(ray: Ray, mesh: Mesh, transform: Matrix) -> RayCollision {
37        unsafe { GetRayCollisionMesh(ray, mesh, transform) }
38    }
39
40    pub fn __get_raycollision_triangle(
41        ray: Ray,
42        p1: Vector3,
43        p2: Vector3,
44        p3: Vector3,
45    ) -> RayCollision {
46        unsafe { GetRayCollisionTriangle(ray, p1, p2, p3) }
47    }
48
49    pub fn __get_raycollision_quad(
50        ray: Ray,
51        p1: Vector3,
52        p2: Vector3,
53        p3: Vector3,
54        p4: Vector3,
55    ) -> RayCollision {
56        unsafe { GetRayCollisionQuad(ray, p1, p2, p3, p4) }
57    }
58}
59
60/// Exported methods
61pub trait RmodelsCollisions: Debug {
62    // Collision detection methods
63
64    // Check collision between two spheres
65    fn check_collision_spheres(
66        &self,
67        center1: Vector3,
68        radius1: f32,
69        center2: Vector3,
70        radius2: f32,
71    ) -> bool {
72        RmodelsCollisionsImpl::__check_collision_spheres(center1, radius1, center2, radius2)
73    }
74
75    /// Check collision between two bounding boxes
76    fn check_collision_boxes(box1: BoundingBox, box2: BoundingBox) -> bool {
77        RmodelsCollisionsImpl::__check_collision_boxes(box1, box2)
78    }
79
80    /// Check collision between box and sphere
81    fn check_collision_box_sphere(&self, box_: BoundingBox, center: Vector3, radius: f32) -> bool {
82        RmodelsCollisionsImpl::__check_collision_box_sphere(box_, center, radius)
83    }
84
85    /// Get collision info between ray and sphere
86    fn get_raycollision_sphere(&self, ray: Ray, center: Vector3, radius: f32) -> RayCollision {
87        RmodelsCollisionsImpl::__get_raycollision_sphere(ray, center, radius)
88    }
89
90    /// Get collision info between ray and box
91    fn get_raycollision_box(&self, ray: Ray, box_: BoundingBox) -> RayCollision {
92        RmodelsCollisionsImpl::__get_raycollision_box(ray, box_)
93    }
94
95    /// Get collision info between ray and mesh
96    fn get_raycollision_mesh(&self, ray: Ray, mesh: Mesh, transform: Matrix) -> RayCollision {
97        RmodelsCollisionsImpl::__get_raycollision_mesh(ray, mesh, transform)
98    }
99
100    /// Get collision info between ray and triangle
101    fn get_raycollision_triangle(
102        &self,
103        ray: Ray,
104        p1: Vector3,
105        p2: Vector3,
106        p3: Vector3,
107    ) -> RayCollision {
108        RmodelsCollisionsImpl::__get_raycollision_triangle(ray, p1, p2, p3)
109    }
110
111    /// Get collision info between ray and quad
112    fn get_raycollision_quad(
113        &self,
114        ray: Ray,
115        p1: Vector3,
116        p2: Vector3,
117        p3: Vector3,
118        p4: Vector3,
119    ) -> RayCollision {
120        RmodelsCollisionsImpl::__get_raycollision_quad(ray, p1, p2, p3, p4)
121    }
122}