From 5d1e18b796d41e035d0d3e828cc6db54ed21a4b6 Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Sat, 3 May 2008 14:47:12 +0000 Subject: camera handling, Cockpit view --- src/game/ship.cc | 36 ++++++++++++++++++++++++------------ 1 file changed, 24 insertions(+), 12 deletions(-) (limited to 'src/game') diff --git a/src/game/ship.cc b/src/game/ship.cc index af98513..9a7c059 100644 --- a/src/game/ship.cc +++ b/src/game/ship.cc @@ -52,10 +52,13 @@ void Ship::frame(float seconds) } else if (current_target_pitch > target_pitch) { current_target_pitch -= direction_change_speed * seconds; } - math::clamp(current_target_pitch, -1.0f, 1.0f); - float pitch_offset = seconds * current_target_pitch; - if (pitch_offset) + if (fabs(current_target_pitch) < 0.005f) { + current_target_pitch = 0.0f; + } else { + math::clamp(current_target_pitch, -1.0f, 1.0f); + float pitch_offset = seconds * current_target_pitch; entity_axis.change_pitch(360.0f * ship_shipmodel->turnspeed() * pitch_offset); + } // update direction math::clamp(target_direction, -1.0f, 1.0f); @@ -64,10 +67,13 @@ void Ship::frame(float seconds) } else if (current_target_direction > target_direction) { current_target_direction -= direction_change_speed * seconds; } - math::clamp(current_target_direction, -1.0f, 1.0f); - float direction_offset = seconds * current_target_direction; - if (direction_offset) + if (fabs(current_target_direction) < 0.005f) { + current_target_direction = 0.0f; + } else { + math::clamp(current_target_direction, -1.0f, 1.0f); + float direction_offset = seconds * current_target_direction; entity_axis.change_direction(360.0f * ship_shipmodel->turnspeed() * direction_offset); + } // update roll math::clamp(target_roll, -1.0f, 1.0f); @@ -76,10 +82,13 @@ void Ship::frame(float seconds) } else if (current_target_roll > target_roll) { current_target_roll -= direction_change_speed * seconds; } - math::clamp(current_target_roll, -1.0f, 1.0f); - float roll_offset = seconds * current_target_roll; - if (roll_offset) + if (fabs(current_target_roll) < 0.005f) { + current_target_roll = 0.0f; + } else { + math::clamp(current_target_roll, -1.0f, 1.0f); + float roll_offset = seconds * current_target_roll; entity_axis.change_roll(360.0f * ship_shipmodel->turnspeed() * roll_offset); + } // update speed if (entity_speed < entity_thrust * ship_shipmodel->maxspeed()) { @@ -92,9 +101,12 @@ void Ship::frame(float seconds) if (entity_speed < 0.0f) entity_speed = 0.0f; } - entity_location += entity_axis.forward() * entity_speed * seconds; - - entity_dirty = true; + if (entity_speed != 0.0f) { + entity_location += entity_axis.forward() * entity_speed * seconds; + entity_dirty = true; + } else if ((current_target_pitch != 0.0f) || (current_target_direction != 0.0f) || (current_target_roll != 0.0f)) { + entity_dirty = true; + } } } // namespace game -- cgit v1.2.3