mirror of
https://github.com/OpenMW/openmw.git
synced 2025-01-21 07:53:53 +00:00
first attempt: hit detection with a sphere (not finished)
This commit is contained in:
parent
b248d85b84
commit
830762722d
3 changed files with 56 additions and 3 deletions
|
@ -268,6 +268,7 @@ namespace MWWorld
|
||||||
std::pair <std::string, float> result;
|
std::pair <std::string, float> result;
|
||||||
/*auto*/ result = mEngine->rayTest(origin, dest);
|
/*auto*/ result = mEngine->rayTest(origin, dest);
|
||||||
result.second *= queryDistance;
|
result.second *= queryDistance;
|
||||||
|
|
||||||
return std::make_pair (result.second, result.first);
|
return std::make_pair (result.second, result.first);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -316,7 +317,11 @@ namespace MWWorld
|
||||||
|
|
||||||
std::pair<std::string,float> result = mEngine->rayTest(origin, dest);
|
std::pair<std::string,float> result = mEngine->rayTest(origin, dest);
|
||||||
result.second *= queryDistance;
|
result.second *= queryDistance;
|
||||||
return result;
|
|
||||||
|
std::pair<std::string,btVector3> 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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -545,15 +545,63 @@ namespace Physic
|
||||||
if (body && !(col0->getBroadphaseHandle()->m_collisionFilterGroup
|
if (body && !(col0->getBroadphaseHandle()->m_collisionFilterGroup
|
||||||
& CollisionType_Raycasting))
|
& CollisionType_Raycasting))
|
||||||
mResult.push_back(body->mName);
|
mResult.push_back(body->mName);
|
||||||
|
|
||||||
return 0.f;
|
return 0.f;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct AabbResultCallback : public btBroadphaseAabbCallback {
|
||||||
|
std::vector<RigidBody*> hits;
|
||||||
|
//AabbResultCallback(){}
|
||||||
|
virtual bool process(const btBroadphaseProxy* proxy) {
|
||||||
|
RigidBody* collisionObject = static_cast<RigidBody*>(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<std::string,btVector3> 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;i<callback.hits.size();i++)
|
||||||
|
{
|
||||||
|
if((callback.hits[i]->getWorldTransform().getOrigin()-pos).length()<radius)
|
||||||
|
{
|
||||||
|
return std::make_pair(callback.hits[i]->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.size();i++)
|
||||||
|
{
|
||||||
|
//TODO: raycasting
|
||||||
|
if(callback.mResultName[i] != "hitDetectionShpere__")
|
||||||
|
return std::pair<std::string,btVector3>(callback.mResultName[i],callback.mResultContact[i]);
|
||||||
|
*/
|
||||||
|
return std::make_pair(std::string(""),btVector3(0,0,0));
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<std::string> PhysicEngine::getCollisions(const std::string& name)
|
std::vector<std::string> PhysicEngine::getCollisions(const std::string& name)
|
||||||
|
|
|
@ -307,7 +307,7 @@ public:
|
||||||
std::pair<bool, float> sphereCast (float radius, btVector3& from, btVector3& to);
|
std::pair<bool, float> sphereCast (float radius, btVector3& from, btVector3& to);
|
||||||
///< @return (hit, relative distance)
|
///< @return (hit, relative distance)
|
||||||
|
|
||||||
std::string sphereTest(float radius,btVector3& pos);
|
std::pair<std::string,btVector3> sphereTest(float radius,btVector3& pos);
|
||||||
|
|
||||||
std::vector<std::string> getCollisions(const std::string& name);
|
std::vector<std::string> getCollisions(const std::string& name);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue