|
|
|
@ -546,11 +546,68 @@ 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<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::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++)
|
|
|
|
|
{
|
|
|
|
|
float d = (callback.hits[i]->getWorldTransform().getOrigin()-pos).length();
|
|
|
|
|
if(d<radius)
|
|
|
|
|
{
|
|
|
|
|
std::pair<std::string,float> rayResult = this->rayTest(pos,callback.hits[i]->getWorldTransform().getOrigin());
|
|
|
|
|
if(rayResult.second>d || rayResult.first == callback.hits[i]->mName)
|
|
|
|
|
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)
|
|
|
|
|
{
|
|
|
|
|
RigidBody* body = getRigidBody(name);
|
|
|
|
|