diff --git a/common/include/maths.h b/common/include/maths.h index ad0e340f5..dadcda307 100644 --- a/common/include/maths.h +++ b/common/include/maths.h @@ -122,6 +122,19 @@ extern const ushort acos_table[258]; #ifdef __cplusplus } + +static inline void clamp_fix_lh(fix& f, const fix& low, const fix& high) +{ + if (f < low) + f = low; + else if (high < f) + f = high; +} + +static inline void clamp_fix_symmetric(fix& f, const fix& bound) +{ + clamp_fix_lh(f, -bound, bound); +} #endif #endif diff --git a/similar/main/automap.cpp b/similar/main/automap.cpp index e20a4e59d..331c6966d 100644 --- a/similar/main/automap.cpp +++ b/similar/main/automap.cpp @@ -774,12 +774,9 @@ static int automap_process_input(window *wind, d_event *event, automap *am) vm_vec_scale_add2( &am->view_position, &am->viewMatrix.rvec, am->controls.sideways_thrust_time*SLIDE_SPEED ); // Crude wrapping check - if (am->view_position.x > F1_0*32000) am->view_position.x = F1_0*32000; - if (am->view_position.x < -F1_0*32000) am->view_position.x = -F1_0*32000; - if (am->view_position.y > F1_0*32000) am->view_position.y = F1_0*32000; - if (am->view_position.y < -F1_0*32000) am->view_position.y = -F1_0*32000; - if (am->view_position.z > F1_0*32000) am->view_position.z = F1_0*32000; - if (am->view_position.z < -F1_0*32000) am->view_position.z = -F1_0*32000; + clamp_fix_symmetric(am->view_position.x, F1_0*32000); + clamp_fix_symmetric(am->view_position.y, F1_0*32000); + clamp_fix_symmetric(am->view_position.z, F1_0*32000); } } else