summaryrefslogtreecommitdiff
path: root/engine/src/camera.rs
blob: 362e0d63b3df6450619ab1f6e4d4b34065d89904 (plain)
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
use crate::vector::Vec3;

pub trait Camera
{
    /// Returns the camera position.
    fn position(&self) -> Vec3<f32>;

    /// Returns the position of the camera target.
    fn target(&self) -> Vec3<f32>;

    /// Returns the direction the camera is looking.
    fn direction(&self) -> Vec3<f32>
    {
        self.target() - self.position()
    }

    /// Returns the right direction relative from where the camera is looking.
    fn right(&self) -> Vec3<f32>
    {
        self.direction().cross(&self.global_up()).normalize()
    }

    /// Returns the left direction relative from where the camera is looking.
    fn left(&self) -> Vec3<f32>
    {
        -self.right()
    }

    /// Returns the upwards direction relative from where the camera is looking.
    fn up(&self) -> Vec3<f32>
    {
        let rev_direction = -self.direction();

        rev_direction.cross(&self.right())
    }

    /// Returns the downwards direction relative from where the camera is looking.
    fn down(&self) -> Vec3<f32>
    {
        -self.up()
    }

    /// Returns the global direction upwards.
    ///
    /// The default implementation which returns [`Vec3::UP`] should be fine in most
    /// cases.
    fn global_up(&self) -> Vec3<f32>
    {
        Vec3::UP
    }
}