Use consistent rayFrom/rayTo API for rayTest for btDbvt and btSoftBody, instead of rayCast/collideRAY(origin,direction). This means RayFromToCaster has a fraction [0..1] instead of distance [0..INF]
Renamed collideRay -> rayTest to reflect change to (rayFrom,rayTo) interface. Re-use btRayAabb2 function from src/LinearMath/btAabbUtil2.h in btDbvt instead of duplicated implementation.
This commit is contained in:
@@ -669,7 +669,7 @@ Benchmarking dbvt...
|
||||
[4] btDbvt::collideTT self: 2814 ms (-20%)
|
||||
[5] btDbvt::collideTT xform: 7379 ms (-1%)
|
||||
[6] btDbvt::collideTT xform,self: 7270 ms (-2%)
|
||||
[7] btDbvt::collideRAY: 6314 ms (0%),(332143 r/s)
|
||||
[7] btDbvt::rayTest: 6314 ms (0%),(332143 r/s)
|
||||
[8] insert/remove: 2093 ms (0%),(1001983 ir/s)
|
||||
[9] updates (teleport): 1879 ms (-3%),(1116100 u/s)
|
||||
[10] updates (jitter): 1244 ms (-4%),(1685813 u/s)
|
||||
@@ -809,7 +809,7 @@ bool cfgBenchmark6_Enable = cfgEnable;
|
||||
static const int cfgBenchmark6_Iterations = 512;
|
||||
static const btScalar cfgBenchmark6_OffsetScale = 2;
|
||||
static const int cfgBenchmark6_Reference = 7270;
|
||||
//[7] btDbvt::collideRAY
|
||||
//[7] btDbvt::rayTest
|
||||
bool cfgBenchmark7_Enable = cfgEnable;
|
||||
static const int cfgBenchmark7_Passes = 32;
|
||||
static const int cfgBenchmark7_Iterations = 65536;
|
||||
@@ -1017,13 +1017,13 @@ if(cfgBenchmark7_Enable)
|
||||
}
|
||||
btDbvtBenchmark::RandTree(cfgVolumeCenterScale,cfgVolumeExentsBase,cfgVolumeExentsScale,cfgLeaves,dbvt);
|
||||
dbvt.optimizeTopDown();
|
||||
printf("[7] btDbvt::collideRAY: ");
|
||||
printf("[7] btDbvt::rayTest: ");
|
||||
wallclock.reset();
|
||||
for(int i=0;i<cfgBenchmark7_Passes;++i)
|
||||
{
|
||||
for(int j=0;j<cfgBenchmark7_Iterations;++j)
|
||||
{
|
||||
btDbvt::collideRAY(dbvt.m_root,rayorg[j],raydir[j],policy);
|
||||
btDbvt::rayTest(dbvt.m_root,rayorg[j],rayorg[j]+raydir[j],policy);
|
||||
}
|
||||
}
|
||||
const int time=(int)wallclock.getTimeMilliseconds();
|
||||
|
||||
@@ -20,6 +20,7 @@ subject to the following restrictions:
|
||||
#include "LinearMath/btAlignedObjectArray.h"
|
||||
#include "LinearMath/btVector3.h"
|
||||
#include "LinearMath/btTransform.h"
|
||||
#include "LinearMath/btAabbUtil2.h"
|
||||
|
||||
//
|
||||
// Compile time configuration
|
||||
@@ -156,10 +157,7 @@ DBVT_INLINE friend bool Intersect( const btDbvtAabbMm& a,
|
||||
const btTransform& xform);
|
||||
DBVT_INLINE friend bool Intersect( const btDbvtAabbMm& a,
|
||||
const btVector3& b);
|
||||
DBVT_INLINE friend bool Intersect( const btDbvtAabbMm& a,
|
||||
const btVector3& org,
|
||||
const btVector3& invdir,
|
||||
const unsigned* signs);
|
||||
|
||||
DBVT_INLINE friend btScalar Proximity( const btDbvtAabbMm& a,
|
||||
const btDbvtAabbMm& b);
|
||||
DBVT_INLINE friend int Select( const btDbvtAabbMm& o,
|
||||
@@ -317,9 +315,9 @@ struct btDbvt
|
||||
const btDbvtVolume& volume,
|
||||
DBVT_IPOLICY);
|
||||
DBVT_PREFIX
|
||||
static void collideRAY( const btDbvtNode* root,
|
||||
const btVector3& origin,
|
||||
const btVector3& direction,
|
||||
static void rayTest( const btDbvtNode* root,
|
||||
const btVector3& rayFrom,
|
||||
const btVector3& rayTo,
|
||||
DBVT_IPOLICY);
|
||||
DBVT_PREFIX
|
||||
static void collideKDOP(const btDbvtNode* root,
|
||||
@@ -539,37 +537,12 @@ return( (b.x()>=a.mi.x())&&
|
||||
(b.z()<=a.mx.z()));
|
||||
}
|
||||
|
||||
//
|
||||
DBVT_INLINE bool Intersect( const btDbvtAabbMm& a,
|
||||
const btVector3& org,
|
||||
const btVector3& invdir,
|
||||
const unsigned* signs)
|
||||
{
|
||||
#if 0
|
||||
const btVector3 b0((a.mi-org)*invdir);
|
||||
const btVector3 b1((a.mx-org)*invdir);
|
||||
const btVector3 tmin(btMin(b0[0],b1[0]),btMin(b0[1],b1[1]),btMin(b0[2],b1[2]));
|
||||
const btVector3 tmax(btMax(b0[0],b1[0]),btMax(b0[1],b1[1]),btMax(b0[2],b1[2]));
|
||||
const btScalar tin=btMax(tmin[0],btMax(tmin[1],tmin[2]));
|
||||
const btScalar tout=btMin(tmax[0],btMin(tmax[1],tmax[2]));
|
||||
return(tin<tout);
|
||||
#else
|
||||
const btVector3* bounds[2]={&a.mi,&a.mx};
|
||||
btScalar txmin=(bounds[ signs[0]]->x()-org[0])*invdir[0];
|
||||
btScalar txmax=(bounds[1-signs[0]]->x()-org[0])*invdir[0];
|
||||
const btScalar tymin=(bounds[ signs[1]]->y()-org[1])*invdir[1];
|
||||
const btScalar tymax=(bounds[1-signs[1]]->y()-org[1])*invdir[1];
|
||||
if((txmin>tymax)||(tymin>txmax)) return(false);
|
||||
if(tymin>txmin) txmin=tymin;
|
||||
if(tymax<txmax) txmax=tymax;
|
||||
const btScalar tzmin=(bounds[ signs[2]]->z()-org[2])*invdir[2];
|
||||
const btScalar tzmax=(bounds[1-signs[2]]->z()-org[2])*invdir[2];
|
||||
if((txmin>tzmax)||(tzmin>txmax)) return(false);
|
||||
if(tzmin>txmin) txmin=tzmin;
|
||||
if(tzmax<txmax) txmax=tzmax;
|
||||
return(txmax>0);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
//////////////////////////////////////
|
||||
|
||||
|
||||
//
|
||||
DBVT_INLINE btScalar Proximity( const btDbvtAabbMm& a,
|
||||
@@ -875,31 +848,51 @@ if(root)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
DBVT_PREFIX
|
||||
inline void btDbvt::collideRAY( const btDbvtNode* root,
|
||||
const btVector3& origin,
|
||||
const btVector3& direction,
|
||||
inline void btDbvt::rayTest( const btDbvtNode* root,
|
||||
const btVector3& rayFrom,
|
||||
const btVector3& rayTo,
|
||||
DBVT_IPOLICY)
|
||||
{
|
||||
DBVT_CHECKTYPE
|
||||
if(root)
|
||||
if(root)
|
||||
{
|
||||
const btVector3 normal=direction.normalized();
|
||||
const btVector3 invdir( 1/normal.x(),
|
||||
1/normal.y(),
|
||||
1/normal.z());
|
||||
const unsigned signs[]={ direction.x()<0,
|
||||
direction.y()<0,
|
||||
direction.z()<0};
|
||||
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};
|
||||
|
||||
|
||||
btVector3 resultNormal;
|
||||
|
||||
|
||||
btAlignedObjectArray<const btDbvtNode*> stack;
|
||||
stack.reserve(SIMPLE_STACKSIZE);
|
||||
stack.push_back(root);
|
||||
do {
|
||||
const btDbvtNode* node=stack[stack.size()-1];
|
||||
stack.pop_back();
|
||||
if(Intersect(node->volume,origin,invdir,signs))
|
||||
{
|
||||
|
||||
btVector3 bounds[2] = {node->volume.Mins(),node->volume.Maxs()};
|
||||
btScalar lambda_max = rayDir.dot(rayTo-rayFrom);
|
||||
btScalar tmin=1.f,lambda_min=0.f;
|
||||
bool 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())
|
||||
{
|
||||
stack.push_back(node->childs[0]);
|
||||
|
||||
@@ -229,12 +229,12 @@ void btDbvtBroadphase::rayTest(const btVector3& rayFrom,const btVector3& rayTo,
|
||||
|
||||
BroadphaseRayTester callback(rayCallback);
|
||||
|
||||
m_sets[0].collideRAY( m_sets[0].m_root,
|
||||
m_sets[0].rayTest( m_sets[0].m_root,
|
||||
rayFrom,
|
||||
rayTo,
|
||||
callback);
|
||||
|
||||
m_sets[1].collideRAY( m_sets[1].m_root,
|
||||
m_sets[1].rayTest( m_sets[1].m_root,
|
||||
rayFrom,
|
||||
rayTo,
|
||||
callback);
|
||||
|
||||
@@ -468,14 +468,15 @@ void btQuantizedBvh::walkStacklessTreeAgainstRay(btNodeOverlapCallback* nodeCall
|
||||
|
||||
#ifdef RAYAABB2
|
||||
btVector3 rayFrom = raySource;
|
||||
btVector3 rayDirection = (rayTarget-raySource);
|
||||
rayDirection.normalize ();
|
||||
lambda_max = rayDirection.dot(rayTarget-raySource);
|
||||
btVector3 rayDir = (rayTarget-raySource);
|
||||
rayDir.normalize ();
|
||||
lambda_max = rayDir.dot(rayTarget-raySource);
|
||||
///what about division by zero? --> just set rayDirection[i] to 1.0
|
||||
rayDirection[0] = rayDirection[0] == btScalar(0.0) ? btScalar(1e30) : btScalar(1.0) / rayDirection[0];
|
||||
rayDirection[1] = rayDirection[1] == btScalar(0.0) ? btScalar(1e30) : btScalar(1.0) / rayDirection[1];
|
||||
rayDirection[2] = rayDirection[2] == btScalar(0.0) ? btScalar(1e30) : btScalar(1.0) / rayDirection[2];
|
||||
unsigned int sign[3] = { rayDirection[0] < 0.0, rayDirection[1] < 0.0, rayDirection[2] < 0.0};
|
||||
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 sign[3] = { rayDirectionInverse[0] < 0.0, rayDirectionInverse[1] < 0.0, rayDirectionInverse[2] < 0.0};
|
||||
#endif
|
||||
|
||||
btVector3 bounds[2];
|
||||
@@ -501,7 +502,7 @@ void btQuantizedBvh::walkStacklessTreeAgainstRay(btNodeOverlapCallback* nodeCall
|
||||
///careful with this check: need to check division by zero (above) and fix the unQuantize method
|
||||
///thanks Joerg/hiker for the reproduction case!
|
||||
///http://www.bulletphysics.com/Bullet/phpBB3/viewtopic.php?f=9&t=1858
|
||||
rayBoxOverlap = aabbOverlap ? btRayAabb2 (raySource, rayDirection, sign, bounds, param, 0.0f, lambda_max) : false;
|
||||
rayBoxOverlap = aabbOverlap ? btRayAabb2 (raySource, rayDirectionInverse, sign, bounds, param, 0.0f, lambda_max) : false;
|
||||
|
||||
#else
|
||||
btVector3 normal;
|
||||
|
||||
Reference in New Issue
Block a user