fix camera projection

This commit is contained in:
Carter Anderson 2019-12-02 15:51:24 -08:00
parent 2a27cacba8
commit 21ce87ba45
3 changed files with 23 additions and 20 deletions

View file

@ -9,6 +9,9 @@ use bevy::{render::*, asset::{Asset, AssetStorage}, math};
fn main() { fn main() {
let universe = Universe::new(); let universe = Universe::new();
let mut world = universe.create_world(); let mut world = universe.create_world();
let mut scheduler = SystemScheduler::<ApplicationStage>::new();
let transform_system_bundle = transform_system_bundle::build(&mut world);
scheduler.add_systems(ApplicationStage::Update, transform_system_bundle);
// Create a query which finds all `Position` and `Velocity` components // Create a query which finds all `Position` and `Velocity` components
// let mut query = Read::<Transform>::query(); // let mut query = Read::<Transform>::query();
let cube = Mesh::load(MeshType::Cube); let cube = Mesh::load(MeshType::Cube);
@ -25,21 +28,21 @@ fn main() {
( (
Material::new(math::vec4(0.1, 0.2, 0.1, 1.0)), Material::new(math::vec4(0.1, 0.2, 0.1, 1.0)),
plane_handle.clone(), plane_handle.clone(),
LocalToWorld(math::translation(&math::vec3(0.0, 0.0, 0.0))), LocalToWorld::identity(),
Translation::new(0.0, 0.0, 0.0) Translation::new(0.0, 0.0, 0.0)
), ),
// cubes // cubes
( (
Material::new(math::vec4(0.1, 0.1, 0.6, 1.0)), Material::new(math::vec4(0.1, 0.1, 0.6, 1.0)),
mesh_handle.clone(), mesh_handle.clone(),
LocalToWorld(math::translation(&math::vec3(1.5, 0.0, 1.0))), LocalToWorld::identity(),
Translation::new(0.0, 0.0, 0.0) Translation::new(1.5, 0.0, 1.0)
), ),
( (
Material::new(math::vec4(0.6, 0.1, 0.1, 1.0)), Material::new(math::vec4(0.6, 0.1, 0.1, 1.0)),
mesh_handle, mesh_handle,
LocalToWorld(math::translation(&math::vec3(-1.5, 0.0, 1.0))), LocalToWorld::identity(),
Translation::new(0.0, 0.0, 0.0) Translation::new(-1.5, 0.0, 1.0)
), ),
]); ]);
world.insert((), vec![ world.insert((), vec![
@ -57,8 +60,8 @@ fn main() {
depth: 1.0 .. 20.0, depth: 1.0 .. 20.0,
target_view: None, target_view: None,
}, },
LocalToWorld(math::translation(&math::vec3(7.0, -5.0, 10.0))), LocalToWorld::identity(),
Translation::new(0.0, 0.0, 0.0) Translation::new(7.0, -5.0, 10.0)
), ),
( (
Light { Light {
@ -73,8 +76,8 @@ fn main() {
depth: 1.0 .. 20.0, depth: 1.0 .. 20.0,
target_view: None, target_view: None,
}, },
LocalToWorld(math::translation(&math::vec3(-1.5, 0.0, 1.0))), LocalToWorld::identity(),
Translation::new(0.0, 0.0, 0.0) Translation::new(-5.0, 7.0, 10.0)
), ),
]); ]);
world.insert((), vec![ world.insert((), vec![
@ -86,13 +89,13 @@ fn main() {
far: 20.0, far: 20.0,
aspect_ratio: 1.0, aspect_ratio: 1.0,
}), }),
LocalToWorld(math::look_at_rh(&math::vec3(3.0, -10.0, 6.0), LocalToWorld(math::look_at_rh(
&math::vec3(0.0, 0.0, 0.0), &math::vec3(3.0, -10.0, 6.0),
&math::vec3(0.0, 0.0, 1.0),)), &math::vec3(0.0, 0.0, 0.0),
Translation::new(0.0, 0.0, 0.0) &math::vec3(0.0, 0.0, 1.0),)),
// Translation::new(0.0, 0.0, 0.0),
) )
]); ]);
// let transform_system_bundle = transform_system_bundle::build(&mut world); Application::run(universe, world, scheduler);
Application::run(universe, world);
} }

View file

@ -194,7 +194,7 @@ impl Application {
} }
#[allow(dead_code)] #[allow(dead_code)]
pub fn run(universe: Universe, world: World) { pub fn run(universe: Universe, world: World, system_scheduler: SystemScheduler<ApplicationStage>) {
env_logger::init(); env_logger::init();
let event_loop = EventLoop::new(); let event_loop = EventLoop::new();
log::info!("Initializing the window..."); log::info!("Initializing the window...");
@ -242,7 +242,7 @@ impl Application {
queue, queue,
swap_chain, swap_chain,
swap_chain_descriptor, swap_chain_descriptor,
scheduler: SystemScheduler::new(), scheduler: system_scheduler,
render_passes: Vec::new(), render_passes: Vec::new(),
}; };

View file

@ -24,9 +24,9 @@ impl Camera {
pub fn update(&mut self, width: u32, height: u32) { pub fn update(&mut self, width: u32, height: u32) {
match &mut self.camera_type { match &mut self.camera_type {
CameraType::Projection { mut aspect_ratio, fov, near, far } => { CameraType::Projection { aspect_ratio, fov, near, far } => {
aspect_ratio = width as f32 / height as f32; *aspect_ratio = width as f32 / height as f32;
self.view_matrix = get_projection_matrix(aspect_ratio, *fov, *near, *far) self.view_matrix = get_projection_matrix(*fov, *aspect_ratio, *near, *far)
} }
} }
} }