Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStijn Buys <ingar@osirion.org>2008-05-01 21:08:40 +0000
committerStijn Buys <ingar@osirion.org>2008-05-01 21:08:40 +0000
commit36ce28a7557c4b2b73316621471558354024ca54 (patch)
tree3aeb4502b3a4f91a54df5d25bedfd262e61d1cec /src/game/ship.cc
parenta22542f273de28d06ecaf2bd6fd741821e98512b (diff)
roll control
Diffstat (limited to 'src/game/ship.cc')
-rw-r--r--src/game/ship.cc53
1 files changed, 36 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;