From 969f213219dc1b8dcaf6b4fd6fdbc9d6f21ad9e0 Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Thu, 14 Jul 2016 19:05:03 +0200 Subject: Base steering control values on mouse aim world space location. --- src/game/base/ship.cc | 117 +++++++++++--------------------------------------- 1 file 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(); -- cgit v1.2.3