mirror of
https://github.com/bevyengine/bevy
synced 2024-11-21 20:23:28 +00:00
fix camera projection
This commit is contained in:
parent
2a27cacba8
commit
21ce87ba45
3 changed files with 23 additions and 20 deletions
|
@ -9,6 +9,9 @@ use bevy::{render::*, asset::{Asset, AssetStorage}, math};
|
|||
fn main() {
|
||||
let universe = Universe::new();
|
||||
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
|
||||
// let mut query = Read::<Transform>::query();
|
||||
let cube = Mesh::load(MeshType::Cube);
|
||||
|
@ -25,21 +28,21 @@ fn main() {
|
|||
(
|
||||
Material::new(math::vec4(0.1, 0.2, 0.1, 1.0)),
|
||||
plane_handle.clone(),
|
||||
LocalToWorld(math::translation(&math::vec3(0.0, 0.0, 0.0))),
|
||||
LocalToWorld::identity(),
|
||||
Translation::new(0.0, 0.0, 0.0)
|
||||
),
|
||||
// cubes
|
||||
(
|
||||
Material::new(math::vec4(0.1, 0.1, 0.6, 1.0)),
|
||||
mesh_handle.clone(),
|
||||
LocalToWorld(math::translation(&math::vec3(1.5, 0.0, 1.0))),
|
||||
Translation::new(0.0, 0.0, 0.0)
|
||||
LocalToWorld::identity(),
|
||||
Translation::new(1.5, 0.0, 1.0)
|
||||
),
|
||||
(
|
||||
Material::new(math::vec4(0.6, 0.1, 0.1, 1.0)),
|
||||
mesh_handle,
|
||||
LocalToWorld(math::translation(&math::vec3(-1.5, 0.0, 1.0))),
|
||||
Translation::new(0.0, 0.0, 0.0)
|
||||
LocalToWorld::identity(),
|
||||
Translation::new(-1.5, 0.0, 1.0)
|
||||
),
|
||||
]);
|
||||
world.insert((), vec![
|
||||
|
@ -57,8 +60,8 @@ fn main() {
|
|||
depth: 1.0 .. 20.0,
|
||||
target_view: None,
|
||||
},
|
||||
LocalToWorld(math::translation(&math::vec3(7.0, -5.0, 10.0))),
|
||||
Translation::new(0.0, 0.0, 0.0)
|
||||
LocalToWorld::identity(),
|
||||
Translation::new(7.0, -5.0, 10.0)
|
||||
),
|
||||
(
|
||||
Light {
|
||||
|
@ -73,8 +76,8 @@ fn main() {
|
|||
depth: 1.0 .. 20.0,
|
||||
target_view: None,
|
||||
},
|
||||
LocalToWorld(math::translation(&math::vec3(-1.5, 0.0, 1.0))),
|
||||
Translation::new(0.0, 0.0, 0.0)
|
||||
LocalToWorld::identity(),
|
||||
Translation::new(-5.0, 7.0, 10.0)
|
||||
),
|
||||
]);
|
||||
world.insert((), vec![
|
||||
|
@ -86,13 +89,13 @@ fn main() {
|
|||
far: 20.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(3.0, -10.0, 6.0),
|
||||
&math::vec3(0.0, 0.0, 0.0),
|
||||
&math::vec3(0.0, 0.0, 1.0),)),
|
||||
Translation::new(0.0, 0.0, 0.0)
|
||||
// Translation::new(0.0, 0.0, 0.0),
|
||||
)
|
||||
]);
|
||||
|
||||
// let transform_system_bundle = transform_system_bundle::build(&mut world);
|
||||
Application::run(universe, world);
|
||||
Application::run(universe, world, scheduler);
|
||||
}
|
|
@ -194,7 +194,7 @@ impl Application {
|
|||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub fn run(universe: Universe, world: World) {
|
||||
pub fn run(universe: Universe, world: World, system_scheduler: SystemScheduler<ApplicationStage>) {
|
||||
env_logger::init();
|
||||
let event_loop = EventLoop::new();
|
||||
log::info!("Initializing the window...");
|
||||
|
@ -242,7 +242,7 @@ impl Application {
|
|||
queue,
|
||||
swap_chain,
|
||||
swap_chain_descriptor,
|
||||
scheduler: SystemScheduler::new(),
|
||||
scheduler: system_scheduler,
|
||||
render_passes: Vec::new(),
|
||||
};
|
||||
|
||||
|
|
|
@ -24,9 +24,9 @@ impl Camera {
|
|||
|
||||
pub fn update(&mut self, width: u32, height: u32) {
|
||||
match &mut self.camera_type {
|
||||
CameraType::Projection { mut aspect_ratio, fov, near, far } => {
|
||||
aspect_ratio = width as f32 / height as f32;
|
||||
self.view_matrix = get_projection_matrix(aspect_ratio, *fov, *near, *far)
|
||||
CameraType::Projection { aspect_ratio, fov, near, far } => {
|
||||
*aspect_ratio = width as f32 / height as f32;
|
||||
self.view_matrix = get_projection_matrix(*fov, *aspect_ratio, *near, *far)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue