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
use super::Controls;
use glam::{Mat4, Vec3};
#[derive(Clone, Debug, Default)]
pub struct FlatInputs {
    /// move in this direction.
    pub left: f32,
    pub right: f32,
    pub up: f32,
    pub down: f32,
}

#[derive(Clone, Debug)]
pub struct FlatSettings {
    pub zoom: f32,
}

impl Default for FlatSettings {
    fn default() -> Self {
        Self { zoom: 1.0 }
    }
}

#[derive(Clone, Debug)]
pub struct FlatControls {
    inputs: FlatInputs,
    settings: FlatSettings,
    view: Mat4,
    eye: Vec3,
    changed: bool,
}

impl FlatControls {
    pub fn inputs(&self) -> &FlatInputs {
        &self.inputs
    }

    pub fn new(settings: FlatSettings) -> Self {
        Self {
            inputs: FlatInputs::default(),
            settings,
            view: Mat4::IDENTITY,
            eye: Vec3::ZERO,
            changed: true,
        }
    }

    pub fn set_inputs(&mut self, inputs: FlatInputs) {
        self.inputs = inputs;
        self.changed = true;
    }
}

impl Controls for FlatControls {
    fn eye(&self) -> [f32; 3] {
        self.eye.into()
    }

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

        if changed {
            self.view = Mat4::IDENTITY;
        }

        self.changed = false;
        changed
    }

    fn view(&self) -> Mat4 {
        self.view
    }

    fn scale(&self) -> f32 {
        self.settings.zoom
    }
}