diff --git a/apps/openmw/mwworld/physicssystem.cpp b/apps/openmw/mwworld/physicssystem.cpp index a5b43b4fc..2615842e9 100644 --- a/apps/openmw/mwworld/physicssystem.cpp +++ b/apps/openmw/mwworld/physicssystem.cpp @@ -268,6 +268,7 @@ namespace MWWorld std::pair result; /*auto*/ result = mEngine->rayTest(origin, dest); result.second *= queryDistance; + return std::make_pair (result.second, result.first); } @@ -316,7 +317,11 @@ namespace MWWorld std::pair result = mEngine->rayTest(origin, dest); result.second *= queryDistance; - return result; + + std::pair result2 = mEngine->sphereTest(queryDistance,origin); + std::cout << "physic system: getFacedHandle" << result2.first << result2.second.length(); + return std::make_pair (result2.first,result2.second.length()); + //return result; } diff --git a/libs/openengine/bullet/physic.cpp b/libs/openengine/bullet/physic.cpp index 32883b48e..a9173e301 100644 --- a/libs/openengine/bullet/physic.cpp +++ b/libs/openengine/bullet/physic.cpp @@ -545,15 +545,63 @@ namespace Physic if (body && !(col0->getBroadphaseHandle()->m_collisionFilterGroup & CollisionType_Raycasting)) mResult.push_back(body->mName); + return 0.f; } #endif }; + struct AabbResultCallback : public btBroadphaseAabbCallback { + std::vector hits; + //AabbResultCallback(){} + virtual bool process(const btBroadphaseProxy* proxy) { + RigidBody* collisionObject = static_cast(proxy->m_clientObject); + if(proxy->m_collisionFilterGroup == CollisionType_Actor && (collisionObject->mName != "player")) + this->hits.push_back(collisionObject); + return true; + } + }; - std::string PhysicEngine::sphereTest(float radius,btVector3& pos) + + std::pair PhysicEngine::sphereTest(float radius,btVector3& pos) { + AabbResultCallback callback; + /*btDefaultMotionState* newMotionState = + new btDefaultMotionState(btTransform(btQuaternion(0,0,0,1),pos)); + btCollisionShape * shape = new btSphereShape(radius); + btRigidBody::btRigidBodyConstructionInfo CI = btRigidBody::btRigidBodyConstructionInfo + (0,newMotionState, shape); + RigidBody* body = new RigidBody(CI,"hitDetectionShpere__"); + btTransform tr = body->getWorldTransform(); + tr.setOrigin(pos); + body->setWorldTransform(tr); + dynamicsWorld->addRigidBody(body,CollisionType_Actor,CollisionType_World|CollisionType_World); + body->setWorldTransform(tr);*/ + btVector3 aabbMin = pos - radius*btVector3(1.0f, 1.0f, 1.0f); + btVector3 aabbMax = pos + radius*btVector3(1.0f, 1.0f, 1.0f); + + broadphase->aabbTest(aabbMin,aabbMax,callback); + for(int i=0;igetWorldTransform().getOrigin()-pos).length()mName,callback.hits[i]->getWorldTransform().getOrigin()); + } + } + //ContactTestResultCallback callback; + //dynamicsWorld->contactTest(body, callback); + //dynamicsWorld->removeRigidBody(body); + //delete body; + //delete shape; + //if(callback.mResultName.empty()) return std::make_pair(std::string(""),btVector3(0,0,0)); + /*for(int i=0;i(callback.mResultName[i],callback.mResultContact[i]); + */ + return std::make_pair(std::string(""),btVector3(0,0,0)); } std::vector PhysicEngine::getCollisions(const std::string& name) diff --git a/libs/openengine/bullet/physic.hpp b/libs/openengine/bullet/physic.hpp index 2ff2009c1..32af0da4e 100644 --- a/libs/openengine/bullet/physic.hpp +++ b/libs/openengine/bullet/physic.hpp @@ -307,7 +307,7 @@ public: std::pair sphereCast (float radius, btVector3& from, btVector3& to); ///< @return (hit, relative distance) - std::string sphereTest(float radius,btVector3& pos); + std::pair sphereTest(float radius,btVector3& pos); std::vector getCollisions(const std::string& name);