From 2bbbabb07858fa7902ce8549c4e5f1afee071896 Mon Sep 17 00:00:00 2001 From: zicodxx Date: Sun, 27 Mar 2011 18:01:14 +0200 Subject: [PATCH] Another rework for anti-stuck-bumping: Execute after calculation of velocity and add fvi check to make sure we deal with an actual wall collision --- CHANGELOG.txt | 4 ++++ main/physics.c | 31 ++++++++++++++++++++----------- 2 files changed, 24 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.txt b/CHANGELOG.txt index 2b550c0d9..f8a243906 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -1,5 +1,9 @@ D1X-Rebirth Changelog +20110327 +-------- +main/physics.c: Another rework for anti-stuck-bumping: Execute after calculation of velocity and add fvi check to make sure we deal with an actual wall collision + 20110314 -------- main/fvi.c, main/physics.c: Again reworked new bump hack to only apply when fate == HIT_WALL (to not break level SKYBOX) and made bumping by distance between object position and wall hit point; Removed/handled some safety checks in find_plane_line_intersection() to make sliding along joining edges smoother again while bad values *should* be handled in pyhsics.c and not make object warp-crashing tru the whole level or stuck in walls (fvi code should still be rewritten tho) diff --git a/main/physics.c b/main/physics.c index 70a52bb0b..a4f512d28 100644 --- a/main/physics.c +++ b/main/physics.c @@ -605,17 +605,6 @@ void do_physics_sim(object *obj) } } - /* - * On joining edges fvi tends to get inaccurate as hell due to object size. And I have no means to fix that - shame on me (that whole code should be rewritten). Approach is to check if the object interects with the wall and if so, move it out towards segment center. (also see FIXME in find_plane_line_intersection) - */ - if (object_intersects_wall(obj) && (obj->type == OBJ_PLAYER || obj->type == OBJ_ROBOT)) - { - vms_vector center,bump_vec; - compute_segment_center(¢er,&Segments[obj->segnum]); - vm_vec_normalized_dir_quick(&bump_vec,¢er,&obj->pos); - vm_vec_scale_add2(&obj->pos,&bump_vec,vm_vec_dist(&hit_info.hit_pnt, &obj->pos)); - } - break; } @@ -711,6 +700,26 @@ void do_physics_sim(object *obj) vm_vec_copy_scale(&obj->mtype.phys_info.velocity,&moved_vec,fixdiv(f1_0,FrameTime)); } + /* + * On joining edges fvi tends to get inaccurate as hell due to object size. And I have no means to fix that - shame on me (that whole code should be rewritten). Approach is to check if the object interects with the wall and if so, move it out towards segment center. (also see FIXME in find_plane_line_intersection) + * NOTE that we also regulary check if we intersect a wall to make sure we ACTUALLY collide with a wall while bumping out of it - and not having sorta faked wall which is not marked as one... + */ + if (object_intersects_wall(obj) && (obj->type == OBJ_PLAYER || obj->type == OBJ_ROBOT)) + { + int success = (fate == HIT_WALL), bcount = obj->size/F0_1; + vms_vector center,bump_vec,safe_pos = obj->pos; + compute_segment_center(¢er,&Segments[obj->segnum]); + while (object_intersects_wall(obj) && bcount-- > 0) + { + vm_vec_normalized_dir_quick(&bump_vec,¢er,&obj->pos); + vm_vec_scale_add2(&obj->pos,&bump_vec,F0_1); + if (!success) + success = (find_vector_intersection(&fq,&hit_info) == HIT_WALL); + } + if (!success) + obj->pos = safe_pos; + } + //Assert(check_point_in_seg(&obj->pos,obj->segnum,0).centermask==0); //if (obj->control_type == CT_FLYING)