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>2010-10-18 19:13:58 +0000
committerStijn Buys <ingar@osirion.org>2010-10-18 19:13:58 +0000
commit4c5b00221c9405c5af06143974fbc6296ebe46b5 (patch)
tree3bbe7fbc47f6238a086260c56964d2d654cf6124 /src/game/base
parent85e3fd447aa3f45ba1dfe063b29a3e13f3416f11 (diff)
local vstrafe support, initial ship collision, g_damping factor
Diffstat (limited to 'src/game/base')
-rw-r--r--src/game/base/cargopod.cc3
-rw-r--r--src/game/base/game.cc14
-rw-r--r--src/game/base/game.h8
-rw-r--r--src/game/base/ship.cc96
4 files changed, 96 insertions, 25 deletions
diff --git a/src/game/base/cargopod.cc b/src/game/base/cargopod.cc
index 3e61cff..efdfe33 100644
--- a/src/game/base/cargopod.cc
+++ b/src/game/base/cargopod.cc
@@ -23,6 +23,9 @@ CargoPod::CargoPod() : EntityDynamic()
// activate physics
reset();
+
+ const float damp = Game::g_damping->value();
+ body()->setDamping(damp, damp);
}
CargoPod::~CargoPod()
diff --git a/src/game/base/game.cc b/src/game/base/game.cc
index a075574..346208b 100644
--- a/src/game/base/game.cc
+++ b/src/game/base/game.cc
@@ -54,6 +54,7 @@ core::Cvar *Game::g_impulsespeed = 0;
core::Cvar *Game::g_impulseacceleration = 0;
core::Cvar *Game::g_jumppointrange = 0;
core::Cvar *Game::g_devel = 0;
+core::Cvar *Game::g_damping = 0;
core::Module *factory()
{
@@ -729,12 +730,14 @@ Game::Game() : core::Module("Project::OSiRiON", true)
return;
}
+ // load world.ini and the zones it refers to
if (!load_world()) {
abort();
return;
}
- if (!load_player()) {
+ // load game default settings
+ if (!load_defaults()) {
abort();
return;
}
@@ -796,6 +799,9 @@ Game::Game() : core::Module("Project::OSiRiON", true)
g_devel = core::Cvar::get("g_devel", "0", core::Cvar::Archive);
g_devel->set_info("[bool] enable or disable developer mode");
+
+ g_damping = core::Cvar::get("g_damping", "0.1", core::Cvar::Archive);
+ g_damping->set_info("[float] physics damping factor (0-1)");
}
Game::~Game()
@@ -1301,13 +1307,13 @@ bool Game::generate_entity_menus(core::Entity *entity)
return true;
}
-// load default player settings
-bool Game::load_player()
+// load game defaults settings
+bool Game::load_defaults()
{
Default::clear();
filesystem::IniFile inifile;
- inifile.open("player");
+ inifile.open("game");
if (!inifile.is_open()) {
con_error << "Could not open " << inifile.name() << "!" << std::endl;
return false;
diff --git a/src/game/base/game.h b/src/game/base/game.h
index 3f67a25..c229a18 100644
--- a/src/game/base/game.h
+++ b/src/game/base/game.h
@@ -78,8 +78,12 @@ public:
/// game variable: jumppoint range
static core::Cvar *g_jumppointrange;
- /// game variable: enable or disable development mode
+ /// game variable: enable or disable development mode (cheat mode)
static core::Cvar *g_devel;
+
+ /// physics variable: default damping factor of space
+ static core::Cvar *g_damping;
+
private:
bool load_world();
@@ -94,7 +98,7 @@ private:
bool load_ships();
- bool load_player();
+ bool load_defaults();
/* ---- engine functions ----------------------------------- */
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();