Display a ground chunk with a given biome
This commit is contained in:
+55
-31
@@ -3,6 +3,7 @@ use glium::glutin::event::{Event, StartCause};
|
||||
use glium::glutin::event_loop::{ControlFlow, EventLoop};
|
||||
use glium::vertex::VertexBufferAny;
|
||||
use glium::{self, Display};
|
||||
use std::fs;
|
||||
use std::time::{Duration, Instant};
|
||||
|
||||
pub mod camera;
|
||||
@@ -65,43 +66,66 @@ pub fn load_ground(display: &Display) -> VertexBufferAny {
|
||||
|
||||
implement_vertex!(Vertex, position, normal, tex_coords);
|
||||
|
||||
let mut vertex_data = Vec::new();
|
||||
let mut vertex_data: Vec<Vertex> = Vec::new();
|
||||
|
||||
vertex_data.push(Vertex {
|
||||
position: [0.0, 0.0, 0.0],
|
||||
normal: [0.0, 0.0, 1.0],
|
||||
tex_coords: [0.0, 0.0],
|
||||
});
|
||||
let contents = fs::read_to_string("Extensions/LemnosLife/Map/Altis/Ground/13 13.height").expect("Unable to load ground file!");
|
||||
|
||||
vertex_data.push(Vertex {
|
||||
position: [1.0, 0.0, 0.0],
|
||||
normal: [0.0, 0.0, 1.0],
|
||||
tex_coords: [1.0, 0.0],
|
||||
});
|
||||
let lines: Vec<&str> = contents.split('\n').collect();
|
||||
|
||||
vertex_data.push(Vertex {
|
||||
position: [0.0, 0.0, 1.0],
|
||||
normal: [0.0, 0.0, 1.0],
|
||||
tex_coords: [0.0, 1.0],
|
||||
});
|
||||
for lines_index in 0..lines.len() - 1 {
|
||||
let line = lines[lines_index];
|
||||
let next_line = lines[lines_index + 1];
|
||||
let columns: Vec<&str> = line.split(' ').collect();
|
||||
let next_columns: Vec<&str> = next_line.split(' ').collect();
|
||||
for columns_index in 0..columns.len() - 1 {
|
||||
let column = columns[columns_index].parse::<f32>().unwrap();
|
||||
let column_right = columns[columns_index + 1].parse::<f32>().unwrap();
|
||||
let column_below = next_columns[columns_index].parse::<f32>().unwrap();
|
||||
let column_below_right = next_columns[columns_index + 1].parse::<f32>().unwrap();
|
||||
|
||||
vertex_data.push(Vertex {
|
||||
position: [1.0, 0.0, 0.0],
|
||||
normal: [0.0, 0.0, 1.0],
|
||||
tex_coords: [1.0, 0.0],
|
||||
});
|
||||
// TODO: normals if necessary.
|
||||
|
||||
vertex_data.push(Vertex {
|
||||
position: [0.0, 0.0, 1.0],
|
||||
normal: [0.0, 0.0, 1.0],
|
||||
tex_coords: [0.0, 1.0],
|
||||
});
|
||||
// First triangle.
|
||||
|
||||
vertex_data.push(Vertex {
|
||||
position: [1.0, 0.0, 1.0],
|
||||
normal: [0.0, 0.0, 1.0],
|
||||
tex_coords: [1.0, 1.0],
|
||||
});
|
||||
vertex_data.push(Vertex {
|
||||
position: [lines_index as f32, column, columns_index as f32],
|
||||
normal: [0.0, 0.0, 1.0],
|
||||
tex_coords: [0.0, 0.0],
|
||||
});
|
||||
|
||||
vertex_data.push(Vertex {
|
||||
position: [lines_index as f32, column_right, (columns_index + 1) as f32],
|
||||
normal: [0.0, 0.0, 1.0],
|
||||
tex_coords: [0.0, 1.0],
|
||||
});
|
||||
|
||||
vertex_data.push(Vertex {
|
||||
position: [(lines_index + 1) as f32, column_below, columns_index as f32],
|
||||
normal: [0.0, 0.0, 1.0],
|
||||
tex_coords: [1.0, 0.0],
|
||||
});
|
||||
|
||||
// Second triangle.
|
||||
|
||||
vertex_data.push(Vertex {
|
||||
position: [(lines_index + 1) as f32, column_below_right, (columns_index + 1) as f32],
|
||||
normal: [0.0, 0.0, 1.0],
|
||||
tex_coords: [1.0, 1.0],
|
||||
});
|
||||
|
||||
vertex_data.push(Vertex {
|
||||
position: [lines_index as f32, column_right, (columns_index + 1) as f32],
|
||||
normal: [0.0, 0.0, 1.0],
|
||||
tex_coords: [0.0, 1.0],
|
||||
});
|
||||
|
||||
vertex_data.push(Vertex {
|
||||
position: [(lines_index + 1) as f32, column_below, columns_index as f32],
|
||||
normal: [0.0, 0.0, 1.0],
|
||||
tex_coords: [1.0, 0.0],
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
glium::vertex::VertexBuffer::new(display, &vertex_data)
|
||||
.unwrap()
|
||||
|
||||
Reference in New Issue
Block a user