Physics Simulation Forum

 

All times are UTC




Post new topic Reply to topic  [ 1 post ] 
Author Message
PostPosted: Tue Apr 17, 2012 10:06 pm 
Offline

Joined: Fri May 07, 2010 2:20 pm
Posts: 11
dear group,

I am trying to implement a ray cast based collision detection.
The case study is quite simple:
it is a rectangular shape falling over a cylinder.
It works fine if I use btGjkConvexCast,
but it doesn't work using collisionWorld::rayTestSingle.
It seems that collisionWorld::rayTestSingle misses a lot of collisions,
even if the rays are the same for both the methods.
Can you explain me why?
What can I do if I want detect collisions against non convex shapes?

Regards,
Francesco

Code:
void ClothSimulator::solveCollision(REAL dt)
{
   BT_PROFILE("solveCollision");
   //TODO: Handle multiple rigid objects
   
   //.. find rigid object
   btCollisionObject* cyl_obj = m_world->getCollisionObjectArray()[1];
   btTransform t = cyl_obj->getWorldTransform();
   btConvexShape* cyl_shape = (btConvexShape*) cyl_obj->getCollisionShape();
   
   btVector3 aabbMin, aabbMax;
   cyl_shape->getAabb(t,aabbMin,aabbMax);   
   
   btVoronoiSimplexSolver   simplexSolver;

   const unsigned npoints = m_particle.m_p.size();
   for ( size_t i=0; i<npoints; i++)
   {
      bool hasHit = false;
      btScalar closestHitResults = 1.f;
      btConvexCast::CastResult rayResult;
      btSphereShape pointShape(0.0f);
 
                vec3 from =......
                vec3 to = .......

      btTransform rayFromTrans;
      btTransform rayToTrans;
      
      rayFromTrans.setIdentity();
      rayFromTrans.setOrigin( btVector3(from.x,from.y,from.z) );
      
      rayToTrans.setIdentity();
      rayToTrans.setOrigin(btVector3(to.x,to.y,to.z));
      
      btScalar hitLambda = 1.f;
      btVector3 hitNormal;

      btVector3 rayFrom = btVector3(from.x,from.y,from.z);
      btVector3 rayTo = btVector3(to.x,to.y,to.z);

                this is the the code for simple ray test:
      btCollisionWorld::ClosestRayResultCallback cb(rayFrom, rayTo);
      m_world->rayTestSingle(rayFromTrans,rayToTrans, cyl_obj, cyl_obj->getCollisionShape(), t, cb);
      //m_world->rayTest(rayFrom, rayTo, cb );

      if (cb.hasHit())
      {
                       ..............
      }
      
                this is the code for convex cast ray test:      
      if (btRayAabb(rayFrom, rayTo, aabbMin, aabbMax, hitLambda, hitNormal))
      {
         btTransform transform;
         //btSubsimplexConvexCast convexCaster(&pointShape, cyl_shape,&simplexSolver);
         btGjkConvexCast convexCaster(&pointShape, cyl_shape,&simplexSolver);
         if (convexCaster.calcTimeOfImpact(rayFromTrans,rayToTrans,t,t,rayResult))
         {
            if (rayResult.m_fraction < closestHitResults)
            {
               closestHitResults = rayResult.m_fraction;
   
               hasHit = true;
               if (hasHit)
               {
                                       .................
               }
            }
         }   
      }
      
      //-- try to discover difference between convex caster and simple ray test
      if (cb.hasHit() && hasHit)
      {
         btVector3 delta = cb.m_hitPointWorld - rayResult.m_hitPoint;
         printf("delta=(%f,%f,%f)\n",delta.getX(),delta.getY(),delta.getZ());
         
      }
      if (hasHit && !cb.hasHit())
      {
         printf("missing detection by simple ray cast\n");
      }
      if (cb.hasHit() && !hasHit)
      {
         printf("missing detection by convex ray cast\n");
      }
   }
}



Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC


Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 5 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group