diff --git a/src/main.rs b/src/main.rs index 0ac99e6..e4955bd 100644 --- a/src/main.rs +++ b/src/main.rs @@ -73,9 +73,12 @@ fn main() { in uint index; in float altitude; + in uvec2 chunk; out vec2 v_tex_coords; + const uint TILE_SIZE = 4u; + void main() { uint index_mod = index % 6u; uint index_div = index / 6u; @@ -99,7 +102,14 @@ fn main() { x++; z++; } - gl_Position = persp_matrix * view_matrix * vec4(vec3(x, altitude, z) * 0.005, 1.0); + + x *= TILE_SIZE; + z *= TILE_SIZE; + + x += chunk.x; + z += chunk.y; + + gl_Position = persp_matrix * view_matrix * vec4(vec3(x, altitude, z), 1.0); } ", diff --git a/src/support/camera.rs b/src/support/camera.rs index db5af3c..a06a0e4 100644 --- a/src/support/camera.rs +++ b/src/support/camera.rs @@ -16,9 +16,9 @@ pub struct CameraState { impl CameraState { pub fn new() -> CameraState { CameraState { - aspect_ratio: 1024.0 / 768.0, - position: (0.1, 0.1, 1.0), + aspect_ratio: 1_024.0 / 768.0, // The second coordinate is for the altitude. + position: (3_646.41, 10.3622, 13_113.7), direction: (0.0, 0.0, -1.0), moving_up: false, moving_left: false, @@ -33,7 +33,7 @@ impl CameraState { pub fn get_perspective(&self) -> [[f32; 4]; 4] { let fov: f32 = 3.141592 / 2.0; - let zfar = 8000.0; + let zfar = 53_209.0; let znear = 0.01; let f = 1.0 / (fov / 2.0).tan(); @@ -118,40 +118,42 @@ impl CameraState { s.0 * f.1 - s.1 * f.0, ); + const SPEED: f32 = 1.0; //0.01; + if self.moving_up { - self.position.0 += u.0 * 0.01; - self.position.1 += u.1 * 0.01; - self.position.2 += u.2 * 0.01; + self.position.0 += u.0 * SPEED; + self.position.1 += u.1 * SPEED; + self.position.2 += u.2 * SPEED; } if self.moving_left { - self.position.0 -= s.0 * 0.01; - self.position.1 -= s.1 * 0.01; - self.position.2 -= s.2 * 0.01; + self.position.0 -= s.0 * SPEED; + self.position.1 -= s.1 * SPEED; + self.position.2 -= s.2 * SPEED; } if self.moving_down { - self.position.0 -= u.0 * 0.01; - self.position.1 -= u.1 * 0.01; - self.position.2 -= u.2 * 0.01; + self.position.0 -= u.0 * SPEED; + self.position.1 -= u.1 * SPEED; + self.position.2 -= u.2 * SPEED; } if self.moving_right { - self.position.0 += s.0 * 0.01; - self.position.1 += s.1 * 0.01; - self.position.2 += s.2 * 0.01; + self.position.0 += s.0 * SPEED; + self.position.1 += s.1 * SPEED; + self.position.2 += s.2 * SPEED; } if self.moving_forward { - self.position.0 += f.0 * 0.01; - self.position.1 += f.1 * 0.01; - self.position.2 += f.2 * 0.01; + self.position.0 += f.0 * SPEED; + self.position.1 += f.1 * SPEED; + self.position.2 += f.2 * SPEED; } if self.moving_backward { - self.position.0 -= f.0 * 0.01; - self.position.1 -= f.1 * 0.01; - self.position.2 -= f.2 * 0.01; + self.position.0 -= f.0 * SPEED; + self.position.1 -= f.1 * SPEED; + self.position.2 -= f.2 * SPEED; } if self.rotate_left { diff --git a/src/support/mod.rs b/src/support/mod.rs index 05d5bb0..d3f25b9 100644 --- a/src/support/mod.rs +++ b/src/support/mod.rs @@ -81,9 +81,10 @@ pub fn load_ground(display: &Display) -> VertexBufferAny { normal: [f32; 3], index: u32, biome: u32, + chunk: [u32; 2], } - implement_vertex!(Vertex, altitude, normal, index, biome); + implement_vertex!(Vertex, altitude, normal, index, biome, chunk); let mut vertex_data: Vec = Vec::new(); @@ -101,6 +102,14 @@ pub fn load_ground(display: &Display) -> VertexBufferAny { .replace("Extensions/LemnosLife/Map/Altis/Ground/", "") .replace(".height", ""); println!("{}", file_name); + let file_name_parts: Vec<&str> = file_name.split(' ').collect(); + + const CHUNK_SIZE: u32 = 1_000; + let chunk = [ + file_name_parts[0].parse::().unwrap() * CHUNK_SIZE, + file_name_parts[1].parse::().unwrap() * CHUNK_SIZE, + ]; + // have deleted a few height files to make it work // TODO: use triangle strip let height_contents = fs::read_to_string(&format!( @@ -114,12 +123,10 @@ pub fn load_ground(display: &Display) -> VertexBufferAny { file_name )) .expect("Unable to load biomes file!"); - println!("alpha"); - let height_lines: Vec<&str> = height_contents.split('\n').collect(); + let height_lines: Vec<&str> = height_contents.split('\n').rev().collect(); let biomes_lines: Vec<&str> = biomes_contents.split('\n').collect(); - println!("beta"); let mut index: u32 = 0; @@ -148,6 +155,7 @@ pub fn load_ground(display: &Display) -> VertexBufferAny { normal: [0.0, 0.0, 1.0], index, biome, + chunk, }); index += 1; @@ -156,6 +164,7 @@ pub fn load_ground(display: &Display) -> VertexBufferAny { normal: [0.0, 0.0, 1.0], index, biome, + chunk, }); index += 1; @@ -164,6 +173,7 @@ pub fn load_ground(display: &Display) -> VertexBufferAny { normal: [0.0, 0.0, 1.0], index, biome, + chunk, }); index += 1; @@ -174,6 +184,7 @@ pub fn load_ground(display: &Display) -> VertexBufferAny { normal: [0.0, 0.0, 1.0], index, biome, + chunk, }); index += 1; @@ -182,6 +193,7 @@ pub fn load_ground(display: &Display) -> VertexBufferAny { normal: [0.0, 0.0, 1.0], index, biome, + chunk, }); index += 1; @@ -190,13 +202,14 @@ pub fn load_ground(display: &Display) -> VertexBufferAny { normal: [0.0, 0.0, 1.0], index, biome, + chunk, }); index += 1; } } i += 1; // i == 250 thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: BufferCreationError(OutOfMemory)', src/support/mod.rs:203:10 - if i == 200 { + if i == 175 { break; } }