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-11-12 19:50:04 +0000
committerStijn Buys <ingar@osirion.org>2010-11-12 19:50:04 +0000
commite6516fb9999ae47a828e032f0908d2f2ae4b2434 (patch)
tree80aaed66e95541d93bd56de6fb8cad997e078856
parentb460b3193e54b7364bb75ff26ce6f999887e454b (diff)
enables entity model scaling, Entity::radius() gets precedence over Model::radius(),
corrected bullet motionstate transfer bug in Entity::reset(), minor cleanups
-rw-r--r--src/core/entity.cc37
-rw-r--r--src/core/gameserver.cc1
-rw-r--r--src/game/base/cargo.cc5
-rw-r--r--src/game/base/cargopod.cc11
-rw-r--r--src/game/base/ship.cc144
-rw-r--r--src/game/base/shipmodel.cc4
-rw-r--r--src/game/base/template.cc2
-rw-r--r--src/render/draw.cc22
-rw-r--r--src/render/particles.cc8
9 files changed, 80 insertions, 154 deletions
diff --git a/src/core/entity.cc b/src/core/entity.cc
index 9e467fe..fe33d2a 100644
--- a/src/core/entity.cc
+++ b/src/core/entity.cc
@@ -316,9 +316,6 @@ void Entity::set_model(model::Model *model)
// server-side property should not clear modelname
entity_model = model;
if (entity_model) {
-
- //entity_radius = entity_model->radius();
-
entity_modelname.assign(entity_model->name());
}
@@ -394,8 +391,6 @@ void Entity::receive_server_create(std::istream &is)
entity_shape = (Shape) s;
is >> entity_radius;
- if (entity_model)
- entity_radius = model()->radius();
is >> entity_axis[0];
is >> entity_axis[1];
@@ -519,8 +514,9 @@ void Entity::reset()
// construct physics body if necessary
if (!entity_body) {
// create collision shape
- if (model()) {
- entity_collision_shape = new btBoxShape(to_btVector3(model()->box().max()));
+ if (model() && model()->radius()) {
+ const float modelscale = radius() / model()->radius();
+ entity_collision_shape = new btBoxShape(to_btVector3(model()->box().max() * modelscale));
} else {
entity_collision_shape = new btSphereShape(radius());
}
@@ -542,12 +538,13 @@ void Entity::reset()
}
// transfer entity location to motion state
- body()->setWorldTransform(t);
body()->setLinearVelocity(btVector3(0.0f, 0.0f, 0.0f));
- body()->setAngularVelocity(btVector3(0.0f, 0.0f, 0.0f));
+ body()->setLinearVelocity(btVector3(0.0f, 0.0f, 0.0f));
+ body()->setWorldTransform(t);
+ motionstate()->setWorldTransform(t);
- if (zone())
- zone()->physics()->synchronizeSingleMotionState(entity_body);
+ //if (zone())
+ // zone()->physics()->synchronizeSingleMotionState(entity_body);
set_dirty();
}
@@ -936,6 +933,9 @@ void EntityControlable::set_zone(Zone *zone)
void EntityControlable::reset()
{
+ if (!radius())
+ return;
+
// location and orientation
btTransform t;
t.setIdentity();
@@ -945,8 +945,10 @@ void EntityControlable::reset()
// construct physics body if necessary
if (!entity_body) {
// create collision shape
- if (model()) {
- entity_collision_shape = new btBoxShape(to_btVector3(model()->box().max()));
+ // create collision shape
+ if (model() && model()->radius()) {
+ const float modelscale = radius() / model()->radius();
+ entity_collision_shape = new btBoxShape(to_btVector3(model()->box().max() * modelscale));
} else {
entity_collision_shape = new btSphereShape(radius());
}
@@ -973,6 +975,7 @@ void EntityControlable::reset()
body()->setLinearVelocity(btVector3(0.0f, 0.0f, 0.0f));
body()->setLinearVelocity(btVector3(0.0f, 0.0f, 0.0f));
body()->setWorldTransform(t);
+ motionstate()->setWorldTransform(t);
if (entity_state == Docked) {
body()->setLinearFactor(btVector3(0.0f, 0.0f, 0.0f));
@@ -982,10 +985,10 @@ void EntityControlable::reset()
body()->setAngularFactor(btVector3(1.0f, 1.0f, 1.0f));
}
- if (zone()) {
- // transfer entity location to motion state
- zone()->physics()->synchronizeSingleMotionState(entity_body);
- }
+ //if (zone()) {
+ // // transfer entity location to motion state
+ // zone()->physics()->synchronizeSingleMotionState(entity_body);
+ //}
set_dirty();
}
diff --git a/src/core/gameserver.cc b/src/core/gameserver.cc
index 7d6fc96..e07774d 100644
--- a/src/core/gameserver.cc
+++ b/src/core/gameserver.cc
@@ -546,6 +546,7 @@ void GameServer::frame(unsigned long timestamp)
Entity *entity = (*it).second;
Zone *zone = entity->zone();
if (zone && entity->flag_is_set(Entity::KeepAlive)) {
+
if (zone->keepalive_run() && zone->keepalive_box().inside(entity->location())) {
entity->set_keepalive(server_timestamp);
}
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();
}
diff --git a/src/render/draw.cc b/src/render/draw.cc
index 3aa9371..c9da6d4 100644
--- a/src/render/draw.cc
+++ b/src/render/draw.cc
@@ -327,7 +327,7 @@ void draw_entity_sphere(const core::Entity* entity)
void draw_entity_cube(const core::Entity* entity)
{
- float radius = entity->radius();
+ const float radius = entity->radius();
gl::scale(radius, radius, radius);
@@ -378,7 +378,7 @@ void draw_entity_cube(const core::Entity* entity)
void draw_entity_diamond(const core::Entity* entity)
{
- float radius = entity->radius() / 2;
+ const float radius = entity->radius() / 2.0f;
/* ---- draw axis lines ---- */
gl::color(entity->color_second());
@@ -792,7 +792,7 @@ void draw_model_bbox(model::Model *model)
void draw_model_axis(const core::Entity *entity)
{
// axis
- const float r = entity->radius() * 1.5f;
+ const float r = entity->model()->radius() * 1.5f;
gl::begin(gl::Lines);
@@ -832,6 +832,9 @@ void draw_pass_model_fragments()
gl::push();
gl::translate(entity->location());
gl::multmatrix(entity->axis());
+
+ const float modelscale = entity->radius() / entity->model()->radius();
+ gl::scale(modelscale, modelscale, modelscale);
draw_model_fragments(
entity->model(),
@@ -851,6 +854,7 @@ void draw_pass_model_fragments()
if (r_axis->value()) {
draw_model_axis(entity);
}
+
gl::pop();
}
}
@@ -885,6 +889,8 @@ void draw_pass_model_fx(float elapsed)
}
if (entity->model() && ext_render(entity)->detailvisible() && power) {
+
+ const float modelscale = entity->radius() / entity->model()->radius();
// disable culling by default
gl::disable(GL_CULL_FACE);
@@ -939,8 +945,8 @@ void draw_pass_model_fx(float elapsed)
}
color.a = a;
- location.assign(entity->location() + (entity->axis() * light->location()));
- light_size = 0.0625f * light->radius();
+ location.assign(entity->location() + (entity->axis() * light->location()) * modelscale);
+ light_size = 0.0625f * light->radius() * modelscale;
// track OpenGL state changes
if (current_texture != light->texture()) {
@@ -1012,8 +1018,8 @@ void draw_pass_model_fx(float elapsed)
}
color.a = a;
- location.assign(entity->location() + (entity->axis() * flare->location()));
- light_size = 0.0625f * flare->radius();
+ location.assign(entity->location() + (entity->axis() * flare->location()) * modelscale );
+ light_size = 0.0625f * flare->radius() * modelscale;
// track OpenGL state changes
if ((current_cull != flare->cull()) || (current_texture != flare->texture())) {
@@ -1110,7 +1116,7 @@ void draw_pass_model_radius()
gl::translate(entity->location());
math::Color color = entity->color();
color.a = 0.25f;
- draw_sphere(color, entity->model()->radius());
+ draw_sphere(color, entity->radius());
gl::pop();
}
}
diff --git a/src/render/particles.cc b/src/render/particles.cc
index 6ffcd35..610c49a 100644
--- a/src/render/particles.cc
+++ b/src/render/particles.cc
@@ -211,6 +211,14 @@ ParticleSystem::ParticleSystem(ParticleScript *script, core::Entity *entity, mod
particlesystem_axis.assign(modelclass->axis());
// particlesystem_cull = particlesystem_modelclass->cull();
}
+
+
+ // rescale particle system according to entity radius
+ if (entity->model() && entity->model()->radius()) {
+ const float modelscale = entity->radius() / entity->model()->radius();
+ particlesystem_location *= modelscale;
+ particlesystem_radius *= modelscale;
+ }
}
ParticleSystem::~ParticleSystem()