tinkering around with bevy

This commit is contained in:
Hartmut Seichter 2022-08-07 22:26:12 +02:00
parent 52bb4d43df
commit c33335fc50
5 changed files with 450 additions and 492 deletions

910
Cargo.lock generated

File diff suppressed because it is too large Load diff

View file

@ -6,5 +6,5 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
bevy = "0.7" # make sure this is the latest version
bevy = "0.8" # make sure this is the latest version
# vrpn = "0.1.0" # not compatible with 2021

View file

@ -15,6 +15,7 @@ fn main() {
.add_plugins(DefaultPlugins)
.add_plugin(scene::BuildScenePlugin)
.add_startup_system(offaxis::camera_setup)
.add_system(bevy::window::close_on_esc)
// .add_system_to_stage(
// CoreStage::PostUpdate,
// camera_system::<offaxis::OffAxisProjection>,

View file

@ -1,8 +1,8 @@
use bevy::prelude::*;
use bevy::render::primitives::Frustum;
use bevy::render::camera::{Camera, Camera2d, CameraProjection, DepthCalculation};
use bevy::render::view::VisibleEntities;
// use bevy::render::primitives::Frustum;
use bevy::render::camera::{Camera, CameraProjection, DepthCalculation};
// use bevy::render::view::VisibleEntities;
#[derive(Component)]
pub struct OffAxisProjection {
@ -13,6 +13,7 @@ pub struct OffAxisProjection {
impl CameraProjection for OffAxisProjection {
fn get_projection_matrix(&self) -> Mat4 {
println!("Here we go!");
Mat4::orthographic_rh(
-self.aspect, self.aspect, -1.0, 1.0, self.near, self.far
)
@ -47,10 +48,11 @@ pub fn camera_setup(mut commands: Commands) {
let projection = OffAxisProjection::default();
let camera = Camera {
near: projection.near,
far: projection.far,
// near: projection.near,
// far: projection.far,
..default()
};
/*
// 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
@ -71,7 +73,10 @@ pub fn camera_setup(mut commands: Commands) {
transform,
GlobalTransform::default(),
Camera2d,
));
)
);
*/
}
// fn main() {

View file

@ -22,10 +22,18 @@ fn build_scene(mut commands: Commands) {
commands.spawn()
.insert(Person)
.insert(Position { x: 10.0, y: 10.0 } );
// camera
// commands.spawn_bundle(OffAxisProjection {
// transform: Transform::from_xyz(-2.0, 2.5, 5.0).looking_at(Vec3::ZERO, Vec3::Y),
// ..default()
// });
}
fn print_positions(query : Query<&Position>) {
for position in query.iter() {
println!("position {:?} {:?}", position.x, position.y)
// println!("position {:?} {:?}", position.x, position.y)
}
}