Shift chunks where they are supposed to be
This commit is contained in:
+11
-1
@@ -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);
|
||||
}
|
||||
",
|
||||
|
||||
|
||||
+23
-21
@@ -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 {
|
||||
|
||||
+18
-5
@@ -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<Vertex> = 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::<u32>().unwrap() * CHUNK_SIZE,
|
||||
file_name_parts[1].parse::<u32>().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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user