summaryrefslogtreecommitdiff
path: root/engine/src/collision.rs
diff options
context:
space:
mode:
Diffstat (limited to 'engine/src/collision.rs')
-rw-r--r--engine/src/collision.rs15
1 files changed, 9 insertions, 6 deletions
diff --git a/engine/src/collision.rs b/engine/src/collision.rs
index aefd9b6..3808754 100644
--- a/engine/src/collision.rs
+++ b/engine/src/collision.rs
@@ -1,6 +1,6 @@
-use ecs::Component;
-
+use crate::ecs::Component;
use crate::mesh::Mesh;
+use crate::reflection::Reflection;
use crate::vector::Vec3;
pub trait Collider<Other>
@@ -8,7 +8,7 @@ pub trait Collider<Other>
fn intersects(&self, other: &Other) -> bool;
}
-#[derive(Debug, Default, Clone, Component)]
+#[derive(Debug, Default, Clone, Component, Reflection)]
#[non_exhaustive]
pub struct BoxCollider
{
@@ -18,6 +18,7 @@ pub struct BoxCollider
impl BoxCollider
{
+ #[must_use]
pub fn for_mesh(mesh: &Mesh) -> Self
{
let furthest_dir_points = mesh.find_furthest_vertex_positions();
@@ -36,6 +37,7 @@ impl BoxCollider
}
}
+ #[must_use]
pub fn offset(self, offset: Vec3<f32>) -> Self
{
Self {
@@ -79,7 +81,7 @@ impl Collider<Vec3<f32>> for BoxCollider
}
}
-#[derive(Debug, Default, Clone, Component)]
+#[derive(Debug, Default, Clone, Component, Reflection)]
pub struct SphereCollider
{
pub center: Vec3<f32>,
@@ -88,6 +90,7 @@ pub struct SphereCollider
impl SphereCollider
{
+ #[must_use]
pub fn offset(self, offset: Vec3<f32>) -> Self
{
Self {
@@ -101,7 +104,7 @@ impl Collider<SphereCollider> for SphereCollider
{
fn intersects(&self, other: &SphereCollider) -> bool
{
- (&self.center - &other.center).length() <= self.radius + other.radius
+ (self.center - other.center).length() <= self.radius + other.radius
}
}
@@ -137,6 +140,6 @@ impl Collider<Vec3<f32>> for SphereCollider
{
fn intersects(&self, other: &Vec3<f32>) -> bool
{
- (&self.center - other).length() <= self.radius
+ (self.center - *other).length() <= self.radius
}
}