various fixes to map size calculations
This commit is contained in:
@@ -2,7 +2,10 @@ use crate::prelude::Chunk;
|
||||
use bevy::prelude::*;
|
||||
|
||||
pub const OUTER_RADIUS: f32 = 1.;
|
||||
pub const INNER_RADIUS: f32 = OUTER_RADIUS * 0.866025404;
|
||||
pub const INNER_RADIUS: f32 = OUTER_RADIUS * (SQRT_3 / 2.);
|
||||
pub const SHORT_DIAGONAL: f32 = 1. * SQRT_3;
|
||||
pub const LONG_DIAGONAL: f32 = 2. * OUTER_RADIUS;
|
||||
const SQRT_3: f32 = 1.7320508076;
|
||||
|
||||
pub fn offset3d_to_world(offset: Vec3) -> Vec3 {
|
||||
let x = (offset.x + (offset.z * 0.5) - (offset.z / 2.).floor()) * (INNER_RADIUS * 2.);
|
||||
@@ -41,11 +44,11 @@ pub fn world_to_offset_pos(world_pos: Vec3) -> IVec2 {
|
||||
return IVec2::new(ox, oz);
|
||||
}
|
||||
|
||||
pub fn tile_to_world_distance(dist: i32) -> f32 {
|
||||
pub fn tile_to_world_distance(dist: u32) -> f32 {
|
||||
return dist as f32 * (2. * INNER_RADIUS);
|
||||
}
|
||||
|
||||
pub fn get_tile_count(radius: i32) -> i32 {
|
||||
pub fn get_tile_count(radius: u32) -> u32 {
|
||||
return 1 + 3 * (radius + 1) * radius;
|
||||
}
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ pub mod tile_manager;
|
||||
pub mod tile_mapper;
|
||||
|
||||
pub mod prelude {
|
||||
use crate::hex_utils::{tile_to_world_distance, HexCoord, INNER_RADIUS, OUTER_RADIUS};
|
||||
use crate::hex_utils::{tile_to_world_distance, HexCoord, INNER_RADIUS, OUTER_RADIUS, SHORT_DIAGONAL};
|
||||
use bevy::math::{IVec2, UVec2, Vec2, Vec3};
|
||||
use bevy::prelude::Resource;
|
||||
use bevy::prelude::*;
|
||||
@@ -77,6 +77,9 @@ pub mod prelude {
|
||||
|
||||
impl Chunk {
|
||||
pub const SIZE: usize = 64;
|
||||
pub const WORLD_WIDTH: f32 = Chunk::SIZE as f32 * SHORT_DIAGONAL;
|
||||
pub const WORLD_HEIGHT: f32 = Chunk::SIZE as f32 * 1.5;
|
||||
pub const WORLD_SIZE: Vec2 = Vec2::new(Chunk::WORLD_WIDTH, Chunk::WORLD_HEIGHT);
|
||||
}
|
||||
|
||||
#[derive(Resource)]
|
||||
@@ -111,6 +114,10 @@ pub mod prelude {
|
||||
return chunk.heights[pos.to_chunk_local_index()];
|
||||
}
|
||||
|
||||
pub fn is_in_bounds(&self, pos: &HexCoord) -> bool {
|
||||
return pos.is_in_bounds(self.height * Chunk::SIZE, self.width * Chunk::SIZE);
|
||||
}
|
||||
|
||||
pub fn get_moisture(&self, pos: &HexCoord) -> f32 {
|
||||
let chunk = &self.chunks[pos.to_chunk_index(self.width)];
|
||||
return chunk.moisture[pos.to_chunk_local_index()];
|
||||
@@ -122,20 +129,20 @@ pub mod prelude {
|
||||
}
|
||||
|
||||
pub fn get_center(&self) -> Vec3 {
|
||||
let w = self.width * Chunk::SIZE;
|
||||
let h = self.height * Chunk::SIZE;
|
||||
return Vec3::new(
|
||||
tile_to_world_distance(w as i32 / 2),
|
||||
self.sea_level,
|
||||
tile_to_world_distance(h as i32 / 2),
|
||||
);
|
||||
let w = self.get_world_width();
|
||||
let h = self.get_world_height();
|
||||
return Vec3::new(w / 2., self.sea_level, h / 2.);
|
||||
}
|
||||
|
||||
pub fn get_world_width(&self) -> f32 {
|
||||
return tile_to_world_distance((self.width * Chunk::SIZE) as i32);
|
||||
return (self.width * Chunk::SIZE) as f32 * SHORT_DIAGONAL;
|
||||
}
|
||||
pub fn get_world_height(&self) -> f32 {
|
||||
return tile_to_world_distance((self.height * Chunk::SIZE) as i32);
|
||||
return (self.height * Chunk::SIZE) as f32 * 1.5;
|
||||
}
|
||||
|
||||
pub fn get_world_size(&self) -> Vec2 {
|
||||
return Vec2::new(self.get_world_width(), self.get_world_height());
|
||||
}
|
||||
}
|
||||
pub const ATTRIBUTE_PACKED_VERTEX_DATA: MeshVertexAttribute =
|
||||
|
||||
Reference in New Issue
Block a user