diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..13566b8 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..3cb6183 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/phos-neo.iml b/.idea/phos-neo.iml new file mode 100644 index 0000000..d1455ed --- /dev/null +++ b/.idea/phos-neo.iml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Cargo.lock b/Cargo.lock index 51222ae..6342dc6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1285,6 +1285,13 @@ dependencies = [ "thiserror", ] +[[package]] +name = "camera_system" +version = "0.1.0" +dependencies = [ + "bevy", +] + [[package]] name = "cc" version = "1.0.90" @@ -2901,6 +2908,7 @@ version = "0.1.0" dependencies = [ "bevy", "bevy-inspector-egui", + "camera_system", "iyes_perf_ui", "noise 0.8.2", "world_generation", diff --git a/Cargo.toml b/Cargo.toml index 9014617..d6a9e7c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,7 +3,7 @@ members = [ "game/main", "engine/world_generation" -] +, "game/camera_system"] resolver = "2" # Enable a small amount of optimization in debug mode diff --git a/engine/world_generation/src/hex_utils.rs b/engine/world_generation/src/hex_utils.rs index b72edcb..0e8a09d 100644 --- a/engine/world_generation/src/hex_utils.rs +++ b/engine/world_generation/src/hex_utils.rs @@ -3,8 +3,7 @@ use bevy::prelude::*; pub const OUTER_RADIUS: f32 = 1.; pub const INNER_RADIUS: f32 = OUTER_RADIUS * 0.866025404; - pub fn to_hex_pos(pos: Vec3) -> Vec3 { let x = (pos.x + pos.z * 0.5 - (pos.z / 2.).floor()) * (INNER_RADIUS * 2.); return Vec3::new(x, pos.y, pos.z * OUTER_RADIUS * 1.5); -} \ No newline at end of file +} diff --git a/game/camera_system/Cargo.toml b/game/camera_system/Cargo.toml new file mode 100644 index 0000000..507a8ae --- /dev/null +++ b/game/camera_system/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "camera_system" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +bevy = "0.13.1" diff --git a/game/camera_system/src/lib.rs b/game/camera_system/src/lib.rs new file mode 100644 index 0000000..0a9c980 --- /dev/null +++ b/game/camera_system/src/lib.rs @@ -0,0 +1,113 @@ +use crate::prelude::PhosCamera; +use bevy::input::mouse::MouseMotion; +use bevy::prelude::*; +use bevy::window::CursorGrabMode; + +pub mod prelude { + use bevy::prelude::Component; + + #[derive(Component, Default)] + pub struct PhosCamera { + pub min_height: f32, + pub max_height: f32, + pub speed: f32, + } +} + +pub struct PhosCameraPlugin; + +impl Plugin for PhosCameraPlugin { + fn build(&self, app: &mut App) { + app.add_systems(Startup, setup) + .add_systems(Update, (update_camera, grab_mouse)); + } +} + +fn setup(mut commands: Commands) { + commands.spawn(( + Camera3dBundle { + transform: Transform::from_xyz(-200., 300., -200.) + .looking_at(Vec3::new(1000., 0., 1000.), Vec3::Y), + ..default() + }, + PhosCamera { + speed: 100., + ..default() + }, + )); +} +fn update_camera( + mut cam_query: Query<(&PhosCamera, &mut Transform)>, + keyboard_input: Res>, + time: Res