diff options
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/entity.cc | 47 | ||||
-rw-r--r-- | src/core/gameserver.cc | 6 |
2 files changed, 43 insertions, 10 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); diff --git a/src/core/gameserver.cc b/src/core/gameserver.cc index 564622f..6a20317 100644 --- a/src/core/gameserver.cc +++ b/src/core/gameserver.cc @@ -549,10 +549,8 @@ void GameServer::frame(unsigned long timestamp) for (Entity::Registry::iterator it = Entity::registry().begin(); it != Entity::registry().end(); it++) { Entity *entity = (*it).second; - if ((entity->type() == Entity::Dynamic) || (entity->type() == Entity::Controlable)) { - entity->frame(elapsed); - - } + entity->frame(elapsed); + } // expand zone keepalive bounding box |