1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
use std::num::FpCategory;
use bevy::math::*;
pub trait Vec3Ext {
fn quat_between(&self, other: Vec3) -> Quat;
}
impl Vec3Ext for Vec3 {
fn quat_between(&self, other: Vec3) -> Quat {
let dot = self.dot(other);
if dot > 0.995 || dot < -0.995 {
return Quat::identity();
}
let axis = self.cross(other);
let angle = (self.length_squared() * other.length_squared()).sqrt() + dot;
Quat::from_axis_angle(axis, angle)
}
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct GlobalFriction(pub f32);
impl Default for GlobalFriction {
fn default() -> Self {
Self(0.95)
}
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub enum Mass {
Infinite,
Real(f32),
}
impl Mass {
pub fn inverse(self) -> f32 {
match self {
Self::Infinite => 0.0,
Self::Real(mass) => mass.recip(),
}
}
pub fn scalar(self) -> f32 {
match self {
Self::Infinite => 0.0,
Self::Real(mass) => mass,
}
}
}
impl From<f32> for Mass {
fn from(mass: f32) -> Self {
match mass.classify() {
FpCategory::Normal | FpCategory::Subnormal => Mass::Real(mass),
_ => Mass::Infinite,
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Status {
Static,
Semikinematic,
}
impl Default for Status {
fn default() -> Self {
Status::Semikinematic
}
}