From e6516fb9999ae47a828e032f0908d2f2ae4b2434 Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Fri, 12 Nov 2010 19:50:04 +0000 Subject: enables entity model scaling, Entity::radius() gets precedence over Model::radius(), corrected bullet motionstate transfer bug in Entity::reset(), minor cleanups --- src/game/base/cargo.cc | 5 +- src/game/base/cargopod.cc | 11 ++++ src/game/base/ship.cc | 144 ++++++--------------------------------------- src/game/base/shipmodel.cc | 4 ++ src/game/base/template.cc | 2 +- 5 files changed, 37 insertions(+), 129 deletions(-) (limited to 'src/game') diff --git a/src/game/base/cargo.cc b/src/game/base/cargo.cc index e75064e..7953185 100644 --- a/src/game/base/cargo.cc +++ b/src/game/base/cargo.cc @@ -369,9 +369,9 @@ void Cargo::eject(core::EntityControlable *ejector, const int amount) pod->set_color(ejector->color()); pod->set_color_second(ejector->color_second()); - pod->set_zone(ejector->zone()); - pod->set_location(ejector->location() + ejector->axis().up() * ejector->radius()); + pod->set_location(ejector->location() + ejector->axis().up() * (ejector->radius() + pod->radius())); pod->set_axis(ejector->axis()); + pod->set_zone(ejector->zone()); // add loot to inventory pod->set_inventory(new core::Inventory()); @@ -389,6 +389,7 @@ void Cargo::eject(core::EntityControlable *ejector, const int amount) ejector->owner()->send(msgstr.str()); ejector->owner()->sound("game/eject"); } + pod->reset(); } diff --git a/src/game/base/cargopod.cc b/src/game/base/cargopod.cc index ed3ea69..09e5183 100644 --- a/src/game/base/cargopod.cc +++ b/src/game/base/cargopod.cc @@ -20,10 +20,21 @@ CargoPod::CargoPod() : EntityDynamic() set_flag(core::Entity::KeepAlive); + set_radius(0); + // use template settings if available if (cargopod_template) { cargopod_template->apply(this); } + + // radius fallback + if (!radius()) { + if (model()->radius()) { + set_radius(model()->radius()); + } else { + set_radius(0.1f); + } + } // activate physics set_mass(radius()); diff --git a/src/game/base/ship.cc b/src/game/base/ship.cc index 0b31a91..726729a 100644 --- a/src/game/base/ship.cc +++ b/src/game/base/ship.cc @@ -30,20 +30,33 @@ Ship::Ship(core::Player *owner, ShipModel *shipmodel) : core::EntityControlable( entity_moduletypeid = ship_enttype; + set_radius(0); + // apply template settings if (shipmodel->model_template()) { - shipmodel->model_template(); + shipmodel->model_template()->apply(this); } // apply ship model settings - // ship model overrides template model + // shipmodel overrides template model and radius if (shipmodel->modelname().size()) { set_modelname(shipmodel->modelname()); } - set_name(shipmodel->name()); - set_info(shipmodel); + if (shipmodel->radius()) { + set_radius(shipmodel->radius()); + } + if (!radius()) { + if (model()) { + set_radius(model()->radius()); + } + } + if (!radius()) { + set_radius(0.5f); + } ship_shipmodel = shipmodel; + set_info(shipmodel); + set_name(shipmodel->name()); ship_jumpdrive = shipmodel->jumpdrive(); ship_impulsedrive_timer = 0; ship_jumpdrive_timer = 0; @@ -61,8 +74,7 @@ Ship::Ship(core::Player *owner, ShipModel *shipmodel) : core::EntityControlable( // add an inventory set_inventory(new core::Inventory()); - inventory()->set_capacity(shipmodel->maxcargo()); - + inventory()->set_capacity(shipmodel->maxcargo()); } else { set_name(shipmodel->name()); set_label(shipmodel->label()); @@ -624,127 +636,7 @@ void Ship::frame(float seconds) if (current_target_roll < target_roll) current_target_roll = target_roll; } - - /* - // -- 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); - - - // 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 - - n.assign(math::crossproduct(axis().forward(), target_axis.forward())); - if (!(n.length() < MIN_DELTA)) { - n.normalize(); - cosangle = math::dotproduct(axis().forward(), target_axis.forward()); - angle = acos(cosangle) * seconds; // * 180.0f / M_PI; - if (angle > MIN_DELTA) - get_axis().rotate(n, -angle); - } - - // 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; - if (entity_speed > max) { - entity_speed = max; - } - } else if (entity_speed > max) { - entity_speed -= actual_acceleration * seconds; - if (entity_speed < max) { - entity_speed = max; - } - } - // 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; - } - - 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) || (entity_speed > 0)) { - set_dirty(); - } - - // transfer entity location to motion state - btTransform t; - t.setIdentity(); - t.setOrigin(math::to_btVector3(location())); - t.setBasis(math::to_btMatrix3x3(axis())); - entity_body->setWorldTransform(t); - - if (zone()) - zone()->physics()->synchronizeSingleMotionState(entity_body); - */ EntityControlable::frame(seconds); } diff --git a/src/game/base/shipmodel.cc b/src/game/base/shipmodel.cc index 1cea640..4c67e72 100644 --- a/src/game/base/shipmodel.cc +++ b/src/game/base/shipmodel.cc @@ -153,7 +153,9 @@ void ShipModel::done() ShipModel::ShipModel() : core::Info(shipmodel_infotype) { shipmodel_maxspeed = 0; + //default specifications + shipmodel_radius = 0; shipmodel_mass = 10.0f; shipmodel_thrust_force = 0.8f; shipmodel_impulse_force = 4.0f; @@ -165,6 +167,8 @@ ShipModel::ShipModel() : core::Info(shipmodel_infotype) shipmodel_jumpdrive = false; // no jumpdrive capability shipmodel_dockable = false; // not dockable + shipmodel_template = 0; + } ShipModel::~ShipModel() diff --git a/src/game/base/template.cc b/src/game/base/template.cc index 7861538..f937e22 100644 --- a/src/game/base/template.cc +++ b/src/game/base/template.cc @@ -93,7 +93,7 @@ bool Template::init() entitytemplate->set_color_second(colorvalue); } else if (inifile.got_key_float("radius", floatvalue)) { - + entitytemplate->set_radius(floatvalue); } else { inifile.unkown_key(); } -- cgit v1.2.3