mirror of
https://github.com/storytold/storyteller-bevy.git
synced 2026-10-17 00:13:17 +00:00
Add math module
This commit is contained in:
@@ -18,6 +18,7 @@ use wasm_bindgen::prelude::*;
|
||||
mod design_system;
|
||||
mod input;
|
||||
mod interaction;
|
||||
mod math;
|
||||
mod orbit_cam;
|
||||
mod skybox;
|
||||
mod test_scene;
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
mod util;
|
||||
|
||||
pub use util::*;
|
||||
@@ -0,0 +1,17 @@
|
||||
use bevy::prelude::Vec3;
|
||||
|
||||
pub trait NearlyEq<Rhs> {
|
||||
fn nearly_eq(self, rhs: Rhs) -> bool;
|
||||
}
|
||||
|
||||
impl NearlyEq<f32> for f32 {
|
||||
fn nearly_eq(self, rhs: f32) -> bool {
|
||||
(self - rhs).abs() < Self::EPSILON
|
||||
}
|
||||
}
|
||||
|
||||
impl NearlyEq<Vec3> for Vec3 {
|
||||
fn nearly_eq(self, rhs: Vec3) -> bool {
|
||||
self.x.nearly_eq(rhs.x) && self.y.nearly_eq(rhs.y) && self.z.nearly_eq(rhs.z)
|
||||
}
|
||||
}
|
||||
+4
-23
@@ -6,7 +6,10 @@ use bevy::{
|
||||
window::{CursorGrabMode, PrimaryWindow},
|
||||
};
|
||||
|
||||
use crate::input::{Action, CameraMotion, InputAction, Lifecycle};
|
||||
use crate::{
|
||||
input::{Action, CameraMotion, InputAction, Lifecycle},
|
||||
math::NearlyEq,
|
||||
};
|
||||
|
||||
pub struct OrbitCamPlugin;
|
||||
|
||||
@@ -286,25 +289,3 @@ fn do_rotate(win: &Window, delta: Vec2, xform: &mut Transform, orbit_cam: &mut O
|
||||
fn curve_sin(t: f32) -> f32 {
|
||||
-1. * (f32::cos(t * consts::PI) / 2.) + 0.5
|
||||
}
|
||||
|
||||
trait NearlyEq {
|
||||
type Rhs;
|
||||
|
||||
fn nearly_eq(self, rhs: Self::Rhs) -> bool;
|
||||
}
|
||||
|
||||
impl NearlyEq for f32 {
|
||||
type Rhs = Self;
|
||||
|
||||
fn nearly_eq(self, rhs: Self::Rhs) -> bool {
|
||||
(self - rhs).abs() < Self::EPSILON
|
||||
}
|
||||
}
|
||||
|
||||
impl NearlyEq for Vec3 {
|
||||
type Rhs = Self;
|
||||
|
||||
fn nearly_eq(self, rhs: Self::Rhs) -> bool {
|
||||
self.x.nearly_eq(rhs.x) && self.y.nearly_eq(rhs.y) && self.z.nearly_eq(rhs.z)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user