Created
December 24, 2020 01:08
-
-
Save alecchendev/fad7c6b930d6275b6c814ad492c965ee to your computer and use it in GitHub Desktop.
OOP in rust article - AABB trait
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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