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
96
97
98
99
100
101
102
103
104
105
use prelude::*;
#[derive (Default, Debug, PartialEq, PartialOrd, Clone)]
pub struct Matrix4Pipe {
pub mtranslation: Matrix4,
pub mrotation: Matrix4,
pub mscale: Matrix4,
pub mperspective: Matrix4,
pub mcamtrans: Matrix4,
pub mcamlook: Matrix4
}
impl Matrix4Pipe {
pub fn result(&self) -> Matrix4 {
self.mperspective.clone()
* self.mcamlook.clone()
* self.mcamtrans.clone()
* self.mtranslation.clone()
* self.mrotation.clone()
* self.mscale.clone()
}
pub fn add_translation(&mut self, x: f64, y: f64, z: f64) {
self.mtranslation = Matrix4::translation(x, y, z);
}
pub fn remove_translation(&mut self) {
self.mtranslation = Matrix4::default();
}
pub fn add_rotation(&mut self, x: Rad, y: Rad, z: Rad) {
self.mrotation = Matrix4::rotation(x, y, z);
}
pub fn add_rotation_axis<N>(&mut self, axis: &N, rad: Rad) where
N: IsNormalized3D {
self.mrotation = Matrix4::rotation_axis(axis, rad)
}
pub fn remove_rotation(&mut self) {
self.mrotation = Matrix4::default();
}
pub fn add_scale(&mut self, x: f64, y: f64, z: f64) {
self.mscale = Matrix4::scale(x, y, z);
}
pub fn remove_scale(&mut self) {
self.mscale = Matrix4::default();
}
pub fn add_perspective(&mut self, close: f64, away: f64, rad: Rad) {
self.mperspective = Matrix4::perspective(close, away, rad);
}
pub fn remove_perspective(&mut self) {
self.mperspective = Matrix4::default();
}
pub fn add_camera_translation(&mut self, x: f64, y: f64, z: f64) {
self.mcamtrans = Matrix4::translation(-x, -y, -z);
}
pub fn remove_camera_translation(&mut self) {
self.mcamtrans = Matrix4::default();
}
pub fn add_look_at<P, N>(&mut self, target: &P, up: &N) -> Result<()> where
P: IsBuildable3D,
N: IsNormalized3D {
self.mcamlook = Matrix4::look_at(target, up)?;
Ok(())
}
pub fn remove_look_at(&mut self) {
self.mcamlook = Matrix4::default();
}
}