mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Fixed scaled terrain collisions
This commit is contained in:
parent
c856f2625c
commit
f140a94dc6
@ -1350,15 +1350,16 @@ fn box_voxel_collision<T: BaseVol<Vox = Block> + ReadVol>(
|
|||||||
read: &PhysicsRead,
|
read: &PhysicsRead,
|
||||||
ori: &Ori,
|
ori: &Ori,
|
||||||
) {
|
) {
|
||||||
let scale = read.scales.get(entity).map_or(1.0, |s| s.0);
|
// We cap out scale at 10.0 to prevent an enormous amount of lag
|
||||||
|
let scale = read.scales.get(entity).map_or(1.0, |s| s.0.min(10.0));
|
||||||
|
|
||||||
//prof_span!("box_voxel_collision");
|
//prof_span!("box_voxel_collision");
|
||||||
|
|
||||||
// Convience function to compute the player aabb
|
// Convience function to compute the player aabb
|
||||||
fn player_aabb(pos: Vec3<f32>, radius: f32, z_range: Range<f32>, scale: f32) -> Aabb<f32> {
|
fn player_aabb(pos: Vec3<f32>, radius: f32, z_range: Range<f32>) -> Aabb<f32> {
|
||||||
Aabb {
|
Aabb {
|
||||||
min: pos + Vec3::new(-radius, -radius, z_range.start) * scale,
|
min: pos + Vec3::new(-radius, -radius, z_range.start),
|
||||||
max: pos + Vec3::new(radius, radius, z_range.end) * scale,
|
max: pos + Vec3::new(radius, radius, z_range.end),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1381,7 +1382,7 @@ fn box_voxel_collision<T: BaseVol<Vox = Block> + ReadVol>(
|
|||||||
z_range: Range<f32>,
|
z_range: Range<f32>,
|
||||||
scale: f32,
|
scale: f32,
|
||||||
) -> bool {
|
) -> bool {
|
||||||
let player_aabb = player_aabb(pos, radius, z_range, scale);
|
let player_aabb = player_aabb(pos, radius, z_range);
|
||||||
|
|
||||||
// Calculate the world space near aabb
|
// Calculate the world space near aabb
|
||||||
let near_aabb = move_aabb(near_aabb, pos);
|
let near_aabb = move_aabb(near_aabb, pos);
|
||||||
@ -1407,7 +1408,7 @@ fn box_voxel_collision<T: BaseVol<Vox = Block> + ReadVol>(
|
|||||||
#[allow(clippy::trivially_copy_pass_by_ref)]
|
#[allow(clippy::trivially_copy_pass_by_ref)]
|
||||||
fn always_hits(_: &Block) -> bool { true }
|
fn always_hits(_: &Block) -> bool { true }
|
||||||
|
|
||||||
let (radius, z_min, z_max) = cylinder;
|
let (radius, z_min, z_max) = (Vec3::from(cylinder) * scale).into_tuple();
|
||||||
|
|
||||||
// Probe distances
|
// Probe distances
|
||||||
let hdist = radius.ceil() as i32;
|
let hdist = radius.ceil() as i32;
|
||||||
@ -1448,7 +1449,7 @@ fn box_voxel_collision<T: BaseVol<Vox = Block> + ReadVol>(
|
|||||||
let try_colliding_block = |pos: &Pos| {
|
let try_colliding_block = |pos: &Pos| {
|
||||||
//prof_span!("most colliding check");
|
//prof_span!("most colliding check");
|
||||||
// Calculate the player's AABB
|
// Calculate the player's AABB
|
||||||
let player_aabb = player_aabb(pos.0, radius, z_range.clone(), scale);
|
let player_aabb = player_aabb(pos.0, radius, z_range.clone());
|
||||||
|
|
||||||
// Determine the block that we are colliding with most
|
// Determine the block that we are colliding with most
|
||||||
// (based on minimum collision axis)
|
// (based on minimum collision axis)
|
||||||
@ -1498,7 +1499,7 @@ fn box_voxel_collision<T: BaseVol<Vox = Block> + ReadVol>(
|
|||||||
.flatten()
|
.flatten()
|
||||||
{
|
{
|
||||||
// Calculate the player's AABB
|
// Calculate the player's AABB
|
||||||
let player_aabb = player_aabb(pos.0, radius, z_range.clone(), scale);
|
let player_aabb = player_aabb(pos.0, radius, z_range.clone());
|
||||||
|
|
||||||
// Find the intrusion vector of the collision
|
// Find the intrusion vector of the collision
|
||||||
let dir = player_aabb.collision_vector_with_aabb(block_aabb);
|
let dir = player_aabb.collision_vector_with_aabb(block_aabb);
|
||||||
@ -1630,7 +1631,7 @@ fn box_voxel_collision<T: BaseVol<Vox = Block> + ReadVol>(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Find liquid immersion and wall collision all in one round of iteration
|
// Find liquid immersion and wall collision all in one round of iteration
|
||||||
let player_aabb = player_aabb(pos.0, radius, z_range.clone(), scale);
|
let player_aabb = player_aabb(pos.0, radius, z_range.clone());
|
||||||
// Calculate the world space near_aabb
|
// Calculate the world space near_aabb
|
||||||
let near_aabb = move_aabb(near_aabb, pos.0);
|
let near_aabb = move_aabb(near_aabb, pos.0);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user