Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
authorStijn Buys <ingar@osirion.org>2011-02-08 16:55:23 +0000
committerStijn Buys <ingar@osirion.org>2011-02-08 16:55:23 +0000
commit38eb51c26ab0d9dbebc974c7a21f96a429ce3098 (patch)
tree8563fdcf4de0d19ad20e660ae30b4b333825e4d4 /src/core
parent84dd93a63305bd3b1ff3c5c897a6f3e729bfefed (diff)
Corrected triangle loading of collision model, added 'complex' flag to ships.ini
to enable collision models on player ships.
Diffstat (limited to 'src/core')
-rw-r--r--src/core/entity.cc95
-rw-r--r--src/core/entity.h12
2 files changed, 86 insertions, 21 deletions
diff --git a/src/core/entity.cc b/src/core/entity.cc
index 6aef6e5..7aa72fa 100644
--- a/src/core/entity.cc
+++ b/src/core/entity.cc
@@ -150,7 +150,6 @@ Entity::Entity() :
entity_body = 0;
entity_body_info = 0;
- entity_motionstate = 0;
entity_collision_shape = 0;
entity_speed = 0.0f;
@@ -191,7 +190,6 @@ Entity::Entity(std::istream & is)
entity_body = 0;
entity_body_info = 0;
- entity_motionstate = 0;
entity_collision_shape = 0;
entity_speed = 0.0f;
@@ -235,9 +233,6 @@ Entity::~Entity()
}
}
- if (entity_motionstate)
- delete entity_motionstate;
-
if (entity_collision_shape)
delete entity_collision_shape;
@@ -511,6 +506,7 @@ void Entity::reset()
if (flag_is_set(Complex) && model()->collisionmesh()) {
// use collision mesh
+ // static entities use a btBvhTriangleMeshShape
btBvhTriangleMeshShape *meshshape = new btBvhTriangleMeshShape(model()->collisionmesh()->triangles(), true, true);
meshshape->buildOptimizedBvh();
meshshape->recalcLocalAabb();
@@ -519,7 +515,7 @@ void Entity::reset()
btVector3 modelscalevec(modelscale, modelscale, modelscale);
meshshape->setLocalScaling(modelscalevec);
- meshshape->setMargin(0.0f);
+ //meshshape->setMargin(0.0f);
//meshshape->updateBound();
entity_collision_shape = meshshape;
@@ -536,14 +532,12 @@ void Entity::reset()
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_info = new btRigidBody::btRigidBodyConstructionInfo(entity_mass, 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);
@@ -553,7 +547,6 @@ void Entity::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 (zone())
// zone()->physics()->synchronizeSingleMotionState(entity_body);
@@ -567,16 +560,20 @@ EntityDynamic::EntityDynamic() : Entity()
{
entity_state = Normal;
entity_timer = 0;
+ entity_motionstate = 0;
}
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)
@@ -593,7 +590,58 @@ void EntityDynamic::reset()
return;
}
- 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() && model()->radius()) {
+ const float modelscale = radius() / model()->radius();
+
+ if (flag_is_set(Complex) && model()->collisionmesh()) {
+ // use collision mesh
+ // dynamic entities use a btGImpactMeshShape
+ btGImpactMeshShape *meshshape = new btGImpactMeshShape(model()->collisionmesh()->triangles());
+
+ btVector3 modelscalevec(modelscale, modelscale, modelscale);
+ meshshape->setLocalScaling(modelscalevec);
+ //meshshape->setMargin(0.0f);
+ meshshape->updateBound();
+
+ entity_collision_shape = meshshape;
+ } else {
+ // use bounding box
+ entity_collision_shape = new btBoxShape(to_btVector3(model()->box().max() * modelscale));
+ }
+ } 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);
+ entity_body->setCollisionFlags(entity_body->getCollisionFlags() | btCollisionObject::CF_KINEMATIC_OBJECT);
+
+ if (zone())
+ zone()->physics()->addRigidBody(entity_body);
+ }
+
+ // transfer entity location to motion state
+ body()->setLinearVelocity(btVector3(0.0f, 0.0f, 0.0f));
+ body()->setLinearVelocity(btVector3(0.0f, 0.0f, 0.0f));
+ body()->setWorldTransform(t);
if (entity_state == Docked) {
body()->setLinearFactor(btVector3(0.0f, 0.0f, 0.0f));
@@ -602,6 +650,8 @@ void EntityDynamic::reset()
body()->setLinearFactor(btVector3(1.0f, 1.0f, 1.0f));
body()->setAngularFactor(btVector3(1.0f, 1.0f, 1.0f));
}
+
+ set_dirty();
}
void EntityDynamic::frame(float seconds)
@@ -967,17 +1017,31 @@ void EntityControlable::reset()
// construct physics body if necessary
if (!entity_body) {
// create collision shape
- // create collision shape
if (model() && model()->radius()) {
const float modelscale = radius() / model()->radius();
- entity_collision_shape = new btBoxShape(to_btVector3(model()->box().max() * modelscale));
+
+ if (flag_is_set(Complex) && model()->collisionmesh()) {
+ // use collision mesh
+ // dynamic entities use a btGImpactMeshShape
+ btGImpactMeshShape *meshshape = new btGImpactMeshShape(model()->collisionmesh()->triangles());
+
+ btVector3 modelscalevec(modelscale, modelscale, modelscale);
+ meshshape->setLocalScaling(modelscalevec);
+ //meshshape->setMargin(0.0f);
+ meshshape->updateBound();
+
+ entity_collision_shape = meshshape;
+ } else {
+ // use bounding box
+ entity_collision_shape = new btBoxShape(to_btVector3(model()->box().max() * modelscale));
+ }
} 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);
@@ -985,6 +1049,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 378a71a..e12123e 100644
--- a/src/core/entity.h
+++ b/src/core/entity.h
@@ -173,11 +173,6 @@ public:
return entity_collision_shape;
}
- /// physics motion info
- inline btMotionState *motionstate() {
- return entity_motionstate;
- }
-
/// indicates a server-side entity
inline const bool serverside() const {
return entity_serverside;
@@ -456,7 +451,6 @@ protected:
btRigidBody *entity_body;
btRigidBody::btRigidBodyConstructionInfo *entity_body_info;
btCollisionShape *entity_collision_shape;
- btMotionState *entity_motionstate;
// the zone the entity belongs to
Zone* entity_zone;
@@ -536,6 +530,11 @@ public:
return entity_timer;
}
+ /// physics motion info
+ inline btMotionState *motionstate() {
+ return entity_motionstate;
+ }
+
/*----- mutators -------------------------------------------------- */
/// mass of the entity
@@ -588,6 +587,7 @@ public:
protected:
float entity_timer;
int entity_state;
+ btMotionState *entity_motionstate;
};
/// an entity that can be controlled by a player