我创建了一个简单的btCollisionShape
(从一个三角形制成的 triMesh):
btTriangleMesh *mTriMesh = new btTriangleMesh();
btVector3 v0(1, 1,0);
btVector3 v1(-1,-1,0);
btVector3 v2(1,-1,0);
mTriMesh->addTriangle(v0,v1,v2);
btCollisionShape *mTriMeshShape = new btBvhTriangleMeshShape(mTriMesh,true);
我创造了ClosestRayResultCallback
btVector3 Start(-1, -1,-1);
btVector3 End(1,1,1);
btCollisionWorld::ClosestRayResultCallback RayCallback(Start, End);
如何btCollisionWorld::rayTestSingle
在btCollisionShape
我的光线开始和结束并且没有应用转换时执行?
同时,我在整个世界上尝试了 rayccast(实际上我不需要),但似乎我做错了 =( 因为我没有看到hasHit
:
int i;
btDefaultCollisionConfiguration* collisionConfiguration = new btDefaultCollisionConfiguration();
btCollisionDispatcher* dispatcher = new btCollisionDispatcher(collisionConfiguration);
btBroadphaseInterface* overlappingPairCache = new btDbvtBroadphase();
btSequentialImpulseConstraintSolver* solver = new btSequentialImpulseConstraintSolver;
btDiscreteDynamicsWorld* World = new btDiscreteDynamicsWorld(dispatcher,overlappingPairCache,solver,collisionConfiguration);
btTriangleMesh *mTriMesh = new btTriangleMesh();
btVector3 v0(1, 1,0);
btVector3 v1(-1,-1,0);
btVector3 v2(1,-1,0);
mTriMesh->addTriangle(v0,v1,v2);
btCollisionShape *mTriMeshShape = new btBvhTriangleMeshShape(mTriMesh,true);
btCollisionObject *mTriMeshCO = new btCollisionObject ();
mTriMeshCO->setCollisionShape(mTriMeshShape);
World->addCollisionObject(mTriMeshCO);
btVector3 End(-1, -1,-1);
btVector3 Start(1,1,1);
btCollisionWorld::ClosestRayResultCallback RayCallback(Start, End);
World->rayTest(Start, End, RayCallback);
if(RayCallback.hasHit()) {
btVector3 End = RayCallback.m_hitPointWorld;
btVector3 Normal = RayCallback.m_hitNormalWorld;
// Do some clever stuff here
}