Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
path: root/src/game
diff options
context:
space:
mode:
Diffstat (limited to 'src/game')
-rw-r--r--src/game/ship.cc53
-rw-r--r--src/game/ship.h4
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;
};
}