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
pub mod vec_conversor {
use amethyst_core::math::Vector3;
use crate::PtReal;
#[allow(clippy::wrong_self_convention)]
pub fn to_physics<N>(v: &Vector3<f32>) -> Vector3<N>
where
N: PtReal,
{
Vector3::new(v.x.into(), v.y.into(), v.z.into())
}
pub fn from_physics<N>(v: &Vector3<N>) -> Vector3<f32>
where
N: PtReal,
{
Vector3::new(v.x.into(), v.y.into(), v.z.into())
}
}
pub mod quat_conversor {
use amethyst_core::math::{Quaternion, Vector4};
use crate::PtReal;
#[allow(clippy::wrong_self_convention)]
pub fn to_physics<N>(r: &Quaternion<f32>) -> Quaternion<N>
where
N: PtReal,
{
Quaternion::from(Vector4::new(r.i.into(), r.j.into(), r.k.into(), r.w.into()))
}
pub fn from_physics<N>(r: &Quaternion<N>) -> Quaternion<f32>
where
N: PtReal,
{
Quaternion::from(Vector4::new(
N::into(r.i),
N::into(r.j),
N::into(r.k),
N::into(r.w),
))
}
}
pub mod transf_conversor {
use amethyst_core::math::{Isometry3, Translation3, UnitQuaternion};
use crate::{
conversors::{quat_conversor, vec_conversor},
PtReal,
};
#[allow(clippy::wrong_self_convention)]
pub fn to_physics<N>(t: &Isometry3<f32>) -> Isometry3<N>
where
N: PtReal,
{
Isometry3::from_parts(
Translation3::from(vec_conversor::to_physics(&t.translation.vector)),
UnitQuaternion::new_normalize(quat_conversor::to_physics(&t.rotation)),
)
}
pub fn from_physics<N>(t: &Isometry3<N>) -> Isometry3<f32>
where
N: PtReal,
{
Isometry3::from_parts(
Translation3::from(vec_conversor::from_physics(&t.translation.vector)),
UnitQuaternion::new_normalize(quat_conversor::from_physics(&t.rotation)),
)
}
}