From 070108cf09b1b561613b6eea04723afbbb464507 Mon Sep 17 00:00:00 2001 From: LLLL Colonq Date: Sun, 3 Mar 2024 00:10:10 -0500 Subject: Initial commit (new winit) --- src/utils.rs | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 src/utils.rs (limited to 'src/utils.rs') diff --git a/src/utils.rs b/src/utils.rs new file mode 100644 index 0000000..57ccf13 --- /dev/null +++ b/src/utils.rs @@ -0,0 +1,58 @@ +#[derive(Clone, Debug, PartialEq)] +pub enum Cardinal { + North, + South, + West, + East, +} + +impl Cardinal { + pub fn turn_cw(&self) -> Self { + match self { + Self::North => Self::East, + Self::South => Self::West, + Self::West => Self::North, + Self::East => Self::South, + } + } + + pub fn turn_ccw(&self) -> Self { + match self { + Self::North => Self::West, + Self::South => Self::East, + Self::West => Self::South, + Self::East => Self::North, + } + } + + pub fn dir(&self) -> glam::Vec3 { + match self { + Self::North => glam::Vec3::new(0.0, 1.0, 0.0), + Self::South => glam::Vec3::new(0.0, -1.0, 0.0), + Self::West => glam::Vec3::new(-1.0, 0.0, 0.0), + Self::East => glam::Vec3::new(1.0, 0.0, 0.0), + } + } + + pub fn offsets(&self) -> (i32, i32) { + match self { + Self::North => (0, 1), + Self::South => (0, -1), + Self::West => (-1, 0), + Self::East => (1, 0), + } + } + + pub fn angle(&self) -> f32 { + match self { + Self::North => 0.0, + Self::South => std::f32::consts::PI, + Self::West => 3.0 * std::f32::consts::PI / 2.0, + Self::East => std::f32::consts::PI / 2.0, + } + } +} + +pub fn lerp(a: f32, b: f32, t: f32) -> f32 { + a + t.clamp(0.0, 1.0) * (b - a) +} -- cgit v1.2.3