Restore getCollisions

c++11
scrawl 10 years ago
parent 8b322fcd06
commit d84990be85

@ -758,9 +758,37 @@ namespace MWPhysics
return std::make_pair(false, osg::Vec3f());
}
std::vector<std::string> PhysicsSystem::getCollisions(const MWWorld::Ptr &ptr, int collisionGroup, int collisionMask)
class ContactTestResultCallback : public btCollisionWorld::ContactResultCallback
{
return std::vector<std::string>();//mEngine->getCollisions(ptr.getRefData().getBaseNodeOld()->getName(), collisionGroup, collisionMask);
public:
std::vector<MWWorld::Ptr> mResult;
virtual btScalar addSingleResult(btManifoldPoint& cp,
const btCollisionObjectWrapper* colObj0Wrap,int partId0,int index0,
const btCollisionObjectWrapper* colObj1Wrap,int partId1,int index1)
{
const PtrHolder* holder = static_cast<const PtrHolder*>(colObj0Wrap->m_collisionObject->getUserPointer());
if (holder)
mResult.push_back(holder->getPtr());
return 0.f;
}
};
std::vector<MWWorld::Ptr> PhysicsSystem::getCollisions(const MWWorld::Ptr &ptr, int collisionGroup, int collisionMask)
{
btCollisionObject* me = NULL;
ObjectMap::iterator found = mObjects.find(ptr);
if (found != mObjects.end())
me = found->second->getCollisionObject();
else
return std::vector<MWWorld::Ptr>();
ContactTestResultCallback resultCallback;
resultCallback.m_collisionFilterGroup = collisionGroup;
resultCallback.m_collisionFilterMask = collisionMask;
mDynamicsWorld->contactTest(me, resultCallback);
return resultCallback.mResult;
}
osg::Vec3f PhysicsSystem::traceDown(const MWWorld::Ptr &ptr, float maxHeight)

@ -77,7 +77,7 @@ namespace MWPhysics
void stepSimulation(float dt);
std::vector<std::string> getCollisions(const MWWorld::Ptr &ptr, int collisionGroup, int collisionMask); ///< get handles this object collides with
std::vector<MWWorld::Ptr> getCollisions(const MWWorld::Ptr &ptr, int collisionGroup, int collisionMask); ///< get handles this object collides with
osg::Vec3f traceDown(const MWWorld::Ptr &ptr, float maxHeight);
std::pair<MWWorld::Ptr, osg::Vec3f> getHitContact(const MWWorld::Ptr& actor,

@ -48,6 +48,7 @@
#include "../mwphysics/physicssystem.hpp"
#include "../mwphysics/actor.hpp"
#include "../mwphysics/collisiontype.hpp"
#include "player.hpp"
#include "manualref.hpp"
@ -1420,7 +1421,6 @@ namespace MWWorld
void World::processDoors(float duration)
{
#if 0
std::map<MWWorld::Ptr, int>::iterator it = mDoorStates.begin();
while (it != mDoorStates.end())
{
@ -1433,19 +1433,18 @@ namespace MWWorld
}
else
{
float oldRot = Ogre::Radian(it->first.getRefData().getLocalRotation().rot[2]).valueDegrees();
float diff = duration * 90;
float oldRot = osg::RadiansToDegrees(it->first.getRefData().getLocalRotation().rot[2]);
float diff = duration * 90.f;
float targetRot = std::min(std::max(0.f, oldRot + diff * (it->second == 1 ? 1 : -1)), 90.f);
localRotateObject(it->first, 0, 0, targetRot);
bool reached = (targetRot == 90.f && it->second) || targetRot == 0.f;
/// \todo should use convexSweepTest here
std::vector<std::string> collisions = mPhysics->getCollisions(it->first, OEngine::Physic::CollisionType_Actor
, OEngine::Physic::CollisionType_Actor);
for (std::vector<std::string>::iterator cit = collisions.begin(); cit != collisions.end(); ++cit)
std::vector<MWWorld::Ptr> collisions = mPhysics->getCollisions(it->first, MWPhysics::CollisionType_Actor, MWPhysics::CollisionType_Actor);
for (std::vector<MWWorld::Ptr>::iterator cit = collisions.begin(); cit != collisions.end(); ++cit)
{
MWWorld::Ptr ptr = getPtrViaHandle(*cit);
MWWorld::Ptr ptr = *cit;
if (ptr.getClass().isActor())
{
// Collided with actor, ask actor to try to avoid door
@ -1471,7 +1470,6 @@ namespace MWWorld
++it;
}
}
#endif
}
bool World::toggleCollisionMode()

Loading…
Cancel
Save