mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Fixed block-hopping, block-snapping, added interpolation to figures
This commit is contained in:
parent
7a1359961c
commit
2c24ba7776
@ -165,31 +165,32 @@ impl<'a> System<'a> for Sys {
|
||||
.flatten()
|
||||
.flatten();
|
||||
|
||||
/*
|
||||
let collision_with = |pos: Vec3<f32>, near_iter| {
|
||||
for (i, j, k) in near_iter {
|
||||
let block_pos = pos.map(|e| e.floor() as i32) + Vec3::new(i, j, k);
|
||||
|
||||
let this_aabb = Aabb { min: pos + Vec3::new(-0.3, -0.3, 0.0), max: pos + Vec3::new(0.3, 0.3, 1.7) };
|
||||
let block_aabb = Aabb { min: block_pos.map(|e| e as f32), max: block_pos.map(|e| e as f32) + 1.0 };
|
||||
if terrain
|
||||
.get(block_pos)
|
||||
.map(|vox| !vox.is_empty())
|
||||
.unwrap_or(false)
|
||||
{
|
||||
let this_aabb = Aabb { min: pos + Vec3::new(-0.3, -0.3, 0.0), max: pos + Vec3::new(0.3, 0.3, 1.7) };
|
||||
let block_aabb = Aabb { min: block_pos.map(|e| e as f32), max: block_pos.map(|e| e as f32) + 1.0 };
|
||||
|
||||
if this_aabb.collides_with_aabb(block_aabb) {
|
||||
return true;
|
||||
if this_aabb.collides_with_aabb(block_aabb) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
false
|
||||
};
|
||||
*/
|
||||
|
||||
//let collision_above = collision_with(pos.0 + Vec3::unit_z() * 1.1, near_iter.clone());
|
||||
//let collision_below = collision_with(pos.0 - Vec3::unit_z() * 1.01, near_iter.clone());
|
||||
|
||||
on_grounds.remove(entity);
|
||||
pos.0.z -= 0.0001; // To force collision with the floor
|
||||
|
||||
// For every nearby block...
|
||||
let mut on_ground = false;
|
||||
for (i, j, k) in near_iter {
|
||||
for (i, j, k) in near_iter.clone() {
|
||||
let block_pos = pos.0.map(|e| e.floor() as i32) + Vec3::new(i, j, k);
|
||||
|
||||
// ...check to see whether it is solid...
|
||||
@ -214,23 +215,23 @@ impl<'a> System<'a> for Sys {
|
||||
on_ground = true;
|
||||
}
|
||||
|
||||
//if resolve_dir.z == 0.0 && !collision_above {
|
||||
// pos.0.z += 1.01;
|
||||
// break;
|
||||
//} else {
|
||||
if resolve_dir.z == 0.0 && !collision_with(pos.0 + Vec3::unit_z() * 1.0, near_iter.clone()) {
|
||||
pos.0.z += 1.0;
|
||||
break;
|
||||
} else {
|
||||
pos.0 += resolve_dir;
|
||||
vel.0 = vel.0.map2(resolve_dir, |e, d| if d == 0.0 { e } else { 0.0 });
|
||||
//}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if on_ground {
|
||||
on_grounds.insert(entity, OnGround);
|
||||
}// else if collision_below && vel.0.z < 0.0 {
|
||||
// pos.0.z -= 0.5;
|
||||
//}
|
||||
} else if collision_with(pos.0 - Vec3::unit_z() * 1.0, near_iter.clone()) && vel.0.z < 0.0 && vel.0.z > -1.0 {
|
||||
pos.0.z = (pos.0.z - 0.05).floor();
|
||||
on_grounds.insert(entity, OnGround);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -6,7 +6,7 @@ use vek::*;
|
||||
const NEAR_PLANE: f32 = 0.1;
|
||||
const FAR_PLANE: f32 = 10000.0;
|
||||
|
||||
const INTERP_TIME: f32 = 0.025;
|
||||
const INTERP_TIME: f32 = 0.05;
|
||||
|
||||
pub struct Camera {
|
||||
tgt_focus: Vec3<f32>,
|
||||
|
@ -741,6 +741,8 @@ pub struct FigureState<S: Skeleton> {
|
||||
bone_consts: Consts<FigureBoneData>,
|
||||
locals: Consts<FigureLocals>,
|
||||
skeleton: S,
|
||||
pos: Vec3<f32>,
|
||||
ori: Vec3<f32>,
|
||||
}
|
||||
|
||||
impl<S: Skeleton> FigureState<S> {
|
||||
@ -751,6 +753,8 @@ impl<S: Skeleton> FigureState<S> {
|
||||
.unwrap(),
|
||||
locals: renderer.create_consts(&[FigureLocals::default()]).unwrap(),
|
||||
skeleton,
|
||||
pos: Vec3::zero(),
|
||||
ori: Vec3::zero(),
|
||||
}
|
||||
}
|
||||
|
||||
@ -761,8 +765,12 @@ impl<S: Skeleton> FigureState<S> {
|
||||
ori: Vec3<f32>,
|
||||
col: Rgba<f32>,
|
||||
) {
|
||||
// Update interpolate pos
|
||||
self.pos = Lerp::lerp(self.pos, pos, 0.4);
|
||||
self.ori = Slerp::slerp(self.ori, ori, 0.2);
|
||||
|
||||
let mat = Mat4::<f32>::identity()
|
||||
* Mat4::translation_3d(pos)
|
||||
* Mat4::translation_3d(self.pos)
|
||||
* Mat4::rotation_z(-ori.x.atan2(ori.y))
|
||||
* Mat4::scaling_3d(Vec3::from(0.8));
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user