Add frustum culling
This commit is contained in:
parent
47297146cf
commit
169f068f75
|
@ -4,6 +4,7 @@ version = "0.0.1"
|
|||
dependencies = [
|
||||
"byteorder 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"cgmath 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"collision 0.5.1 (git+https://github.com/csherratt/collision-rs?rev=f80825e)",
|
||||
"flate2 0.2.13 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"glutin 0.4.9 (git+https://github.com/Thinkofname/glutin?branch=hide-cursor-state-x11)",
|
||||
"hyper 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
|
@ -94,6 +95,15 @@ dependencies = [
|
|||
"objc 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "collision"
|
||||
version = "0.5.1"
|
||||
source = "git+https://github.com/csherratt/collision-rs?rev=f80825e#f80825eca687ff1053ff492e54fa782944c9cf6b"
|
||||
dependencies = [
|
||||
"cgmath 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"num 0.1.31 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "color_quant"
|
||||
version = "1.0.0"
|
||||
|
|
|
@ -18,6 +18,7 @@ rustc-serialize = "0.3.18"
|
|||
log = "0.3.5"
|
||||
cgmath = "0.7.0"
|
||||
lazy_static = "0.1.15"
|
||||
collision = {git = "https://github.com/csherratt/collision-rs", rev = "f80825e"}
|
||||
|
||||
[dependencies.steven_gl]
|
||||
path = "./gl"
|
||||
|
|
|
@ -31,6 +31,7 @@ extern crate cgmath;
|
|||
extern crate log;
|
||||
#[macro_use]
|
||||
extern crate lazy_static;
|
||||
extern crate collision;
|
||||
|
||||
#[macro_use]
|
||||
pub mod macros;
|
||||
|
|
|
@ -29,6 +29,7 @@ use byteorder::{WriteBytesExt, NativeEndian};
|
|||
use serde_json;
|
||||
use cgmath::{self, Vector, Point};
|
||||
use world;
|
||||
use collision;
|
||||
|
||||
const ATLAS_SIZE: usize = 1024;
|
||||
|
||||
|
@ -287,11 +288,17 @@ impl Renderer {
|
|||
self.chunk_shader.light_level.set_float(LIGHT_LEVEL);
|
||||
self.chunk_shader.sky_offset.set_float(SKY_OFFSET);
|
||||
|
||||
let frustum = collision::Frustum::from_matrix4(self.perspective_matrix * camera_matrix).unwrap();
|
||||
|
||||
for (pos, info) in &self.chunks {
|
||||
if let Some(solid) = info.solid.as_ref() {
|
||||
self.chunk_shader.offset.set_int3(pos.0, pos.1 * 4096, pos.2);
|
||||
solid.array.bind();
|
||||
gl::draw_elements(gl::TRIANGLES, solid.count, self.element_buffer_type, 0);
|
||||
let min = cgmath::Point3::new(pos.0 as f32 * 16.0, -pos.1 as f32 * 16.0, pos.2 as f32 * 16.0);
|
||||
let bounds = collision::Aabb3::new(min, min + cgmath::Vector3::new(16.0, -16.0, 16.0));
|
||||
if frustum.contains(bounds) != collision::Relation::Out {
|
||||
self.chunk_shader.offset.set_int3(pos.0, pos.1 * 4096, pos.2);
|
||||
solid.array.bind();
|
||||
gl::draw_elements(gl::TRIANGLES, solid.count, self.element_buffer_type, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue