first step done: we have a custom and updatable matrix

This commit is contained in:
Hartmut Seichter 2022-12-05 23:01:16 +01:00
parent 8234a61364
commit 4a8c9a298a
7 changed files with 360 additions and 180 deletions

View file

@ -4,16 +4,21 @@ use bevy::render::camera::{Camera, CameraProjection};
use bevy::render::primitives::Frustum;
use bevy::render::view::VisibleEntities;
#[derive(Component)]
#[derive(Component, Debug, Clone, Reflect)]
#[reflect(Component, Default)]
pub struct OffAxisProjection {
near: f32,
far: f32,
pub far: f32,
aspect: f32,
}
impl CameraProjection for OffAxisProjection {
fn get_projection_matrix(&self) -> Mat4 {
println!("Here we go!");
println!("Here we go! {:?}",self);
Mat4::orthographic_rh(-self.aspect, self.aspect, -1.0, 1.0, self.near, self.far)
}
@ -45,23 +50,20 @@ impl Default for OffAxisProjection {
}
}
pub fn camera_setup(mut commands: Commands) {
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();
let camera = Camera {
// near: projection.near,
// far: projection.far,
..default()
};
print!("Setup {0}", line!());
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);
// frustum construction code copied from Bevy
let view_projection = projection.get_projection_matrix() * transform.compute_matrix().inverse();
@ -75,15 +77,17 @@ pub fn camera_setup(mut commands: Commands) {
print!("Setup {0}\n", line!());
commands.spawn((
camera,
bevy::render::camera::CameraRenderGraph::new(bevy::core_pipeline::core_3d::graph::NAME),
projection,
frustum,
VisibleEntities::default(),
transform,
GlobalTransform::default(),
VisibleEntities::default(),
Camera::default(),
Camera3d::default()
));
print!("Setup {0}\t{1}\n", line!(), file!());
println!("Setup {0}\t{1}\n", line!(), file!());
}
// fn main() {