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-19 21:16:41 +0000
committerStijn Buys <ingar@osirion.org>2010-10-19 21:16:41 +0000
commita76489275b7c66ab0264e8e29c4d4d08c22e3e16 (patch)
treea634d0d09dcc0244ba315f5997707c407c5aa0ec
parent0a96c7741937a09f1ec8d410c81cf8cee4588b51 (diff)
bullet ship physics
-rw-r--r--doc/TODO5
-rw-r--r--src/game/base/ship.cc100
-rw-r--r--src/game/base/ship.h5
-rw-r--r--src/render/draw.cc1
4 files changed, 94 insertions, 17 deletions
diff --git a/doc/TODO b/doc/TODO
index 58037db..2aa34d9 100644
--- a/doc/TODO
+++ b/doc/TODO
@@ -79,16 +79,17 @@ ui:
fix slider mouse dragging
sound:
+ suppress sound errors if the sound subsystem failed to initialize
entity/event positional sounds
jump drive sound events
game:
entity health/shield/armor
- fix 'give ship' and 'buy ship' destroying inventory
+
+ fix 'give ship' and 'buy ship' destroying inventory (ok)
data:
update starsystem roadmap
rename skies (lindblade1, lindblade2, ...)
win32 port:
-
diff --git a/src/game/base/ship.cc b/src/game/base/ship.cc
index 9f04e43..7cd602e 100644
--- a/src/game/base/ship.cc
+++ b/src/game/base/ship.cc
@@ -77,11 +77,12 @@ Ship::Ship(core::Player *owner, ShipModel *shipmodel) : core::EntityControlable(
set_flag(core::Entity::Dockable);
}
- set_mass(radius());
+ set_mass(radius() * 10.0f);
reset();
- const float damp = Game::g_damping->value();
- body()->setDamping(damp, damp);
+ const float linear_damp = 0.5f;
+ const float angular_damp = 0.75f;
+ body()->setDamping(linear_damp, angular_damp);
}
Ship::~Ship()
@@ -298,22 +299,96 @@ void Ship::set_zone(core::Zone *zone)
owner()->set_zone(zone);
}
+void Ship::action (btScalar seconds)
+{
+ /* controls
+ *
+ * current_target_direction
+ * current_target_pitch
+ * current_target_roll
+ * current_target_strafe
+ * current_target_vstrafe
+ * entity_thrust
+ */
+
+ float actual_maxspeed = 0;
+ float actual_acceleration = 0;
+ float actual_thrust = 0;
+ btTransform t;
+
+ switch (entity_state) {
+ case core::Entity::Normal:
+ actual_maxspeed = ship_shipmodel->maxspeed();
+ actual_acceleration = ship_shipmodel->acceleration();
+ actual_thrust = entity_thrust;
+ break;
+ case core::Entity::ImpulseInitiate:
+ case core::Entity::Impulse:
+ actual_maxspeed = Game::g_impulsespeed->value();
+ actual_acceleration = Game::g_impulseacceleration->value();
+ actual_thrust = 1.0f;
+ break;
+ case core::Entity::JumpInitiate:
+ case core::Entity::Jump:
+ actual_maxspeed = 0.0f;
+ actual_acceleration = Game::g_impulseacceleration->value();
+ actual_thrust = 0.0f;
+ break;
+ case core::Entity::Docked:
+
+ t.setIdentity();
+ t.setOrigin(to_btVector3(location()));
+ t.setBasis(to_btMatrix3x3(axis()));
+ body()->setWorldTransform(t);
+ return;
+ break;
+ default:
+ break;
+ }
+
+ t.setIdentity();
+ entity_motionstate->getWorldTransform(t);
+ get_location().assign(t.getOrigin());
+ get_axis().assign(t.getBasis());
+
+ const float force_scale = 1.0f;
+ const float thrust_scale = 4.0f;
+
+ body()->applyCentralImpulse(math::to_btVector3(axis().up() * current_target_vstrafe * actual_acceleration * force_scale));
+ body()->applyCentralImpulse(math::to_btVector3(axis().left() * current_target_strafe * actual_acceleration * force_scale));
+
+ body()->applyCentralImpulse(math::to_btVector3(axis().forward() * current_target_afterburner * actual_acceleration * force_scale));
+ if (current_target_afterburner >= 0) {
+ body()->applyCentralImpulse(math::to_btVector3(axis().forward() * actual_thrust * actual_acceleration * thrust_scale));
+ }
+
+ const float torque_scale = 0.001f;
+ body()->applyTorqueImpulse(math::to_btVector3(axis().up() * current_target_direction * ship_shipmodel->turnspeed() * torque_scale));
+ body()->applyTorqueImpulse(math::to_btVector3(axis().left() * -current_target_pitch * ship_shipmodel->turnspeed() * torque_scale));
+
+ body()->applyTorqueImpulse(math::to_btVector3(axis().forward() * -current_target_roll * ship_shipmodel->turnspeed() * torque_scale * 0.25f));
+
+ entity_speed = (float) entity_body->getLinearVelocity().length();
+ if (entity_speed > Game::g_impulsespeed->value()) {
+ body()->setLinearVelocity(math::to_btVector3(axis().forward() * Game::g_impulsespeed->value()));
+ entity_speed = actual_maxspeed;
+ }
+
+}
void Ship::frame(float seconds)
{
const float direction_reaction = 2.0f; // direction controls reaction time factor
const float thrust_reaction = 0.5f; // thrust control reaction time factor
const float strafe_reaction = 1.5f;
const float afterburner_reaction = 1.0f; // a fterburner control reaction time
+ //const float actual_turnspeed = ship_shipmodel->turnspeed();
- float actual_maxspeed = ship_shipmodel->maxspeed();
- float actual_turnspeed = ship_shipmodel->turnspeed();
+ float actual_maxspeed = ship_shipmodel->maxspeed();
float actual_acceleration = ship_shipmodel->acceleration();
- float actual_thrust = 0;
+ //float actual_thrust = 0;
- math::Vector3f n; // normal of a plane
-
+ math::Vector3f n; // normal of a plane
math::Axis target_axis(axis()); // target axis
-
entity_movement = 0;
/* -- update state ----------------------------------------- */
@@ -438,7 +513,6 @@ void Ship::frame(float seconds)
actual_maxspeed = Game::g_impulsespeed->value();
actual_acceleration = Game::g_impulseacceleration->value();
- actual_turnspeed *= 0.5;
}
} else if (entity_state == core::Entity::Impulse) {
@@ -458,7 +532,6 @@ void Ship::frame(float seconds)
} else {
actual_maxspeed = Game::g_impulsespeed->value();
actual_acceleration = Game::g_impulseacceleration->value();
- actual_turnspeed *= 0.5;
target_afterburner = 0.0f;
target_thrust = 0.0f;
}
@@ -474,7 +547,6 @@ void Ship::frame(float seconds)
if (speed() > actual_maxspeed * 1.15f) {
actual_acceleration = Game::g_impulseacceleration->value();
- actual_turnspeed *= 0.5;
}
} else if (entity_state == core::Entity::Destroyed) {
@@ -602,7 +674,7 @@ void Ship::frame(float seconds)
}
EntityDynamic::frame(seconds);
- */
+
// apply direction rotation to target axis
if (fabs(current_target_direction) > MIN_DELTA) {
@@ -697,6 +769,8 @@ void Ship::frame(float seconds)
if (zone())
zone()->physics()->synchronizeSingleMotionState(entity_body);
+ */
+ EntityControlable::frame(seconds);
}
} // namespace game
diff --git a/src/game/base/ship.h b/src/game/base/ship.h
index 1f4f743..2c1bc2c 100644
--- a/src/game/base/ship.h
+++ b/src/game/base/ship.h
@@ -23,7 +23,10 @@ public:
Ship(core::Player *owner, ShipModel *shipmodel);
~Ship();
- /// update the ship state
+ /// physices frame
+ virtual void action (btScalar seconds);
+
+ /// game frame
virtual void frame(float seconds);
/// move the ship to a different zone
diff --git a/src/render/draw.cc b/src/render/draw.cc
index 04ccce4..4fc0b60 100644
--- a/src/render/draw.cc
+++ b/src/render/draw.cc
@@ -1134,7 +1134,6 @@ void draw_pass_model_fx(float elapsed)
gl::enable(GL_CULL_FACE);
}
-
void draw_pass_model_radius()
{
for (core::Zone::Content::iterator it = zone->content().begin(); it != zone->content().end(); it++) {