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>2011-05-09 12:23:36 +0000
committerStijn Buys <ingar@osirion.org>2011-05-09 12:23:36 +0000
commit3de78ec1bef2a0274a719ea229709523650ade40 (patch)
treeb4cabd7b1e3912a041cafd78f837a080c7593f4d
parentf0d632ac59896570e809757cb133aa570dbfa1f4 (diff)
Corrected collisionmesh scaling.
-rw-r--r--src/core/entity.cc39
1 files changed, 18 insertions, 21 deletions
diff --git a/src/core/entity.cc b/src/core/entity.cc
index 1535de8..915dafe 100644
--- a/src/core/entity.cc
+++ b/src/core/entity.cc
@@ -493,7 +493,8 @@ void Entity::frame(float seconds)
if (entity_collision_child_shapes.size() > 0) {
btCompoundShape *compoundshape = static_cast<btCompoundShape *> (entity_collision_shape);
bool recalculate = false;
-
+ const float modelscale = radius() / model()->radius();
+
for (int n = 0; n < compoundshape->getNumChildShapes(); n++) {
model::CollisionMesh *mesh = static_cast<model::CollisionMesh *>(compoundshape->getChildShape(n)->getUserPointer());
@@ -505,20 +506,19 @@ void Entity::frame(float seconds)
btTransform child_transform;
child_transform.setIdentity();
- child_transform.setOrigin(math::to_btVector3(mesh->location()));
+ child_transform.setOrigin(math::to_btVector3(mesh->location() * modelscale ));
child_transform.setBasis(math::to_btMatrix3x3(mesh->axis() * rotation_axis));
compoundshape->updateChildTransform(n, child_transform);
} else if (mesh->type() == model::FragmentGroup::Move ) {
-
const float freq = mesh->speed() / mesh->distance();
math::Vector3f translation(mesh->movement() * mesh->distance());
translation *= sinf(core::game()->time() * M_PI * freq) * 0.5f + 0.5f;
btTransform child_transform;
child_transform.setIdentity();
- child_transform.setOrigin(to_btVector3(mesh->location() + mesh->axis() * translation));
+ child_transform.setOrigin(to_btVector3((mesh->location() + mesh->axis() * translation * mesh->scale()) * modelscale));
child_transform.setBasis(math::to_btMatrix3x3(mesh->axis()));
compoundshape->updateChildTransform(n, child_transform);
@@ -567,7 +567,10 @@ void Entity::reset()
// static entities use a btBvhTriangleMeshShape
btBvhTriangleMeshShape *meshshape = new btBvhTriangleMeshShape(mesh->triangles(), true, true);
meshshape->setMargin(Cvar::sv_collisionmargin->value());
- btVector3 meshscalevec(mesh->scale(), mesh->scale(), mesh->scale());
+
+ const float meshscale = mesh->scale() * modelscale;
+ const btVector3 meshscalevec(meshscale, meshscale, meshscale);
+
meshshape->setLocalScaling(meshscalevec);
meshshape->buildOptimizedBvh();
meshshape->recalcLocalAabb();
@@ -575,13 +578,12 @@ void Entity::reset()
// apply collision mesh properties to the btCollisionShape
btTransform child_transform;
child_transform.setIdentity();
- child_transform.setOrigin(to_btVector3(mesh->location()));
+ child_transform.setOrigin(to_btVector3(mesh->location() * modelscale));
child_transform.setBasis(to_btMatrix3x3(mesh->axis()));
switch (mesh->type()) {
case model::FragmentGroup::Rotate:
case model::FragmentGroup::Move:
- con_debug << " ^Rcollision mesh attached to btCollisionShape " << std::endl;
meshshape->setUserPointer((void *) mesh);
break;
@@ -594,9 +596,6 @@ void Entity::reset()
entity_collision_child_shapes.push_back(meshshape);
}
- btVector3 modelscalevec(modelscale, modelscale, modelscale);
- compoundshape->setLocalScaling(modelscalevec);
-
entity_collision_shape = compoundshape;
} else {
@@ -698,13 +697,15 @@ void EntityDynamic::reset()
// dynamic entities use btGImpactMeshShape
btGImpactMeshShape *meshshape = new btGImpactMeshShape(mesh->triangles());
meshshape->setMargin(Cvar::sv_collisionmargin->value());
- btVector3 meshscalevec(mesh->scale(), mesh->scale(), mesh->scale());
+
+ const float meshscale = mesh->scale() * modelscale;
+ const btVector3 meshscalevec(meshscale, meshscale, meshscale);
meshshape->setLocalScaling(meshscalevec);
// apply collision mesh properties to the btCollisionShape
btTransform child_transform;
child_transform.setIdentity();
- child_transform.setOrigin(to_btVector3(mesh->location()));
+ child_transform.setOrigin(to_btVector3(mesh->location() * modelscale));
child_transform.setBasis(to_btMatrix3x3(mesh->axis()));
switch (mesh->type()) {
@@ -721,10 +722,7 @@ void EntityDynamic::reset()
compoundshape->addChildShape(child_transform, meshshape);
entity_collision_child_shapes.push_back(meshshape);
}
-
- btVector3 modelscalevec(modelscale, modelscale, modelscale);
- compoundshape->setLocalScaling(modelscalevec);
-
+
entity_collision_shape = compoundshape;
} else {
@@ -1161,14 +1159,16 @@ void EntityControlable::reset()
// dynamic entities use btGImpactMeshShape
btGImpactMeshShape *meshshape = new btGImpactMeshShape(mesh->triangles());
meshshape->setMargin(Cvar::sv_collisionmargin->value());
- btVector3 meshscalevec(mesh->scale(), mesh->scale(), mesh->scale());
+ const float meshscale = mesh->scale() * modelscale;
+ const btVector3 meshscalevec(meshscale, meshscale, meshscale);
+
meshshape->setLocalScaling(meshscalevec);
meshshape->updateBound();
// apply collision mesh properties to the btCollisionShape
btTransform child_transform;
child_transform.setIdentity();
- child_transform.setOrigin(to_btVector3(mesh->location()));
+ child_transform.setOrigin(to_btVector3(mesh->location() * modelscale));
child_transform.setBasis(to_btMatrix3x3(mesh->axis()));
switch (mesh->type()) {
@@ -1186,9 +1186,6 @@ void EntityControlable::reset()
entity_collision_child_shapes.push_back(meshshape);
}
- btVector3 modelscalevec(modelscale, modelscale, modelscale);
- compoundshape->setLocalScaling(modelscalevec);
-
entity_collision_shape = compoundshape;
} else {