hex coords

This commit is contained in:
2024-03-27 22:02:15 -04:00
parent 5c9b5efbf8
commit c4da9ab87a
7 changed files with 191 additions and 37 deletions

View File

@@ -19,7 +19,7 @@ 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));
.add_systems(Update, (update_camera, grab_mouse, update_camera_mouse));
}
}
@@ -84,14 +84,15 @@ fn update_camera_mouse(
let (mut pitch, mut yaw, _) = transform.rotation.to_euler(EulerRot::XYZ);
pitch -= cam_rot.y.to_radians() ;
yaw -= cam_rot.x.to_radians() ;
pitch -= cam_rot.y.to_radians();
yaw -= cam_rot.x.to_radians();
pitch = pitch.clamp(-1.54, 1.54);
// if rot_x > PI && cam_rot.x < 2. * PI {
// rot_x = PI;
// }
transform.rotation = Quat::from_axis_angle(Vec3::Y, yaw) * Quat::from_axis_angle(Vec3::X, pitch);
transform.rotation =
Quat::from_axis_angle(Vec3::Y, yaw) * Quat::from_axis_angle(Vec3::X, pitch);
}
fn grab_mouse(

View File

@@ -1,10 +1,12 @@
use bevy::{pbr::CascadeShadowConfig, prelude::*};
use camera_system::PhosCameraPlugin;
use iyes_perf_ui::prelude::*;
use world_generation::hex_utils::offset_to_world;
use world_generation::{
heightmap::generate_heightmap, hex_utils::to_hex_pos, mesh_generator::generate_chunk_mesh,
prelude::*,
heightmap::generate_heightmap, hex_utils::offset3d_to_world,
mesh_generator::generate_chunk_mesh, prelude::*,
};
pub struct PhosGamePlugin;
impl Plugin for PhosGamePlugin {
@@ -74,10 +76,7 @@ fn create_map(
for chunk in heightmap.chunks {
let mesh = generate_chunk_mesh(&chunk);
let pos = to_hex_pos(
Vec3::new(chunk.chunk_offset.x as f32, 0., chunk.chunk_offset.y as f32)
* chunk.size as f32,
);
let pos = offset_to_world(chunk.chunk_offset * Chunk::SIZE as i32);
commands.spawn(PbrBundle {
mesh: meshes.add(mesh),
material: debug_material.clone(),