finally realized that bevy uses right handed coords
This commit is contained in:
@@ -2,7 +2,6 @@ use core::f32;
|
||||
|
||||
use bevy::math::{IVec2, UVec2};
|
||||
use bevy::prelude::{FloatExt, Vec2};
|
||||
use bevy::render::render_resource::encase::internal::BufferMut;
|
||||
use bevy::utils::default;
|
||||
use noise::{NoiseFn, SuperSimplex};
|
||||
use rayon::iter::{IntoParallelIterator, ParallelIterator};
|
||||
|
||||
@@ -72,12 +72,12 @@ impl Display for HexCoord {
|
||||
|
||||
impl HexCoord {
|
||||
pub const DIRECTIONS: [IVec3; 6] = [
|
||||
IVec3::new(1, -1, 0),
|
||||
IVec3::new(1, 0, -1),
|
||||
IVec3::new(0, 1, -1),
|
||||
IVec3::new(-1, 1, 0),
|
||||
IVec3::new(-1, 0, 1),
|
||||
IVec3::new(1, 0, -1),
|
||||
IVec3::new(1, -1, 0),
|
||||
IVec3::new(0, -1, 1),
|
||||
IVec3::new(-1, 0, 1),
|
||||
IVec3::new(-1, 1, 0),
|
||||
];
|
||||
|
||||
pub const ZERO: HexCoord = HexCoord { hex: IVec3::ZERO };
|
||||
|
||||
@@ -11,7 +11,7 @@ impl MeshChunkData {
|
||||
pub fn get_neighbors(&self, coord: &HexCoord) -> [f32; 6] {
|
||||
let mut data = [0.; 6];
|
||||
let n_tiles = coord.get_neighbors();
|
||||
for i in 6..0 {
|
||||
for i in 0..6 {
|
||||
let n = n_tiles[i];
|
||||
if !n.is_in_bounds(Chunk::SIZE, Chunk::SIZE) {
|
||||
continue;
|
||||
|
||||
@@ -106,6 +106,9 @@ fn hq_placement(
|
||||
if let Some((_e, dist)) = collision {
|
||||
let contact_point = cam_ray.get_point(dist);
|
||||
let contact_coord = HexCoord::from_world_pos(contact_point);
|
||||
if !map.is_in_bounds(&contact_coord) {
|
||||
return;
|
||||
}
|
||||
let positions = map.hex_select(&contact_coord, 3, true, |pos, h, _| pos.to_world(h));
|
||||
show_indicators(positions, &mut commands, &indicator);
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@ fn setup(mut commands: Commands, mut msaa: ResMut<Msaa>) {
|
||||
commands
|
||||
.spawn((
|
||||
Camera3dBundle {
|
||||
transform: Transform::from_xyz(0., 30., 0.).looking_to(Vec3::Z, Vec3::Y),
|
||||
transform: Transform::from_xyz(0., 30., 0.).looking_to(Vec3::NEG_Z, Vec3::Y),
|
||||
..default()
|
||||
},
|
||||
PhosCamera::default(),
|
||||
@@ -138,15 +138,15 @@ fn rts_camera_system(
|
||||
let mut cam_pos = cam.translation;
|
||||
|
||||
if key.pressed(KeyCode::KeyA) {
|
||||
cam_move.x = 1.;
|
||||
} else if key.pressed(KeyCode::KeyD) {
|
||||
cam_move.x = -1.;
|
||||
} else if key.pressed(KeyCode::KeyD) {
|
||||
cam_move.x = 1.;
|
||||
}
|
||||
|
||||
if key.pressed(KeyCode::KeyW) {
|
||||
cam_move.z = 1.;
|
||||
} else if key.pressed(KeyCode::KeyS) {
|
||||
cam_move.z = -1.;
|
||||
} else if key.pressed(KeyCode::KeyS) {
|
||||
cam_move.z = 1.;
|
||||
}
|
||||
|
||||
let move_speed = if key.pressed(KeyCode::ShiftLeft) {
|
||||
@@ -156,7 +156,7 @@ fn rts_camera_system(
|
||||
};
|
||||
|
||||
cam_move = cam_move.normalize_or_zero() * move_speed * time.delta_seconds();
|
||||
cam_pos -= cam_move;
|
||||
cam_pos += cam_move;
|
||||
|
||||
let mut scroll = 0.0;
|
||||
for e in wheel.read() {
|
||||
@@ -209,8 +209,11 @@ fn rts_camera_system(
|
||||
cam_targets.rotate_time = cam_targets.rotate_time.min(1.);
|
||||
}
|
||||
let angle = cam_cfg.min_angle.lerp(cam_cfg.max_angle, t);
|
||||
let rot = Quat::from_axis_angle(Vec3::X, -angle);
|
||||
cam.rotation = rot;
|
||||
let mut rot = cam.rotation.to_euler(EulerRot::XYZ);
|
||||
rot.0 = -angle;
|
||||
cam.rotation = Quat::from_euler(EulerRot::XYZ, rot.0, rot.1, rot.2);
|
||||
// let rot = Quat::from_axis_angle(Vec3::X, -angle);
|
||||
// cam.rotation = rot;
|
||||
|
||||
cam.translation = cam_pos;
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ impl Default for PhosCameraTargets {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
height: Default::default(),
|
||||
forward: Vec3::Z,
|
||||
forward: Vec3::NEG_Z,
|
||||
last_height: Default::default(),
|
||||
anim_time: Default::default(),
|
||||
rotate_time: Default::default(),
|
||||
|
||||
@@ -55,7 +55,7 @@ impl Plugin for MapInitPlugin {
|
||||
app.register_asset_reflect::<ExtendedMaterial<StandardMaterial, WaterMaterial>>();
|
||||
app.add_plugins((
|
||||
ChunkRebuildPlugin,
|
||||
TerraFormingTestPlugin,
|
||||
// TerraFormingTestPlugin,
|
||||
MaterialPlugin::<ExtendedMaterial<StandardMaterial, ChunkMaterial>>::default(),
|
||||
MaterialPlugin::<ExtendedMaterial<StandardMaterial, WaterMaterial>> {
|
||||
prepass_enabled: false,
|
||||
|
||||
@@ -69,6 +69,9 @@ fn deform(
|
||||
let span = info_span!("Deform Mesh").entered();
|
||||
let contact_point = cam_ray.get_point(dist);
|
||||
let contact_coord = HexCoord::from_world_pos(contact_point);
|
||||
if !heightmap.is_in_bounds(&contact_coord) {
|
||||
return;
|
||||
}
|
||||
let modified_tiles = heightmap.create_crater(&contact_coord, 5, 5. * multi);
|
||||
let mut chunk_set: HashSet<usize> = HashSet::new();
|
||||
for (tile, height) in modified_tiles {
|
||||
|
||||
@@ -81,7 +81,9 @@ fn show_tile_heights(
|
||||
if let Some((_e, dist)) = collision {
|
||||
let contact_point = cam_ray.get_point(dist);
|
||||
let contact_coord = HexCoord::from_world_pos(contact_point);
|
||||
if map.is_in_bounds(&contact_coord) {
|
||||
if !map.is_in_bounds(&contact_coord) {
|
||||
return;
|
||||
}
|
||||
let height = map.sample_height(&contact_coord);
|
||||
gizmos.primitive_3d(
|
||||
&shape.0,
|
||||
@@ -89,17 +91,24 @@ fn show_tile_heights(
|
||||
Quat::IDENTITY,
|
||||
Color::WHITE,
|
||||
);
|
||||
}
|
||||
let nbors = map.get_neighbors(&contact_coord);
|
||||
let contact_tile_pos = contact_coord.to_world(map.sample_height(&contact_coord));
|
||||
|
||||
for i in 0..6 {
|
||||
if let Some(s) = nbors[i] {
|
||||
let coord = contact_coord.get_neighbor(i);
|
||||
let p = coord.to_world(s);
|
||||
gizmos.arrow(p, p + Vec3::Y * (i as f32 + 1.0), Color::WHITE);
|
||||
}
|
||||
|
||||
let p = HEX_CORNERS[i] + contact_tile_pos;
|
||||
gizmos.arrow(p, p + Vec3::Y * (i as f32 + 1.0), LinearRgba::rgb(1.0, 0.0, 0.5));
|
||||
}
|
||||
|
||||
gizmos.sphere(contact_point, Quat::IDENTITY, 0.1, Srgba::rgb(1., 0., 0.5));
|
||||
gizmos.line(contact_point, contact_point + Vec3::X, LinearRgba::RED);
|
||||
gizmos.line(contact_point, contact_point + Vec3::Y, LinearRgba::GREEN);
|
||||
gizmos.line(contact_point, contact_point + Vec3::Z, LinearRgba::BLUE);
|
||||
//gizmos.sphere(contact_point, Quat::IDENTITY, 0.1, LinearRgba::rgb(1., 0., 0.5));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user