Skip to content

Instantly share code, notes, and snippets.

@alecchendev
Created December 24, 2020 01:08
Show Gist options
  • Save alecchendev/fad7c6b930d6275b6c814ad492c965ee to your computer and use it in GitHub Desktop.
Save alecchendev/fad7c6b930d6275b6c814ad492c965ee to your computer and use it in GitHub Desktop.
OOP in rust article - AABB trait
trait AABB {
fn min(&self) -> Vec3;
fn max(&self) -> Vec3;
fn collision(&self, other: &impl AABB, vel: &Vec3) -> Vec3 {
// default implementation
}
}
struct Player {
position: Vec3,
dims: Vec3,
// ...
}
impl AABB for Player {
fn min(&self) -> Vec3 {
self.position - self.dims / 2.
}
fn max(&self) -> Vec3 {
self.position + self.dims / 2.
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment