#include "recastmeshobject.hpp" #include #include #include namespace DetourNavigator { RecastMeshObject::RecastMeshObject(const btCollisionShape& shape, const btTransform& transform) : mShape(shape) , mTransform(transform) , mChildren(makeChildrenObjects(shape)) { } bool RecastMeshObject::update(const btTransform& transform) { bool result = false; if (!(mTransform == transform)) { mTransform = transform; result = true; } if (mShape.get().isCompound()) result = updateCompoundObject(static_cast(mShape.get()), mChildren) || result; return result; } bool RecastMeshObject::updateCompoundObject(const btCompoundShape& shape, std::vector& children) { assert(static_cast(shape.getNumChildShapes()) == children.size()); bool result = false; for (int i = 0, num = shape.getNumChildShapes(); i < num; ++i) { assert(shape.getChildShape(i) == std::addressof(children[static_cast(i)].mShape.get())); result = children[static_cast(i)].update(shape.getChildTransform(i)) || result; } return result; } std::vector makeChildrenObjects(const btCollisionShape& shape) { if (shape.isCompound()) return makeChildrenObjects(static_cast(shape)); else return std::vector(); } std::vector makeChildrenObjects(const btCompoundShape& shape) { std::vector result; for (int i = 0, num = shape.getNumChildShapes(); i < num; ++i) result.emplace_back(*shape.getChildShape(i), shape.getChildTransform(i)); return result; } }