mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Replace view distance culling with frustum culling
This commit is contained in:
parent
a8e0d6943f
commit
f312299e62
@ -2,6 +2,7 @@ use client::Client;
|
|||||||
use common::vol::{ReadVol, Vox};
|
use common::vol::{ReadVol, Vox};
|
||||||
use std::f32::consts::PI;
|
use std::f32::consts::PI;
|
||||||
use vek::*;
|
use vek::*;
|
||||||
|
use frustum_query::frustum::Frustum;
|
||||||
|
|
||||||
const NEAR_PLANE: f32 = 0.01;
|
const NEAR_PLANE: f32 = 0.01;
|
||||||
const FAR_PLANE: f32 = 10000.0;
|
const FAR_PLANE: f32 = 10000.0;
|
||||||
@ -92,6 +93,15 @@ impl Camera {
|
|||||||
(view_mat, proj_mat, cam_pos)
|
(view_mat, proj_mat, cam_pos)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn frustum(&self, client: &Client) -> Frustum {
|
||||||
|
let (view_mat, proj_mat, _) = self.compute_dependents(client);
|
||||||
|
|
||||||
|
Frustum::from_modelview_and_projection(
|
||||||
|
&view_mat.into_col_array(),
|
||||||
|
&proj_mat.into_col_array(),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
/// Rotate the camera about its focus by the given delta, limiting the input accordingly.
|
/// Rotate the camera about its focus by the given delta, limiting the input accordingly.
|
||||||
pub fn rotate_by(&mut self, delta: Vec3<f32>) {
|
pub fn rotate_by(&mut self, delta: Vec3<f32>) {
|
||||||
// Wrap camera yaw
|
// Wrap camera yaw
|
||||||
|
@ -851,14 +851,7 @@ impl FigureMgr {
|
|||||||
let tick = client.get_tick();
|
let tick = client.get_tick();
|
||||||
let ecs = client.state().ecs();
|
let ecs = client.state().ecs();
|
||||||
|
|
||||||
let view_distance = client.view_distance().unwrap_or(1);
|
let frustum = camera.frustum(client);
|
||||||
// Get player position.
|
|
||||||
let player_pos = client
|
|
||||||
.state()
|
|
||||||
.ecs()
|
|
||||||
.read_storage::<comp::Pos>()
|
|
||||||
.get(client.entity())
|
|
||||||
.map_or(Vec3::zero(), |pos| pos.0);
|
|
||||||
|
|
||||||
for (entity, _, _, _, body, _) in (
|
for (entity, _, _, _, body, _) in (
|
||||||
&ecs.entities(),
|
&ecs.entities(),
|
||||||
@ -869,13 +862,8 @@ impl FigureMgr {
|
|||||||
ecs.read_storage::<comp::Stats>().maybe(),
|
ecs.read_storage::<comp::Stats>().maybe(),
|
||||||
)
|
)
|
||||||
.join()
|
.join()
|
||||||
// Don't render figures outside the vd
|
// Don't render figures outside of frustum (camera viewport, max draw distance is farplane)
|
||||||
.filter(|(_, pos, _, _, _, _)| {
|
.filter(|(_, pos, _, _, _, _)| frustum.sphere_intersecting(&pos.0.x, &pos.0.y, &pos.0.z, &0.0))
|
||||||
(pos.0 - player_pos)
|
|
||||||
.map2(TerrainChunkSize::SIZE, |d, sz| d.abs() as f32 / sz as f32)
|
|
||||||
.magnitude()
|
|
||||||
< view_distance as f32
|
|
||||||
})
|
|
||||||
// Don't render dead entities
|
// Don't render dead entities
|
||||||
.filter(|(_, _, _, _, _, stats)| stats.map_or(true, |s| !s.is_dead))
|
.filter(|(_, _, _, _, _, stats)| stats.map_or(true, |s| !s.is_dead))
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user