Logo Search packages:      
Sourcecode: blender version File versions  Download package

DBVT_PREFIX void btDbvt::rayTest ( const btDbvtNode *  root,
const btVector3 &  rayFrom,
const btVector3 &  rayTo,
DBVT_IPOLICY   
) [inline, static]

rayTest is a re-entrant ray test, and can be called in parallel as long as the btAlignedAlloc is thread-safe (uses locking etc) rayTest is slower than rayTestInternal, because it builds a local stack, using memory allocations, and it recomputes signs/rayDirectionInverses each time

what about division by zero? --> just set rayDirection[i] to INF/1e30

Definition at line 992 of file btDbvt.h.

References btAlignedObjectArray< T >::resize(), and btAlignedObjectArray< T >::size().

{
      DBVT_CHECKTYPE
            if(root)
            {
                  btVector3 rayDir = (rayTo-rayFrom);
                  rayDir.normalize ();

                  ///what about division by zero? --> just set rayDirection[i] to INF/1e30
                  btVector3 rayDirectionInverse;
                  rayDirectionInverse[0] = rayDir[0] == btScalar(0.0) ? btScalar(1e30) : btScalar(1.0) / rayDir[0];
                  rayDirectionInverse[1] = rayDir[1] == btScalar(0.0) ? btScalar(1e30) : btScalar(1.0) / rayDir[1];
                  rayDirectionInverse[2] = rayDir[2] == btScalar(0.0) ? btScalar(1e30) : btScalar(1.0) / rayDir[2];
                  unsigned int signs[3] = { rayDirectionInverse[0] < 0.0, rayDirectionInverse[1] < 0.0, rayDirectionInverse[2] < 0.0};

                  btScalar lambda_max = rayDir.dot(rayTo-rayFrom);

                  btVector3 resultNormal;

                  btAlignedObjectArray<const btDbvtNode*>   stack;

                  int                                             depth=1;
                  int                                             treshold=DOUBLE_STACKSIZE-2;

                  stack.resize(DOUBLE_STACKSIZE);
                  stack[0]=root;
                  btVector3 bounds[2];
                  do    {
                        const btDbvtNode* node=stack[--depth];

                        bounds[0] = node->volume.Mins();
                        bounds[1] = node->volume.Maxs();
                        
                        btScalar tmin=1.f,lambda_min=0.f;
                        unsigned int result1 = btRayAabb2(rayFrom,rayDirectionInverse,signs,bounds,tmin,lambda_min,lambda_max);

#ifdef COMPARE_BTRAY_AABB2
                        btScalar param=1.f;
                        bool result2 = btRayAabb(rayFrom,rayTo,node->volume.Mins(),node->volume.Maxs(),param,resultNormal);
                        btAssert(result1 == result2);
#endif //TEST_BTRAY_AABB2

                        if(result1)
                        {
                              if(node->isinternal())
                              {
                                    if(depth>treshold)
                                    {
                                          stack.resize(stack.size()*2);
                                          treshold=stack.size()-2;
                                    }
                                    stack[depth++]=node->childs[0];
                                    stack[depth++]=node->childs[1];
                              }
                              else
                              {
                                    policy.Process(node);
                              }
                        }
                  } while(depth);

            }
}


Generated by  Doxygen 1.6.0   Back to index