diff --git a/CHANGELOG.txt b/CHANGELOG.txt index e50b6ddef..472124e04 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -3,6 +3,7 @@ D1X-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 39474633d..548a983a0 100644 --- a/main/fvi.c +++ b/main/fvi.c @@ -58,11 +58,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 5bc63de76..ab0e3903b 100644 --- a/main/physics.c +++ b/main/physics.c @@ -562,6 +562,17 @@ void do_physics_sim(object *obj) vms_vector moved_v; 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); @@ -678,9 +689,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) { @@ -704,26 +716,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)