Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'src/game/base/ship.cc')
-rw-r--r--src/game/base/ship.cc96
1 files changed, 77 insertions, 19 deletions
diff --git a/src/game/base/ship.cc b/src/game/base/ship.cc
index 88aefbe..44676c4 100644
--- a/src/game/base/ship.cc
+++ b/src/game/base/ship.cc
@@ -77,9 +77,11 @@ Ship::Ship(core::Player *owner, ShipModel *shipmodel) : core::EntityControlable(
set_flag(core::Entity::Dockable);
}
- //set_mass(radius());
- set_mass(0);
+ set_mass(radius());
reset();
+
+ const float damp = Game::g_damping->value();
+ body()->setDamping(damp, damp);
}
Ship::~Ship()
@@ -271,14 +273,17 @@ void Ship::explode()
{
set_state(core::Entity::Destroyed);
- target_thrust = 0;
+ target_direction = 0;
target_pitch = 0;
target_roll = 0;
- target_direction = 0;
+ target_strafe = 0.0f;
+ target_vstrafe = 0.0f;
+
target_afterburner = 0.0f;
target_thrust = 0;
- entity_thrust = 0;
+ entity_thrust = 0;
+
if (owner()) {
if (owner()->control() == this)
owner()->set_view(this);
@@ -305,8 +310,6 @@ void Ship::frame(float seconds)
float actual_acceleration = ship_shipmodel->acceleration();
float actual_thrust = 0;
- float cosangle; // cosine of an angle
- float angle; // angle in radians
math::Vector3f n; // normal of a plane
math::Axis target_axis(axis()); // target axis
@@ -321,15 +324,17 @@ void Ship::frame(float seconds)
if (entity_state == core::Entity::Docked) {
- target_thrust = 0;
+ target_direction = 0;
target_pitch = 0;
target_roll = 0;
- target_direction = 0;
+ target_strafe = 0.0f;
+ target_vstrafe = 0.0f;
+
target_afterburner = 0.0f;
target_thrust = 0;
- entity_speed = 0;
entity_thrust = 0;
+ entity_speed = 0.0f;
} else if (entity_state == core::Entity::JumpInitiate) {
@@ -369,22 +374,26 @@ void Ship::frame(float seconds)
}
// control is disabled while the jumpdrive is activated
- target_thrust = 0;
+ target_direction = 0;
target_pitch = 0;
target_roll = 0;
- target_direction = 0;
+ target_strafe = 0.0f;
+ target_vstrafe = 0.0f;
+
target_afterburner = 0.0f;
- target_thrust = 0.1;
+ target_thrust = 0.1f;
} else if (entity_state == core::Entity::Jump) {
// control is disabled while the jumpdrive is activated
- target_thrust = 0;
+ target_direction = 0;
target_pitch = 0;
target_roll = 0;
- target_direction = 0;
+ target_strafe = 0.0f;
+ target_vstrafe = 0.0f;
+
target_afterburner = 0.0f;
- target_thrust = 0;
+ target_thrust = 0.0f;
// FIXME 5 second cooldown
entity_state = core::Entity::Normal;
@@ -469,11 +478,13 @@ void Ship::frame(float seconds)
}
} else if (entity_state == core::Entity::Destroyed) {
-
- target_thrust = 0;
+
+ target_direction = 0;
target_pitch = 0;
target_roll = 0;
- target_direction = 0;
+ target_strafe = 0.0f;
+ target_vstrafe = 0.0f;
+
target_afterburner = 0.0f;
target_thrust = 0;
@@ -523,6 +534,17 @@ void Ship::frame(float seconds)
if (current_target_strafe < target_strafe)
current_target_strafe = target_strafe;
}
+
+ // update vstrafe control target
+ if (current_target_vstrafe < target_vstrafe) {
+ current_target_vstrafe += strafe_reaction * seconds;
+ if (current_target_vstrafe > target_vstrafe)
+ current_target_vstrafe = target_vstrafe;
+ } else if (current_target_vstrafe > target_vstrafe) {
+ current_target_vstrafe -= strafe_reaction * seconds;
+ if (current_target_vstrafe < target_vstrafe)
+ current_target_vstrafe = target_vstrafe;
+ }
// update roll control target
if (current_target_roll < target_roll) {
@@ -581,6 +603,34 @@ void Ship::frame(float seconds)
current_target_pitch = 0.0f;
}
+ /*
+ // -- BULLET
+
+ // apply thrust
+ body()->applyCentralForce(math::to_btVector3(axis().forward() * (actual_thrust * actual_acceleration)));
+
+ // apply strafe
+ body()->applyCentralForce(math::to_btVector3(axis().left() * (current_target_strafe * 0.15f * actual_acceleration)));
+ body()->applyCentralForce(math::to_btVector3(axis().up() * (current_target_vstrafe * 0.15f * actual_acceleration)));
+
+ // FIXME get movement state from linear/angular velocity
+ entity_movement = target_thrust;
+ entity_movement = math::max(entity_movement, fabs(current_target_pitch));
+ entity_movement = math::max(entity_movement, fabs(current_target_direction));
+ entity_movement = math::max(entity_movement, fabs(current_target_roll));
+ entity_movement = math::max(entity_movement, fabs(current_target_afterburner));
+ entity_movement = math::max(entity_movement, fabs(current_target_strafe));
+ entity_movement = math::max(entity_movement, fabs(current_target_vstrafe));
+
+ if (entity_movement > 0) {
+ set_dirty();
+ }
+
+ EntityDynamic::frame(seconds);
+ */
+ float cosangle; // cosine of an angle
+ float angle; // angle in radians
+
// update axis
n.assign(math::crossproduct(axis().forward(), target_axis.forward()));
if (!(n.length() < MIN_DELTA)) {
@@ -605,10 +655,17 @@ void Ship::frame(float seconds)
}
}
+ // apply strafe to location
if (fabs(current_target_strafe) > MIN_DELTA) {
get_location() += axis().left() * (current_target_strafe * 0.15f * actual_maxspeed) * seconds;
}
+
+ // apply vstrafe to location
+ if (fabs(current_target_vstrafe) > MIN_DELTA) {
+ get_location() += axis().up() * (current_target_vstrafe * 0.15f * actual_maxspeed) * seconds;
+ }
+ // apply speed to location
if (fabs(speed()) > MIN_DELTA) {
get_location() += axis().forward() * speed() * seconds;
}
@@ -619,6 +676,7 @@ void Ship::frame(float seconds)
entity_movement = math::max(entity_movement, fabs(current_target_roll));
entity_movement = math::max(entity_movement, fabs(current_target_afterburner));
entity_movement = math::max(entity_movement, fabs(current_target_strafe));
+ entity_movement = math::max(entity_movement, fabs(current_target_vstrafe));
if ((entity_movement > 0) || (entity_speed > 0)) {
set_dirty();