From 17e9ce54ee3972b9804174b874652ec0856efcd0 Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Sat, 10 May 2008 21:44:58 +0000 Subject: interpolation & oscilating debugging --- src/game/ship.cc | 33 ++++++++++++++++++++++++--------- 1 file changed, 24 insertions(+), 9 deletions(-) (limited to 'src/game') diff --git a/src/game/ship.cc b/src/game/ship.cc index 525bf71..5c36205 100644 --- a/src/game/ship.cc +++ b/src/game/ship.cc @@ -47,12 +47,17 @@ void Ship::frame(float seconds) // update pitch math::clamp(target_pitch, -1.0f, 1.0f); - if (current_target_pitch - target_pitch < 0) { + if (current_target_pitch < target_pitch) { current_target_pitch += direction_change_speed * seconds; - } else if (current_target_pitch - target_pitch > 0) { + if (current_target_pitch > target_pitch) + current_target_pitch = target_pitch; + } else if (current_target_pitch > target_pitch) { current_target_pitch -= direction_change_speed * seconds; + if (current_target_pitch < target_pitch) + current_target_pitch = target_pitch; } - if (fabs(current_target_pitch) < direction_change_speed * seconds) { + + if (fabs(seconds*current_target_pitch) < 0.00005f) { current_target_pitch = 0.0f; } else { math::clamp(current_target_pitch, -1.0f, 1.0f); @@ -62,12 +67,18 @@ void Ship::frame(float seconds) // update direction math::clamp(target_direction, -1.0f, 1.0f); - if (current_target_direction - target_direction < 0) { + if (current_target_direction < target_direction) { current_target_direction += direction_change_speed * seconds; - } else if (current_target_direction - target_direction > 0) { + if (current_target_direction > target_direction) { + current_target_direction = target_direction; + } + } else if (current_target_direction > target_direction) { current_target_direction -= direction_change_speed * seconds; + if (current_target_direction < target_direction) { + current_target_direction = target_direction; + } } - if (fabs(current_target_direction) < direction_change_speed * seconds) { + if (fabs(seconds*current_target_direction) < 0.00005f) { current_target_direction = 0.0f; } else { math::clamp(current_target_direction, -1.0f, 1.0f); @@ -77,12 +88,16 @@ void Ship::frame(float seconds) // update roll math::clamp(target_roll, -1.0f, 1.0f); - if (current_target_roll - target_roll < 0) { + if (current_target_roll < target_roll) { current_target_roll += direction_change_speed * seconds; - } else if (current_target_roll - target_roll > 0) { + if (current_target_roll > target_roll) + current_target_roll = target_roll; + } else if (current_target_roll > target_roll) { current_target_roll -= direction_change_speed * seconds; + if (current_target_roll < target_roll) + current_target_roll = target_roll; } - if (fabs(current_target_roll) < direction_change_speed * seconds) { + if (fabs(current_target_roll) < 0.00005f) { current_target_roll = 0.0f; } else { math::clamp(current_target_roll, -1.0f, 1.0f); -- cgit v1.2.3