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>2016-07-14 19:05:03 +0200
committerStijn Buys <ingar@osirion.org>2016-07-14 19:05:03 +0200
commit969f213219dc1b8dcaf6b4fd6fdbc9d6f21ad9e0 (patch)
treec1d0119e8c174a3099c4597070fbec23d3b390f6
parentfe9f4d477772d68eb06c9b31b9553cba67124606 (diff)
Base steering control values on mouse aim world space location.
-rw-r--r--src/game/base/ship.cc117
1 files changed, 24 insertions, 93 deletions
diff --git a/src/game/base/ship.cc b/src/game/base/ship.cc
index 78e6973..ccd8718 100644
--- a/src/game/base/ship.cc
+++ b/src/game/base/ship.cc
@@ -1088,8 +1088,7 @@ void Ship::frame(const unsigned long elapsed)
}
}
- /* -- SNAPPY ------------------------------------------ */
-
+ // set steering controls
current_target_afterburner = target_afterburner;
if (current_target_afterburner < 0.0f) {
target_thrust = 0;
@@ -1099,103 +1098,35 @@ void Ship::frame(const unsigned long elapsed)
current_target_strafe = target_strafe;
current_target_vstrafe = target_vstrafe;
+ if (has_target_controlflag(core::EntityControlable::ControlFlagOverride)) {
+ const float powersteering = 4.0f;
+ // use mouse aim location to set steering controls
+ math::Vector3f direction(target_aim - location());
+ direction.normalize();
+
+ // transform direction from world coordinates to local entity coordinates
+ direction = axis().transpose() * direction;
+
+ if (direction.x() < 0) {
+ // aim is behind the ship
+ target_pitch = direction.z() * powersteering;
+ target_direction = direction.y() * powersteering;
+ } else {
+ // target is in front of the ship
+ target_pitch = direction.z() * powersteering;
+ target_direction = direction.y() * powersteering;
+ }
+ math::clamp(target_pitch, -1.0f, 1.0f);
+ math::clamp(target_direction, -1.0f, 1.0f);
+ }
+
current_target_roll = target_roll;
current_target_pitch = target_pitch;
current_target_direction = target_direction;
- // clamp values
- math::clamp(entity_thrust, 0.0f, 1.0f);
-
- /* -- NOT SNAPPY -------------------------------------- */
- /*
- // update afterburner control target
-
- if (current_target_afterburner < target_afterburner) {
- current_target_afterburner += afterburner_reaction * seconds;
- if (current_target_afterburner > target_afterburner)
- current_target_afterburner = target_afterburner;
-
- } else if (current_target_afterburner > target_afterburner) {
- current_target_afterburner -= afterburner_reaction * seconds;
- if (current_target_afterburner < target_afterburner)
- current_target_afterburner = target_afterburner;
- }
- // update thrust control target
- if (current_target_afterburner < 0.0f) {
- target_thrust = 0;
- }
-
- if (entity_thrust < target_thrust) {
- entity_thrust += thrust_reaction * seconds;
- if (entity_thrust > target_thrust)
- entity_thrust = target_thrust;
-
- } else if (entity_thrust > target_thrust) {
- entity_thrust -= thrust_reaction * seconds;
- if (entity_thrust < target_thrust)
- entity_thrust = target_thrust;
- }
math::clamp(entity_thrust, 0.0f, 1.0f);
- // update strafe control target
- if (current_target_strafe < target_strafe) {
- current_target_strafe += strafe_reaction * seconds;
- if (current_target_strafe > target_strafe)
- current_target_strafe = target_strafe;
- } else if (current_target_strafe > target_strafe) {
- current_target_strafe -= strafe_reaction * 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 direction control target
- if (current_target_direction < target_direction) {
- current_target_direction += direction_reaction * seconds;
- if (current_target_direction > target_direction) {
- current_target_direction = target_direction;
- }
- } else if (current_target_direction > target_direction) {
- current_target_direction -= direction_reaction * seconds;
- if (current_target_direction < target_direction) {
- current_target_direction = target_direction;
- }
- }
-
- // update pitch control target
- if (current_target_pitch < target_pitch) {
- current_target_pitch += direction_reaction * seconds;
- if (current_target_pitch > target_pitch)
- current_target_pitch = target_pitch;
- } else if (current_target_pitch > target_pitch) {
- current_target_pitch -= direction_reaction * seconds;
- if (current_target_pitch < target_pitch)
- current_target_pitch = target_pitch;
- }
-
- // update roll control target
- if (current_target_roll < target_roll) {
- current_target_roll += direction_reaction * seconds;
- if (current_target_roll > target_roll)
- current_target_roll = target_roll;
- } else if (current_target_roll > target_roll) {
- current_target_roll -= direction_reaction * seconds;
- if (current_target_roll < target_roll)
- current_target_roll = target_roll;
- }
- */
-
EntityControlable::frame(elapsed);
// fire weapons
@@ -1436,7 +1367,7 @@ void Ship::frame_autopilot_combat(const unsigned long elapsed, core::Entity *tar
if (direction.x() < 0) {
// target is behind the ship
- if (distance > 4.0f * r) {
+ if (distance > 5.0f * radius() + target->radius()) {
// turn at a distance
target_direction = (direction.y() > 0.0f ? 1.0f : -1.0f);
target_pitch = direction.z();