diff options
author | Stijn Buys <ingar@osirion.org> | 2008-05-01 21:08:40 +0000 |
---|---|---|
committer | Stijn Buys <ingar@osirion.org> | 2008-05-01 21:08:40 +0000 |
commit | 36ce28a7557c4b2b73316621471558354024ca54 (patch) | |
tree | 3aeb4502b3a4f91a54df5d25bedfd262e61d1cec /src/game | |
parent | a22542f273de28d06ecaf2bd6fd741821e98512b (diff) |
roll control
Diffstat (limited to 'src/game')
-rw-r--r-- | src/game/ship.cc | 53 | ||||
-rw-r--r-- | src/game/ship.h | 4 |
2 files changed, 40 insertions, 17 deletions
diff --git a/src/game/ship.cc b/src/game/ship.cc index 538a1e6..af98513 100644 --- a/src/game/ship.cc +++ b/src/game/ship.cc @@ -25,6 +25,10 @@ Ship::Ship(core::Player *owner, ShipModel *shipmodel) : ship_shipmodel = shipmodel; entity_moduletypeid = ship_enttype; + + current_target_direction = 0.0f; + current_target_pitch = 0.0f;; + current_target_roll = 0.0f;; } Ship::~Ship() @@ -35,33 +39,48 @@ Ship::~Ship() void Ship::frame(float seconds) { + const float direction_change_speed = 2; + // update thrust + math::clamp(target_thrust, 0.0f, 1.0f); entity_thrust = target_thrust; - if (entity_thrust < 0.0f) - entity_thrust = 0.0f; - else if(entity_thrust > 1.0f) - entity_thrust = 1.0f; - + // update pitch - if (target_pitch > 1.0f) - target_pitch = 1.0f; - else if (target_pitch < -1.0f) - target_pitch = -1.0f; - - float pitch_offset = seconds * target_pitch; + math::clamp(target_pitch, -1.0f, 1.0f); + if (current_target_pitch < target_pitch) { + current_target_pitch += direction_change_speed * 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) entity_axis.change_pitch(360.0f * ship_shipmodel->turnspeed() * pitch_offset); // update direction - if (target_direction > 1.0f) - target_direction = 1.0f; - else if (target_direction < -1.0f) - target_direction = -1.0f; - - float direction_offset = seconds * target_direction; + math::clamp(target_direction, -1.0f, 1.0f); + if (current_target_direction < target_direction) { + current_target_direction += direction_change_speed * 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) entity_axis.change_direction(360.0f * ship_shipmodel->turnspeed() * direction_offset); + // update roll + math::clamp(target_roll, -1.0f, 1.0f); + if (current_target_roll < target_roll) { + current_target_roll += direction_change_speed * 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) + entity_axis.change_roll(360.0f * ship_shipmodel->turnspeed() * roll_offset); + // update speed if (entity_speed < entity_thrust * ship_shipmodel->maxspeed()) { entity_speed += ship_shipmodel->acceleration() * seconds; diff --git a/src/game/ship.h b/src/game/ship.h index 633c722..9e978bb 100644 --- a/src/game/ship.h +++ b/src/game/ship.h @@ -26,6 +26,10 @@ public: private: ShipModel *ship_shipmodel; + + float current_target_direction; + float current_target_pitch; + float current_target_roll; }; } |