minor update

This commit is contained in:
Hartmut Seichter 2022-12-06 15:44:16 +01:00
parent 4a8c9a298a
commit 3b18d1e032
7 changed files with 154 additions and 133 deletions

View file

@ -4,9 +4,7 @@ use bevy::render::camera::{Camera, CameraProjection};
use bevy::render::primitives::Frustum;
use bevy::render::view::VisibleEntities;
use crate::screeninfo::ScreenInfo;
#[derive(Component, Debug, Clone, Reflect)]
#[reflect(Component, Default)]
@ -18,7 +16,9 @@ pub struct OffAxisProjection {
impl CameraProjection for OffAxisProjection {
fn get_projection_matrix(&self) -> Mat4 {
println!("Here we go! {:?}",self);
Mat4::orthographic_rh(-self.aspect, self.aspect, -1.0, 1.0, self.near, self.far)
}
@ -27,14 +27,6 @@ impl CameraProjection for OffAxisProjection {
self.aspect = width / height;
}
// fn depth_calculation(&self) -> DepthCalculation {
// // for 2D (camera doesn't rotate)
// DepthCalculation::ZDifference
// // otherwise
// //DepthCalculation::Distance
// }
fn far(&self) -> f32 {
self.far
}
@ -51,16 +43,9 @@ impl Default for OffAxisProjection {
}
pub fn offaxis_camera_setup(mut commands: Commands) {
print!("Setup {0}", line!());
// We need all the components that Bevy's built-in camera bundles would add
let projection = OffAxisProjection::default();
println!("Setup {0}", line!());
// position the camera like bevy would do by default for 2D:
let transform = Transform::from_xyz(0.0, 0.0, projection.far - 0.1);
@ -73,9 +58,7 @@ pub fn offaxis_camera_setup(mut commands: Commands) {
&transform.back(),
projection.far,
);
print!("Setup {0}\n", line!());
commands.spawn((
bevy::render::camera::CameraRenderGraph::new(bevy::core_pipeline::core_3d::graph::NAME),
projection,
@ -84,24 +67,7 @@ pub fn offaxis_camera_setup(mut commands: Commands) {
GlobalTransform::default(),
VisibleEntities::default(),
Camera::default(),
Camera3d::default()
Camera3d::default(),
ScreenInfo::default()
));
println!("Setup {0}\t{1}\n", line!(), file!());
}
// fn main() {
// // need to add a bevy-internal camera system to update
// // the projection on window resizing
// use bevy::render::camera::camera_system;
// App::new()
// .add_plugins(DefaultPlugins)
// .add_startup_system(setup)
// .add_system_to_stage(
// CoreStage::PostUpdate,
// camera_system::<SimpleOrthoProjection>,
// )
// .run();
// }