rust/lib-hedgewars-engine/src/render/camera.rs
author alfadur
Fri, 22 Mar 2019 21:09:17 +0300
changeset 14729 19358c313ebb
parent 14726 19122a329774
child 14730 65c971417780
permissions -rw-r--r--
fix texture initialization
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,
14729
19358c313ebb fix texture initialization
alfadur
parents: 14726
diff changeset
    18
            zoom: 1.0,
14726
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
}