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
use super::projection::Projection;

#[derive(Clone, Debug)]
pub struct Camera<Controls>
where
    Controls: super::controls::Controls,
{
    projection: Projection,
    controls: Controls,
    changed: bool,
}

impl<Controls> Camera<Controls>
where
    Controls: super::controls::Controls,
{
    pub fn controls(&self) -> &Controls {
        &self.controls
    }

    pub fn controls_mut(&mut self) -> &mut Controls {
        &mut self.controls
    }

    pub fn eye(&self) -> [f32; 3] {
        self.controls.eye()
    }

    pub fn new(projection: Projection, controls: Controls) -> Self {
        Self {
            projection,
            controls,
            changed: true,
        }
    }

    pub fn projection(&self) -> mint::ColumnMatrix4<f32> {
        self.projection.into()
    }

    pub fn set_controls(&mut self, controls: Controls) -> Controls {
        let controls = std::mem::replace(&mut self.controls, controls);
        self.changed = true;
        controls
    }

    pub fn set_projection(&mut self, projection: Projection) {
        self.projection = projection;
        self.changed = true;
    }

    pub fn update(&mut self, delta: f32) -> bool {
        let mut changed = self.changed;

        changed |= self.controls.update(delta);

        self.changed = false;
        changed
    }

    pub fn view(&self) -> mint::ColumnMatrix4<f32> {
        self.controls.view()
    }

    pub fn scale(&self) -> f32 {
        self.controls.scale()
    }
}