Skip to content

Commit

Permalink
Merge pull request #32 from BlackPhlox/bevy_dolly_v2
Browse files Browse the repository at this point in the history
  • Loading branch information
BlackPhlox authored Sep 17, 2023
2 parents af6f811 + 469fe14 commit e94d792
Show file tree
Hide file tree
Showing 16 changed files with 646 additions and 194 deletions.
14 changes: 7 additions & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,17 @@ name = "bevy_config_cam"

[dependencies]
rand = "0.8"
strum = "0.24"
strum_macros = "0.24"
bevy_dolly = { git = "https://github.com/BlackPhlox/bevy_dolly"}
driver_marker_derive = { path = "driver_marker_derive" }
strum = "0.25"
strum_macros = "0.25"
bevy_dolly = "0.0.1"
config_cam_derive = { path = "config_cam_derive" }

[dependencies.bevy]
version = "0.9"
version = "0.11"
features = ["bevy_render","bevy_pbr"]
default-features = false

[dev-dependencies.bevy]
version = "0.9"
version = "0.11"
features = ["bevy_core_pipeline", "bevy_asset", "bevy_scene", "bevy_pbr", "bevy_gltf", "x11", "wayland"]
default-features = false
default-features = false
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = "driver_marker_derive"
name = "config_cam_derive"
version = "0.1.0"
edition = "2021"

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
extern crate proc_macro;

use proc_macro::TokenStream;
use quote::quote;
use syn;

#[proc_macro_derive(DriverMarker)]
pub fn driver_marker_derive(input: TokenStream) -> TokenStream {
// Construct a representation of Rust code as a syntax tree
// that we can manipulate
Expand Down
10 changes: 10 additions & 0 deletions config_cam_derive/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
use proc_macro::TokenStream;

extern crate proc_macro;

mod driver_marker;

#[proc_macro_derive(DriverMarker)]
pub fn driver_marker_derive(input: TokenStream) -> TokenStream {
driver_marker::driver_marker_derive(input)
}
25 changes: 7 additions & 18 deletions examples/minimal.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use bevy::{prelude::*, render::camera::ScalingMode};
use bevy::prelude::*;
use bevy_config_cam::*;

fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_plugin(ConfigCam)
.add_startup_system(setup)
.add_plugins(ConfigCam)
.add_systems(Startup, setup)
.run();
}

Expand All @@ -17,7 +17,10 @@ fn setup(
) {
// plane
commands.spawn(PbrBundle {
mesh: meshes.add(Mesh::from(shape::Plane { size: 5.0 })),
mesh: meshes.add(Mesh::from(shape::Plane {
size: 5.0,
..Default::default()
})),
material: materials.add(Color::rgb(0.3, 0.5, 0.3).into()),
..Default::default()
});
Expand All @@ -35,18 +38,4 @@ fn setup(
transform: Transform::from_xyz(4.0, 8.0, 4.0),
..Default::default()
});

commands.spawn(Camera3dBundle {
camera: Camera {
is_active: true,
..Default::default()
},
projection: OrthographicProjection {
scale: 3.0,
scaling_mode: ScalingMode::FixedVertical(1.0),
..default()
}
.into(),
..Default::default()
});
}
35 changes: 23 additions & 12 deletions examples/multiple_targets.rs
Original file line number Diff line number Diff line change
@@ -1,29 +1,35 @@
use bevy::prelude::*;
use bevy_config_cam::*;
use bevy_config_cam::{driver::driver_core::DriverMarker, *};
use bevy_dolly::prelude::*;
use config_cam_derive::DriverMarker;

fn main() {
App::new()
.insert_resource(Msaa { samples: 4 })
.insert_resource(Msaa::default())
.add_plugins(DefaultPlugins)
.add_plugin(ConfigCam)
.insert_resource(MovementSettings {
.add_rig_component(T1)
.add_dolly_component(MainCamera)
/*.insert_resource(MovementSettings {
sensitivity: 0.00015, // default: 0.00012
speed: 12.0, // default: 12.0
..Default::default()
})
.insert_resource(PlayerSettings {
})*/
/*.insert_resource(PlayerSettings {
pos: Vec3::new(2., 0., 0.),
player_asset: "models/craft_speederA.glb#Scene0",
..Default::default()
})
})*/
.add_startup_system(setup)
.add_system(set_closest_target)
//.add_system(set_closest_target)
.run();
}

#[derive(Component)]
struct MainCamera;

#[derive(DriverMarker, Component, Clone, Copy, Debug)]
struct T1;
#[derive(Component)]
struct T2;

/// set up a simple 3D scene
fn setup(
Expand All @@ -33,7 +39,10 @@ fn setup(
) {
// plane
commands.spawn(PbrBundle {
mesh: meshes.add(Mesh::from(shape::Plane { size: 11.0 })),
mesh: meshes.add(Mesh::from(shape::Plane {
size: 11.0,
..Default::default()
})),
material: materials.add(Color::rgb(0.3, 0.5, 0.3).into()),
..Default::default()
});
Expand All @@ -46,7 +55,7 @@ fn setup(
transform: Transform::from_xyz(-5.0, 0.5, 0.0),
..Default::default()
},
T1,
Target,
));

//Target 2
Expand All @@ -57,7 +66,7 @@ fn setup(
transform: Transform::from_xyz(5.0, 0.5, 0.0),
..Default::default()
},
T2,
Target,
));

// light
Expand All @@ -67,6 +76,7 @@ fn setup(
});
}

