Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
Diffstat (limited to 'src/core')
-rw-r--r--src/core/entity.cc49
-rw-r--r--src/core/entity.h13
2 files changed, 29 insertions, 33 deletions
diff --git a/src/core/entity.cc b/src/core/entity.cc
index ebe4938..ec25017 100644
--- a/src/core/entity.cc
+++ b/src/core/entity.cc
@@ -153,7 +153,6 @@ Entity::Entity() :
entity_collision_shape = 0;
entity_speed = 0.0f;
- entity_mass = 0.0f;
entity_radius = 0.5f;
entity_shape = Diamond;
@@ -193,7 +192,6 @@ Entity::Entity(std::istream & is)
entity_collision_shape = 0;
entity_speed = 0.0f;
- entity_mass = 0.0f;
entity_created = true;
entity_destroyed = false;
@@ -511,15 +509,10 @@ void Entity::reset()
meshshape->buildOptimizedBvh();
meshshape->recalcLocalAabb();
- //btGImpactMeshShape *meshshape = new btGImpactMeshShape(model()->collisionmesh()->triangles());
-
btVector3 modelscalevec(modelscale, modelscale, modelscale);
meshshape->setLocalScaling(modelscalevec);
- meshshape->setMargin(Cvar::sv_collisionmargin->value());
entity_collision_shape = meshshape;
- // con_debug << " " << label() << " attached collision mesh: " << model()->collisionmesh()->size() << " triangles" << std::endl;
-
} else {
// use bounding box
entity_collision_shape = new btBoxShape(to_btVector3(model()->box().max() * modelscale));
@@ -527,16 +520,14 @@ void Entity::reset()
} else {
entity_collision_shape = new btSphereShape(radius());
}
+ entity_collision_shape->setMargin(Cvar::sv_collisionmargin->value());
btVector3 inertia(0, 0, 0);
- if (entity_mass)
- entity_collision_shape->calculateLocalInertia(entity_mass, inertia);
-
+
// create physics body
- entity_body_info = new btRigidBody::btRigidBodyConstructionInfo(entity_mass, 0, entity_collision_shape, inertia);
+ entity_body_info = new btRigidBody::btRigidBodyConstructionInfo(0, 0, entity_collision_shape, inertia);
entity_body = new btRigidBody(*entity_body_info);
entity_body->setActivationState(ISLAND_SLEEPING);
- entity_body->setCollisionFlags(entity_body->getCollisionFlags() | btCollisionObject::CF_STATIC_OBJECT);
if (zone())
zone()->physics()->addRigidBody(entity_body);
@@ -547,9 +538,6 @@ void Entity::reset()
body()->setLinearVelocity(btVector3(0.0f, 0.0f, 0.0f));
body()->setWorldTransform(t);
- //if (zone())
- // zone()->physics()->synchronizeSingleMotionState(entity_body);
-
set_dirty();
}
@@ -560,6 +548,7 @@ EntityDynamic::EntityDynamic() : Entity()
entity_state = Normal;
entity_timer = 0;
entity_motionstate = 0;
+ entity_mass = 0.0f;
}
EntityDynamic::EntityDynamic(std::istream & is) : Entity(is)
@@ -567,6 +556,7 @@ EntityDynamic::EntityDynamic(std::istream & is) : Entity(is)
entity_state = Normal;
entity_timer = 0;
entity_motionstate = 0;
+ entity_mass = 0.0f;
}
EntityDynamic::~EntityDynamic()
@@ -608,10 +598,9 @@ void EntityDynamic::reset()
btVector3 modelscalevec(modelscale, modelscale, modelscale);
meshshape->setLocalScaling(modelscalevec);
- meshshape->setMargin(Cvar::sv_collisionmargin->value());
meshshape->updateBound();
- entity_collision_shape = meshshape;
+ entity_collision_shape = meshshape;
} else {
// use bounding box
entity_collision_shape = new btBoxShape(to_btVector3(model()->box().max() * modelscale));
@@ -619,6 +608,8 @@ void EntityDynamic::reset()
} else {
entity_collision_shape = new btSphereShape(radius());
}
+ entity_collision_shape->setMargin(Cvar::sv_collisionmargin->value());
+
btVector3 inertia(0, 0, 0);
if (entity_mass)
entity_collision_shape->calculateLocalInertia(entity_mass, inertia);
@@ -627,11 +618,14 @@ void EntityDynamic::reset()
entity_motionstate = new btDefaultMotionState(t);
// create physics body
- entity_body_info = new btRigidBody::btRigidBodyConstructionInfo(entity_mass, entity_motionstate, entity_collision_shape, inertia);
-
+ 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);
- entity_body->setCollisionFlags(entity_body->getCollisionFlags() | btCollisionObject::CF_KINEMATIC_OBJECT);
+
+ if (entity_mass) {
+ entity_body->setActivationState(DISABLE_DEACTIVATION);
+ } else {
+ entity_body->setActivationState(ISLAND_SLEEPING);
+ }
if (zone())
zone()->physics()->addRigidBody(entity_body);
@@ -641,6 +635,10 @@ void EntityDynamic::reset()
body()->setLinearVelocity(btVector3(0.0f, 0.0f, 0.0f));
body()->setLinearVelocity(btVector3(0.0f, 0.0f, 0.0f));
body()->setWorldTransform(t);
+
+ if (motionstate()) {
+ motionstate()->setWorldTransform(t);
+ }
if (entity_state == Docked) {
body()->setLinearFactor(btVector3(0.0f, 0.0f, 0.0f));
@@ -661,11 +659,7 @@ void EntityDynamic::frame(float seconds)
// transfer bullet state to entity state
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();
- }
-
+
btTransform t;
entity_motionstate->getWorldTransform(t);
get_location().assign(t.getOrigin());
@@ -675,7 +669,7 @@ void EntityDynamic::frame(float seconds)
if (entity_speed > 0) {
set_dirty();
}
- entity_speed = (float) entity_body->getLinearVelocity().length();
+ entity_speed = (float) entity_body->getLinearVelocity().length();
if (entity_speed > 0) {
set_dirty();
}
@@ -1048,6 +1042,7 @@ void EntityControlable::reset()
entity_body_info = new btRigidBody::btRigidBodyConstructionInfo(entity_mass, entity_motionstate, entity_collision_shape, inertia);
entity_body = new btRigidBody(*entity_body_info);
entity_body->setActivationState(DISABLE_DEACTIVATION);
+
//entity_body->setCollisionFlags(entity_body->getCollisionFlags() | btCollisionObject::CF_KINEMATIC_OBJECT);
entity_actioninterface = new ActionInterface(this);
diff --git a/src/core/entity.h b/src/core/entity.h
index e12123e..54849b7 100644
--- a/src/core/entity.h
+++ b/src/core/entity.h
@@ -158,11 +158,6 @@ public:
return entity_speed;
}
- /// mass of the entity
- inline const float mass() const {
- return entity_mass;
- }
-
/// physics body
inline btRigidBody *body() {
return entity_body;
@@ -457,7 +452,6 @@ protected:
// the previous zone the entity belonged too
Zone* entity_oldzone;
- float entity_mass;
float entity_speed;
private:
@@ -525,6 +519,11 @@ public:
return entity_state;
}
+ /// mass of the entity
+ inline const float mass() const {
+ return entity_mass;
+ }
+
/// event state timer
inline const float timer() const {
return entity_timer;
@@ -585,9 +584,11 @@ public:
virtual void reset();
protected:
+ float entity_mass;
float entity_timer;
int entity_state;
btMotionState *entity_motionstate;
+
};
/// an entity that can be controlled by a player