Autoformat selection for soft body, btDbvt related classes (no code change, just layout using Visual Studio)
This commit is contained in:
1 parent
cac172d422
commit
60ce828419
20 files changed
+3941
-3941
No files matched your search
+394
-394
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
@@ -26,19 +26,19 @@ subject to the following restrictions:
|
||||
|
||||
#if DBVT_BP_PROFILE
|
||||
struct ProfileScope
|
||||
{
|
||||
{
|
||||
__forceinline ProfileScope(btClock& clock,unsigned long& value) :
|
||||
m_clock(&clock),m_value(&value),m_base(clock.getTimeMicroseconds())
|
||||
{
|
||||
}
|
||||
m_clock(&clock),m_value(&value),m_base(clock.getTimeMicroseconds())
|
||||
{
|
||||
}
|
||||
__forceinline ~ProfileScope()
|
||||
{
|
||||
{
|
||||
(*m_value)+=m_clock->getTimeMicroseconds()-m_base;
|
||||
}
|
||||
}
|
||||
btClock* m_clock;
|
||||
unsigned long* m_value;
|
||||
unsigned long m_base;
|
||||
};
|
||||
};
|
||||
#define SPC(_value_) ProfileScope spc_scope(m_clock,_value_)
|
||||
#else
|
||||
#define SPC(_value_)
|
||||
@@ -52,35 +52,35 @@ struct ProfileScope
|
||||
template <typename T>
|
||||
static inline void listappend(T* item,T*& list)
|
||||
{
|
||||
item->links[0]=0;
|
||||
item->links[1]=list;
|
||||
if(list) list->links[0]=item;
|
||||
list=item;
|
||||
item->links[0]=0;
|
||||
item->links[1]=list;
|
||||
if(list) list->links[0]=item;
|
||||
list=item;
|
||||
}
|
||||
|
||||
//
|
||||
template <typename T>
|
||||
static inline void listremove(T* item,T*& list)
|
||||
{
|
||||
if(item->links[0]) item->links[0]->links[1]=item->links[1]; else list=item->links[1];
|
||||
if(item->links[1]) item->links[1]->links[0]=item->links[0];
|
||||
if(item->links[0]) item->links[0]->links[1]=item->links[1]; else list=item->links[1];
|
||||
if(item->links[1]) item->links[1]->links[0]=item->links[0];
|
||||
}
|
||||
|
||||
//
|
||||
template <typename T>
|
||||
static inline int listcount(T* root)
|
||||
{
|
||||
int n=0;
|
||||
while(root) { ++n;root=root->links[1]; }
|
||||
return(n);
|
||||
int n=0;
|
||||
while(root) { ++n;root=root->links[1]; }
|
||||
return(n);
|
||||
}
|
||||
|
||||
//
|
||||
template <typename T>
|
||||
static inline void clear(T& value)
|
||||
{
|
||||
static const struct ZeroDummy : T {} zerodummy;
|
||||
value=zerodummy;
|
||||
static const struct ZeroDummy : T {} zerodummy;
|
||||
value=zerodummy;
|
||||
}
|
||||
|
||||
//
|
||||
@@ -90,25 +90,25 @@ value=zerodummy;
|
||||
/* Tree collider */
|
||||
struct btDbvtTreeCollider : btDbvt::ICollide
|
||||
{
|
||||
btDbvtBroadphase* pbp;
|
||||
btDbvtProxy* proxy;
|
||||
btDbvtTreeCollider(btDbvtBroadphase* p) : pbp(p) {}
|
||||
void Process(const btDbvtNode* na,const btDbvtNode* nb)
|
||||
btDbvtBroadphase* pbp;
|
||||
btDbvtProxy* proxy;
|
||||
btDbvtTreeCollider(btDbvtBroadphase* p) : pbp(p) {}
|
||||
void Process(const btDbvtNode* na,const btDbvtNode* nb)
|
||||
{
|
||||
if(na!=nb)
|
||||
if(na!=nb)
|
||||
{
|
||||
btDbvtProxy* pa=(btDbvtProxy*)na->data;
|
||||
btDbvtProxy* pb=(btDbvtProxy*)nb->data;
|
||||
#if DBVT_BP_SORTPAIRS
|
||||
if(pa>pb) btSwap(pa,pb);
|
||||
#endif
|
||||
pbp->m_paircache->addOverlappingPair(pa,pb);
|
||||
++pbp->m_newpairs;
|
||||
btDbvtProxy* pa=(btDbvtProxy*)na->data;
|
||||
btDbvtProxy* pb=(btDbvtProxy*)nb->data;
|
||||
#if DBVT_BP_SORTPAIRS
|
||||
if(pa>pb) btSwap(pa,pb);
|
||||
#endif
|
||||
pbp->m_paircache->addOverlappingPair(pa,pb);
|
||||
++pbp->m_newpairs;
|
||||
}
|
||||
}
|
||||
void Process(const btDbvtNode* n)
|
||||
void Process(const btDbvtNode* n)
|
||||
{
|
||||
Process(n,proxy->leaf);
|
||||
Process(n,proxy->leaf);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -119,88 +119,88 @@ void Process(const btDbvtNode* n)
|
||||
//
|
||||
btDbvtBroadphase::btDbvtBroadphase(btOverlappingPairCache* paircache)
|
||||
{
|
||||
m_deferedcollide = false;
|
||||
m_needcleanup = true;
|
||||
m_releasepaircache = (paircache!=0)?false:true;
|
||||
m_prediction = 1/(btScalar)2;
|
||||
m_stageCurrent = 0;
|
||||
m_fixedleft = 0;
|
||||
m_fupdates = 1;
|
||||
m_dupdates = 0;
|
||||
m_cupdates = 10;
|
||||
m_newpairs = 1;
|
||||
m_updates_call = 0;
|
||||
m_updates_done = 0;
|
||||
m_updates_ratio = 0;
|
||||
m_paircache = paircache?
|
||||
paircache :
|
||||
new(btAlignedAlloc(sizeof(btHashedOverlappingPairCache),16)) btHashedOverlappingPairCache();
|
||||
m_gid = 0;
|
||||
m_pid = 0;
|
||||
m_cid = 0;
|
||||
for(int i=0;i<=STAGECOUNT;++i)
|
||||
m_deferedcollide = false;
|
||||
m_needcleanup = true;
|
||||
m_releasepaircache = (paircache!=0)?false:true;
|
||||
m_prediction = 1/(btScalar)2;
|
||||
m_stageCurrent = 0;
|
||||
m_fixedleft = 0;
|
||||
m_fupdates = 1;
|
||||
m_dupdates = 0;
|
||||
m_cupdates = 10;
|
||||
m_newpairs = 1;
|
||||
m_updates_call = 0;
|
||||
m_updates_done = 0;
|
||||
m_updates_ratio = 0;
|
||||
m_paircache = paircache?
|
||||
paircache :
|
||||
new(btAlignedAlloc(sizeof(btHashedOverlappingPairCache),16)) btHashedOverlappingPairCache();
|
||||
m_gid = 0;
|
||||
m_pid = 0;
|
||||
m_cid = 0;
|
||||
for(int i=0;i<=STAGECOUNT;++i)
|
||||
{
|
||||
m_stageRoots[i]=0;
|
||||
m_stageRoots[i]=0;
|
||||
}
|
||||
#if DBVT_BP_PROFILE
|
||||
clear(m_profiling);
|
||||
clear(m_profiling);
|
||||
#endif
|
||||
}
|
||||
|
||||
//
|
||||
btDbvtBroadphase::~btDbvtBroadphase()
|
||||
{
|
||||
if(m_releasepaircache)
|
||||
{
|
||||
m_paircache->~btOverlappingPairCache();
|
||||
btAlignedFree(m_paircache);
|
||||
}
|
||||
if(m_releasepaircache)
|
||||
{
|
||||
m_paircache->~btOverlappingPairCache();
|
||||
btAlignedFree(m_paircache);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
btBroadphaseProxy* btDbvtBroadphase::createProxy( const btVector3& aabbMin,
|
||||
const btVector3& aabbMax,
|
||||
int /*shapeType*/,
|
||||
void* userPtr,
|
||||
short int collisionFilterGroup,
|
||||
short int collisionFilterMask,
|
||||
btDispatcher* /*dispatcher*/,
|
||||
void* /*multiSapProxy*/)
|
||||
const btVector3& aabbMax,
|
||||
int /*shapeType*/,
|
||||
void* userPtr,
|
||||
short int collisionFilterGroup,
|
||||
short int collisionFilterMask,
|
||||
btDispatcher* /*dispatcher*/,
|
||||
void* /*multiSapProxy*/)
|
||||
{
|
||||
btDbvtProxy* proxy=new(btAlignedAlloc(sizeof(btDbvtProxy),16)) btDbvtProxy( aabbMin,aabbMax,userPtr,
|
||||
collisionFilterGroup,
|
||||
collisionFilterMask);
|
||||
btDbvtProxy* proxy=new(btAlignedAlloc(sizeof(btDbvtProxy),16)) btDbvtProxy( aabbMin,aabbMax,userPtr,
|
||||
collisionFilterGroup,
|
||||
collisionFilterMask);
|
||||
|
||||
btDbvtAabbMm aabb = btDbvtVolume::FromMM(aabbMin,aabbMax);
|
||||
btDbvtAabbMm aabb = btDbvtVolume::FromMM(aabbMin,aabbMax);
|
||||
|
||||
//bproxy->aabb = btDbvtVolume::FromMM(aabbMin,aabbMax);
|
||||
proxy->stage = m_stageCurrent;
|
||||
proxy->m_uniqueId = ++m_gid;
|
||||
proxy->leaf = m_sets[0].insert(aabb,proxy);
|
||||
listappend(proxy,m_stageRoots[m_stageCurrent]);
|
||||
if(!m_deferedcollide)
|
||||
//bproxy->aabb = btDbvtVolume::FromMM(aabbMin,aabbMax);
|
||||
proxy->stage = m_stageCurrent;
|
||||
proxy->m_uniqueId = ++m_gid;
|
||||
proxy->leaf = m_sets[0].insert(aabb,proxy);
|
||||
listappend(proxy,m_stageRoots[m_stageCurrent]);
|
||||
if(!m_deferedcollide)
|
||||
{
|
||||
btDbvtTreeCollider collider(this);
|
||||
collider.proxy=proxy;
|
||||
btDbvt::collideTV(m_sets[0].m_root,aabb,collider);
|
||||
btDbvt::collideTV(m_sets[1].m_root,aabb,collider);
|
||||
btDbvtTreeCollider collider(this);
|
||||
collider.proxy=proxy;
|
||||
btDbvt::collideTV(m_sets[0].m_root,aabb,collider);
|
||||
btDbvt::collideTV(m_sets[1].m_root,aabb,collider);
|
||||
}
|
||||
return(proxy);
|
||||
return(proxy);
|
||||
}
|
||||
|
||||
//
|
||||
void btDbvtBroadphase::destroyProxy( btBroadphaseProxy* absproxy,
|
||||
btDispatcher* dispatcher)
|
||||
btDispatcher* dispatcher)
|
||||
{
|
||||
btDbvtProxy* proxy=(btDbvtProxy*)absproxy;
|
||||
if(proxy->stage==STAGECOUNT)
|
||||
m_sets[1].remove(proxy->leaf);
|
||||
btDbvtProxy* proxy=(btDbvtProxy*)absproxy;
|
||||
if(proxy->stage==STAGECOUNT)
|
||||
m_sets[1].remove(proxy->leaf);
|
||||
else
|
||||
m_sets[0].remove(proxy->leaf);
|
||||
listremove(proxy,m_stageRoots[proxy->stage]);
|
||||
m_paircache->removeOverlappingPairsContainingProxy(proxy,dispatcher);
|
||||
btAlignedFree(proxy);
|
||||
m_needcleanup=true;
|
||||
m_sets[0].remove(proxy->leaf);
|
||||
listremove(proxy,m_stageRoots[proxy->stage]);
|
||||
m_paircache->removeOverlappingPairsContainingProxy(proxy,dispatcher);
|
||||
btAlignedFree(proxy);
|
||||
m_needcleanup=true;
|
||||
}
|
||||
|
||||
void btDbvtBroadphase::getAabb(btBroadphaseProxy* absproxy,btVector3& aabbMin, btVector3& aabbMax ) const
|
||||
@@ -230,79 +230,79 @@ void btDbvtBroadphase::rayTest(const btVector3& rayFrom,const btVector3& rayTo,
|
||||
BroadphaseRayTester callback(rayCallback);
|
||||
|
||||
m_sets[0].rayTest( m_sets[0].m_root,
|
||||
rayFrom,
|
||||
rayTo,
|
||||
callback);
|
||||
rayFrom,
|
||||
rayTo,
|
||||
callback);
|
||||
|
||||
m_sets[1].rayTest( m_sets[1].m_root,
|
||||
rayFrom,
|
||||
rayTo,
|
||||
callback);
|
||||
rayFrom,
|
||||
rayTo,
|
||||
callback);
|
||||
|
||||
}
|
||||
|
||||
//
|
||||
void btDbvtBroadphase::setAabb( btBroadphaseProxy* absproxy,
|
||||
const btVector3& aabbMin,
|
||||
const btVector3& aabbMax,
|
||||
btDispatcher* /*dispatcher*/)
|
||||
const btVector3& aabbMin,
|
||||
const btVector3& aabbMax,
|
||||
btDispatcher* /*dispatcher*/)
|
||||
{
|
||||
btDbvtProxy* proxy=(btDbvtProxy*)absproxy;
|
||||
ATTRIBUTE_ALIGNED16(btDbvtVolume) aabb=btDbvtVolume::FromMM(aabbMin,aabbMax);
|
||||
btDbvtProxy* proxy=(btDbvtProxy*)absproxy;
|
||||
ATTRIBUTE_ALIGNED16(btDbvtVolume) aabb=btDbvtVolume::FromMM(aabbMin,aabbMax);
|
||||
#if DBVT_BP_PREVENTFALSEUPDATE
|
||||
if(NotEqual(aabb,proxy->leaf->volume))
|
||||
if(NotEqual(aabb,proxy->leaf->volume))
|
||||
#endif
|
||||
{
|
||||
bool docollide=false;
|
||||
if(proxy->stage==STAGECOUNT)
|
||||
bool docollide=false;
|
||||
if(proxy->stage==STAGECOUNT)
|
||||
{/* fixed -> dynamic set */
|
||||
m_sets[1].remove(proxy->leaf);
|
||||
proxy->leaf=m_sets[0].insert(aabb,proxy);
|
||||
docollide=true;
|
||||
m_sets[1].remove(proxy->leaf);
|
||||
proxy->leaf=m_sets[0].insert(aabb,proxy);
|
||||
docollide=true;
|
||||
}
|
||||
else
|
||||
{/* dynamic set */
|
||||
++m_updates_call;
|
||||
if(Intersect(proxy->leaf->volume,aabb))
|
||||
++m_updates_call;
|
||||
if(Intersect(proxy->leaf->volume,aabb))
|
||||
{/* Moving */
|
||||
|
||||
const btVector3 delta=aabbMin-proxy->m_aabbMin;
|
||||
btVector3 velocity(((proxy->m_aabbMax-proxy->m_aabbMin)/2)*m_prediction);
|
||||
if(delta[0]<0) velocity[0]=-velocity[0];
|
||||
if(delta[1]<0) velocity[1]=-velocity[1];
|
||||
if(delta[2]<0) velocity[2]=-velocity[2];
|
||||
if (
|
||||
#ifdef DBVT_BP_MARGIN
|
||||
m_sets[0].update(proxy->leaf,aabb,velocity,DBVT_BP_MARGIN)
|
||||
#else
|
||||
m_sets[0].update(proxy->leaf,aabb,velocity)
|
||||
#endif
|
||||
)
|
||||
const btVector3 delta=aabbMin-proxy->m_aabbMin;
|
||||
btVector3 velocity(((proxy->m_aabbMax-proxy->m_aabbMin)/2)*m_prediction);
|
||||
if(delta[0]<0) velocity[0]=-velocity[0];
|
||||
if(delta[1]<0) velocity[1]=-velocity[1];
|
||||
if(delta[2]<0) velocity[2]=-velocity[2];
|
||||
if (
|
||||
#ifdef DBVT_BP_MARGIN
|
||||
m_sets[0].update(proxy->leaf,aabb,velocity,DBVT_BP_MARGIN)
|
||||
#else
|
||||
m_sets[0].update(proxy->leaf,aabb,velocity)
|
||||
#endif
|
||||
)
|
||||
{
|
||||
++m_updates_done;
|
||||
docollide=true;
|
||||
++m_updates_done;
|
||||
docollide=true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{/* Teleporting */
|
||||
m_sets[0].update(proxy->leaf,aabb);
|
||||
++m_updates_done;
|
||||
docollide=true;
|
||||
m_sets[0].update(proxy->leaf,aabb);
|
||||
++m_updates_done;
|
||||
docollide=true;
|
||||
}
|
||||
}
|
||||
listremove(proxy,m_stageRoots[proxy->stage]);
|
||||
proxy->m_aabbMin = aabbMin;
|
||||
proxy->m_aabbMax = aabbMax;
|
||||
proxy->stage = m_stageCurrent;
|
||||
listappend(proxy,m_stageRoots[m_stageCurrent]);
|
||||
if(docollide)
|
||||
listremove(proxy,m_stageRoots[proxy->stage]);
|
||||
proxy->m_aabbMin = aabbMin;
|
||||
proxy->m_aabbMax = aabbMax;
|
||||
proxy->stage = m_stageCurrent;
|
||||
listappend(proxy,m_stageRoots[m_stageCurrent]);
|
||||
if(docollide)
|
||||
{
|
||||
m_needcleanup=true;
|
||||
if(!m_deferedcollide)
|
||||
m_needcleanup=true;
|
||||
if(!m_deferedcollide)
|
||||
{
|
||||
btDbvtTreeCollider collider(this);
|
||||
btDbvt::collideTT(m_sets[1].m_root,proxy->leaf,collider);
|
||||
btDbvt::collideTT(m_sets[0].m_root,proxy->leaf,collider);
|
||||
btDbvtTreeCollider collider(this);
|
||||
btDbvt::collideTT(m_sets[1].m_root,proxy->leaf,collider);
|
||||
btDbvt::collideTT(m_sets[0].m_root,proxy->leaf,collider);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -311,24 +311,24 @@ if(NotEqual(aabb,proxy->leaf->volume))
|
||||
//
|
||||
void btDbvtBroadphase::calculateOverlappingPairs(btDispatcher* dispatcher)
|
||||
{
|
||||
collide(dispatcher);
|
||||
collide(dispatcher);
|
||||
#if DBVT_BP_PROFILE
|
||||
if(0==(m_pid%DBVT_BP_PROFILING_RATE))
|
||||
if(0==(m_pid%DBVT_BP_PROFILING_RATE))
|
||||
{
|
||||
printf("fixed(%u) dynamics(%u) pairs(%u)\r\n",m_sets[1].m_leaves,m_sets[0].m_leaves,m_paircache->getNumOverlappingPairs());
|
||||
unsigned int total=m_profiling.m_total;
|
||||
if(total<=0) total=1;
|
||||
printf("ddcollide: %u%% (%uus)\r\n",(50+m_profiling.m_ddcollide*100)/total,m_profiling.m_ddcollide/DBVT_BP_PROFILING_RATE);
|
||||
printf("fdcollide: %u%% (%uus)\r\n",(50+m_profiling.m_fdcollide*100)/total,m_profiling.m_fdcollide/DBVT_BP_PROFILING_RATE);
|
||||
printf("cleanup: %u%% (%uus)\r\n",(50+m_profiling.m_cleanup*100)/total,m_profiling.m_cleanup/DBVT_BP_PROFILING_RATE);
|
||||
printf("total: %uus\r\n",total/DBVT_BP_PROFILING_RATE);
|
||||
const unsigned long sum=m_profiling.m_ddcollide+
|
||||
m_profiling.m_fdcollide+
|
||||
m_profiling.m_cleanup;
|
||||
printf("leaked: %u%% (%uus)\r\n",100-((50+sum*100)/total),(total-sum)/DBVT_BP_PROFILING_RATE);
|
||||
printf("job counts: %u%%\r\n",(m_profiling.m_jobcount*100)/((m_sets[0].m_leaves+m_sets[1].m_leaves)*DBVT_BP_PROFILING_RATE));
|
||||
clear(m_profiling);
|
||||
m_clock.reset();
|
||||
printf("fixed(%u) dynamics(%u) pairs(%u)\r\n",m_sets[1].m_leaves,m_sets[0].m_leaves,m_paircache->getNumOverlappingPairs());
|
||||
unsigned int total=m_profiling.m_total;
|
||||
if(total<=0) total=1;
|
||||
printf("ddcollide: %u%% (%uus)\r\n",(50+m_profiling.m_ddcollide*100)/total,m_profiling.m_ddcollide/DBVT_BP_PROFILING_RATE);
|
||||
printf("fdcollide: %u%% (%uus)\r\n",(50+m_profiling.m_fdcollide*100)/total,m_profiling.m_fdcollide/DBVT_BP_PROFILING_RATE);
|
||||
printf("cleanup: %u%% (%uus)\r\n",(50+m_profiling.m_cleanup*100)/total,m_profiling.m_cleanup/DBVT_BP_PROFILING_RATE);
|
||||
printf("total: %uus\r\n",total/DBVT_BP_PROFILING_RATE);
|
||||
const unsigned long sum=m_profiling.m_ddcollide+
|
||||
m_profiling.m_fdcollide+
|
||||
m_profiling.m_cleanup;
|
||||
printf("leaked: %u%% (%uus)\r\n",100-((50+sum*100)/total),(total-sum)/DBVT_BP_PROFILING_RATE);
|
||||
printf("job counts: %u%%\r\n",(m_profiling.m_jobcount*100)/((m_sets[0].m_leaves+m_sets[1].m_leaves)*DBVT_BP_PROFILING_RATE));
|
||||
clear(m_profiling);
|
||||
m_clock.reset();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@@ -336,108 +336,108 @@ if(0==(m_pid%DBVT_BP_PROFILING_RATE))
|
||||
//
|
||||
void btDbvtBroadphase::collide(btDispatcher* dispatcher)
|
||||
{
|
||||
SPC(m_profiling.m_total);
|
||||
/* optimize */
|
||||
m_sets[0].optimizeIncremental(1+(m_sets[0].m_leaves*m_dupdates)/100);
|
||||
if(m_fixedleft)
|
||||
SPC(m_profiling.m_total);
|
||||
/* optimize */
|
||||
m_sets[0].optimizeIncremental(1+(m_sets[0].m_leaves*m_dupdates)/100);
|
||||
if(m_fixedleft)
|
||||
{
|
||||
const int count=1+(m_sets[1].m_leaves*m_fupdates)/100;
|
||||
m_sets[1].optimizeIncremental(1+(m_sets[1].m_leaves*m_fupdates)/100);
|
||||
m_fixedleft=btMax<int>(0,m_fixedleft-count);
|
||||
const int count=1+(m_sets[1].m_leaves*m_fupdates)/100;
|
||||
m_sets[1].optimizeIncremental(1+(m_sets[1].m_leaves*m_fupdates)/100);
|
||||
m_fixedleft=btMax<int>(0,m_fixedleft-count);
|
||||
}
|
||||
/* dynamic -> fixed set */
|
||||
m_stageCurrent=(m_stageCurrent+1)%STAGECOUNT;
|
||||
btDbvtProxy* current=m_stageRoots[m_stageCurrent];
|
||||
if(current)
|
||||
/* dynamic -> fixed set */
|
||||
m_stageCurrent=(m_stageCurrent+1)%STAGECOUNT;
|
||||
btDbvtProxy* current=m_stageRoots[m_stageCurrent];
|
||||
if(current)
|
||||
{
|
||||
btDbvtTreeCollider collider(this);
|
||||
do {
|
||||
btDbvtProxy* next=current->links[1];
|
||||
listremove(current,m_stageRoots[current->stage]);
|
||||
listappend(current,m_stageRoots[STAGECOUNT]);
|
||||
#if DBVT_BP_ACCURATESLEEPING
|
||||
m_paircache->removeOverlappingPairsContainingProxy(current,dispatcher);
|
||||
collider.proxy=current;
|
||||
btDbvt::collideTV(m_sets[0].m_root,current->aabb,collider);
|
||||
btDbvt::collideTV(m_sets[1].m_root,current->aabb,collider);
|
||||
#endif
|
||||
m_sets[0].remove(current->leaf);
|
||||
ATTRIBUTE_ALIGNED16(btDbvtVolume) curAabb=btDbvtVolume::FromMM(current->m_aabbMin,current->m_aabbMax);
|
||||
current->leaf = m_sets[1].insert(curAabb,current);
|
||||
current->stage = STAGECOUNT;
|
||||
current = next;
|
||||
btDbvtTreeCollider collider(this);
|
||||
do {
|
||||
btDbvtProxy* next=current->links[1];
|
||||
listremove(current,m_stageRoots[current->stage]);
|
||||
listappend(current,m_stageRoots[STAGECOUNT]);
|
||||
#if DBVT_BP_ACCURATESLEEPING
|
||||
m_paircache->removeOverlappingPairsContainingProxy(current,dispatcher);
|
||||
collider.proxy=current;
|
||||
btDbvt::collideTV(m_sets[0].m_root,current->aabb,collider);
|
||||
btDbvt::collideTV(m_sets[1].m_root,current->aabb,collider);
|
||||
#endif
|
||||
m_sets[0].remove(current->leaf);
|
||||
ATTRIBUTE_ALIGNED16(btDbvtVolume) curAabb=btDbvtVolume::FromMM(current->m_aabbMin,current->m_aabbMax);
|
||||
current->leaf = m_sets[1].insert(curAabb,current);
|
||||
current->stage = STAGECOUNT;
|
||||
current = next;
|
||||
} while(current);
|
||||
m_fixedleft=m_sets[1].m_leaves;
|
||||
m_needcleanup=true;
|
||||
m_fixedleft=m_sets[1].m_leaves;
|
||||
m_needcleanup=true;
|
||||
}
|
||||
/* collide dynamics */
|
||||
/* collide dynamics */
|
||||
{
|
||||
btDbvtTreeCollider collider(this);
|
||||
if(m_deferedcollide)
|
||||
btDbvtTreeCollider collider(this);
|
||||
if(m_deferedcollide)
|
||||
{
|
||||
SPC(m_profiling.m_fdcollide);
|
||||
btDbvt::collideTT(m_sets[0].m_root,m_sets[1].m_root,collider);
|
||||
SPC(m_profiling.m_fdcollide);
|
||||
btDbvt::collideTT(m_sets[0].m_root,m_sets[1].m_root,collider);
|
||||
}
|
||||
if(m_deferedcollide)
|
||||
if(m_deferedcollide)
|
||||
{
|
||||
SPC(m_profiling.m_ddcollide);
|
||||
btDbvt::collideTT(m_sets[0].m_root,m_sets[0].m_root,collider);
|
||||
SPC(m_profiling.m_ddcollide);
|
||||
btDbvt::collideTT(m_sets[0].m_root,m_sets[0].m_root,collider);
|
||||
}
|
||||
}
|
||||
/* clean up */
|
||||
if(m_needcleanup)
|
||||
/* clean up */
|
||||
if(m_needcleanup)
|
||||
{
|
||||
SPC(m_profiling.m_cleanup);
|
||||
btBroadphasePairArray& pairs=m_paircache->getOverlappingPairArray();
|
||||
if(pairs.size()>0)
|
||||
SPC(m_profiling.m_cleanup);
|
||||
btBroadphasePairArray& pairs=m_paircache->getOverlappingPairArray();
|
||||
if(pairs.size()>0)
|
||||
{
|
||||
const int ci=pairs.size();
|
||||
int ni=btMin(ci,btMax<int>(m_newpairs,(ci*m_cupdates)/100));
|
||||
for(int i=0;i<ni;++i)
|
||||
const int ci=pairs.size();
|
||||
int ni=btMin(ci,btMax<int>(m_newpairs,(ci*m_cupdates)/100));
|
||||
for(int i=0;i<ni;++i)
|
||||
{
|
||||
btBroadphasePair& p=pairs[(m_cid+i)%ci];
|
||||
btDbvtProxy* pa=(btDbvtProxy*)p.m_pProxy0;
|
||||
btDbvtProxy* pb=(btDbvtProxy*)p.m_pProxy1;
|
||||
if(!Intersect(pa->leaf->volume,pb->leaf->volume))
|
||||
btBroadphasePair& p=pairs[(m_cid+i)%ci];
|
||||
btDbvtProxy* pa=(btDbvtProxy*)p.m_pProxy0;
|
||||
btDbvtProxy* pb=(btDbvtProxy*)p.m_pProxy1;
|
||||
if(!Intersect(pa->leaf->volume,pb->leaf->volume))
|
||||
{
|
||||
#if DBVT_BP_SORTPAIRS
|
||||
if(pa>pb) btSwap(pa,pb);
|
||||
#endif
|
||||
m_paircache->removeOverlappingPair(pa,pb,dispatcher);
|
||||
--ni;--i;
|
||||
#if DBVT_BP_SORTPAIRS
|
||||
if(pa>pb) btSwap(pa,pb);
|
||||
#endif
|
||||
m_paircache->removeOverlappingPair(pa,pb,dispatcher);
|
||||
--ni;--i;
|
||||
}
|
||||
}
|
||||
if(pairs.size()>0) m_cid=(m_cid+ni)%pairs.size(); else m_cid=0;
|
||||
if(pairs.size()>0) m_cid=(m_cid+ni)%pairs.size(); else m_cid=0;
|
||||
}
|
||||
}
|
||||
++m_pid;
|
||||
m_newpairs=1;
|
||||
m_needcleanup=false;
|
||||
if(m_updates_call>0)
|
||||
++m_pid;
|
||||
m_newpairs=1;
|
||||
m_needcleanup=false;
|
||||
if(m_updates_call>0)
|
||||
{ m_updates_ratio=m_updates_done/(btScalar)m_updates_call; }
|
||||
else
|
||||
{ m_updates_ratio=0; }
|
||||
m_updates_done/=2;
|
||||
m_updates_call/=2;
|
||||
m_updates_done/=2;
|
||||
m_updates_call/=2;
|
||||
}
|
||||
|
||||
//
|
||||
void btDbvtBroadphase::optimize()
|
||||
{
|
||||
m_sets[0].optimizeTopDown();
|
||||
m_sets[1].optimizeTopDown();
|
||||
m_sets[0].optimizeTopDown();
|
||||
m_sets[1].optimizeTopDown();
|
||||
}
|
||||
|
||||
//
|
||||
btOverlappingPairCache* btDbvtBroadphase::getOverlappingPairCache()
|
||||
{
|
||||
return(m_paircache);
|
||||
return(m_paircache);
|
||||
}
|
||||
|
||||
//
|
||||
const btOverlappingPairCache* btDbvtBroadphase::getOverlappingPairCache() const
|
||||
{
|
||||
return(m_paircache);
|
||||
return(m_paircache);
|
||||
}
|
||||
|
||||
//
|
||||
@@ -446,16 +446,16 @@ void btDbvtBroadphase::getBroadphaseAabb(btVector3& aabbMin,btVector3& aab
|
||||
|
||||
ATTRIBUTE_ALIGNED16(btDbvtVolume) bounds;
|
||||
|
||||
if(!m_sets[0].empty())
|
||||
if(!m_sets[1].empty()) Merge( m_sets[0].m_root->volume,
|
||||
m_sets[1].m_root->volume,bounds);
|
||||
else
|
||||
bounds=m_sets[0].m_root->volume;
|
||||
else if(!m_sets[1].empty()) bounds=m_sets[1].m_root->volume;
|
||||
else
|
||||
bounds=btDbvtVolume::FromCR(btVector3(0,0,0),0);
|
||||
aabbMin=bounds.Mins();
|
||||
aabbMax=bounds.Maxs();
|
||||
if(!m_sets[0].empty())
|
||||
if(!m_sets[1].empty()) Merge( m_sets[0].m_root->volume,
|
||||
m_sets[1].m_root->volume,bounds);
|
||||
else
|
||||
bounds=m_sets[0].m_root->volume;
|
||||
else if(!m_sets[1].empty()) bounds=m_sets[1].m_root->volume;
|
||||
else
|
||||
bounds=btDbvtVolume::FromCR(btVector3(0,0,0),0);
|
||||
aabbMin=bounds.Mins();
|
||||
aabbMax=bounds.Maxs();
|
||||
}
|
||||
|
||||
//
|
||||
@@ -466,9 +466,9 @@ void btDbvtBroadphase::printStats()
|
||||
#if DBVT_BP_ENABLE_BENCHMARK
|
||||
|
||||
struct btBroadphaseBenchmark
|
||||
{
|
||||
{
|
||||
struct Experiment
|
||||
{
|
||||
{
|
||||
const char* name;
|
||||
int object_count;
|
||||
int update_count;
|
||||
@@ -476,109 +476,109 @@ struct btBroadphaseBenchmark
|
||||
int iterations;
|
||||
btScalar speed;
|
||||
btScalar amplitude;
|
||||
};
|
||||
};
|
||||
struct Object
|
||||
{
|
||||
{
|
||||
btVector3 center;
|
||||
btVector3 extents;
|
||||
btBroadphaseProxy* proxy;
|
||||
btScalar time;
|
||||
void update(btScalar speed,btScalar amplitude,btBroadphaseInterface* pbi)
|
||||
{
|
||||
{
|
||||
time += speed;
|
||||
center[0] = btCos(time*(btScalar)2.17)*amplitude+
|
||||
btSin(time)*amplitude/2;
|
||||
btSin(time)*amplitude/2;
|
||||
center[1] = btCos(time*(btScalar)1.38)*amplitude+
|
||||
btSin(time)*amplitude;
|
||||
btSin(time)*amplitude;
|
||||
center[2] = btSin(time*(btScalar)0.777)*amplitude;
|
||||
pbi->setAabb(proxy,center-extents,center+extents,0);
|
||||
}
|
||||
};
|
||||
}
|
||||
};
|
||||
static int UnsignedRand(int range=RAND_MAX-1) { return(rand()%(range+1)); }
|
||||
static btScalar UnitRand() { return(UnsignedRand(16384)/(btScalar)16384); }
|
||||
static void OutputTime(const char* name,btClock& c,unsigned count=0)
|
||||
{
|
||||
{
|
||||
const unsigned long us=c.getTimeMicroseconds();
|
||||
const unsigned long ms=(us+500)/1000;
|
||||
const btScalar sec=us/(btScalar)(1000*1000);
|
||||
if(count>0)
|
||||
printf("%s : %u us (%u ms), %.2f/s\r\n",name,us,ms,count/sec);
|
||||
else
|
||||
else
|
||||
printf("%s : %u us (%u ms)\r\n",name,us,ms);
|
||||
}
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
void btDbvtBroadphase::benchmark(btBroadphaseInterface* pbi)
|
||||
{
|
||||
static const btBroadphaseBenchmark::Experiment experiments[]=
|
||||
static const btBroadphaseBenchmark::Experiment experiments[]=
|
||||
{
|
||||
{"1024o.10%",1024,10,0,8192,(btScalar)0.005,(btScalar)100},
|
||||
/*{"4096o.10%",4096,10,0,8192,(btScalar)0.005,(btScalar)100},
|
||||
{"8192o.10%",8192,10,0,8192,(btScalar)0.005,(btScalar)100},*/
|
||||
{"1024o.10%",1024,10,0,8192,(btScalar)0.005,(btScalar)100},
|
||||
/*{"4096o.10%",4096,10,0,8192,(btScalar)0.005,(btScalar)100},
|
||||
{"8192o.10%",8192,10,0,8192,(btScalar)0.005,(btScalar)100},*/
|
||||
};
|
||||
static const int nexperiments=sizeof(experiments)/sizeof(experiments[0]);
|
||||
btAlignedObjectArray<btBroadphaseBenchmark::Object*> objects;
|
||||
btClock wallclock;
|
||||
/* Begin */
|
||||
for(int iexp=0;iexp<nexperiments;++iexp)
|
||||
static const int nexperiments=sizeof(experiments)/sizeof(experiments[0]);
|
||||
btAlignedObjectArray<btBroadphaseBenchmark::Object*> objects;
|
||||
btClock wallclock;
|
||||
/* Begin */
|
||||
for(int iexp=0;iexp<nexperiments;++iexp)
|
||||
{
|
||||
const btBroadphaseBenchmark::Experiment& experiment=experiments[iexp];
|
||||
const int object_count=experiment.object_count;
|
||||
const int update_count=(object_count*experiment.update_count)/100;
|
||||
const int spawn_count=(object_count*experiment.spawn_count)/100;
|
||||
const btScalar speed=experiment.speed;
|
||||
const btScalar amplitude=experiment.amplitude;
|
||||
printf("Experiment #%u '%s':\r\n",iexp,experiment.name);
|
||||
printf("\tObjects: %u\r\n",object_count);
|
||||
printf("\tUpdate: %u\r\n",update_count);
|
||||
printf("\tSpawn: %u\r\n",spawn_count);
|
||||
printf("\tSpeed: %f\r\n",speed);
|
||||
printf("\tAmplitude: %f\r\n",amplitude);
|
||||
srand(180673);
|
||||
/* Create objects */
|
||||
wallclock.reset();
|
||||
objects.reserve(object_count);
|
||||
for(int i=0;i<object_count;++i)
|
||||
const btBroadphaseBenchmark::Experiment& experiment=experiments[iexp];
|
||||
const int object_count=experiment.object_count;
|
||||
const int update_count=(object_count*experiment.update_count)/100;
|
||||
const int spawn_count=(object_count*experiment.spawn_count)/100;
|
||||
const btScalar speed=experiment.speed;
|
||||
const btScalar amplitude=experiment.amplitude;
|
||||
printf("Experiment #%u '%s':\r\n",iexp,experiment.name);
|
||||
printf("\tObjects: %u\r\n",object_count);
|
||||
printf("\tUpdate: %u\r\n",update_count);
|
||||
printf("\tSpawn: %u\r\n",spawn_count);
|
||||
printf("\tSpeed: %f\r\n",speed);
|
||||
printf("\tAmplitude: %f\r\n",amplitude);
|
||||
srand(180673);
|
||||
/* Create objects */
|
||||
wallclock.reset();
|
||||
objects.reserve(object_count);
|
||||
for(int i=0;i<object_count;++i)
|
||||
{
|
||||
btBroadphaseBenchmark::Object* po=new btBroadphaseBenchmark::Object();
|
||||
po->center[0]=btBroadphaseBenchmark::UnitRand()*50;
|
||||
po->center[1]=btBroadphaseBenchmark::UnitRand()*50;
|
||||
po->center[2]=btBroadphaseBenchmark::UnitRand()*50;
|
||||
po->extents[0]=btBroadphaseBenchmark::UnitRand()*2+2;
|
||||
po->extents[1]=btBroadphaseBenchmark::UnitRand()*2+2;
|
||||
po->extents[2]=btBroadphaseBenchmark::UnitRand()*2+2;
|
||||
po->time=btBroadphaseBenchmark::UnitRand()*2000;
|
||||
po->proxy=pbi->createProxy(po->center-po->extents,po->center+po->extents,0,po,1,1,0,0);
|
||||
objects.push_back(po);
|
||||
btBroadphaseBenchmark::Object* po=new btBroadphaseBenchmark::Object();
|
||||
po->center[0]=btBroadphaseBenchmark::UnitRand()*50;
|
||||
po->center[1]=btBroadphaseBenchmark::UnitRand()*50;
|
||||
po->center[2]=btBroadphaseBenchmark::UnitRand()*50;
|
||||
po->extents[0]=btBroadphaseBenchmark::UnitRand()*2+2;
|
||||
po->extents[1]=btBroadphaseBenchmark::UnitRand()*2+2;
|
||||
po->extents[2]=btBroadphaseBenchmark::UnitRand()*2+2;
|
||||
po->time=btBroadphaseBenchmark::UnitRand()*2000;
|
||||
po->proxy=pbi->createProxy(po->center-po->extents,po->center+po->extents,0,po,1,1,0,0);
|
||||
objects.push_back(po);
|
||||
}
|
||||
btBroadphaseBenchmark::OutputTime("\tInitialization",wallclock);
|
||||
/* First update */
|
||||
wallclock.reset();
|
||||
for(int i=0;i<objects.size();++i)
|
||||
btBroadphaseBenchmark::OutputTime("\tInitialization",wallclock);
|
||||
/* First update */
|
||||
wallclock.reset();
|
||||
for(int i=0;i<objects.size();++i)
|
||||
{
|
||||
objects[i]->update(speed,amplitude,pbi);
|
||||
objects[i]->update(speed,amplitude,pbi);
|
||||
}
|
||||
btBroadphaseBenchmark::OutputTime("\tFirst update",wallclock);
|
||||
/* Updates */
|
||||
wallclock.reset();
|
||||
for(int i=0;i<experiment.iterations;++i)
|
||||
btBroadphaseBenchmark::OutputTime("\tFirst update",wallclock);
|
||||
/* Updates */
|
||||
wallclock.reset();
|
||||
for(int i=0;i<experiment.iterations;++i)
|
||||
{
|
||||
for(int j=0;j<update_count;++j)
|
||||
for(int j=0;j<update_count;++j)
|
||||
{
|
||||
objects[j]->update(speed,amplitude,pbi);
|
||||
objects[j]->update(speed,amplitude,pbi);
|
||||
}
|
||||
pbi->calculateOverlappingPairs(0);
|
||||
pbi->calculateOverlappingPairs(0);
|
||||
}
|
||||
btBroadphaseBenchmark::OutputTime("\tUpdate",wallclock,experiment.iterations);
|
||||
/* Clean up */
|
||||
wallclock.reset();
|
||||
for(int i=0;i<objects.size();++i)
|
||||
btBroadphaseBenchmark::OutputTime("\tUpdate",wallclock,experiment.iterations);
|
||||
/* Clean up */
|
||||
wallclock.reset();
|
||||
for(int i=0;i<objects.size();++i)
|
||||
{
|
||||
pbi->destroyProxy(objects[i]->proxy,0);
|
||||
delete objects[i];
|
||||
pbi->destroyProxy(objects[i]->proxy,0);
|
||||
delete objects[i];
|
||||
}
|
||||
objects.resize(0);
|
||||
btBroadphaseBenchmark::OutputTime("\tRelease",wallclock);
|
||||
objects.resize(0);
|
||||
btBroadphaseBenchmark::OutputTime("\tRelease",wallclock);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -31,8 +31,8 @@ subject to the following restrictions:
|
||||
#define DBVT_BP_MARGIN (btScalar)0.05
|
||||
|
||||
#if DBVT_BP_PROFILE
|
||||
#define DBVT_BP_PROFILING_RATE 256
|
||||
#include "LinearMath/btQuickprof.h"
|
||||
#define DBVT_BP_PROFILING_RATE 256
|
||||
#include "LinearMath/btQuickprof.h"
|
||||
#endif
|
||||
|
||||
//
|
||||
@@ -40,16 +40,16 @@ subject to the following restrictions:
|
||||
//
|
||||
struct btDbvtProxy : btBroadphaseProxy
|
||||
{
|
||||
/* Fields */
|
||||
//btDbvtAabbMm aabb;
|
||||
btDbvtNode* leaf;
|
||||
btDbvtProxy* links[2];
|
||||
int stage;
|
||||
/* ctor */
|
||||
btDbvtProxy(const btVector3& aabbMin,const btVector3& aabbMax,void* userPtr,short int collisionFilterGroup, short int collisionFilterMask) :
|
||||
/* Fields */
|
||||
//btDbvtAabbMm aabb;
|
||||
btDbvtNode* leaf;
|
||||
btDbvtProxy* links[2];
|
||||
int stage;
|
||||
/* ctor */
|
||||
btDbvtProxy(const btVector3& aabbMin,const btVector3& aabbMax,void* userPtr,short int collisionFilterGroup, short int collisionFilterMask) :
|
||||
btBroadphaseProxy(aabbMin,aabbMax,userPtr,collisionFilterGroup,collisionFilterMask)
|
||||
{
|
||||
links[0]=links[1]=0;
|
||||
links[0]=links[1]=0;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -60,60 +60,60 @@ typedef btAlignedObjectArray<btDbvtProxy*> btDbvtProxyArray;
|
||||
///This is a very fast broadphase, especially for very dynamic worlds where many objects are moving. Its insert/add and remove of objects is generally faster than the sweep and prune broadphases btAxisSweep3 and bt32BitAxisSweep3.
|
||||
struct btDbvtBroadphase : btBroadphaseInterface
|
||||
{
|
||||
/* Config */
|
||||
enum {
|
||||
/* Config */
|
||||
enum {
|
||||
DYNAMIC_SET = 0, /* Dynamic set index */
|
||||
FIXED_SET = 1, /* Fixed set index */
|
||||
STAGECOUNT = 2 /* Number of stages */
|
||||
};
|
||||
/* Fields */
|
||||
btDbvt m_sets[2]; // Dbvt sets
|
||||
btDbvtProxy* m_stageRoots[STAGECOUNT+1]; // Stages list
|
||||
btOverlappingPairCache* m_paircache; // Pair cache
|
||||
btScalar m_prediction; // Velocity prediction
|
||||
int m_stageCurrent; // Current stage
|
||||
int m_fupdates; // % of fixed updates per frame
|
||||
int m_dupdates; // % of dynamic updates per frame
|
||||
int m_cupdates; // % of cleanup updates per frame
|
||||
int m_newpairs; // Number of pairs created
|
||||
int m_fixedleft; // Fixed optimization left
|
||||
unsigned m_updates_call; // Number of updates call
|
||||
unsigned m_updates_done; // Number of updates done
|
||||
btScalar m_updates_ratio; // m_updates_done/m_updates_call
|
||||
int m_pid; // Parse id
|
||||
int m_cid; // Cleanup index
|
||||
int m_gid; // Gen id
|
||||
bool m_releasepaircache; // Release pair cache on delete
|
||||
bool m_deferedcollide; // Defere dynamic/static collision to collide call
|
||||
bool m_needcleanup; // Need to run cleanup?
|
||||
};
|
||||
/* Fields */
|
||||
btDbvt m_sets[2]; // Dbvt sets
|
||||
btDbvtProxy* m_stageRoots[STAGECOUNT+1]; // Stages list
|
||||
btOverlappingPairCache* m_paircache; // Pair cache
|
||||
btScalar m_prediction; // Velocity prediction
|
||||
int m_stageCurrent; // Current stage
|
||||
int m_fupdates; // % of fixed updates per frame
|
||||
int m_dupdates; // % of dynamic updates per frame
|
||||
int m_cupdates; // % of cleanup updates per frame
|
||||
int m_newpairs; // Number of pairs created
|
||||
int m_fixedleft; // Fixed optimization left
|
||||
unsigned m_updates_call; // Number of updates call
|
||||
unsigned m_updates_done; // Number of updates done
|
||||
btScalar m_updates_ratio; // m_updates_done/m_updates_call
|
||||
int m_pid; // Parse id
|
||||
int m_cid; // Cleanup index
|
||||
int m_gid; // Gen id
|
||||
bool m_releasepaircache; // Release pair cache on delete
|
||||
bool m_deferedcollide; // Defere dynamic/static collision to collide call
|
||||
bool m_needcleanup; // Need to run cleanup?
|
||||
#if DBVT_BP_PROFILE
|
||||
btClock m_clock;
|
||||
struct {
|
||||
btClock m_clock;
|
||||
struct {
|
||||
unsigned long m_total;
|
||||
unsigned long m_ddcollide;
|
||||
unsigned long m_fdcollide;
|
||||
unsigned long m_cleanup;
|
||||
unsigned long m_jobcount;
|
||||
} m_profiling;
|
||||
} m_profiling;
|
||||
#endif
|
||||
/* Methods */
|
||||
btDbvtBroadphase(btOverlappingPairCache* paircache=0);
|
||||
~btDbvtBroadphase();
|
||||
void collide(btDispatcher* dispatcher);
|
||||
void optimize();
|
||||
/* btBroadphaseInterface Implementation */
|
||||
btBroadphaseProxy* createProxy(const btVector3& aabbMin,const btVector3& aabbMax,int shapeType,void* userPtr,short int collisionFilterGroup,short int collisionFilterMask,btDispatcher* dispatcher,void* multiSapProxy);
|
||||
void destroyProxy(btBroadphaseProxy* proxy,btDispatcher* dispatcher);
|
||||
void setAabb(btBroadphaseProxy* proxy,const btVector3& aabbMin,const btVector3& aabbMax,btDispatcher* dispatcher);
|
||||
virtual void rayTest(const btVector3& rayFrom,const btVector3& rayTo, btBroadphaseRayCallback& rayCallback);
|
||||
/* Methods */
|
||||
btDbvtBroadphase(btOverlappingPairCache* paircache=0);
|
||||
~btDbvtBroadphase();
|
||||
void collide(btDispatcher* dispatcher);
|
||||
void optimize();
|
||||
/* btBroadphaseInterface Implementation */
|
||||
btBroadphaseProxy* createProxy(const btVector3& aabbMin,const btVector3& aabbMax,int shapeType,void* userPtr,short int collisionFilterGroup,short int collisionFilterMask,btDispatcher* dispatcher,void* multiSapProxy);
|
||||
void destroyProxy(btBroadphaseProxy* proxy,btDispatcher* dispatcher);
|
||||
void setAabb(btBroadphaseProxy* proxy,const btVector3& aabbMin,const btVector3& aabbMax,btDispatcher* dispatcher);
|
||||
virtual void rayTest(const btVector3& rayFrom,const btVector3& rayTo, btBroadphaseRayCallback& rayCallback);
|
||||
|
||||
virtual void getAabb(btBroadphaseProxy* proxy,btVector3& aabbMin, btVector3& aabbMax ) const;
|
||||
void calculateOverlappingPairs(btDispatcher* dispatcher);
|
||||
btOverlappingPairCache* getOverlappingPairCache();
|
||||
const btOverlappingPairCache* getOverlappingPairCache() const;
|
||||
void getBroadphaseAabb(btVector3& aabbMin,btVector3& aabbMax) const;
|
||||
void printStats();
|
||||
static void benchmark(btBroadphaseInterface*);
|
||||
virtual void getAabb(btBroadphaseProxy* proxy,btVector3& aabbMin, btVector3& aabbMax ) const;
|
||||
void calculateOverlappingPairs(btDispatcher* dispatcher);
|
||||
btOverlappingPairCache* getOverlappingPairCache();
|
||||
const btOverlappingPairCache* getOverlappingPairCache() const;
|
||||
void getBroadphaseAabb(btVector3& aabbMin,btVector3& aabbMax) const;
|
||||
void printStats();
|
||||
static void benchmark(btBroadphaseInterface*);
|
||||
};
|
||||
|
||||
#endif
|
||||
+946
-946
File diff suppressed because it is too large.
Load diff
+115
-115
@@ -62,13 +62,13 @@ public:
|
||||
F_OneSided, ///Face normals are taken as it is
|
||||
END
|
||||
};};
|
||||
|
||||
|
||||
///eVSolver : velocities solvers
|
||||
struct eVSolver { enum _ {
|
||||
Linear, ///Linear solver
|
||||
END
|
||||
};};
|
||||
|
||||
|
||||
///ePSolver : positions solvers
|
||||
struct ePSolver { enum _ {
|
||||
Linear, ///Linear solver
|
||||
@@ -77,7 +77,7 @@ public:
|
||||
SContacts, ///Soft contacts solver
|
||||
END
|
||||
};};
|
||||
|
||||
|
||||
///eSolverPresets
|
||||
struct eSolverPresets { enum _ {
|
||||
Positions,
|
||||
@@ -85,7 +85,7 @@ public:
|
||||
Default = Positions,
|
||||
END
|
||||
};};
|
||||
|
||||
|
||||
///eFeature
|
||||
struct eFeature { enum _ {
|
||||
None,
|
||||
@@ -94,20 +94,20 @@ public:
|
||||
Face,
|
||||
END
|
||||
};};
|
||||
|
||||
|
||||
typedef btAlignedObjectArray<eVSolver::_> tVSolverArray;
|
||||
typedef btAlignedObjectArray<ePSolver::_> tPSolverArray;
|
||||
|
||||
|
||||
//
|
||||
// Flags
|
||||
//
|
||||
|
||||
|
||||
///fCollision
|
||||
struct fCollision { enum _ {
|
||||
RVSmask = 0x000f, ///Rigid versus soft mask
|
||||
SDF_RS = 0x0001, ///SDF based rigid vs soft
|
||||
CL_RS = 0x0002, ///Cluster vs convex rigid vs soft
|
||||
|
||||
|
||||
SVSmask = 0x00f0, ///Rigid versus soft mask
|
||||
VF_SS = 0x0010, ///Vertex vs face soft vs soft handling
|
||||
CL_SS = 0x0020, ///Cluster vs cluster soft vs soft handling
|
||||
@@ -115,7 +115,7 @@ public:
|
||||
Default = SDF_RS,
|
||||
END
|
||||
};};
|
||||
|
||||
|
||||
///fMaterial
|
||||
struct fMaterial { enum _ {
|
||||
DebugDraw = 0x0001, /// Enable debug draw
|
||||
@@ -123,11 +123,11 @@ public:
|
||||
Default = DebugDraw,
|
||||
END
|
||||
};};
|
||||
|
||||
|
||||
//
|
||||
// API Types
|
||||
//
|
||||
|
||||
|
||||
/* sRayCast */
|
||||
struct sRayCast
|
||||
{
|
||||
@@ -136,13 +136,13 @@ public:
|
||||
int index; /// feature index
|
||||
btScalar fraction; /// time of impact fraction (rayorg+(rayto-rayfrom)*fraction)
|
||||
};
|
||||
|
||||
|
||||
/* ImplicitFn */
|
||||
struct ImplicitFn
|
||||
{
|
||||
virtual btScalar Eval(const btVector3& x)=0;
|
||||
};
|
||||
|
||||
|
||||
//
|
||||
// Internal types
|
||||
//
|
||||
@@ -180,7 +180,7 @@ public:
|
||||
btScalar m_kVST; // Volume stiffness coefficient [0,1]
|
||||
int m_flags; // Flags
|
||||
};
|
||||
|
||||
|
||||
/* Feature */
|
||||
struct Feature : Element
|
||||
{
|
||||
@@ -296,7 +296,7 @@ public:
|
||||
btScalar m_adamping;
|
||||
btScalar m_matching;
|
||||
bool m_collide;
|
||||
Cluster() : m_leaf(0),m_ndamping(0),m_ldamping(0),m_adamping(0),m_matching(0) {}
|
||||
Cluster() : m_leaf(0),m_ndamping(0),m_ldamping(0),m_adamping(0),m_matching(0) {}
|
||||
};
|
||||
/* Impulse */
|
||||
struct Impulse
|
||||
@@ -307,109 +307,109 @@ public:
|
||||
int m_asDrift:1;
|
||||
Impulse() : m_velocity(0,0,0),m_drift(0,0,0),m_asVelocity(0),m_asDrift(0) {}
|
||||
Impulse operator -() const
|
||||
{
|
||||
{
|
||||
Impulse i=*this;
|
||||
i.m_velocity=-i.m_velocity;
|
||||
i.m_drift=-i.m_drift;
|
||||
return(i);
|
||||
}
|
||||
}
|
||||
Impulse operator*(btScalar x) const
|
||||
{
|
||||
{
|
||||
Impulse i=*this;
|
||||
i.m_velocity*=x;
|
||||
i.m_drift*=x;
|
||||
return(i);
|
||||
}
|
||||
}
|
||||
};
|
||||
/* Body */
|
||||
struct Body
|
||||
{
|
||||
Cluster* m_soft;
|
||||
btRigidBody* m_rigid;
|
||||
Body() : m_soft(0),m_rigid(0) {}
|
||||
Body(Cluster* p) : m_soft(p),m_rigid(0) {}
|
||||
Body(btRigidBody* p) : m_soft(0),m_rigid(p) {}
|
||||
Body() : m_soft(0),m_rigid(0) {}
|
||||
Body(Cluster* p) : m_soft(p),m_rigid(0) {}
|
||||
Body(btRigidBody* p) : m_soft(0),m_rigid(p) {}
|
||||
void activate() const
|
||||
{
|
||||
{
|
||||
if(m_rigid) m_rigid->activate();
|
||||
}
|
||||
}
|
||||
const btMatrix3x3& invWorldInertia() const
|
||||
{
|
||||
{
|
||||
static const btMatrix3x3 iwi(0,0,0,0,0,0,0,0,0);
|
||||
if(m_rigid) return(m_rigid->getInvInertiaTensorWorld());
|
||||
if(m_soft) return(m_soft->m_invwi);
|
||||
return(iwi);
|
||||
}
|
||||
}
|
||||
btScalar invMass() const
|
||||
{
|
||||
{
|
||||
if(m_rigid) return(m_rigid->getInvMass());
|
||||
if(m_soft) return(m_soft->m_imass);
|
||||
return(0);
|
||||
}
|
||||
}
|
||||
const btTransform& xform() const
|
||||
{
|
||||
{
|
||||
static const btTransform identity=btTransform::getIdentity();
|
||||
if(m_rigid) return(m_rigid->getInterpolationWorldTransform());
|
||||
if(m_soft) return(m_soft->m_framexform);
|
||||
return(identity);
|
||||
}
|
||||
}
|
||||
btVector3 linearVelocity() const
|
||||
{
|
||||
{
|
||||
if(m_rigid) return(m_rigid->getLinearVelocity());
|
||||
if(m_soft) return(m_soft->m_lv);
|
||||
return(btVector3(0,0,0));
|
||||
}
|
||||
}
|
||||
btVector3 angularVelocity(const btVector3& rpos) const
|
||||
{
|
||||
{
|
||||
if(m_rigid) return(cross(m_rigid->getAngularVelocity(),rpos));
|
||||
if(m_soft) return(cross(m_soft->m_av,rpos));
|
||||
return(btVector3(0,0,0));
|
||||
}
|
||||
}
|
||||
btVector3 angularVelocity() const
|
||||
{
|
||||
{
|
||||
if(m_rigid) return(m_rigid->getAngularVelocity());
|
||||
if(m_soft) return(m_soft->m_av);
|
||||
return(btVector3(0,0,0));
|
||||
}
|
||||
}
|
||||
btVector3 velocity(const btVector3& rpos) const
|
||||
{
|
||||
{
|
||||
return(linearVelocity()+angularVelocity(rpos));
|
||||
}
|
||||
}
|
||||
void applyVImpulse(const btVector3& impulse,const btVector3& rpos) const
|
||||
{
|
||||
{
|
||||
if(m_rigid) m_rigid->applyImpulse(impulse,rpos);
|
||||
if(m_soft) btSoftBody::clusterVImpulse(m_soft,rpos,impulse);
|
||||
}
|
||||
}
|
||||
void applyDImpulse(const btVector3& impulse,const btVector3& rpos) const
|
||||
{
|
||||
{
|
||||
if(m_rigid) m_rigid->applyImpulse(impulse,rpos);
|
||||
if(m_soft) btSoftBody::clusterDImpulse(m_soft,rpos,impulse);
|
||||
}
|
||||
}
|
||||
void applyImpulse(const Impulse& impulse,const btVector3& rpos) const
|
||||
{
|
||||
{
|
||||
if(impulse.m_asVelocity) applyVImpulse(impulse.m_velocity,rpos);
|
||||
if(impulse.m_asDrift) applyDImpulse(impulse.m_drift,rpos);
|
||||
}
|
||||
}
|
||||
void applyVAImpulse(const btVector3& impulse) const
|
||||
{
|
||||
{
|
||||
if(m_rigid) m_rigid->applyTorqueImpulse(impulse);
|
||||
if(m_soft) btSoftBody::clusterVAImpulse(m_soft,impulse);
|
||||
}
|
||||
}
|
||||
void applyDAImpulse(const btVector3& impulse) const
|
||||
{
|
||||
{
|
||||
if(m_rigid) m_rigid->applyTorqueImpulse(impulse);
|
||||
if(m_soft) btSoftBody::clusterDAImpulse(m_soft,impulse);
|
||||
}
|
||||
}
|
||||
void applyAImpulse(const Impulse& impulse) const
|
||||
{
|
||||
{
|
||||
if(impulse.m_asVelocity) applyVAImpulse(impulse.m_velocity);
|
||||
if(impulse.m_asDrift) applyDAImpulse(impulse.m_drift);
|
||||
}
|
||||
}
|
||||
void applyDCImpulse(const btVector3& impulse) const
|
||||
{
|
||||
{
|
||||
if(m_rigid) m_rigid->applyCentralImpulse(impulse);
|
||||
if(m_soft) btSoftBody::clusterDCImpulse(m_soft,impulse);
|
||||
}
|
||||
}
|
||||
};
|
||||
/* Joint */
|
||||
struct Joint
|
||||
@@ -420,12 +420,12 @@ public:
|
||||
Contact,
|
||||
};};
|
||||
struct Specs
|
||||
{
|
||||
Specs() : erp(1),cfm(1),split(1) {}
|
||||
{
|
||||
Specs() : erp(1),cfm(1),split(1) {}
|
||||
btScalar erp;
|
||||
btScalar cfm;
|
||||
btScalar split;
|
||||
};
|
||||
};
|
||||
Body m_bodies[2];
|
||||
btVector3 m_refs[2];
|
||||
btScalar m_cfm;
|
||||
@@ -436,7 +436,7 @@ public:
|
||||
btMatrix3x3 m_massmatrix;
|
||||
bool m_delete;
|
||||
virtual ~Joint() {}
|
||||
Joint() : m_delete(false) {}
|
||||
Joint() : m_delete(false) {}
|
||||
virtual void Prepare(btScalar dt,int iterations);
|
||||
virtual void Solve(btScalar dt,btScalar sor)=0;
|
||||
virtual void Terminate(btScalar dt)=0;
|
||||
@@ -446,9 +446,9 @@ public:
|
||||
struct LJoint : Joint
|
||||
{
|
||||
struct Specs : Joint::Specs
|
||||
{
|
||||
{
|
||||
btVector3 position;
|
||||
};
|
||||
};
|
||||
btVector3 m_rpos[2];
|
||||
void Prepare(btScalar dt,int iterations);
|
||||
void Solve(btScalar dt,btScalar sor);
|
||||
@@ -459,17 +459,17 @@ public:
|
||||
struct AJoint : Joint
|
||||
{
|
||||
struct IControl
|
||||
{
|
||||
{
|
||||
virtual void Prepare(AJoint*) {}
|
||||
virtual btScalar Speed(AJoint*,btScalar current) { return(current); }
|
||||
static IControl* Default() { static IControl def;return(&def); }
|
||||
};
|
||||
};
|
||||
struct Specs : Joint::Specs
|
||||
{
|
||||
Specs() : icontrol(IControl::Default()) {}
|
||||
{
|
||||
Specs() : icontrol(IControl::Default()) {}
|
||||
btVector3 axis;
|
||||
IControl* icontrol;
|
||||
};
|
||||
};
|
||||
btVector3 m_axis[2];
|
||||
IControl* m_icontrol;
|
||||
void Prepare(btScalar dt,int iterations);
|
||||
@@ -534,24 +534,24 @@ public:
|
||||
};
|
||||
/// RayFromToCaster takes a ray from, ray to (instead of direction!)
|
||||
struct RayFromToCaster : btDbvt::ICollide
|
||||
{
|
||||
{
|
||||
btVector3 m_rayFrom;
|
||||
btVector3 m_rayTo;
|
||||
btVector3 m_rayNormalizedDirection;
|
||||
btScalar m_mint;
|
||||
Face* m_face;
|
||||
int m_tests;
|
||||
RayFromToCaster(const btVector3& rayFrom,const btVector3& rayTo,btScalar mxt);
|
||||
RayFromToCaster(const btVector3& rayFrom,const btVector3& rayTo,btScalar mxt);
|
||||
void Process(const btDbvtNode* leaf);
|
||||
|
||||
|
||||
static inline btScalar rayFromToTriangle(const btVector3& rayFrom,
|
||||
const btVector3& rayTo,
|
||||
const btVector3& rayNormalizedDirection,
|
||||
const btVector3& a,
|
||||
const btVector3& b,
|
||||
const btVector3& c,
|
||||
btScalar maxt=SIMD_INFINITY);
|
||||
};
|
||||
const btVector3& rayTo,
|
||||
const btVector3& rayNormalizedDirection,
|
||||
const btVector3& a,
|
||||
const btVector3& b,
|
||||
const btVector3& c,
|
||||
btScalar maxt=SIMD_INFINITY);
|
||||
};
|
||||
|
||||
//
|
||||
// Typedef's
|
||||
@@ -597,15 +597,15 @@ public:
|
||||
btDbvt m_fdbvt; // Faces tree
|
||||
btDbvt m_cdbvt; // Clusters tree
|
||||
tClusterArray m_clusters; // Clusters
|
||||
|
||||
|
||||
//
|
||||
// Api
|
||||
//
|
||||
|
||||
|
||||
/* ctor */
|
||||
btSoftBody( btSoftBodyWorldInfo* worldInfo,int node_count,
|
||||
const btVector3* x,
|
||||
const btScalar* m);
|
||||
const btVector3* x,
|
||||
const btScalar* m);
|
||||
/* dtor */
|
||||
virtual ~btSoftBody();
|
||||
/* Check for existing link */
|
||||
@@ -625,51 +625,51 @@ public:
|
||||
bool checkLink( int node0,
|
||||
int node1) const;
|
||||
bool checkLink( const Node* node0,
|
||||
const Node* node1) const;
|
||||
const Node* node1) const;
|
||||
/* Check for existring face */
|
||||
bool checkFace( int node0,
|
||||
int node1,
|
||||
int node2) const;
|
||||
int node1,
|
||||
int node2) const;
|
||||
/* Append material */
|
||||
Material* appendMaterial();
|
||||
/* Append note */
|
||||
void appendNote( const char* text,
|
||||
const btVector3& o,
|
||||
const btVector4& c=btVector4(1,0,0,0),
|
||||
Node* n0=0,
|
||||
Node* n1=0,
|
||||
Node* n2=0,
|
||||
Node* n3=0);
|
||||
const btVector3& o,
|
||||
const btVector4& c=btVector4(1,0,0,0),
|
||||
Node* n0=0,
|
||||
Node* n1=0,
|
||||
Node* n2=0,
|
||||
Node* n3=0);
|
||||
void appendNote( const char* text,
|
||||
const btVector3& o,
|
||||
Node* feature);
|
||||
const btVector3& o,
|
||||
Node* feature);
|
||||
void appendNote( const char* text,
|
||||
const btVector3& o,
|
||||
Link* feature);
|
||||
const btVector3& o,
|
||||
Link* feature);
|
||||
void appendNote( const char* text,
|
||||
const btVector3& o,
|
||||
Face* feature);
|
||||
const btVector3& o,
|
||||
Face* feature);
|
||||
/* Append node */
|
||||
void appendNode( const btVector3& x,btScalar m);
|
||||
/* Append link */
|
||||
void appendLink(int model=-1,Material* mat=0);
|
||||
void appendLink( int node0,
|
||||
int node1,
|
||||
Material* mat=0,
|
||||
bool bcheckexist=false);
|
||||
int node1,
|
||||
Material* mat=0,
|
||||
bool bcheckexist=false);
|
||||
void appendLink( Node* node0,
|
||||
Node* node1,
|
||||
Material* mat=0,
|
||||
bool bcheckexist=false);
|
||||
Node* node1,
|
||||
Material* mat=0,
|
||||
bool bcheckexist=false);
|
||||
/* Append face */
|
||||
void appendFace(int model=-1,Material* mat=0);
|
||||
void appendFace( int node0,
|
||||
int node1,
|
||||
int node2,
|
||||
Material* mat=0);
|
||||
int node1,
|
||||
int node2,
|
||||
Material* mat=0);
|
||||
/* Append anchor */
|
||||
void appendAnchor( int node,
|
||||
btRigidBody* body);
|
||||
btRigidBody* body);
|
||||
/* Append linear joint */
|
||||
void appendLinearJoint(const LJoint::Specs& specs,Cluster* body0,Body body1);
|
||||
void appendLinearJoint(const LJoint::Specs& specs,Body body=Body());
|
||||
@@ -682,7 +682,7 @@ public:
|
||||
void addForce( const btVector3& force);
|
||||
/* Add force (or gravity) to a node of the body */
|
||||
void addForce( const btVector3& force,
|
||||
int node);
|
||||
int node);
|
||||
/* Add velocity to the entire body */
|
||||
void addVelocity( const btVector3& velocity);
|
||||
|
||||
@@ -691,17 +691,17 @@ public:
|
||||
|
||||
/* Add velocity to a node of the body */
|
||||
void addVelocity( const btVector3& velocity,
|
||||
int node);
|
||||
int node);
|
||||
/* Set mass */
|
||||
void setMass( int node,
|
||||
btScalar mass);
|
||||
btScalar mass);
|
||||
/* Get mass */
|
||||
btScalar getMass( int node) const;
|
||||
/* Get total mass */
|
||||
btScalar getTotalMass() const;
|
||||
/* Set total mass (weighted by previous masses) */
|
||||
void setTotalMass( btScalar mass,
|
||||
bool fromfaces=false);
|
||||
bool fromfaces=false);
|
||||
/* Set total density */
|
||||
void setTotalDensity(btScalar density);
|
||||
/* Transform */
|
||||
@@ -714,7 +714,7 @@ public:
|
||||
void scale( const btVector3& scl);
|
||||
/* Set current state as pose */
|
||||
void setPose( bool bvolume,
|
||||
bool bframe);
|
||||
bool bframe);
|
||||
/* Return the volume */
|
||||
btScalar getVolume() const;
|
||||
/* Cluster count */
|
||||
@@ -734,7 +734,7 @@ public:
|
||||
static void clusterDCImpulse(Cluster* cluster,const btVector3& impulse);
|
||||
/* Generate bending constraints based on distance in the adjency graph */
|
||||
int generateBendingConstraints( int distance,
|
||||
Material* mat=0);
|
||||
Material* mat=0);
|
||||
/* Randomize constraints to reduce solver bias */
|
||||
void randomizeConstraints();
|
||||
/* Release clusters */
|
||||
@@ -747,11 +747,11 @@ public:
|
||||
/* CutLink */
|
||||
bool cutLink(int node0,int node1,btScalar position);
|
||||
bool cutLink(const Node* node0,const Node* node1,btScalar position);
|
||||
|
||||
|
||||
///Ray casting using rayFrom and rayTo in worldspace, (not direction!)
|
||||
bool rayTest(const btVector3& rayFrom,
|
||||
const btVector3& rayTo,
|
||||
sRayCast& results);
|
||||
const btVector3& rayTo,
|
||||
sRayCast& results);
|
||||
/* Solver presets */
|
||||
void setSolver(eSolverPresets::_ preset);
|
||||
/* predictMotion */
|
||||
@@ -769,11 +769,11 @@ public:
|
||||
/* defaultCollisionHandlers */
|
||||
void defaultCollisionHandler(btCollisionObject* pco);
|
||||
void defaultCollisionHandler(btSoftBody* psb);
|
||||
|
||||
|
||||
//
|
||||
// Cast
|
||||
//
|
||||
|
||||
|
||||
static const btSoftBody* upcast(const btCollisionObject* colObj)
|
||||
{
|
||||
if (colObj->getInternalType()==CO_SOFT_BODY)
|
||||
@@ -803,7 +803,7 @@ public:
|
||||
void indicesToPointers(const int* map=0);
|
||||
|
||||
int rayTest(const btVector3& rayFrom,const btVector3& rayTo,
|
||||
btScalar& mint,eFeature::_& feature,int& index,bool bcountonly) const;
|
||||
btScalar& mint,eFeature::_& feature,int& index,bool bcountonly) const;
|
||||
void initializeFaceTree();
|
||||
btVector3 evaluateCom() const;
|
||||
bool checkContact(btRigidBody* prb,const btVector3& x,btScalar margin,btSoftBody::sCti& cti) const;
|
||||
@@ -826,7 +826,7 @@ public:
|
||||
static void VSolve_Links(btSoftBody* psb,btScalar kst);
|
||||
static psolver_t getSolver(ePSolver::_ solver);
|
||||
static vsolver_t getSolver(eVSolver::_ solver);
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -50,27 +50,27 @@ btSoftBodyConcaveCollisionAlgorithm::~btSoftBodyConcaveCollisionAlgorithm()
|
||||
|
||||
|
||||
btSoftBodyTriangleCallback::btSoftBodyTriangleCallback(btDispatcher* dispatcher,btCollisionObject* body0,btCollisionObject* body1,bool isSwapped):
|
||||
m_dispatcher(dispatcher),
|
||||
m_dispatchInfoPtr(0)
|
||||
m_dispatcher(dispatcher),
|
||||
m_dispatchInfoPtr(0)
|
||||
{
|
||||
m_softBody = (btSoftBody*) (isSwapped? body1:body0);
|
||||
m_triBody = isSwapped? body0:body1;
|
||||
|
||||
//
|
||||
// create the manifold from the dispatcher 'manifold pool'
|
||||
//
|
||||
// m_manifoldPtr = m_dispatcher->getNewManifold(m_convexBody,m_triBody);
|
||||
|
||||
clearCache();
|
||||
//
|
||||
// create the manifold from the dispatcher 'manifold pool'
|
||||
//
|
||||
// m_manifoldPtr = m_dispatcher->getNewManifold(m_convexBody,m_triBody);
|
||||
|
||||
clearCache();
|
||||
}
|
||||
|
||||
btSoftBodyTriangleCallback::~btSoftBodyTriangleCallback()
|
||||
{
|
||||
clearCache();
|
||||
// m_dispatcher->releaseManifold( m_manifoldPtr );
|
||||
|
||||
// m_dispatcher->releaseManifold( m_manifoldPtr );
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
void btSoftBodyTriangleCallback::clearCache()
|
||||
{
|
||||
@@ -88,13 +88,13 @@ void btSoftBodyTriangleCallback::clearCache()
|
||||
|
||||
void btSoftBodyTriangleCallback::processTriangle(btVector3* triangle,int partId, int triangleIndex)
|
||||
{
|
||||
//just for debugging purposes
|
||||
//just for debugging purposes
|
||||
//printf("triangle %d",m_triangleCount++);
|
||||
btCollisionObject* ob = static_cast<btCollisionObject*>(m_triBody);
|
||||
btCollisionAlgorithmConstructionInfo ci;
|
||||
ci.m_dispatcher1 = m_dispatcher;
|
||||
|
||||
///debug drawing of the overlapping triangles
|
||||
///debug drawing of the overlapping triangles
|
||||
if (m_dispatchInfoPtr && m_dispatchInfoPtr->m_debugDraw && m_dispatchInfoPtr->m_debugDraw->getDebugMode() > 0)
|
||||
{
|
||||
btVector3 color(255,255,0);
|
||||
@@ -107,7 +107,7 @@ void btSoftBodyTriangleCallback::processTriangle(btVector3* triangle,int partId,
|
||||
btTriIndex triIndex(partId,triangleIndex,0);
|
||||
btHashKey<btTriIndex> triKey(triIndex.getUid());
|
||||
|
||||
|
||||
|
||||
btTriIndex* shapeIndex = m_shapeCache[triKey];
|
||||
if (shapeIndex)
|
||||
{
|
||||
@@ -116,13 +116,13 @@ void btSoftBodyTriangleCallback::processTriangle(btVector3* triangle,int partId,
|
||||
|
||||
//copy over user pointers to temporary shape
|
||||
tm->setUserPointer(ob->getRootCollisionShape()->getUserPointer());
|
||||
|
||||
|
||||
btCollisionShape* tmpShape = ob->getCollisionShape();
|
||||
ob->internalSetTemporaryCollisionShape( tm );
|
||||
|
||||
|
||||
|
||||
btCollisionAlgorithm* colAlgo = ci.m_dispatcher1->findAlgorithm(m_softBody,m_triBody,0);//m_manifoldPtr);
|
||||
|
||||
|
||||
colAlgo->processCollision(m_softBody,m_triBody,*m_dispatchInfoPtr,m_resultOut);
|
||||
colAlgo->~btCollisionAlgorithm();
|
||||
ci.m_dispatcher1->freeCollisionAlgorithm(colAlgo);
|
||||
@@ -133,56 +133,56 @@ void btSoftBodyTriangleCallback::processTriangle(btVector3* triangle,int partId,
|
||||
//aabb filter is already applied!
|
||||
|
||||
//btCollisionObject* colObj = static_cast<btCollisionObject*>(m_convexProxy->m_clientObject);
|
||||
|
||||
// if (m_softBody->getCollisionShape()->getShapeType()==
|
||||
|
||||
// if (m_softBody->getCollisionShape()->getShapeType()==
|
||||
{
|
||||
// btVector3 other;
|
||||
// btVector3 other;
|
||||
btVector3 normal = (triangle[1]-triangle[0]).cross(triangle[2]-triangle[0]);
|
||||
normal.normalize();
|
||||
normal*= BT_SOFTBODY_TRIANGLE_EXTRUSION;
|
||||
// other=(triangle[0]+triangle[1]+triangle[2])*0.333333f;
|
||||
// other+=normal*22.f;
|
||||
// other=(triangle[0]+triangle[1]+triangle[2])*0.333333f;
|
||||
// other+=normal*22.f;
|
||||
btVector3 pts[6] = {triangle[0]+normal,
|
||||
triangle[1]+normal,
|
||||
triangle[2]+normal,
|
||||
triangle[0]-normal,
|
||||
triangle[1]-normal,
|
||||
triangle[2]-normal};
|
||||
triangle[2]+normal,
|
||||
triangle[0]-normal,
|
||||
triangle[1]-normal,
|
||||
triangle[2]-normal};
|
||||
|
||||
btConvexHullShape* tm = new btConvexHullShape(&pts[0].getX(),6);
|
||||
|
||||
|
||||
// btBU_Simplex1to4 tm(triangle[0],triangle[1],triangle[2],other);
|
||||
|
||||
// btBU_Simplex1to4 tm(triangle[0],triangle[1],triangle[2],other);
|
||||
|
||||
//btTriangleShape tm(triangle[0],triangle[1],triangle[2]);
|
||||
// tm.setMargin(m_collisionMarginTriangle);
|
||||
|
||||
// tm.setMargin(m_collisionMarginTriangle);
|
||||
|
||||
//copy over user pointers to temporary shape
|
||||
tm->setUserPointer(ob->getRootCollisionShape()->getUserPointer());
|
||||
|
||||
|
||||
btCollisionShape* tmpShape = ob->getCollisionShape();
|
||||
ob->internalSetTemporaryCollisionShape( tm );
|
||||
|
||||
|
||||
|
||||
btCollisionAlgorithm* colAlgo = ci.m_dispatcher1->findAlgorithm(m_softBody,m_triBody,0);//m_manifoldPtr);
|
||||
///this should use the btDispatcher, so the actual registered algorithm is used
|
||||
// btConvexConvexAlgorithm cvxcvxalgo(m_manifoldPtr,ci,m_convexBody,m_triBody);
|
||||
|
||||
//m_resultOut->setShapeIdentifiers(-1,-1,partId,triangleIndex);
|
||||
// cvxcvxalgo.setShapeIdentifiers(-1,-1,partId,triangleIndex);
|
||||
// cvxcvxalgo.processCollision(m_convexBody,m_triBody,*m_dispatchInfoPtr,m_resultOut);
|
||||
// cvxcvxalgo.setShapeIdentifiers(-1,-1,partId,triangleIndex);
|
||||
// cvxcvxalgo.processCollision(m_convexBody,m_triBody,*m_dispatchInfoPtr,m_resultOut);
|
||||
colAlgo->processCollision(m_softBody,m_triBody,*m_dispatchInfoPtr,m_resultOut);
|
||||
colAlgo->~btCollisionAlgorithm();
|
||||
ci.m_dispatcher1->freeCollisionAlgorithm(colAlgo);
|
||||
|
||||
|
||||
|
||||
|
||||
ob->internalSetTemporaryCollisionShape( tmpShape );
|
||||
triIndex.m_childShape = tm;
|
||||
m_shapeCache.insert(triKey,triIndex);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -194,7 +194,7 @@ void btSoftBodyTriangleCallback::setTimeStepAndCounters(btScalar collisionMargin
|
||||
m_collisionMarginTriangle = collisionMarginTriangle+btScalar(BT_SOFTBODY_TRIANGLE_EXTRUSION);
|
||||
m_resultOut = resultOut;
|
||||
|
||||
|
||||
|
||||
btVector3 aabbWorldSpaceMin,aabbWorldSpaceMax;
|
||||
m_softBody->getAabb(aabbWorldSpaceMin,aabbWorldSpaceMax);
|
||||
btVector3 halfExtents = (aabbWorldSpaceMax-aabbWorldSpaceMin)*btScalar(0.5);
|
||||
@@ -217,8 +217,8 @@ void btSoftBodyConcaveCollisionAlgorithm::clearCache()
|
||||
|
||||
void btSoftBodyConcaveCollisionAlgorithm::processCollision (btCollisionObject* body0,btCollisionObject* body1,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut)
|
||||
{
|
||||
|
||||
|
||||
|
||||
|
||||
btCollisionObject* convexBody = m_isSwapped ? body1 : body0;
|
||||
btCollisionObject* triBody = m_isSwapped ? body0 : body1;
|
||||
|
||||
@@ -228,26 +228,26 @@ void btSoftBodyConcaveCollisionAlgorithm::processCollision (btCollisionObject* b
|
||||
|
||||
btCollisionObject* triOb = triBody;
|
||||
btConcaveShape* concaveShape = static_cast<btConcaveShape*>( triOb->getCollisionShape());
|
||||
|
||||
// if (convexBody->getCollisionShape()->isConvex())
|
||||
|
||||
// if (convexBody->getCollisionShape()->isConvex())
|
||||
{
|
||||
btScalar collisionMarginTriangle = concaveShape->getMargin();
|
||||
|
||||
// resultOut->setPersistentManifold(m_btSoftBodyTriangleCallback.m_manifoldPtr);
|
||||
|
||||
// resultOut->setPersistentManifold(m_btSoftBodyTriangleCallback.m_manifoldPtr);
|
||||
m_btSoftBodyTriangleCallback.setTimeStepAndCounters(collisionMarginTriangle,dispatchInfo,resultOut);
|
||||
|
||||
//Disable persistency. previously, some older algorithm calculated all contacts in one go, so you can clear it here.
|
||||
//m_dispatcher->clearManifold(m_btSoftBodyTriangleCallback.m_manifoldPtr);
|
||||
|
||||
// m_btSoftBodyTriangleCallback.m_manifoldPtr->setBodies(convexBody,triBody);
|
||||
// m_btSoftBodyTriangleCallback.m_manifoldPtr->setBodies(convexBody,triBody);
|
||||
|
||||
|
||||
concaveShape->processAllTriangles( &m_btSoftBodyTriangleCallback,m_btSoftBodyTriangleCallback.getAabbMin(),m_btSoftBodyTriangleCallback.getAabbMax());
|
||||
|
||||
// resultOut->refreshContactPoints();
|
||||
|
||||
|
||||
// resultOut->refreshContactPoints();
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -287,7 +287,7 @@ btScalar btSoftBodyConcaveCollisionAlgorithm::calculateTimeOfImpact(btCollisionO
|
||||
|
||||
btScalar m_ccdSphereRadius;
|
||||
btScalar m_hitFraction;
|
||||
|
||||
|
||||
|
||||
LocalTriangleSphereCastCallback(const btTransform& from,const btTransform& to,btScalar ccdSphereRadius,btScalar hitFraction)
|
||||
:m_ccdSphereFromTrans(from),
|
||||
@@ -296,8 +296,8 @@ btScalar btSoftBodyConcaveCollisionAlgorithm::calculateTimeOfImpact(btCollisionO
|
||||
m_hitFraction(hitFraction)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
virtual void processTriangle(btVector3* triangle, int partId, int triangleIndex)
|
||||
{
|
||||
(void)partId;
|
||||
@@ -327,9 +327,9 @@ btScalar btSoftBodyConcaveCollisionAlgorithm::calculateTimeOfImpact(btCollisionO
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
if (triBody->getCollisionShape()->isConcave())
|
||||
{
|
||||
btVector3 rayAabbMin = convexFromLocal.getOrigin();
|
||||
@@ -349,12 +349,12 @@ btScalar btSoftBodyConcaveCollisionAlgorithm::calculateTimeOfImpact(btCollisionO
|
||||
btCollisionObject* concavebody = triBody;
|
||||
|
||||
btConcaveShape* triangleMesh = (btConcaveShape*) concavebody->getCollisionShape();
|
||||
|
||||
|
||||
if (triangleMesh)
|
||||
{
|
||||
triangleMesh->processAllTriangles(&raycastCallback,rayAabbMin,rayAabbMax);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
if (raycastCallback.m_hitFraction < convexbody->getHitFraction())
|
||||
|
||||
@@ -35,7 +35,7 @@ struct btTriIndex
|
||||
{
|
||||
int m_PartIdTriangleIndex;
|
||||
class btCollisionShape* m_childShape;
|
||||
|
||||
|
||||
btTriIndex(int partId,int triangleIndex,btCollisionShape* shape)
|
||||
{
|
||||
m_PartIdTriangleIndex = (partId<<(31-MAX_NUM_PARTS_IN_BITS)) | triangleIndex;
|
||||
@@ -75,11 +75,11 @@ class btSoftBodyTriangleCallback : public btTriangleCallback
|
||||
btScalar m_collisionMarginTriangle;
|
||||
|
||||
btHashMap<btHashKey<btTriIndex>,btTriIndex> m_shapeCache;
|
||||
|
||||
|
||||
public:
|
||||
int m_triangleCount;
|
||||
|
||||
// btPersistentManifold* m_manifoldPtr;
|
||||
int m_triangleCount;
|
||||
|
||||
// btPersistentManifold* m_manifoldPtr;
|
||||
|
||||
btSoftBodyTriangleCallback(btDispatcher* dispatcher,btCollisionObject* body0,btCollisionObject* body1,bool isSwapped);
|
||||
|
||||
@@ -88,7 +88,7 @@ int m_triangleCount;
|
||||
virtual ~btSoftBodyTriangleCallback();
|
||||
|
||||
virtual void processTriangle(btVector3* triangle, int partId, int triangleIndex);
|
||||
|
||||
|
||||
void clearCache();
|
||||
|
||||
SIMD_FORCE_INLINE const btVector3& getAabbMin() const
|
||||
|
||||
@@ -22,57 +22,57 @@ subject to the following restrictions:
|
||||
|
||||
//
|
||||
static void drawVertex( btIDebugDraw* idraw,
|
||||
const btVector3& x,btScalar s,const btVector3& c)
|
||||
{
|
||||
idraw->drawLine(x-btVector3(s,0,0),x+btVector3(s,0,0),c);
|
||||
idraw->drawLine(x-btVector3(0,s,0),x+btVector3(0,s,0),c);
|
||||
idraw->drawLine(x-btVector3(0,0,s),x+btVector3(0,0,s),c);
|
||||
}
|
||||
const btVector3& x,btScalar s,const btVector3& c)
|
||||
{
|
||||
idraw->drawLine(x-btVector3(s,0,0),x+btVector3(s,0,0),c);
|
||||
idraw->drawLine(x-btVector3(0,s,0),x+btVector3(0,s,0),c);
|
||||
idraw->drawLine(x-btVector3(0,0,s),x+btVector3(0,0,s),c);
|
||||
}
|
||||
|
||||
//
|
||||
static void drawBox( btIDebugDraw* idraw,
|
||||
const btVector3& mins,
|
||||
const btVector3& maxs,
|
||||
const btVector3& color)
|
||||
const btVector3& mins,
|
||||
const btVector3& maxs,
|
||||
const btVector3& color)
|
||||
{
|
||||
const btVector3 c[]={ btVector3(mins.x(),mins.y(),mins.z()),
|
||||
btVector3(maxs.x(),mins.y(),mins.z()),
|
||||
btVector3(maxs.x(),maxs.y(),mins.z()),
|
||||
btVector3(mins.x(),maxs.y(),mins.z()),
|
||||
btVector3(mins.x(),mins.y(),maxs.z()),
|
||||
btVector3(maxs.x(),mins.y(),maxs.z()),
|
||||
btVector3(maxs.x(),maxs.y(),maxs.z()),
|
||||
btVector3(mins.x(),maxs.y(),maxs.z())};
|
||||
idraw->drawLine(c[0],c[1],color);idraw->drawLine(c[1],c[2],color);
|
||||
idraw->drawLine(c[2],c[3],color);idraw->drawLine(c[3],c[0],color);
|
||||
idraw->drawLine(c[4],c[5],color);idraw->drawLine(c[5],c[6],color);
|
||||
idraw->drawLine(c[6],c[7],color);idraw->drawLine(c[7],c[4],color);
|
||||
idraw->drawLine(c[0],c[4],color);idraw->drawLine(c[1],c[5],color);
|
||||
idraw->drawLine(c[2],c[6],color);idraw->drawLine(c[3],c[7],color);
|
||||
const btVector3 c[]={ btVector3(mins.x(),mins.y(),mins.z()),
|
||||
btVector3(maxs.x(),mins.y(),mins.z()),
|
||||
btVector3(maxs.x(),maxs.y(),mins.z()),
|
||||
btVector3(mins.x(),maxs.y(),mins.z()),
|
||||
btVector3(mins.x(),mins.y(),maxs.z()),
|
||||
btVector3(maxs.x(),mins.y(),maxs.z()),
|
||||
btVector3(maxs.x(),maxs.y(),maxs.z()),
|
||||
btVector3(mins.x(),maxs.y(),maxs.z())};
|
||||
idraw->drawLine(c[0],c[1],color);idraw->drawLine(c[1],c[2],color);
|
||||
idraw->drawLine(c[2],c[3],color);idraw->drawLine(c[3],c[0],color);
|
||||
idraw->drawLine(c[4],c[5],color);idraw->drawLine(c[5],c[6],color);
|
||||
idraw->drawLine(c[6],c[7],color);idraw->drawLine(c[7],c[4],color);
|
||||
idraw->drawLine(c[0],c[4],color);idraw->drawLine(c[1],c[5],color);
|
||||
idraw->drawLine(c[2],c[6],color);idraw->drawLine(c[3],c[7],color);
|
||||
}
|
||||
|
||||
//
|
||||
static void drawTree( btIDebugDraw* idraw,
|
||||
const btDbvtNode* node,
|
||||
int depth,
|
||||
const btVector3& ncolor,
|
||||
const btVector3& lcolor,
|
||||
int mindepth,
|
||||
int maxdepth)
|
||||
const btDbvtNode* node,
|
||||
int depth,
|
||||
const btVector3& ncolor,
|
||||
const btVector3& lcolor,
|
||||
int mindepth,
|
||||
int maxdepth)
|
||||
{
|
||||
if(node)
|
||||
if(node)
|
||||
{
|
||||
if(node->isinternal()&&((depth<maxdepth)||(maxdepth<0)))
|
||||
if(node->isinternal()&&((depth<maxdepth)||(maxdepth<0)))
|
||||
{
|
||||
drawTree(idraw,node->childs[0],depth+1,ncolor,lcolor,mindepth,maxdepth);
|
||||
drawTree(idraw,node->childs[1],depth+1,ncolor,lcolor,mindepth,maxdepth);
|
||||
drawTree(idraw,node->childs[0],depth+1,ncolor,lcolor,mindepth,maxdepth);
|
||||
drawTree(idraw,node->childs[1],depth+1,ncolor,lcolor,mindepth,maxdepth);
|
||||
}
|
||||
if(depth>=mindepth)
|
||||
if(depth>=mindepth)
|
||||
{
|
||||
const btScalar scl=(btScalar)(node->isinternal()?1:1);
|
||||
const btVector3 mi=node->volume.Center()-node->volume.Extents()*scl;
|
||||
const btVector3 mx=node->volume.Center()+node->volume.Extents()*scl;
|
||||
drawBox(idraw,mi,mx,node->isleaf()?lcolor:ncolor);
|
||||
const btScalar scl=(btScalar)(node->isinternal()?1:1);
|
||||
const btVector3 mi=node->volume.Center()-node->volume.Extents()*scl;
|
||||
const btVector3 mx=node->volume.Center()+node->volume.Extents()*scl;
|
||||
drawBox(idraw,mi,mx,node->isleaf()?lcolor:ncolor);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -81,25 +81,25 @@ if(node)
|
||||
template <typename T>
|
||||
static inline T sum(const btAlignedObjectArray<T>& items)
|
||||
{
|
||||
T v;
|
||||
if(items.size())
|
||||
T v;
|
||||
if(items.size())
|
||||
{
|
||||
v=items[0];
|
||||
for(int i=1,ni=items.size();i<ni;++i)
|
||||
v=items[0];
|
||||
for(int i=1,ni=items.size();i<ni;++i)
|
||||
{
|
||||
v+=items[i];
|
||||
v+=items[i];
|
||||
}
|
||||
}
|
||||
return(v);
|
||||
return(v);
|
||||
}
|
||||
|
||||
//
|
||||
template <typename T,typename Q>
|
||||
static inline void add(btAlignedObjectArray<T>& items,const Q& value)
|
||||
{
|
||||
for(int i=0,ni=items.size();i<ni;++i)
|
||||
for(int i=0,ni=items.size();i<ni;++i)
|
||||
{
|
||||
items[i]+=value;
|
||||
items[i]+=value;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -107,9 +107,9 @@ for(int i=0,ni=items.size();i<ni;++i)
|
||||
template <typename T,typename Q>
|
||||
static inline void mul(btAlignedObjectArray<T>& items,const Q& value)
|
||||
{
|
||||
for(int i=0,ni=items.size();i<ni;++i)
|
||||
for(int i=0,ni=items.size();i<ni;++i)
|
||||
{
|
||||
items[i]*=value;
|
||||
items[i]*=value;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -117,8 +117,8 @@ for(int i=0,ni=items.size();i<ni;++i)
|
||||
template <typename T>
|
||||
static inline T average(const btAlignedObjectArray<T>& items)
|
||||
{
|
||||
const btScalar n=(btScalar)(items.size()>0?items.size():1);
|
||||
return(sum(items)/n);
|
||||
const btScalar n=(btScalar)(items.size()>0?items.size():1);
|
||||
return(sum(items)/n);
|
||||
}
|
||||
|
||||
//
|
||||
@@ -136,27 +136,27 @@ static inline btScalar tetravolume(const btVector3& x0,
|
||||
//
|
||||
#if 0
|
||||
static btVector3 stresscolor(btScalar stress)
|
||||
{
|
||||
{
|
||||
static const btVector3 spectrum[]= { btVector3(1,0,1),
|
||||
btVector3(0,0,1),
|
||||
btVector3(0,1,1),
|
||||
btVector3(0,1,0),
|
||||
btVector3(1,1,0),
|
||||
btVector3(1,0,0),
|
||||
btVector3(1,0,0)};
|
||||
btVector3(0,0,1),
|
||||
btVector3(0,1,1),
|
||||
btVector3(0,1,0),
|
||||
btVector3(1,1,0),
|
||||
btVector3(1,0,0),
|
||||
btVector3(1,0,0)};
|
||||
static const int ncolors=sizeof(spectrum)/sizeof(spectrum[0])-1;
|
||||
static const btScalar one=1;
|
||||
stress=btMax<btScalar>(0,btMin<btScalar>(1,stress))*ncolors;
|
||||
const int sel=(int)stress;
|
||||
const btScalar frc=stress-sel;
|
||||
return(spectrum[sel]+(spectrum[sel+1]-spectrum[sel])*frc);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
//
|
||||
void btSoftBodyHelpers::Draw( btSoftBody* psb,
|
||||
btIDebugDraw* idraw,
|
||||
int drawflags)
|
||||
btIDebugDraw* idraw,
|
||||
int drawflags)
|
||||
{
|
||||
const btScalar scl=(btScalar)0.1;
|
||||
const btScalar nscl=scl*5;
|
||||
@@ -251,29 +251,29 @@ void btSoftBodyHelpers::Draw( btSoftBody* psb,
|
||||
const btVector3 x[]={f.m_n[0]->m_x,f.m_n[1]->m_x,f.m_n[2]->m_x};
|
||||
const btVector3 c=(x[0]+x[1]+x[2])/3;
|
||||
idraw->drawTriangle((x[0]-c)*scl+c,
|
||||
(x[1]-c)*scl+c,
|
||||
(x[2]-c)*scl+c,
|
||||
col,alp);
|
||||
(x[1]-c)*scl+c,
|
||||
(x[2]-c)*scl+c,
|
||||
col,alp);
|
||||
}
|
||||
}
|
||||
/* Clusters */
|
||||
if(0!=(drawflags&fDrawFlags::Clusters))
|
||||
{
|
||||
{
|
||||
srand(1806);
|
||||
for(i=0;i<psb->m_clusters.size();++i)
|
||||
{
|
||||
{
|
||||
if(psb->m_clusters[i]->m_collide)
|
||||
{
|
||||
{
|
||||
btVector3 color( rand()/(btScalar)RAND_MAX,
|
||||
rand()/(btScalar)RAND_MAX,
|
||||
rand()/(btScalar)RAND_MAX);
|
||||
rand()/(btScalar)RAND_MAX,
|
||||
rand()/(btScalar)RAND_MAX);
|
||||
color=color.normalized()*0.75;
|
||||
btAlignedObjectArray<btVector3> vertices;
|
||||
vertices.resize(psb->m_clusters[i]->m_nodes.size());
|
||||
for(j=0,nj=vertices.size();j<nj;++j)
|
||||
{
|
||||
{
|
||||
vertices[j]=psb->m_clusters[i]->m_nodes[j]->m_x;
|
||||
}
|
||||
}
|
||||
HullDesc hdsc(QF_TRIANGLES,vertices.size(),&vertices[0]);
|
||||
HullResult hres;
|
||||
HullLibrary hlib;
|
||||
@@ -284,32 +284,32 @@ void btSoftBodyHelpers::Draw( btSoftBody* psb,
|
||||
mul(hres.m_OutputVertices,(btScalar)1);
|
||||
add(hres.m_OutputVertices,center);
|
||||
for(j=0;j<(int)hres.mNumFaces;++j)
|
||||
{
|
||||
{
|
||||
const int idx[]={hres.m_Indices[j*3+0],hres.m_Indices[j*3+1],hres.m_Indices[j*3+2]};
|
||||
idraw->drawTriangle(hres.m_OutputVertices[idx[0]],
|
||||
hres.m_OutputVertices[idx[1]],
|
||||
hres.m_OutputVertices[idx[2]],
|
||||
color,1);
|
||||
}
|
||||
hlib.ReleaseResult(hres);
|
||||
hres.m_OutputVertices[idx[1]],
|
||||
hres.m_OutputVertices[idx[2]],
|
||||
color,1);
|
||||
}
|
||||
hlib.ReleaseResult(hres);
|
||||
}
|
||||
/* Velocities */
|
||||
#if 0
|
||||
#if 0
|
||||
for(int j=0;j<psb->m_clusters[i].m_nodes.size();++j)
|
||||
{
|
||||
{
|
||||
const btSoftBody::Cluster& c=psb->m_clusters[i];
|
||||
const btVector3 r=c.m_nodes[j]->m_x-c.m_com;
|
||||
const btVector3 v=c.m_lv+cross(c.m_av,r);
|
||||
idraw->drawLine(c.m_nodes[j]->m_x,c.m_nodes[j]->m_x+v,btVector3(1,0,0));
|
||||
}
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
/* Frame */
|
||||
btSoftBody::Cluster& c=*psb->m_clusters[i];
|
||||
idraw->drawLine(c.m_com,c.m_framexform*btVector3(10,0,0),btVector3(1,0,0));
|
||||
idraw->drawLine(c.m_com,c.m_framexform*btVector3(0,10,0),btVector3(0,1,0));
|
||||
idraw->drawLine(c.m_com,c.m_framexform*btVector3(0,0,10),btVector3(0,0,1));
|
||||
}
|
||||
}
|
||||
}
|
||||
/* Notes */
|
||||
if(0!=(drawflags&fDrawFlags::Notes))
|
||||
{
|
||||
@@ -318,9 +318,9 @@ void btSoftBodyHelpers::Draw( btSoftBody* psb,
|
||||
const btSoftBody::Note& n=psb->m_notes[i];
|
||||
btVector3 p=n.m_offset;
|
||||
for(int j=0;j<n.m_rank;++j)
|
||||
{
|
||||
{
|
||||
p+=n.m_nodes[j]->m_x*n.m_coords[j];
|
||||
}
|
||||
}
|
||||
idraw->draw3dText(p,n.m_text);
|
||||
}
|
||||
}
|
||||
@@ -333,33 +333,33 @@ void btSoftBodyHelpers::Draw( btSoftBody* psb,
|
||||
/* Joints */
|
||||
if(0!=(drawflags&fDrawFlags::Joints))
|
||||
{
|
||||
for(i=0;i<psb->m_joints.size();++i)
|
||||
for(i=0;i<psb->m_joints.size();++i)
|
||||
{
|
||||
const btSoftBody::Joint* pj=psb->m_joints[i];
|
||||
switch(pj->Type())
|
||||
const btSoftBody::Joint* pj=psb->m_joints[i];
|
||||
switch(pj->Type())
|
||||
{
|
||||
case btSoftBody::Joint::eType::Linear:
|
||||
{
|
||||
const btSoftBody::LJoint* pjl=(const btSoftBody::LJoint*)pj;
|
||||
const btVector3 a0=pj->m_bodies[0].xform()*pjl->m_refs[0];
|
||||
const btVector3 a1=pj->m_bodies[1].xform()*pjl->m_refs[1];
|
||||
idraw->drawLine(pj->m_bodies[0].xform().getOrigin(),a0,btVector3(1,1,0));
|
||||
idraw->drawLine(pj->m_bodies[1].xform().getOrigin(),a1,btVector3(0,1,1));
|
||||
drawVertex(idraw,a0,0.25,btVector3(1,1,0));
|
||||
drawVertex(idraw,a1,0.25,btVector3(0,1,1));
|
||||
const btSoftBody::LJoint* pjl=(const btSoftBody::LJoint*)pj;
|
||||
const btVector3 a0=pj->m_bodies[0].xform()*pjl->m_refs[0];
|
||||
const btVector3 a1=pj->m_bodies[1].xform()*pjl->m_refs[1];
|
||||
idraw->drawLine(pj->m_bodies[0].xform().getOrigin(),a0,btVector3(1,1,0));
|
||||
idraw->drawLine(pj->m_bodies[1].xform().getOrigin(),a1,btVector3(0,1,1));
|
||||
drawVertex(idraw,a0,0.25,btVector3(1,1,0));
|
||||
drawVertex(idraw,a1,0.25,btVector3(0,1,1));
|
||||
}
|
||||
break;
|
||||
break;
|
||||
case btSoftBody::Joint::eType::Angular:
|
||||
{
|
||||
const btSoftBody::AJoint* pja=(const btSoftBody::AJoint*)pj;
|
||||
const btVector3 o0=pj->m_bodies[0].xform().getOrigin();
|
||||
const btVector3 o1=pj->m_bodies[1].xform().getOrigin();
|
||||
const btVector3 a0=pj->m_bodies[0].xform().getBasis()*pj->m_refs[0];
|
||||
const btVector3 a1=pj->m_bodies[1].xform().getBasis()*pj->m_refs[1];
|
||||
idraw->drawLine(o0,o0+a0*10,btVector3(1,1,0));
|
||||
idraw->drawLine(o0,o0+a1*10,btVector3(1,1,0));
|
||||
idraw->drawLine(o1,o1+a0*10,btVector3(0,1,1));
|
||||
idraw->drawLine(o1,o1+a1*10,btVector3(0,1,1));
|
||||
const btSoftBody::AJoint* pja=(const btSoftBody::AJoint*)pj;
|
||||
const btVector3 o0=pj->m_bodies[0].xform().getOrigin();
|
||||
const btVector3 o1=pj->m_bodies[1].xform().getOrigin();
|
||||
const btVector3 a0=pj->m_bodies[0].xform().getBasis()*pj->m_refs[0];
|
||||
const btVector3 a1=pj->m_bodies[1].xform().getBasis()*pj->m_refs[1];
|
||||
idraw->drawLine(o0,o0+a0*10,btVector3(1,1,0));
|
||||
idraw->drawLine(o0,o0+a1*10,btVector3(1,1,0));
|
||||
idraw->drawLine(o1,o1+a0*10,btVector3(0,1,1));
|
||||
idraw->drawLine(o1,o1+a1*10,btVector3(0,1,1));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -368,10 +368,10 @@ void btSoftBodyHelpers::Draw( btSoftBody* psb,
|
||||
|
||||
//
|
||||
void btSoftBodyHelpers::DrawInfos( btSoftBody* psb,
|
||||
btIDebugDraw* idraw,
|
||||
bool masses,
|
||||
bool areas,
|
||||
bool /*stress*/)
|
||||
btIDebugDraw* idraw,
|
||||
bool masses,
|
||||
bool areas,
|
||||
bool /*stress*/)
|
||||
{
|
||||
for(int i=0;i<psb->m_nodes.size();++i)
|
||||
{
|
||||
@@ -394,34 +394,34 @@ void btSoftBodyHelpers::DrawInfos( btSoftBody* psb,
|
||||
|
||||
//
|
||||
void btSoftBodyHelpers::DrawNodeTree( btSoftBody* psb,
|
||||
btIDebugDraw* idraw,
|
||||
int mindepth,
|
||||
int maxdepth)
|
||||
btIDebugDraw* idraw,
|
||||
int mindepth,
|
||||
int maxdepth)
|
||||
{
|
||||
drawTree(idraw,psb->m_ndbvt.m_root,0,btVector3(1,0,1),btVector3(1,1,1),mindepth,maxdepth);
|
||||
drawTree(idraw,psb->m_ndbvt.m_root,0,btVector3(1,0,1),btVector3(1,1,1),mindepth,maxdepth);
|
||||
}
|
||||
|
||||
//
|
||||
void btSoftBodyHelpers::DrawFaceTree( btSoftBody* psb,
|
||||
btIDebugDraw* idraw,
|
||||
int mindepth,
|
||||
int maxdepth)
|
||||
btIDebugDraw* idraw,
|
||||
int mindepth,
|
||||
int maxdepth)
|
||||
{
|
||||
drawTree(idraw,psb->m_fdbvt.m_root,0,btVector3(0,1,0),btVector3(1,0,0),mindepth,maxdepth);
|
||||
drawTree(idraw,psb->m_fdbvt.m_root,0,btVector3(0,1,0),btVector3(1,0,0),mindepth,maxdepth);
|
||||
}
|
||||
|
||||
//
|
||||
void btSoftBodyHelpers::DrawClusterTree( btSoftBody* psb,
|
||||
btIDebugDraw* idraw,
|
||||
int mindepth,
|
||||
int maxdepth)
|
||||
btIDebugDraw* idraw,
|
||||
int mindepth,
|
||||
int maxdepth)
|
||||
{
|
||||
drawTree(idraw,psb->m_cdbvt.m_root,0,btVector3(0,1,1),btVector3(1,0,0),mindepth,maxdepth);
|
||||
drawTree(idraw,psb->m_cdbvt.m_root,0,btVector3(0,1,1),btVector3(1,0,0),mindepth,maxdepth);
|
||||
}
|
||||
|
||||
//
|
||||
void btSoftBodyHelpers::DrawFrame( btSoftBody* psb,
|
||||
btIDebugDraw* idraw)
|
||||
btIDebugDraw* idraw)
|
||||
{
|
||||
if(psb->m_pose.m_bframe)
|
||||
{
|
||||
@@ -445,9 +445,9 @@ void btSoftBodyHelpers::DrawFrame( btSoftBody* psb,
|
||||
|
||||
//
|
||||
btSoftBody* btSoftBodyHelpers::CreateRope( btSoftBodyWorldInfo& worldInfo, const btVector3& from,
|
||||
const btVector3& to,
|
||||
int res,
|
||||
int fixeds)
|
||||
const btVector3& to,
|
||||
int res,
|
||||
int fixeds)
|
||||
{
|
||||
/* Create nodes */
|
||||
const int r=res+2;
|
||||
@@ -477,13 +477,13 @@ btSoftBody* btSoftBodyHelpers::CreateRope( btSoftBodyWorldInfo& worldInfo, cons
|
||||
|
||||
//
|
||||
btSoftBody* btSoftBodyHelpers::CreatePatch(btSoftBodyWorldInfo& worldInfo,const btVector3& corner00,
|
||||
const btVector3& corner10,
|
||||
const btVector3& corner01,
|
||||
const btVector3& corner11,
|
||||
int resx,
|
||||
int resy,
|
||||
int fixeds,
|
||||
bool gendiags)
|
||||
const btVector3& corner10,
|
||||
const btVector3& corner01,
|
||||
const btVector3& corner11,
|
||||
int resx,
|
||||
int resy,
|
||||
int fixeds,
|
||||
bool gendiags)
|
||||
{
|
||||
#define IDX(_x_,_y_) ((_y_)*rx+(_x_))
|
||||
/* Create nodes */
|
||||
@@ -554,83 +554,83 @@ btSoftBody* btSoftBodyHelpers::CreatePatch(btSoftBodyWorldInfo& worldInfo,const
|
||||
|
||||
//
|
||||
btSoftBody* btSoftBodyHelpers::CreatePatchUV(btSoftBodyWorldInfo& worldInfo,
|
||||
const btVector3& corner00,
|
||||
const btVector3& corner10,
|
||||
const btVector3& corner01,
|
||||
const btVector3& corner11,
|
||||
int resx,
|
||||
int resy,
|
||||
int fixeds,
|
||||
bool gendiags,
|
||||
float* tex_coords)
|
||||
const btVector3& corner00,
|
||||
const btVector3& corner10,
|
||||
const btVector3& corner01,
|
||||
const btVector3& corner11,
|
||||
int resx,
|
||||
int resy,
|
||||
int fixeds,
|
||||
bool gendiags,
|
||||
float* tex_coords)
|
||||
{
|
||||
|
||||
/*
|
||||
*
|
||||
* corners:
|
||||
*
|
||||
* [0][0] corner00 ------- corner01 [resx][0]
|
||||
* | |
|
||||
* | |
|
||||
* [0][resy] corner10 -------- corner11 [resx][resy]
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
* "fixedgs" map:
|
||||
*
|
||||
* corner00 --> +1
|
||||
* corner01 --> +2
|
||||
* corner10 --> +4
|
||||
* corner11 --> +8
|
||||
* upper middle --> +16
|
||||
* left middle --> +32
|
||||
* right middle --> +64
|
||||
* lower middle --> +128
|
||||
* center --> +256
|
||||
*
|
||||
*
|
||||
* tex_coords size (resx-1)*(resy-1)*12
|
||||
*
|
||||
*
|
||||
*
|
||||
* SINGLE QUAD INTERNALS
|
||||
*
|
||||
* 1) btSoftBody's nodes and links,
|
||||
* diagonal link is optional ("gendiags")
|
||||
*
|
||||
*
|
||||
* node00 ------ node01
|
||||
* | .
|
||||
* | .
|
||||
* | .
|
||||
* | .
|
||||
* | .
|
||||
* node10 node11
|
||||
*
|
||||
*
|
||||
*
|
||||
* 2) Faces:
|
||||
* two triangles,
|
||||
* UV Coordinates (hier example for single quad)
|
||||
*
|
||||
* (0,1) (0,1) (1,1)
|
||||
* 1 |\ 3 \-----| 2
|
||||
* | \ \ |
|
||||
* | \ \ |
|
||||
* | \ \ |
|
||||
* | \ \ |
|
||||
* 2 |-----\ 3 \| 1
|
||||
* (0,0) (1,0) (1,0)
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*/
|
||||
/*
|
||||
*
|
||||
* corners:
|
||||
*
|
||||
* [0][0] corner00 ------- corner01 [resx][0]
|
||||
* | |
|
||||
* | |
|
||||
* [0][resy] corner10 -------- corner11 [resx][resy]
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
* "fixedgs" map:
|
||||
*
|
||||
* corner00 --> +1
|
||||
* corner01 --> +2
|
||||
* corner10 --> +4
|
||||
* corner11 --> +8
|
||||
* upper middle --> +16
|
||||
* left middle --> +32
|
||||
* right middle --> +64
|
||||
* lower middle --> +128
|
||||
* center --> +256
|
||||
*
|
||||
*
|
||||
* tex_coords size (resx-1)*(resy-1)*12
|
||||
*
|
||||
*
|
||||
*
|
||||
* SINGLE QUAD INTERNALS
|
||||
*
|
||||
* 1) btSoftBody's nodes and links,
|
||||
* diagonal link is optional ("gendiags")
|
||||
*
|
||||
*
|
||||
* node00 ------ node01
|
||||
* | .
|
||||
* | .
|
||||
* | .
|
||||
* | .
|
||||
* | .
|
||||
* node10 node11
|
||||
*
|
||||
*
|
||||
*
|
||||
* 2) Faces:
|
||||
* two triangles,
|
||||
* UV Coordinates (hier example for single quad)
|
||||
*
|
||||
* (0,1) (0,1) (1,1)
|
||||
* 1 |\ 3 \-----| 2
|
||||
* | \ \ |
|
||||
* | \ \ |
|
||||
* | \ \ |
|
||||
* | \ \ |
|
||||
* 2 |-----\ 3 \| 1
|
||||
* (0,0) (1,0) (1,0)
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
#define IDX(_x_,_y_) ((_y_)*rx+(_x_))
|
||||
/* Create nodes */
|
||||
@@ -675,12 +675,12 @@ btSoftBody* btSoftBodyHelpers::CreatePatchUV(btSoftBodyWorldInfo& worldInfo,
|
||||
{
|
||||
const bool mdx=(ix+1)<rx;
|
||||
const bool mdy=(iy+1)<ry;
|
||||
|
||||
|
||||
int node00=IDX(ix,iy);
|
||||
int node01=IDX(ix+1,iy);
|
||||
int node10=IDX(ix,iy+1);
|
||||
int node11=IDX(ix+1,iy+1);
|
||||
|
||||
|
||||
if(mdx) psb->appendLink(node00,node01);
|
||||
if(mdy) psb->appendLink(node00,node10);
|
||||
if(mdx&&mdy)
|
||||
@@ -716,32 +716,32 @@ btSoftBody* btSoftBodyHelpers::CreatePatchUV(btSoftBodyWorldInfo& worldInfo,
|
||||
float btSoftBodyHelpers::CalculateUV(int resx,int resy,int ix,int iy,int id)
|
||||
{
|
||||
|
||||
/*
|
||||
*
|
||||
*
|
||||
* node00 --- node01
|
||||
* | |
|
||||
* node10 --- node11
|
||||
*
|
||||
*
|
||||
* ID map:
|
||||
*
|
||||
* node00 s --> 0
|
||||
* node00 t --> 1
|
||||
*
|
||||
* node01 s --> 3
|
||||
* node01 t --> 1
|
||||
*
|
||||
* node10 s --> 0
|
||||
* node10 t --> 2
|
||||
*
|
||||
* node11 s --> 3
|
||||
* node11 t --> 2
|
||||
*
|
||||
*
|
||||
*/
|
||||
/*
|
||||
*
|
||||
*
|
||||
* node00 --- node01
|
||||
* | |
|
||||
* node10 --- node11
|
||||
*
|
||||
*
|
||||
* ID map:
|
||||
*
|
||||
* node00 s --> 0
|
||||
* node00 t --> 1
|
||||
*
|
||||
* node01 s --> 3
|
||||
* node01 t --> 1
|
||||
*
|
||||
* node10 s --> 0
|
||||
* node10 t --> 2
|
||||
*
|
||||
* node11 s --> 3
|
||||
* node11 t --> 2
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
float tc=0.0f;
|
||||
float tc=0.0f;
|
||||
if (id == 0) {
|
||||
tc = (1.0f/((resx-1))*ix);
|
||||
}
|
||||
@@ -754,12 +754,12 @@ float tc=0.0f;
|
||||
else if (id==3) {
|
||||
tc = (1.0f/((resx-1))*(ix+1));
|
||||
}
|
||||
return tc;
|
||||
return tc;
|
||||
}
|
||||
//
|
||||
btSoftBody* btSoftBodyHelpers::CreateEllipsoid(btSoftBodyWorldInfo& worldInfo,const btVector3& center,
|
||||
const btVector3& radius,
|
||||
int res)
|
||||
const btVector3& radius,
|
||||
int res)
|
||||
{
|
||||
struct Hammersley
|
||||
{
|
||||
@@ -790,8 +790,8 @@ btSoftBody* btSoftBodyHelpers::CreateEllipsoid(btSoftBodyWorldInfo& worldInfo,c
|
||||
|
||||
//
|
||||
btSoftBody* btSoftBodyHelpers::CreateFromTriMesh(btSoftBodyWorldInfo& worldInfo,const btScalar* vertices,
|
||||
const int* triangles,
|
||||
int ntriangles)
|
||||
const int* triangles,
|
||||
int ntriangles)
|
||||
{
|
||||
int maxidx=0;
|
||||
int i,j,ni;
|
||||
@@ -832,7 +832,7 @@ btSoftBody* btSoftBodyHelpers::CreateFromTriMesh(btSoftBodyWorldInfo& worldInfo
|
||||
|
||||
//
|
||||
btSoftBody* btSoftBodyHelpers::CreateFromConvexHull(btSoftBodyWorldInfo& worldInfo, const btVector3* vertices,
|
||||
int nvertices)
|
||||
int nvertices)
|
||||
{
|
||||
HullDesc hdsc(QF_TRIANGLES,nvertices,vertices);
|
||||
HullResult hres;
|
||||
|
||||
@@ -46,74 +46,74 @@ struct btSoftBodyHelpers
|
||||
{
|
||||
/* Draw body */
|
||||
static void Draw( btSoftBody* psb,
|
||||
btIDebugDraw* idraw,
|
||||
int drawflags=fDrawFlags::Std);
|
||||
btIDebugDraw* idraw,
|
||||
int drawflags=fDrawFlags::Std);
|
||||
/* Draw body infos */
|
||||
static void DrawInfos( btSoftBody* psb,
|
||||
btIDebugDraw* idraw,
|
||||
bool masses,
|
||||
bool areas,
|
||||
bool stress);
|
||||
btIDebugDraw* idraw,
|
||||
bool masses,
|
||||
bool areas,
|
||||
bool stress);
|
||||
/* Draw node tree */
|
||||
static void DrawNodeTree( btSoftBody* psb,
|
||||
btIDebugDraw* idraw,
|
||||
int mindepth=0,
|
||||
int maxdepth=-1);
|
||||
btIDebugDraw* idraw,
|
||||
int mindepth=0,
|
||||
int maxdepth=-1);
|
||||
/* Draw face tree */
|
||||
static void DrawFaceTree( btSoftBody* psb,
|
||||
btIDebugDraw* idraw,
|
||||
int mindepth=0,
|
||||
int maxdepth=-1);
|
||||
btIDebugDraw* idraw,
|
||||
int mindepth=0,
|
||||
int maxdepth=-1);
|
||||
/* Draw cluster tree */
|
||||
static void DrawClusterTree(btSoftBody* psb,
|
||||
btIDebugDraw* idraw,
|
||||
int mindepth=0,
|
||||
int maxdepth=-1);
|
||||
btIDebugDraw* idraw,
|
||||
int mindepth=0,
|
||||
int maxdepth=-1);
|
||||
/* Draw rigid frame */
|
||||
static void DrawFrame( btSoftBody* psb,
|
||||
btIDebugDraw* idraw);
|
||||
btIDebugDraw* idraw);
|
||||
/* Create a rope */
|
||||
static btSoftBody* CreateRope( btSoftBodyWorldInfo& worldInfo,
|
||||
const btVector3& from,
|
||||
const btVector3& to,
|
||||
int res,
|
||||
int fixeds);
|
||||
const btVector3& from,
|
||||
const btVector3& to,
|
||||
int res,
|
||||
int fixeds);
|
||||
/* Create a patch */
|
||||
static btSoftBody* CreatePatch(btSoftBodyWorldInfo& worldInfo,
|
||||
const btVector3& corner00,
|
||||
const btVector3& corner10,
|
||||
const btVector3& corner01,
|
||||
const btVector3& corner11,
|
||||
int resx,
|
||||
int resy,
|
||||
int fixeds,
|
||||
bool gendiags);
|
||||
const btVector3& corner00,
|
||||
const btVector3& corner10,
|
||||
const btVector3& corner01,
|
||||
const btVector3& corner11,
|
||||
int resx,
|
||||
int resy,
|
||||
int fixeds,
|
||||
bool gendiags);
|
||||
/* Create a patch with UV Texture Coordinates */
|
||||
static btSoftBody* CreatePatchUV(btSoftBodyWorldInfo& worldInfo,
|
||||
const btVector3& corner00,
|
||||
const btVector3& corner10,
|
||||
const btVector3& corner01,
|
||||
const btVector3& corner11,
|
||||
int resx,
|
||||
int resy,
|
||||
int fixeds,
|
||||
bool gendiags,
|
||||
float* tex_coords=0);
|
||||
const btVector3& corner00,
|
||||
const btVector3& corner10,
|
||||
const btVector3& corner01,
|
||||
const btVector3& corner11,
|
||||
int resx,
|
||||
int resy,
|
||||
int fixeds,
|
||||
bool gendiags,
|
||||
float* tex_coords=0);
|
||||
static float CalculateUV(int resx,int resy,int ix,int iy,int id);
|
||||
/* Create an ellipsoid */
|
||||
static btSoftBody* CreateEllipsoid(btSoftBodyWorldInfo& worldInfo,
|
||||
const btVector3& center,
|
||||
const btVector3& radius,
|
||||
int res);
|
||||
const btVector3& center,
|
||||
const btVector3& radius,
|
||||
int res);
|
||||
/* Create from trimesh */
|
||||
static btSoftBody* CreateFromTriMesh( btSoftBodyWorldInfo& worldInfo,
|
||||
const btScalar* vertices,
|
||||
const int* triangles,
|
||||
int ntriangles);
|
||||
const btScalar* vertices,
|
||||
const int* triangles,
|
||||
int ntriangles);
|
||||
/* Create from convex-hull */
|
||||
static btSoftBody* CreateFromConvexHull( btSoftBodyWorldInfo& worldInfo,
|
||||
const btVector3* vertices,
|
||||
int nvertices);
|
||||
const btVector3* vertices,
|
||||
int nvertices);
|
||||
};
|
||||
|
||||
#endif //SOFT_BODY_HELPERS_H
|
||||
File diff suppressed because it is too large.
Load diff
@@ -29,10 +29,10 @@ btSoftBodyRigidBodyCollisionConfiguration::btSoftBodyRigidBodyCollisionConfigura
|
||||
|
||||
mem = btAlignedAlloc(sizeof(btSoftSoftCollisionAlgorithm::CreateFunc),16);
|
||||
m_softSoftCreateFunc = new(mem) btSoftSoftCollisionAlgorithm::CreateFunc;
|
||||
|
||||
|
||||
mem = btAlignedAlloc(sizeof(btSoftRigidCollisionAlgorithm::CreateFunc),16);
|
||||
m_softRigidConvexCreateFunc = new(mem) btSoftRigidCollisionAlgorithm::CreateFunc;
|
||||
|
||||
|
||||
mem = btAlignedAlloc(sizeof(btSoftRigidCollisionAlgorithm::CreateFunc),16);
|
||||
m_swappedSoftRigidConvexCreateFunc = new(mem) btSoftRigidCollisionAlgorithm::CreateFunc;
|
||||
m_swappedSoftRigidConvexCreateFunc->m_swapped=true;
|
||||
@@ -40,20 +40,20 @@ btSoftBodyRigidBodyCollisionConfiguration::btSoftBodyRigidBodyCollisionConfigura
|
||||
#ifdef ENABLE_SOFTBODY_CONCAVE_COLLISIONS
|
||||
mem = btAlignedAlloc(sizeof(btSoftBodyConcaveCollisionAlgorithm::CreateFunc),16);
|
||||
m_softRigidConcaveCreateFunc = new(mem) btSoftBodyConcaveCollisionAlgorithm::CreateFunc;
|
||||
|
||||
|
||||
mem = btAlignedAlloc(sizeof(btSoftBodyConcaveCollisionAlgorithm::CreateFunc),16);
|
||||
m_swappedSoftRigidConcaveCreateFunc = new(mem) btSoftBodyConcaveCollisionAlgorithm::SwappedCreateFunc;
|
||||
m_swappedSoftRigidConcaveCreateFunc->m_swapped=true;
|
||||
#endif
|
||||
|
||||
//replace pool by a new one, with potential larger size
|
||||
|
||||
|
||||
if (m_ownsCollisionAlgorithmPool && m_collisionAlgorithmPool)
|
||||
{
|
||||
int curElemSize = m_collisionAlgorithmPool->getElementSize();
|
||||
///calculate maximum element size, big enough to fit any collision algorithm in the memory pool
|
||||
|
||||
|
||||
|
||||
|
||||
int maxSize0 = sizeof(btSoftSoftCollisionAlgorithm);
|
||||
int maxSize1 = sizeof(btSoftRigidCollisionAlgorithm);
|
||||
int maxSize2 = sizeof(btSoftBodyConcaveCollisionAlgorithm);
|
||||
@@ -92,7 +92,7 @@ btSoftBodyRigidBodyCollisionConfiguration::~btSoftBodyRigidBodyCollisionConfigur
|
||||
btAlignedFree( m_swappedSoftRigidConcaveCreateFunc);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
///creation of soft-soft and soft-rigid, and otherwise fallback to base class implementation
|
||||
btCollisionAlgorithmCreateFunc* btSoftBodyRigidBodyCollisionConfiguration::getCollisionAlgorithmCreateFunc(int proxyType0,int proxyType1)
|
||||
{
|
||||
|
||||
@@ -32,7 +32,7 @@ class btSoftBodyRigidBodyCollisionConfiguration : public btDefaultCollisionConfi
|
||||
btCollisionAlgorithmCreateFunc* m_swappedSoftRigidConvexCreateFunc;
|
||||
btCollisionAlgorithmCreateFunc* m_softRigidConcaveCreateFunc;
|
||||
btCollisionAlgorithmCreateFunc* m_swappedSoftRigidConcaveCreateFunc;
|
||||
|
||||
|
||||
public:
|
||||
|
||||
btSoftBodyRigidBodyCollisionConfiguration(const btDefaultCollisionConstructionInfo& constructionInfo = btDefaultCollisionConstructionInfo());
|
||||
|
||||
@@ -35,13 +35,13 @@ m_isSwapped(isSwapped)
|
||||
|
||||
btSoftRigidCollisionAlgorithm::~btSoftRigidCollisionAlgorithm()
|
||||
{
|
||||
|
||||
|
||||
//m_softBody->m_overlappingRigidBodies.remove(m_rigidCollisionObject);
|
||||
|
||||
/*if (m_ownManifold)
|
||||
{
|
||||
if (m_manifoldPtr)
|
||||
m_dispatcher->releaseManifold(m_manifoldPtr);
|
||||
if (m_manifoldPtr)
|
||||
m_dispatcher->releaseManifold(m_manifoldPtr);
|
||||
}
|
||||
*/
|
||||
|
||||
@@ -58,7 +58,7 @@ void btSoftRigidCollisionAlgorithm::processCollision (btCollisionObject* body0,b
|
||||
|
||||
btSoftBody* softBody = m_isSwapped? (btSoftBody*)body1 : (btSoftBody*)body0;
|
||||
btCollisionObject* rigidCollisionObject = m_isSwapped? body0 : body1;
|
||||
|
||||
|
||||
softBody->defaultCollisionHandler(rigidCollisionObject);
|
||||
|
||||
|
||||
|
||||
@@ -28,15 +28,15 @@ class btSoftBody;
|
||||
/// btSoftRigidCollisionAlgorithm provides collision detection between btSoftBody and btRigidBody
|
||||
class btSoftRigidCollisionAlgorithm : public btCollisionAlgorithm
|
||||
{
|
||||
// bool m_ownManifold;
|
||||
// btPersistentManifold* m_manifoldPtr;
|
||||
// bool m_ownManifold;
|
||||
// btPersistentManifold* m_manifoldPtr;
|
||||
|
||||
btSoftBody* m_softBody;
|
||||
btCollisionObject* m_rigidCollisionObject;
|
||||
|
||||
///for rigid versus soft (instead of soft versus rigid), we use this swapped boolean
|
||||
bool m_isSwapped;
|
||||
|
||||
|
||||
public:
|
||||
|
||||
btSoftRigidCollisionAlgorithm(btPersistentManifold* mf,const btCollisionAlgorithmConstructionInfo& ci,btCollisionObject* col0,btCollisionObject* col1, bool isSwapped);
|
||||
@@ -52,7 +52,7 @@ public:
|
||||
//we don't add any manifolds
|
||||
}
|
||||
|
||||
|
||||
|
||||
struct CreateFunc :public btCollisionAlgorithmCreateFunc
|
||||
{
|
||||
virtual btCollisionAlgorithm* CreateCollisionAlgorithm(btCollisionAlgorithmConstructionInfo& ci, btCollisionObject* body0,btCollisionObject* body1)
|
||||
|
||||
@@ -28,17 +28,17 @@ subject to the following restrictions:
|
||||
btSoftRigidDynamicsWorld::btSoftRigidDynamicsWorld(btDispatcher* dispatcher,btBroadphaseInterface* pairCache,btConstraintSolver* constraintSolver,btCollisionConfiguration* collisionConfiguration)
|
||||
:btDiscreteDynamicsWorld(dispatcher,pairCache,constraintSolver,collisionConfiguration)
|
||||
{
|
||||
m_drawFlags = fDrawFlags::Std;
|
||||
m_drawNodeTree = true;
|
||||
m_drawFaceTree = false;
|
||||
m_drawClusterTree = false;
|
||||
m_sbi.m_broadphase = pairCache;
|
||||
m_sbi.m_dispatcher = dispatcher;
|
||||
m_sbi.m_sparsesdf.Initialize();
|
||||
m_sbi.m_sparsesdf.Reset();
|
||||
m_drawFlags = fDrawFlags::Std;
|
||||
m_drawNodeTree = true;
|
||||
m_drawFaceTree = false;
|
||||
m_drawClusterTree = false;
|
||||
m_sbi.m_broadphase = pairCache;
|
||||
m_sbi.m_dispatcher = dispatcher;
|
||||
m_sbi.m_sparsesdf.Initialize();
|
||||
m_sbi.m_sparsesdf.Reset();
|
||||
|
||||
}
|
||||
|
||||
|
||||
btSoftRigidDynamicsWorld::~btSoftRigidDynamicsWorld()
|
||||
{
|
||||
|
||||
@@ -55,7 +55,7 @@ void btSoftRigidDynamicsWorld::predictUnconstraintMotion(btScalar timeStep)
|
||||
psb->predictMotion(timeStep);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void btSoftRigidDynamicsWorld::internalSingleStepSimulation( btScalar timeStep)
|
||||
{
|
||||
btDiscreteDynamicsWorld::internalSingleStepSimulation( timeStep );
|
||||
@@ -71,7 +71,7 @@ void btSoftRigidDynamicsWorld::internalSingleStepSimulation( btScalar timeStep)
|
||||
void btSoftRigidDynamicsWorld::updateSoftBodies()
|
||||
{
|
||||
BT_PROFILE("updateSoftBodies");
|
||||
|
||||
|
||||
for ( int i=0;i<m_softBodies.size();i++)
|
||||
{
|
||||
btSoftBody* psb=(btSoftBody*)m_softBodies[i];
|
||||
@@ -82,12 +82,12 @@ void btSoftRigidDynamicsWorld::updateSoftBodies()
|
||||
void btSoftRigidDynamicsWorld::solveSoftBodiesConstraints()
|
||||
{
|
||||
BT_PROFILE("solveSoftConstraints");
|
||||
|
||||
|
||||
if(m_softBodies.size())
|
||||
{
|
||||
{
|
||||
btSoftBody::solveClusters(m_softBodies);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
for(int i=0;i<m_softBodies.size();++i)
|
||||
{
|
||||
btSoftBody* psb=(btSoftBody*)m_softBodies[i];
|
||||
@@ -100,8 +100,8 @@ void btSoftRigidDynamicsWorld::addSoftBody(btSoftBody* body)
|
||||
m_softBodies.push_back(body);
|
||||
|
||||
btCollisionWorld::addCollisionObject(body,
|
||||
btBroadphaseProxy::DefaultFilter,
|
||||
btBroadphaseProxy::AllFilter);
|
||||
btBroadphaseProxy::DefaultFilter,
|
||||
btBroadphaseProxy::AllFilter);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ typedef btAlignedObjectArray<btSoftBody*> btSoftBodyArray;
|
||||
|
||||
class btSoftRigidDynamicsWorld : public btDiscreteDynamicsWorld
|
||||
{
|
||||
|
||||
|
||||
btSoftBodyArray m_softBodies;
|
||||
int m_drawFlags;
|
||||
bool m_drawNodeTree;
|
||||
@@ -32,9 +32,9 @@ class btSoftRigidDynamicsWorld : public btDiscreteDynamicsWorld
|
||||
btSoftBodyWorldInfo m_sbi;
|
||||
|
||||
protected:
|
||||
|
||||
|
||||
virtual void predictUnconstraintMotion(btScalar timeStep);
|
||||
|
||||
|
||||
virtual void internalSingleStepSimulation( btScalar timeStep);
|
||||
|
||||
void updateSoftBodies();
|
||||
@@ -43,17 +43,17 @@ protected:
|
||||
|
||||
|
||||
public:
|
||||
|
||||
|
||||
btSoftRigidDynamicsWorld(btDispatcher* dispatcher,btBroadphaseInterface* pairCache,btConstraintSolver* constraintSolver,btCollisionConfiguration* collisionConfiguration);
|
||||
|
||||
virtual ~btSoftRigidDynamicsWorld();
|
||||
|
||||
|
||||
virtual void debugDrawWorld();
|
||||
|
||||
|
||||
void addSoftBody(btSoftBody* body);
|
||||
|
||||
void removeSoftBody(btSoftBody* body);
|
||||
|
||||
|
||||
int getDrawFlags() const { return(m_drawFlags); }
|
||||
void setDrawFlags(int f) { m_drawFlags=f; }
|
||||
|
||||
@@ -66,7 +66,7 @@ public:
|
||||
return m_sbi;
|
||||
}
|
||||
|
||||
|
||||
|
||||
btSoftBodyArray& getSoftBodyArray()
|
||||
{
|
||||
return m_softBodies;
|
||||
@@ -76,7 +76,7 @@ public:
|
||||
{
|
||||
return m_softBodies;
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
#endif //BT_SOFT_RIGID_DYNAMICS_WORLD_H
|
||||
@@ -33,7 +33,7 @@ class btSoftSoftCollisionAlgorithm : public btCollisionAlgorithm
|
||||
btSoftBody* m_softBody0;
|
||||
btSoftBody* m_softBody1;
|
||||
|
||||
|
||||
|
||||
public:
|
||||
btSoftSoftCollisionAlgorithm(const btCollisionAlgorithmConstructionInfo& ci)
|
||||
: btCollisionAlgorithm(ci) {}
|
||||
|
||||
@@ -23,139 +23,139 @@ subject to the following restrictions:
|
||||
// Modified Paul Hsieh hash
|
||||
template <const int DWORDLEN>
|
||||
unsigned int HsiehHash(const void* pdata)
|
||||
{
|
||||
{
|
||||
const unsigned short* data=(const unsigned short*)pdata;
|
||||
unsigned hash=DWORDLEN<<2,tmp;
|
||||
for(int i=0;i<DWORDLEN;++i)
|
||||
{
|
||||
{
|
||||
hash += data[0];
|
||||
tmp = (data[1]<<11)^hash;
|
||||
hash = (hash<<16)^tmp;
|
||||
data += 2;
|
||||
hash += hash>>11;
|
||||
}
|
||||
}
|
||||
hash^=hash<<3;hash+=hash>>5;
|
||||
hash^=hash<<4;hash+=hash>>17;
|
||||
hash^=hash<<25;hash+=hash>>6;
|
||||
return(hash);
|
||||
}
|
||||
}
|
||||
|
||||
template <const int CELLSIZE>
|
||||
struct btSparseSdf
|
||||
{
|
||||
{
|
||||
//
|
||||
// Inner types
|
||||
//
|
||||
struct IntFrac
|
||||
{
|
||||
{
|
||||
int b;
|
||||
int i;
|
||||
btScalar f;
|
||||
};
|
||||
};
|
||||
struct Cell
|
||||
{
|
||||
{
|
||||
btScalar d[CELLSIZE+1][CELLSIZE+1][CELLSIZE+1];
|
||||
int c[3];
|
||||
int puid;
|
||||
unsigned hash;
|
||||
btCollisionShape* pclient;
|
||||
Cell* next;
|
||||
};
|
||||
};
|
||||
//
|
||||
// Fields
|
||||
//
|
||||
|
||||
|
||||
btAlignedObjectArray<Cell*> cells;
|
||||
btScalar voxelsz;
|
||||
int puid;
|
||||
int ncells;
|
||||
int nprobes;
|
||||
int nqueries;
|
||||
|
||||
|
||||
//
|
||||
// Methods
|
||||
//
|
||||
|
||||
|
||||
//
|
||||
void Initialize(int hashsize=2383)
|
||||
{
|
||||
{
|
||||
cells.resize(hashsize,0);
|
||||
Reset();
|
||||
}
|
||||
}
|
||||
//
|
||||
void Reset()
|
||||
{
|
||||
{
|
||||
for(int i=0,ni=cells.size();i<ni;++i)
|
||||
{
|
||||
{
|
||||
Cell* pc=cells[i];
|
||||
cells[i]=0;
|
||||
while(pc)
|
||||
{
|
||||
{
|
||||
Cell* pn=pc->next;
|
||||
delete pc;
|
||||
pc=pn;
|
||||
}
|
||||
}
|
||||
}
|
||||
voxelsz =0.25;
|
||||
puid =0;
|
||||
ncells =0;
|
||||
nprobes =1;
|
||||
nqueries =1;
|
||||
}
|
||||
}
|
||||
//
|
||||
void GarbageCollect(int lifetime=256)
|
||||
{
|
||||
{
|
||||
const int life=puid-lifetime;
|
||||
for(int i=0;i<cells.size();++i)
|
||||
{
|
||||
{
|
||||
Cell*& root=cells[i];
|
||||
Cell* pp=0;
|
||||
Cell* pc=root;
|
||||
while(pc)
|
||||
{
|
||||
{
|
||||
Cell* pn=pc->next;
|
||||
if(pc->puid<life)
|
||||
{
|
||||
{
|
||||
if(pp) pp->next=pn; else root=pn;
|
||||
delete pc;pc=pp;--ncells;
|
||||
}
|
||||
pp=pc;pc=pn;
|
||||
}
|
||||
pp=pc;pc=pn;
|
||||
}
|
||||
}
|
||||
//printf("GC[%d]: %d cells, PpQ: %f\r\n",puid,ncells,nprobes/(btScalar)nqueries);
|
||||
nqueries=1;
|
||||
nprobes=1;
|
||||
++puid; /* TODO: Reset puid's when int range limit is reached */
|
||||
/* else setup a priority list... */
|
||||
}
|
||||
/* else setup a priority list... */
|
||||
}
|
||||
//
|
||||
int RemoveReferences(btCollisionShape* pcs)
|
||||
{
|
||||
{
|
||||
int refcount=0;
|
||||
for(int i=0;i<cells.size();++i)
|
||||
{
|
||||
{
|
||||
Cell*& root=cells[i];
|
||||
Cell* pp=0;
|
||||
Cell* pc=root;
|
||||
while(pc)
|
||||
{
|
||||
{
|
||||
Cell* pn=pc->next;
|
||||
if(pc->pclient==pcs)
|
||||
{
|
||||
{
|
||||
if(pp) pp->next=pn; else root=pn;
|
||||
delete pc;pc=pp;++refcount;
|
||||
}
|
||||
pp=pc;pc=pn;
|
||||
}
|
||||
pp=pc;pc=pn;
|
||||
}
|
||||
return(refcount);
|
||||
}
|
||||
return(refcount);
|
||||
}
|
||||
//
|
||||
btScalar Evaluate( const btVector3& x,
|
||||
btCollisionShape* shape,
|
||||
btVector3& normal,
|
||||
btScalar margin)
|
||||
{
|
||||
btCollisionShape* shape,
|
||||
btVector3& normal,
|
||||
btScalar margin)
|
||||
{
|
||||
/* Lookup cell */
|
||||
const btVector3 scx=x/voxelsz;
|
||||
const IntFrac ix=Decompose(scx.x());
|
||||
@@ -166,19 +166,19 @@ struct btSparseSdf
|
||||
Cell* c=root;
|
||||
++nqueries;
|
||||
while(c)
|
||||
{
|
||||
{
|
||||
++nprobes;
|
||||
if( (c->hash==h) &&
|
||||
(c->c[0]==ix.b) &&
|
||||
(c->c[1]==iy.b) &&
|
||||
(c->c[2]==iz.b) &&
|
||||
(c->pclient==shape))
|
||||
{ break; }
|
||||
else
|
||||
{ c=c->next; }
|
||||
}
|
||||
{ break; }
|
||||
else
|
||||
{ c=c->next; }
|
||||
}
|
||||
if(!c)
|
||||
{
|
||||
{
|
||||
++nprobes;
|
||||
++ncells;
|
||||
c=new Cell();
|
||||
@@ -187,82 +187,82 @@ struct btSparseSdf
|
||||
c->hash=h;
|
||||
c->c[0]=ix.b;c->c[1]=iy.b;c->c[2]=iz.b;
|
||||
BuildCell(*c);
|
||||
}
|
||||
}
|
||||
c->puid=puid;
|
||||
/* Extract infos */
|
||||
const int o[]={ ix.i,iy.i,iz.i};
|
||||
const btScalar d[]={ c->d[o[0]+0][o[1]+0][o[2]+0],
|
||||
c->d[o[0]+1][o[1]+0][o[2]+0],
|
||||
c->d[o[0]+1][o[1]+1][o[2]+0],
|
||||
c->d[o[0]+0][o[1]+1][o[2]+0],
|
||||
c->d[o[0]+0][o[1]+0][o[2]+1],
|
||||
c->d[o[0]+1][o[1]+0][o[2]+1],
|
||||
c->d[o[0]+1][o[1]+1][o[2]+1],
|
||||
c->d[o[0]+0][o[1]+1][o[2]+1]};
|
||||
c->d[o[0]+1][o[1]+0][o[2]+0],
|
||||
c->d[o[0]+1][o[1]+1][o[2]+0],
|
||||
c->d[o[0]+0][o[1]+1][o[2]+0],
|
||||
c->d[o[0]+0][o[1]+0][o[2]+1],
|
||||
c->d[o[0]+1][o[1]+0][o[2]+1],
|
||||
c->d[o[0]+1][o[1]+1][o[2]+1],
|
||||
c->d[o[0]+0][o[1]+1][o[2]+1]};
|
||||
/* Normal */
|
||||
#if 1
|
||||
#if 1
|
||||
const btScalar gx[]={ d[1]-d[0],d[2]-d[3],
|
||||
d[5]-d[4],d[6]-d[7]};
|
||||
d[5]-d[4],d[6]-d[7]};
|
||||
const btScalar gy[]={ d[3]-d[0],d[2]-d[1],
|
||||
d[7]-d[4],d[6]-d[5]};
|
||||
d[7]-d[4],d[6]-d[5]};
|
||||
const btScalar gz[]={ d[4]-d[0],d[5]-d[1],
|
||||
d[7]-d[3],d[6]-d[2]};
|
||||
d[7]-d[3],d[6]-d[2]};
|
||||
normal.setX(Lerp( Lerp(gx[0],gx[1],iy.f),
|
||||
Lerp(gx[2],gx[3],iy.f),iz.f));
|
||||
Lerp(gx[2],gx[3],iy.f),iz.f));
|
||||
normal.setY(Lerp( Lerp(gy[0],gy[1],ix.f),
|
||||
Lerp(gy[2],gy[3],ix.f),iz.f));
|
||||
Lerp(gy[2],gy[3],ix.f),iz.f));
|
||||
normal.setZ(Lerp( Lerp(gz[0],gz[1],ix.f),
|
||||
Lerp(gz[2],gz[3],ix.f),iy.f));
|
||||
Lerp(gz[2],gz[3],ix.f),iy.f));
|
||||
normal = normal.normalized();
|
||||
#else
|
||||
#else
|
||||
normal = btVector3(d[1]-d[0],d[3]-d[0],d[4]-d[0]).normalized();
|
||||
#endif
|
||||
#endif
|
||||
/* Distance */
|
||||
const btScalar d0=Lerp(Lerp(d[0],d[1],ix.f),
|
||||
Lerp(d[3],d[2],ix.f),iy.f);
|
||||
Lerp(d[3],d[2],ix.f),iy.f);
|
||||
const btScalar d1=Lerp(Lerp(d[4],d[5],ix.f),
|
||||
Lerp(d[7],d[6],ix.f),iy.f);
|
||||
Lerp(d[7],d[6],ix.f),iy.f);
|
||||
return(Lerp(d0,d1,iz.f)-margin);
|
||||
}
|
||||
}
|
||||
//
|
||||
void BuildCell(Cell& c)
|
||||
{
|
||||
{
|
||||
const btVector3 org=btVector3( (btScalar)c.c[0],
|
||||
(btScalar)c.c[1],
|
||||
(btScalar)c.c[2]) *
|
||||
CELLSIZE*voxelsz;
|
||||
(btScalar)c.c[1],
|
||||
(btScalar)c.c[2]) *
|
||||
CELLSIZE*voxelsz;
|
||||
for(int k=0;k<=CELLSIZE;++k)
|
||||
{
|
||||
{
|
||||
const btScalar z=voxelsz*k+org.z();
|
||||
for(int j=0;j<=CELLSIZE;++j)
|
||||
{
|
||||
{
|
||||
const btScalar y=voxelsz*j+org.y();
|
||||
for(int i=0;i<=CELLSIZE;++i)
|
||||
{
|
||||
{
|
||||
const btScalar x=voxelsz*i+org.x();
|
||||
c.d[i][j][k]=DistanceToShape( btVector3(x,y,z),
|
||||
c.pclient);
|
||||
}
|
||||
c.pclient);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
//
|
||||
static inline btScalar DistanceToShape(const btVector3& x,
|
||||
btCollisionShape* shape)
|
||||
{
|
||||
btCollisionShape* shape)
|
||||
{
|
||||
btTransform unit;
|
||||
unit.setIdentity();
|
||||
if(shape->isConvex())
|
||||
{
|
||||
{
|
||||
btGjkEpaSolver2::sResults res;
|
||||
btConvexShape* csh=static_cast<btConvexShape*>(shape);
|
||||
return(btGjkEpaSolver2::SignedDistance(x,0,csh,unit,res));
|
||||
}
|
||||
return(0);
|
||||
}
|
||||
return(0);
|
||||
}
|
||||
//
|
||||
static inline IntFrac Decompose(btScalar x)
|
||||
{
|
||||
{
|
||||
/* That one need a lot of improvements... */
|
||||
/* Remove test, faster floor... */
|
||||
IntFrac r;
|
||||
@@ -272,18 +272,18 @@ struct btSparseSdf
|
||||
const btScalar k=(x-r.b)*CELLSIZE;
|
||||
r.i=(int)k;r.f=k-r.i;r.b-=o;
|
||||
return(r);
|
||||
}
|
||||
}
|
||||
//
|
||||
static inline btScalar Lerp(btScalar a,btScalar b,btScalar t)
|
||||
{
|
||||
{
|
||||
return(a+(b-a)*t);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
//
|
||||
static inline unsigned int Hash(int x,int y,int z,btCollisionShape* shape)
|
||||
{
|
||||
{
|
||||
struct btS
|
||||
{
|
||||
int x,y,z;
|
||||
@@ -291,16 +291,16 @@ struct btSparseSdf
|
||||
};
|
||||
|
||||
btS myset;
|
||||
|
||||
|
||||
myset.x=x;myset.y=y;myset.z=z;myset.p=shape;
|
||||
const void* ptr = &myset;
|
||||
|
||||
unsigned int result = HsiehHash<sizeof(btS)/4> (ptr);
|
||||
|
||||
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
Reference in new issue
Block a user