WiP
This commit is contained in:
parent
c33335fc50
commit
b4965a3b05
5 changed files with 727 additions and 546 deletions
45
src/main.rs
45
src/main.rs
|
@ -1,4 +1,5 @@
|
|||
use bevy::prelude::*;
|
||||
use bevy::{prelude::*, window::PresentMode};
|
||||
use crate::scene::{*};
|
||||
|
||||
mod scene;
|
||||
mod offaxis;
|
||||
|
@ -6,25 +7,49 @@ mod offaxis;
|
|||
fn main() {
|
||||
App::new()
|
||||
.insert_resource(ClearColor(Color::rgb(0.0,0.1,0.9)))
|
||||
.insert_resource(WindowDescriptor{
|
||||
title: "PixSpace".to_string(),
|
||||
width: 1280.0,
|
||||
height: 800.0,
|
||||
..Default::default()
|
||||
})
|
||||
|
||||
// .insert_resource(WindowDescriptor{
|
||||
// title: "PixSpace".to_string(),
|
||||
// width: 1280.0,
|
||||
// height: 800.0,
|
||||
// present_mode: PresentMode::AutoVsync,
|
||||
// ..Default::default()
|
||||
// })
|
||||
|
||||
.add_plugins(DefaultPlugins.set(WindowPlugin {
|
||||
window: WindowDescriptor {
|
||||
width: 1280.0,
|
||||
height: 720.0,
|
||||
present_mode: PresentMode::AutoVsync,
|
||||
..default()
|
||||
},
|
||||
..default()
|
||||
}))
|
||||
.add_plugins(DefaultPlugins)
|
||||
.add_plugin(scene::BuildScenePlugin)
|
||||
.add_startup_system(offaxis::camera_setup)
|
||||
// .add_startup_system(offaxis::camera_setup)
|
||||
.add_system(bevy::window::close_on_esc)
|
||||
.add_system(cycle_msaa)
|
||||
// .add_system_to_stage(
|
||||
// CoreStage::PostUpdate,
|
||||
// camera_system::<offaxis::OffAxisProjection>,
|
||||
// )
|
||||
// .add_system(hello_world)
|
||||
// .add_startup_system(add_scene)
|
||||
// .add_system(print_positions)
|
||||
.add_startup_system(build_scene)
|
||||
.add_system(print_positions)
|
||||
.run();
|
||||
}
|
||||
|
||||
|
||||
|
||||
fn cycle_msaa(input: Res<Input<KeyCode>>, mut msaa: ResMut<Msaa>) {
|
||||
if input.just_pressed(KeyCode::M) {
|
||||
if msaa.samples == 4 {
|
||||
info!("Not using MSAA");
|
||||
msaa.samples = 1;
|
||||
} else {
|
||||
info!("Using 4x MSAA");
|
||||
msaa.samples = 4;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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() {
|
||||
|
|
15
src/scene.rs
15
src/scene.rs
|
@ -4,21 +4,19 @@ pub struct BuildScenePlugin;
|
|||
|
||||
impl Plugin for BuildScenePlugin {
|
||||
fn build(&self, app: &mut App) {
|
||||
app
|
||||
.add_startup_system(build_scene)
|
||||
.add_system(print_positions);
|
||||
app.add_startup_system(build_scene) // actual scene
|
||||
.add_system(print_positions); // debugging
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#[derive(Component)]
|
||||
struct Person;
|
||||
|
||||
#[derive(Component)]
|
||||
struct Position { x: f32, y: f32 }
|
||||
pub struct Position { x: f32, y: f32 }
|
||||
|
||||
|
||||
fn build_scene(mut commands: Commands) {
|
||||
pub fn build_scene(mut commands: Commands) {
|
||||
commands.spawn()
|
||||
.insert(Person)
|
||||
.insert(Position { x: 10.0, y: 10.0 } );
|
||||
|
@ -30,9 +28,10 @@ fn build_scene(mut commands: Commands) {
|
|||
// });
|
||||
}
|
||||
|
||||
fn print_positions(query : Query<&Position>) {
|
||||
for position in query.iter() {
|
||||
pub fn print_positions(query : Query<&Position>) {
|
||||
for _position in query.iter() {
|
||||
|
||||
_ = 33;
|
||||
// println!("position {:?} {:?}", position.x, position.y)
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue