rust/lib-hedgewars-engine/src/render/camera.rs
author alfadur
Fri, 22 Mar 2019 20:26:29 +0300
changeset 14726 19122a329774
parent 14725 12db7e435ea6
child 14729 19358c313ebb
permissions -rw-r--r--
make world renderer optional + fmt
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
14725
12db7e435ea6 move camera into engine
alfadur
parents:
diff changeset
     1
use integral_geometry::{Point, Rect, Size};
12db7e435ea6 move camera into engine
alfadur
parents:
diff changeset
     2
12db7e435ea6 move camera into engine
alfadur
parents:
diff changeset
     3
#[derive(Debug)]
12db7e435ea6 move camera into engine
alfadur
parents:
diff changeset
     4
pub struct Camera {
12db7e435ea6 move camera into engine
alfadur
parents:
diff changeset
     5
    pub position: Point,
12db7e435ea6 move camera into engine
alfadur
parents:
diff changeset
     6
    pub zoom: f32,
14726
19122a329774 make world renderer optional + fmt
alfadur
parents: 14725
diff changeset
     7
    size: Size,
14725
12db7e435ea6 move camera into engine
alfadur
parents:
diff changeset
     8
}
12db7e435ea6 move camera into engine
alfadur
parents:
diff changeset
     9
12db7e435ea6 move camera into engine
alfadur
parents:
diff changeset
    10
impl Camera {
12db7e435ea6 move camera into engine
alfadur
parents:
diff changeset
    11
    pub fn new() -> Self {
14726
19122a329774 make world renderer optional + fmt
alfadur
parents: 14725
diff changeset
    12
        Self::with_size(Size::new(1024, 768))
19122a329774 make world renderer optional + fmt
alfadur
parents: 14725
diff changeset
    13
    }
19122a329774 make world renderer optional + fmt
alfadur
parents: 14725
diff changeset
    14
19122a329774 make world renderer optional + fmt
alfadur
parents: 14725
diff changeset
    15
    pub fn with_size(size: Size) -> Self {
19122a329774 make world renderer optional + fmt
alfadur
parents: 14725
diff changeset
    16
        Self {
19122a329774 make world renderer optional + fmt
alfadur
parents: 14725
diff changeset
    17
            position: Point::ZERO,
19122a329774 make world renderer optional + fmt
alfadur
parents: 14725
diff changeset
    18
            zoom: 0.0,
19122a329774 make world renderer optional + fmt
alfadur
parents: 14725
diff changeset
    19
            size,
19122a329774 make world renderer optional + fmt
alfadur
parents: 14725
diff changeset
    20
        }
14725
12db7e435ea6 move camera into engine
alfadur
parents:
diff changeset
    21
    }
12db7e435ea6 move camera into engine
alfadur
parents:
diff changeset
    22
12db7e435ea6 move camera into engine
alfadur
parents:
diff changeset
    23
    pub fn viewport(&self) -> Rect {
12db7e435ea6 move camera into engine
alfadur
parents:
diff changeset
    24
        Rect::from_size(self.position, self.size)
12db7e435ea6 move camera into engine
alfadur
parents:
diff changeset
    25
    }
14726
19122a329774 make world renderer optional + fmt
alfadur
parents: 14725
diff changeset
    26
}