From 7a373c3f1fb8ea9dbef7690154bbe332fc386eca Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Mon, 18 Oct 2010 23:41:41 +0000 Subject: bullet ActionInterface for controlable entities, KeepAlive flag and g_keepalive --- src/game/base/ship.cc | 80 +++++++++++++++++++++++++++------------------------ 1 file changed, 43 insertions(+), 37 deletions(-) (limited to 'src/game/base/ship.cc') diff --git a/src/game/base/ship.cc b/src/game/base/ship.cc index 44676c4..9f04e43 100644 --- a/src/game/base/ship.cc +++ b/src/game/base/ship.cc @@ -519,10 +519,7 @@ void Ship::frame(float seconds) entity_thrust = target_thrust; } math::clamp(entity_thrust, 0.0f, 1.0f); - actual_thrust = entity_thrust + current_target_afterburner * 0.15f; - if ((entity_state == core::Entity::ImpulseInitiate) || (entity_state == core::Entity::Impulse)) { - actual_thrust = 1.0f; - } + // update strafe control target if (current_target_strafe < target_strafe) { @@ -546,25 +543,6 @@ void Ship::frame(float seconds) current_target_vstrafe = target_vstrafe; } - // 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; - } - math::clamp(current_target_roll, -1.0f, 1.0f); - - if (fabs(current_target_roll) > MIN_DELTA) { - float roll_offset = seconds * current_target_roll; - get_axis().change_roll(actual_turnspeed * roll_offset); - } else { - current_target_roll = 0.0f; - } - // update direction control target if (current_target_direction < target_direction) { current_target_direction += direction_reaction * seconds; @@ -578,13 +556,6 @@ void Ship::frame(float seconds) } } - if (fabs(current_target_direction) > MIN_DELTA) { - math::clamp(current_target_direction, -1.0f, 1.0f); - target_axis.change_direction(actual_turnspeed * current_target_direction); - } else { - current_target_direction = 0.0f; - } - // update pitch control target if (current_target_pitch < target_pitch) { current_target_pitch += direction_reaction * seconds; @@ -596,13 +567,17 @@ void Ship::frame(float seconds) current_target_pitch = target_pitch; } - if (fabs(current_target_pitch) > MIN_DELTA) { - math::clamp(current_target_pitch, -1.0f, 1.0f); - target_axis.change_pitch(actual_turnspeed * current_target_pitch); - } else { - current_target_pitch = 0.0f; + // 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; } - + /* // -- BULLET @@ -628,10 +603,35 @@ void Ship::frame(float seconds) EntityDynamic::frame(seconds); */ + + // apply direction rotation to target axis + if (fabs(current_target_direction) > MIN_DELTA) { + math::clamp(current_target_direction, -1.0f, 1.0f); + target_axis.change_direction(actual_turnspeed * current_target_direction); + } else { + current_target_direction = 0.0f; + } + + // apply pitch rotation to target axis + if (fabs(current_target_pitch) > MIN_DELTA) { + math::clamp(current_target_pitch, -1.0f, 1.0f); + target_axis.change_pitch(actual_turnspeed * current_target_pitch); + } else { + current_target_pitch = 0.0f; + } + + // apply roll rotation to axis + if (fabs(current_target_roll) > MIN_DELTA) { + math::clamp(current_target_roll, -1.0f, 1.0f); + get_axis().change_roll(actual_turnspeed * current_target_roll * seconds); + } else { + current_target_roll = 0.0f; + } + + // update axis 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)) { n.normalize(); @@ -642,6 +642,12 @@ void Ship::frame(float seconds) } // update speed + if ((entity_state == core::Entity::ImpulseInitiate) || (entity_state == core::Entity::Impulse)) { + actual_thrust = 1.0f; + } else { + actual_thrust = entity_thrust + current_target_afterburner * 0.15f; + } + const float max = actual_thrust * actual_maxspeed; if (entity_speed < max) { entity_speed += actual_acceleration * seconds; -- cgit v1.2.3