Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Xaeroxe committed Jan 4, 2019
1 parent b122360 commit 5c41546
Showing 1 changed file with 9 additions and 12 deletions.
21 changes: 9 additions & 12 deletions amethyst_utils/src/ortho_camera.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
use amethyst_assets::{PrefabData, PrefabError};
use amethyst_core::{
nalgebra::Orthographic3,
specs::{
Component, DenseVecStorage, Entity, Join, ReadExpect, ReadStorage, System, WriteStorage,
},
specs::{Component, DenseVecStorage, Entity, Join, ReadExpect, System, WriteStorage},
Axis2,
};
use amethyst_renderer::{Camera, ScreenDimensions};
Expand Down Expand Up @@ -70,6 +68,7 @@ pub struct CameraOrtho {
pub mode: CameraNormalizeMode,
/// The world coordinates that this camera will keep visible as the window size changes
pub world_coordinates: CameraOrthoWorldCoordinates,
aspect_ratio_cache: f32,
}

impl CameraOrtho {
Expand All @@ -78,6 +77,7 @@ impl CameraOrtho {
CameraOrtho {
mode,
world_coordinates: Default::default(),
aspect_ratio_cache: 0.0,
}
}

Expand Down Expand Up @@ -204,25 +204,22 @@ impl Default for CameraNormalizeMode {
/// System that automatically changes the camera matrix according to the settings in
/// the `CameraOrtho` attached to the camera entity.
#[derive(Default)]
pub struct CameraOrthoSystem {
aspect_ratio_cache: f32,
}
pub struct CameraOrthoSystem;

impl<'a> System<'a> for CameraOrthoSystem {
type SystemData = (
ReadExpect<'a, ScreenDimensions>,
WriteStorage<'a, Camera>,
ReadStorage<'a, CameraOrtho>,
WriteStorage<'a, CameraOrtho>,
);

#[cfg_attr(feature = "cargo-clippy", allow(float_cmp))] // cmp just used to recognize change
fn run(&mut self, (dimensions, mut cameras, ortho_cameras): Self::SystemData) {
fn run(&mut self, (dimensions, mut cameras, mut ortho_cameras): Self::SystemData) {
let aspect = dimensions.aspect_ratio();

if aspect != self.aspect_ratio_cache {
self.aspect_ratio_cache = aspect;

for (mut camera, ortho_camera) in (&mut cameras, &ortho_cameras).join() {
for (mut camera, mut ortho_camera) in (&mut cameras, &mut ortho_cameras).join() {
if aspect != ortho_camera.aspect_ratio_cache {
ortho_camera.aspect_ratio_cache = aspect;
let offsets = ortho_camera.camera_offsets(aspect);

let prev = Orthographic3::from_matrix_unchecked(camera.proj);
Expand Down

0 comments on commit 5c41546

Please sign in to comment.