diff options
author | Stijn Buys <ingar@osirion.org> | 2010-10-17 21:25:27 +0000 |
---|---|---|
committer | Stijn Buys <ingar@osirion.org> | 2010-10-17 21:25:27 +0000 |
commit | 1032161366da1b2153de8d804465061e6bcc4fce (patch) | |
tree | d9163c92c79791c9495e6d5f2944aea27c24e77f /src/core/entity.cc | |
parent | 31c4ff4ff080ea34389c60ba4edd268dc7f3c08a (diff) |
moved bullet objets to core::Entity,
moved docking functions to game.cc and removed entity->dock(),
enabled depth testing for bullet debug draw
Diffstat (limited to 'src/core/entity.cc')
-rw-r--r-- | src/core/entity.cc | 131 |
1 files changed, 62 insertions, 69 deletions
diff --git a/src/core/entity.cc b/src/core/entity.cc index 8a7976f..2f8b8a5 100644 --- a/src/core/entity.cc +++ b/src/core/entity.cc @@ -144,7 +144,10 @@ Entity::Entity() : entity_moduletypeid = 0; entity_model = 0; + + entity_body = 0; entity_body = 0; + entity_motionstate = 0; entity_collision_shape = 0; entity_speed = 0.0f; @@ -180,7 +183,10 @@ Entity::Entity(std::istream & is) entity_visible = true; entity_model = 0; + entity_body = 0; + entity_body = 0; + entity_motionstate = 0; entity_collision_shape = 0; entity_speed = 0.0f; @@ -219,11 +225,19 @@ Entity::~Entity() if (entity_zone) entity_zone->remove(this); + if (entity_motionstate) + delete entity_motionstate; + if (entity_collision_shape) delete entity_collision_shape; if (entity_body) delete entity_body; + + if (entity_body_info) + delete entity_body_info; + + } void Entity::die() @@ -244,34 +258,6 @@ void Entity::clear_updates() } } -// reset physics state -void Entity::reset() -{ - if (!entity_body) { - if (entity_collision_shape ) { - delete entity_collision_shape ; - entity_collision_shape = 0; - } - - if (model()) { - entity_collision_shape = new btBoxShape(to_btVector3(model()->maxbbox())); - } else { - entity_collision_shape = new btSphereShape(radius()); - } - - btVector3 inertia(0, 0, 0); - entity_body = new btRigidBody(0.0f, 0, entity_collision_shape, inertia); - } - - btTransform t; - t.setIdentity(); - t.setOrigin(to_btVector3(location())); - t.setBasis(to_btMatrix3x3(axis())); - - entity_body->setWorldTransform(t); - set_dirty(); -} - void Entity::set_info(Info *info) { entity_info = info; @@ -467,10 +453,6 @@ void Entity::receive_server_update(std::istream &is) { } -void Entity::dock(core::Entity *entity) -{ -} - void Entity::frame(float seconds) { } @@ -498,27 +480,63 @@ void Entity::remove_menu(std::string const &label) } } +void Entity::reset() +{ + // location and orientation + btTransform t; + t.setIdentity(); + t.setOrigin(to_btVector3(location())); + t.setBasis(to_btMatrix3x3(axis())); + + // construct physics body if necessary + if (!entity_body) { + // create collision shape + if (model()) { + entity_collision_shape = new btBoxShape(to_btVector3(model()->maxbbox())); + } else { + entity_collision_shape = new btSphereShape(radius()); + } + btVector3 inertia(0, 0, 0); + if (entity_mass) + entity_collision_shape->calculateLocalInertia(entity_mass, inertia); + + // create motion state + entity_motionstate = new btDefaultMotionState(t); + + // create physics body + entity_body_info = new btRigidBody::btRigidBodyConstructionInfo(entity_mass, entity_motionstate, entity_collision_shape, inertia); + + entity_body = new btRigidBody(*entity_body_info); + //entity_body->setActivationState(ISLAND_SLEEPING); + + if (zone()) + zone()->physics()->addRigidBody(entity_body); + } + + // transfer entity location to motion state + entity_body->setWorldTransform(t); + if (zone()) + zone()->physics()->synchronizeSingleMotionState(entity_body); + + set_dirty(); +} + /* ---- class EntityDynamic ---------------------------------------- */ EntityDynamic::EntityDynamic() : Entity() { entity_state = Normal; entity_timer = 0; - - entity_motionstate = new btDefaultMotionState(); } EntityDynamic::EntityDynamic(std::istream & is) : Entity(is) { entity_state = Normal; entity_timer = 0; - entity_motionstate = 0; } EntityDynamic::~EntityDynamic() { - if (entity_motionstate) - delete entity_motionstate; } void EntityDynamic::set_state(int state) @@ -529,39 +547,15 @@ void EntityDynamic::set_state(int state) } } -// reset physics state void EntityDynamic::reset() { - assert(entity_motionstate); - - // construct physics body if necessary - if (!entity_body) { - if (entity_collision_shape ) { - delete entity_collision_shape ; - entity_collision_shape = 0; - } - - if (model()) { - entity_collision_shape = new btBoxShape(to_btVector3(model()->maxbbox())); - } else { - entity_collision_shape = new btSphereShape(radius()); - } - - btVector3 inertia(0, 0, 0); - entity_collision_shape->calculateLocalInertia(entity_mass, inertia); - entity_body = new btRigidBody(entity_mass, entity_motionstate, entity_collision_shape, inertia); + Entity::reset(); + + if ((entity_state == Docked) || (entity_state == Destroyed) || (!visible())){ + entity_body->activate(false); + } else { + entity_body->activate(true); } - - // transfer entity location to motion state - btTransform t; - t.setIdentity(); - t.setOrigin(to_btVector3(location())); - t.setBasis(to_btMatrix3x3(axis())); - entity_body->setWorldTransform(t); - if (zone()) - zone()->physics()->synchronizeSingleMotionState(entity_body); - - set_dirty(); } void EntityDynamic::frame(float seconds) @@ -571,8 +565,7 @@ void EntityDynamic::frame(float seconds) // transfer bullet state to entity state // FIXME disable physics when docked - if (entity_body && entity_motionstate) { - + if (entity_body) { // this makes sure an update is sent if speed goes to 0 in the next step if (entity_speed > 0) { set_dirty(); |