Logo Search packages:      
Sourcecode: blender version File versions

void btCollisionWorld::rayTestSingle ( const btTransform rayFromTrans,
const btTransform rayToTrans,
btCollisionObject collisionObject,
const btCollisionShape collisionShape,
const btTransform colObjWorldTransform,
RayResultCallback resultCallback 
) [inherited]

rayTestSingle performs a raycast call and calls the resultCallback. It is used internally by rayTest. In a future implementation, we consider moving the ray test as a virtual method in btCollisionShape. This allows more customization.

Definition at line 181 of file btCollisionWorld.cpp.

References btCollisionWorld::RayResultCallback::AddSingleResult(), btSubsimplexConvexCast::calcTimeOfImpact(), btCompoundShape::getChildShape(), btCompoundShape::getChildTransform(), btCompoundShape::getNumChildShapes(), btTransform::getOrigin(), btTransform::inverse(), btCollisionShape::isCompound(), btCollisionShape::isConcave(), btCollisionShape::isConvex(), btVector3::length2(), btCollisionWorld::RayResultCallback::m_closestHitFraction, btConvexCast::CastResult::m_fraction, btConvexCast::CastResult::m_normal, btCollisionWorld::LocalShapeInfo::m_shapePart, btCollisionWorld::LocalShapeInfo::m_triangleIndex, btVector3::normalize(), and btTriangleMeshShape::processAllTriangles().

Referenced by btCollisionWorld::rayTest().

{
      
      btSphereShape pointShape(0.0f);

      if (collisionShape->isConvex())
                  {
                        btConvexCast::CastResult castResult;
                        castResult.m_fraction = 1.f;//??

                        btConvexShape* convexShape = (btConvexShape*) collisionShape;
                        btVoronoiSimplexSolver  simplexSolver;
                        btSubsimplexConvexCast convexCaster(&pointShape,convexShape,&simplexSolver);
                        //GjkConvexCast   convexCaster(&pointShape,convexShape,&simplexSolver);
                        //ContinuousConvexCollision convexCaster(&pointShape,convexShape,&simplexSolver,0);
                        
                        if (convexCaster.calcTimeOfImpact(rayFromTrans,rayToTrans,colObjWorldTransform,colObjWorldTransform,castResult))
                        {
                              //add hit
                              if (castResult.m_normal.length2() > 0.0001f)
                              {
                                    castResult.m_normal.normalize();
                                    if (castResult.m_fraction < resultCallback.m_closestHitFraction)
                                    {

                                          btCollisionWorld::LocalRayResult localRayResult
                                                (
                                                      collisionObject, 
                                                      0,
                                                      castResult.m_normal,
                                                      castResult.m_fraction
                                                );

                                          resultCallback.AddSingleResult(localRayResult);

                                    }
                              }
                        }
                  }
                  else
                  {
                        
                        if (collisionShape->isConcave())
                              {

                                    btTriangleMeshShape* triangleMesh = (btTriangleMeshShape*)collisionShape;
                                    
                                    btTransform worldTocollisionObject = colObjWorldTransform.inverse();

                                    btVector3 rayFromLocal = worldTocollisionObject * rayFromTrans.getOrigin();
                                    btVector3 rayToLocal = worldTocollisionObject * rayToTrans.getOrigin();

                                    //ConvexCast::CastResult

                                    struct BridgeTriangleRaycastCallback : public btTriangleRaycastCallback 
                                    {
                                          btCollisionWorld::RayResultCallback* m_resultCallback;
                                          btCollisionObject*      m_collisionObject;
                                          btTriangleMeshShape*    m_triangleMesh;

                                          BridgeTriangleRaycastCallback( const btVector3& from,const btVector3& to,
                                                btCollisionWorld::RayResultCallback* resultCallback, btCollisionObject* collisionObject,btTriangleMeshShape*      triangleMesh):
                                                btTriangleRaycastCallback(from,to),
                                                      m_resultCallback(resultCallback),
                                                      m_collisionObject(collisionObject),
                                                      m_triangleMesh(triangleMesh)
                                                {
                                                }


                                          virtual float reportHit(const btVector3& hitNormalLocal, float hitFraction, int partId, int triangleIndex )
                                          {
                                                btCollisionWorld::LocalShapeInfo    shapeInfo;
                                                shapeInfo.m_shapePart = partId;
                                                shapeInfo.m_triangleIndex = triangleIndex;
                                                
                                                btCollisionWorld::LocalRayResult rayResult
                                                (m_collisionObject, 
                                                      &shapeInfo,
                                                      hitNormalLocal,
                                                      hitFraction);
                                                
                                                return m_resultCallback->AddSingleResult(rayResult);
                                                
                                                
                                          }
      
                                    };


                                    BridgeTriangleRaycastCallback rcb(rayFromLocal,rayToLocal,&resultCallback,collisionObject,triangleMesh);
                                    rcb.m_hitFraction = resultCallback.m_closestHitFraction;

                                    btVector3 rayAabbMinLocal = rayFromLocal;
                                    rayAabbMinLocal.setMin(rayToLocal);
                                    btVector3 rayAabbMaxLocal = rayFromLocal;
                                    rayAabbMaxLocal.setMax(rayToLocal);

                                    triangleMesh->processAllTriangles(&rcb,rayAabbMinLocal,rayAabbMaxLocal);
                                                                  
                              } else
                              {
                                    //todo: use AABB tree or other BVH acceleration structure!
                                    if (collisionShape->isCompound())
                                    {
                                          const btCompoundShape* compoundShape = static_cast<const btCompoundShape*>(collisionShape);
                                          int i=0;
                                          for (i=0;i<compoundShape->getNumChildShapes();i++)
                                          {
                                                btTransform childTrans = compoundShape->getChildTransform(i);
                                                const btCollisionShape* childCollisionShape = compoundShape->getChildShape(i);
                                                btTransform childWorldTrans = colObjWorldTransform * childTrans;
                                                rayTestSingle(rayFromTrans,rayToTrans,
                                                      collisionObject,
                                                      childCollisionShape,
                                                      childWorldTrans,
                                                      resultCallback);

                                          }


                                    }
                              }
                  }
}


Generated by  Doxygen 1.6.0   Back to index