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
use crate::uses::*;

#[derive(Default)]
pub struct Camera {
	proj: M4,
	view: M4,
	view_proj: M4,
}
impl Camera {
	pub fn new(p: M4, v: M4) -> Self {
		Self {
			proj: p,
			view: v,
			view_proj: p * v,
		}
	}
	pub fn setProj(&mut self, p: M4) {
		self.proj = p;
		self.view_proj = p * self.view;
	}
	pub fn setView(&mut self, v: M4) {
		self.view = v;
		self.view_proj = self.proj * v;
	}
	pub fn V(&self) -> Mat4 {
		Mat4::to(self.view)
	}
	pub fn VP(&self) -> Mat4 {
		Mat4::to(self.view_proj)
	}
	pub fn MV(&self, model: &M4) -> Mat4 {
		Mat4::to(self.view * model)
	}
	pub fn MVP(&self, model: &M4) -> Mat4 {
		Mat4::to(self.view_proj * model)
	}
	pub fn N(&self, model: &M4) -> Mat3 {
		Mat3::to(glm::inverse_transpose(model.fixed_resize(0.)))
	}
	pub fn NV(&self, model: &M4) -> Mat3 {
		Mat3::to(glm::inverse_transpose((self.view * model).fixed_resize(0.)))
	}
}
type M3 = glm::Mat3;
type M4 = glm::Mat4;