This commit is contained in:
Hartmut Seichter 2022-11-16 23:07:49 +01:00
parent c33335fc50
commit b4965a3b05
5 changed files with 727 additions and 546 deletions

View file

@ -1,8 +1,8 @@
use bevy::prelude::*;
// use bevy::render::primitives::Frustum;
use bevy::render::camera::{Camera, CameraProjection, DepthCalculation};
// use bevy::render::view::VisibleEntities;
use bevy::render::primitives::Frustum;
use bevy::render::camera::{Camera, CameraProjection};
use bevy::render::view::VisibleEntities;
#[derive(Component)]
pub struct OffAxisProjection {
@ -24,13 +24,13 @@ impl CameraProjection for OffAxisProjection {
self.aspect = width / height;
}
fn depth_calculation(&self) -> DepthCalculation {
// for 2D (camera doesn't rotate)
DepthCalculation::ZDifference
// fn depth_calculation(&self) -> DepthCalculation {
// // for 2D (camera doesn't rotate)
// DepthCalculation::ZDifference
// otherwise
//DepthCalculation::Distance
}
// // otherwise
// //DepthCalculation::Distance
// }
fn far(&self) -> f32 {
self.far
@ -44,27 +44,35 @@ impl Default for OffAxisProjection {
}
pub fn 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();
let camera = Camera {
// near: projection.near,
// far: projection.far,
..default()
};
/*
print!("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);
// frustum construction code copied from Bevy
let view_projection =
projection.get_projection_matrix() * transform.compute_matrix().inverse();
let frustum = Frustum::from_view_projection(
let frustum = Frustum::from_view_projection(
&view_projection,
&transform.translation,
&transform.back(),
projection.far,
);
);
print!("Setup {0}",line!());
commands.spawn_bundle((
camera,
projection,
@ -72,11 +80,12 @@ pub fn camera_setup(mut commands: Commands) {
VisibleEntities::default(),
transform,
GlobalTransform::default(),
Camera2d,
// Camera2d,
)
);
*/
print!("Setup {0}",line!());
}
// fn main() {