tinkering around with bevy
This commit is contained in:
parent
52bb4d43df
commit
c33335fc50
5 changed files with 450 additions and 492 deletions
910
Cargo.lock
generated
910
Cargo.lock
generated
File diff suppressed because it is too large
Load diff
|
@ -6,5 +6,5 @@ edition = "2021"
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
[dependencies]
|
[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
|
# vrpn = "0.1.0" # not compatible with 2021
|
||||||
|
|
|
@ -15,6 +15,7 @@ fn main() {
|
||||||
.add_plugins(DefaultPlugins)
|
.add_plugins(DefaultPlugins)
|
||||||
.add_plugin(scene::BuildScenePlugin)
|
.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_to_stage(
|
// .add_system_to_stage(
|
||||||
// CoreStage::PostUpdate,
|
// CoreStage::PostUpdate,
|
||||||
// camera_system::<offaxis::OffAxisProjection>,
|
// camera_system::<offaxis::OffAxisProjection>,
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
use bevy::prelude::*;
|
use bevy::prelude::*;
|
||||||
|
|
||||||
use bevy::render::primitives::Frustum;
|
// use bevy::render::primitives::Frustum;
|
||||||
use bevy::render::camera::{Camera, Camera2d, CameraProjection, DepthCalculation};
|
use bevy::render::camera::{Camera, CameraProjection, DepthCalculation};
|
||||||
use bevy::render::view::VisibleEntities;
|
// use bevy::render::view::VisibleEntities;
|
||||||
|
|
||||||
#[derive(Component)]
|
#[derive(Component)]
|
||||||
pub struct OffAxisProjection {
|
pub struct OffAxisProjection {
|
||||||
|
@ -13,6 +13,7 @@ pub struct OffAxisProjection {
|
||||||
|
|
||||||
impl CameraProjection for OffAxisProjection {
|
impl CameraProjection for OffAxisProjection {
|
||||||
fn get_projection_matrix(&self) -> Mat4 {
|
fn get_projection_matrix(&self) -> Mat4 {
|
||||||
|
println!("Here we go!");
|
||||||
Mat4::orthographic_rh(
|
Mat4::orthographic_rh(
|
||||||
-self.aspect, self.aspect, -1.0, 1.0, self.near, self.far
|
-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 projection = OffAxisProjection::default();
|
||||||
let camera = Camera {
|
let camera = Camera {
|
||||||
near: projection.near,
|
// near: projection.near,
|
||||||
far: projection.far,
|
// far: projection.far,
|
||||||
..default()
|
..default()
|
||||||
};
|
};
|
||||||
|
/*
|
||||||
// position the camera like bevy would do by default for 2D:
|
// position the camera like bevy would do by default for 2D:
|
||||||
let transform = Transform::from_xyz(0.0, 0.0, projection.far - 0.1);
|
let transform = Transform::from_xyz(0.0, 0.0, projection.far - 0.1);
|
||||||
// frustum construction code copied from Bevy
|
// frustum construction code copied from Bevy
|
||||||
|
@ -71,7 +73,10 @@ pub fn camera_setup(mut commands: Commands) {
|
||||||
transform,
|
transform,
|
||||||
GlobalTransform::default(),
|
GlobalTransform::default(),
|
||||||
Camera2d,
|
Camera2d,
|
||||||
));
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
// fn main() {
|
// fn main() {
|
||||||
|
|
10
src/scene.rs
10
src/scene.rs
|
@ -22,10 +22,18 @@ fn build_scene(mut commands: Commands) {
|
||||||
commands.spawn()
|
commands.spawn()
|
||||||
.insert(Person)
|
.insert(Person)
|
||||||
.insert(Position { x: 10.0, y: 10.0 } );
|
.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>) {
|
fn print_positions(query : Query<&Position>) {
|
||||||
for position in query.iter() {
|
for position in query.iter() {
|
||||||
println!("position {:?} {:?}", position.x, position.y)
|
|
||||||
|
// println!("position {:?} {:?}", position.x, position.y)
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue