From 87f0b2ee74a6ddb696d4a330995ade0afb4dd78c Mon Sep 17 00:00:00 2001 From: zicodxx Date: Wed, 13 Apr 2011 21:08:11 +0200 Subject: [PATCH] Bit more safeguarding in find_plane_line_intersection() and as a result less agressive but more beautiful back-bumping on illegal wall interesections; Scaling of movement from PhysTime to FrameTime now done with vector math functions --- CHANGELOG.txt | 1 + main/fvi.c | 12 +++++++----- main/physics.c | 40 ++++++++++++++++------------------------ 3 files changed, 24 insertions(+), 29 deletions(-) diff --git a/CHANGELOG.txt b/CHANGELOG.txt index 2be4f7d42..09852a65b 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -3,6 +3,7 @@ D2X-Rebirth Changelog 20110413 -------- main/net_udp.c, main/net_udp.h: Improved security for UDP protocol: Add checks for correct packet size and - if possible - valid sender address (valid player) and making sure Clients only accept packets meant for Clients and Hosts only accept packets meant for Hosts +main/fvi.c, main/physics.c: Bit more safeguarding in find_plane_line_intersection() and as a result less agressive but more beautiful back-bumping on illegal wall interesections; Scaling of movement from PhysTime to FrameTime now done with vector math functions 20110412 -------- diff --git a/main/fvi.c b/main/fvi.c index e9a13cac9..b17789bb7 100644 --- a/main/fvi.c +++ b/main/fvi.c @@ -60,11 +60,13 @@ int find_plane_line_intersection(vms_vector *new_pnt,vms_vector *plane_pnt,vms_v //check for various bad values if (den > 0 && (-num>>15) >= den) //will overflow (large negative) num = (f1_0-f0_5)*den; - // FIXME: need to handle those or catch somewhere else? -// if (den > 0 && num > den) //frac greater than one -// return 0; -// if (den < 0 && num < den) //frac greater than one -// return 0; + // FIXME: Handle those better! + if (den > 0 && num > den) //frac greater than one + num = den; //return 0; + if (den < 0 && num < den) //frac greater than one + num = den; //return 0; + if (labs (num) / (f1_0 / 2) >= labs (den)) + return 0; vm_vec_scale2(&d,num,den); vm_vec_add(new_pnt,p0,&d); diff --git a/main/physics.c b/main/physics.c index 8890b3f41..79c619a05 100644 --- a/main/physics.c +++ b/main/physics.c @@ -574,7 +574,18 @@ void do_physics_sim(object *obj) vms_vector moved_v; //@@fix total_d,moved_d; fix hit_speed=0,wall_part=0; - + + /* + * 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,F0_1); + } + // Find hit speed vm_vec_sub(&moved_v,&obj->pos,&save_pos); @@ -721,9 +732,10 @@ void do_physics_sim(object *obj) // As sim_time may not base on FrameTime, scale actual object position to get accurate movement if (PhysTime/FrameTime > 0) { - obj->pos.x = start_pos.x + ((obj->pos.x - start_pos.x) / ((float)PhysTime/FrameTime)); - obj->pos.y = start_pos.y + ((obj->pos.y - start_pos.y) / ((float)PhysTime/FrameTime)); - obj->pos.z = start_pos.z + ((obj->pos.z - start_pos.z) / ((float)PhysTime/FrameTime)); + vms_vector md; + vm_vec_sub(&md, &obj->pos, &start_pos); + vm_vec_scale(&md, F1_0/((float)PhysTime/FrameTime)); + vm_vec_add(&obj->pos,&start_pos, &md); //check for and update correct object segment if(!get_seg_masks(&obj->pos, obj->segnum, 0, __FILE__, __LINE__).centermask == 0) { @@ -747,26 +759,6 @@ 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)