/*
fn set_closest_target(
mut cl: ResMut<CamLogic>,
mut transforms: Query<(&PlayerMove, &Transform)>,
Expand Down Expand Up @@ -97,3 +107,4 @@ fn set_closest_target(
cl.target = None;
}
}
*/
109 changes: 70 additions & 39 deletions examples/simple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,11 @@ use std::f32::consts::PI;
use bevy::{
pbr::wireframe::{Wireframe, WireframePlugin},
prelude::*,
render::{
camera::ScalingMode,
settings::{WgpuFeatures, WgpuSettings},
},
};
use bevy_config_cam::driver::driver_core::DriverMarker;
use bevy_config_cam::*;

use driver_marker_derive::DriverMarker;
use config_cam_derive::DriverMarker;

fn main() {
App::new()
Expand All @@ -37,7 +34,10 @@ fn setup(
) {
// plane
commands.spawn(PbrBundle {
mesh: meshes.add(Mesh::from(shape::Plane { size: 5.0 })),
mesh: meshes.add(Mesh::from(shape::Plane {
size: 5.0,
..Default::default()
})),
material: materials.add(Color::rgb(0.3, 0.5, 0.3).into()),
..Default::default()
});
Expand All @@ -63,8 +63,26 @@ fn setup(
));
});

commands
.spawn(SpatialBundle::from_transform(Transform {
rotation: Quat::IDENTITY,
translation: Vec3::new(-2., 0., 0.),
..default()
}))
.with_children(|cell| {
cell.spawn((
Target,
PbrBundle {
mesh: meshes.add(Mesh::from(shape::Cube { size: 1.0 })),
material: materials.add(Color::rgb(0.8, 0.7, 0.6).into()),
transform: Transform::from_xyz(0.0, 0.5, 0.0),
..Default::default()
},
));
});

// light
commands.spawn_bundle(PointLightBundle {
commands.spawn(PointLightBundle {
transform: Transform::from_xyz(4.0, 8.0, 4.0),
..Default::default()
});
Expand All @@ -77,19 +95,17 @@ fn setup(
}).insert(Wireframe);*/

commands
.spawn_bundle(PbrBundle {
mesh: cam.clone(),
material: materials
.add(
Color::Rgba {
red: 0.,
green: 0.,
blue: 0.,
alpha: 0.,
}
.into(),
)
.clone(),
.spawn(PbrBundle {
mesh: cam,
material: materials.add(
Color::Rgba {
red: 0.,
green: 0.,
blue: 0.,
alpha: 0.,
}
.into(),
),
transform: Transform {
translation: Vec3 {
x: 0.0,
Expand All @@ -103,21 +119,28 @@ fn setup(
})
.insert(Wireframe);

commands.spawn_bundle(Camera3dBundle {
camera: Camera {
is_active: true,
/*
commands.spawn((
Camera3dBundle {
camera: Camera {
is_active: true,
..Default::default()
},
projection: OrthographicProjection {
scale: 3.0,
scaling_mode: ScalingMode::FixedVertical(1.0),
..default()
}
.into(),
..Default::default()
},
projection: OrthographicProjection {
scale: 3.0,
scaling_mode: ScalingMode::FixedVertical(1.0),
..default()
}
.into(),
..Default::default()
});
Rig::builder()
.with(Fpv::from_position_target(Transform::default()))
.build(),
CCFpv,
));
commands.spawn_bundle(Camera3dBundle {
commands.spawn(Camera3dBundle {
camera: Camera {
is_active: false,
..Default::default()
Expand All @@ -130,6 +153,7 @@ fn setup(
.into(),
..Default::default()
});
*/

commands.spawn(CameraCount { total: 2, index: 0 });
}
Expand All @@ -143,6 +167,9 @@ struct CameraCount {
#[derive(Component)]
struct Rotates;

#[derive(Component)]
struct Selected;

fn rotator_system(time: Res<Time>, mut query: Query<&mut Transform, With<Rotates>>) {
for mut transform in query.iter_mut() {
*transform = Transform::from_rotation(Quat::from_rotation_y(
Expand All @@ -154,41 +181,45 @@ fn rotator_system(time: Res<Time>, mut query: Query<&mut Transform, With<Rotates
fn remove_target_system(
keys: Res<Input<KeyCode>>,
mut commands: Commands,
q: Query<Entity, (With<Rotates>, With<Target>)>,
q: Query<Entity, (With<Selected>, Without<Target>)>,
) {
if keys.just_pressed(KeyCode::G) {
for e in &q {
commands.entity(e).remove::<Target>();
commands.entity(e).remove::<Rotates>();
println!("Removed Target");
}
}
}

fn add_target_system(
keys: Res<Input<KeyCode>>,
mut commands: Commands,
q: Query<Entity, (With<Rotates>, Without<Target>)>,
q: Query<Entity, (Without<Selected>, With<Target>)>,
) {
if keys.just_pressed(KeyCode::G) {
if keys.just_pressed(KeyCode::H) {
for e in &q {
commands.entity(e).insert(Target);
commands.entity(e).insert(Rotates);
println!("Added Target");
}
}
}

fn switch_camera(
keys: Res<Input<KeyCode>>,
mut commands: Commands,
_commands: Commands,
mut q: Query<&Camera>,
mut q2: Query<&CameraCount>,
) {
let mut cc = q2.single_mut();
let cc = q2.single_mut();
if keys.just_pressed(KeyCode::V) {
for (i, c) in &mut q.iter_mut().enumerate() {
for (i, _c) in &mut q.iter_mut().enumerate() {
if i + 1 > (cc.total - 1).into() {
//cc.index = 0;
//c.is_active = true;
}
if i.eq(&(cc.index + 1 as usize)) {}
if i.eq(&(cc.index + 1_usize)) {}
}
}
}
Loading

0 comments on commit e94d792

Please sign in to comment.