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-06 18:27:55 +0000
committerStijn Buys <ingar@osirion.org>2011-05-06 18:27:55 +0000
commit50947891a97f19fa11f9f073c8988156f9655d97 (patch)
tree2373dd39d70edd7995210aabb6973315465ba737 /src/core/entity.cc
parente7a0b54c4717afdfa12a8847d5bc72b7b68290b4 (diff)
Support for func_rotate and func_move collision meshes.
Diffstat (limited to 'src/core/entity.cc')
-rw-r--r--src/core/entity.cc47
1 files changed, 41 insertions, 6 deletions
diff --git a/src/core/entity.cc b/src/core/entity.cc
index bba3c5c..1535de8 100644
--- a/src/core/entity.cc
+++ b/src/core/entity.cc
@@ -490,11 +490,44 @@ void Entity::remove_menu(std::string const &label)
void Entity::frame(float seconds)
{
- if (entity_collision_child_shapes.size()) {
- //btCompoundShape *compoundshape = static_cast<btCompoundShape *> (entity_collision_shape);
-
- // TODO apply collision mesh animation
-
+ if (entity_collision_child_shapes.size() > 0) {
+ btCompoundShape *compoundshape = static_cast<btCompoundShape *> (entity_collision_shape);
+ bool recalculate = false;
+
+ for (int n = 0; n < compoundshape->getNumChildShapes(); n++) {
+ model::CollisionMesh *mesh = static_cast<model::CollisionMesh *>(compoundshape->getChildShape(n)->getUserPointer());
+
+ if (mesh) {
+ if (mesh->type() == model::FragmentGroup::Rotate) {
+ const float rotation_radians = math::degrees360f(game()->time() * mesh->speed()) * M_PI / 180.0f;
+ math::Axis rotation_axis;
+ rotation_axis.rotate(mesh->movement(), rotation_radians);
+
+ btTransform child_transform;
+ child_transform.setIdentity();
+ child_transform.setOrigin(math::to_btVector3(mesh->location()));
+ 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.setBasis(math::to_btMatrix3x3(mesh->axis()));
+
+ compoundshape->updateChildTransform(n, child_transform);
+ }
+ }
+
+ if (recalculate)
+ compoundshape->recalculateLocalAabb();
+ }
}
}
@@ -548,11 +581,13 @@ void Entity::reset()
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;
default:
- meshshape->setUserPointer(0);
+ meshshape->setUserPointer(0);
+ break;
}
// add the mesh to the compoundhape and store a pointer to the child shape
compoundshape->addChildShape(child_transform, meshshape);