Autoformat selection for soft body, btDbvt related classes (no code change, just layout using Visual Studio)

This commit is contained in:
erwin.coumans
2008-10-15 18:39:27 +00:00
parent cac172d422
commit 60ce828419
20 changed files with 3941 additions and 3941 deletions

View File

@@ -229,11 +229,11 @@ void SoftDemo::displayCallback(void) {
//
struct ImplicitSphere : btSoftBody::ImplicitFn
{
btVector3 center;
btScalar sqradius;
btVector3 center;
btScalar sqradius;
ImplicitSphere() {}
ImplicitSphere(const btVector3& c,btScalar r) : center(c),sqradius(r*r) {}
btScalar Eval(const btVector3& x)
btScalar Eval(const btVector3& x)
{
return((x-center).length2()-sqradius);
}
@@ -289,7 +289,7 @@ static void Ctor_RbUpStack(SoftDemo* pdemo,int count)
cylinderCompound->addChildShape(localTransform,boxShape);
btQuaternion orn(SIMD_HALF_PI,0,0);
localTransform.setRotation(orn);
// localTransform.setOrigin(btVector3(1,1,1));
// localTransform.setOrigin(btVector3(1,1,1));
cylinderCompound->addChildShape(localTransform,cylinderShape);
@@ -883,67 +883,67 @@ static void Init_Cutting1(SoftDemo* pdemo)
//
static void Ctor_Gear(SoftDemo* pdemo,const btVector3& pos,btScalar speed)
{
btTransform startTransform;
startTransform.setIdentity();
startTransform.setOrigin(pos);
btCompoundShape* shape=new btCompoundShape();
btTransform startTransform;
startTransform.setIdentity();
startTransform.setOrigin(pos);
btCompoundShape* shape=new btCompoundShape();
#if 1
shape->addChildShape(btTransform(btQuaternion(0,0,0)),new btBoxShape(btVector3(5,1,6)));
shape->addChildShape(btTransform(btQuaternion(0,0,SIMD_HALF_PI)),new btBoxShape(btVector3(5,1,6)));
shape->addChildShape(btTransform(btQuaternion(0,0,0)),new btBoxShape(btVector3(5,1,6)));
shape->addChildShape(btTransform(btQuaternion(0,0,SIMD_HALF_PI)),new btBoxShape(btVector3(5,1,6)));
#else
shape->addChildShape(btTransform(btQuaternion(0,0,0)),new btCylinderShapeZ(btVector3(5,1,7)));
shape->addChildShape(btTransform(btQuaternion(0,0,SIMD_HALF_PI)),new btBoxShape(btVector3(4,1,8)));
shape->addChildShape(btTransform(btQuaternion(0,0,0)),new btCylinderShapeZ(btVector3(5,1,7)));
shape->addChildShape(btTransform(btQuaternion(0,0,SIMD_HALF_PI)),new btBoxShape(btVector3(4,1,8)));
#endif
btRigidBody* body=pdemo->localCreateRigidBody(10,startTransform,shape);
body->setFriction(1);
btDynamicsWorld* world=pdemo->getDynamicsWorld();
btHingeConstraint* hinge=new btHingeConstraint(*body,btTransform::getIdentity());
if(speed!=0) hinge->enableAngularMotor(true,speed,3);
world->addConstraint(hinge);
btRigidBody* body=pdemo->localCreateRigidBody(10,startTransform,shape);
body->setFriction(1);
btDynamicsWorld* world=pdemo->getDynamicsWorld();
btHingeConstraint* hinge=new btHingeConstraint(*body,btTransform::getIdentity());
if(speed!=0) hinge->enableAngularMotor(true,speed,3);
world->addConstraint(hinge);
}
//
static btSoftBody* Ctor_ClusterBunny(SoftDemo* pdemo,const btVector3& x,const btVector3& a)
{
btSoftBody* psb=btSoftBodyHelpers::CreateFromTriMesh(pdemo->m_softBodyWorldInfo,gVerticesBunny,&gIndicesBunny[0][0],BUNNY_NUM_TRIANGLES);
btSoftBody::Material* pm=psb->appendMaterial();
pm->m_kLST = 1;
pm->m_flags -= btSoftBody::fMaterial::DebugDraw;
psb->generateBendingConstraints(2,pm);
psb->m_cfg.piterations = 2;
psb->m_cfg.kDF = 1;
psb->m_cfg.collisions = btSoftBody::fCollision::CL_SS+
btSoftBody* psb=btSoftBodyHelpers::CreateFromTriMesh(pdemo->m_softBodyWorldInfo,gVerticesBunny,&gIndicesBunny[0][0],BUNNY_NUM_TRIANGLES);
btSoftBody::Material* pm=psb->appendMaterial();
pm->m_kLST = 1;
pm->m_flags -= btSoftBody::fMaterial::DebugDraw;
psb->generateBendingConstraints(2,pm);
psb->m_cfg.piterations = 2;
psb->m_cfg.kDF = 1;
psb->m_cfg.collisions = btSoftBody::fCollision::CL_SS+
btSoftBody::fCollision::CL_RS;
psb->randomizeConstraints();
btMatrix3x3 m;
m.setEulerZYX(a.x(),a.y(),a.z());
psb->transform(btTransform(m,x));
psb->scale(btVector3(8,8,8));
psb->setTotalMass(150,true);
psb->generateClusters(1);
pdemo->getSoftDynamicsWorld()->addSoftBody(psb);
return(psb);
psb->randomizeConstraints();
btMatrix3x3 m;
m.setEulerZYX(a.x(),a.y(),a.z());
psb->transform(btTransform(m,x));
psb->scale(btVector3(8,8,8));
psb->setTotalMass(150,true);
psb->generateClusters(1);
pdemo->getSoftDynamicsWorld()->addSoftBody(psb);
return(psb);
}
//
static btSoftBody* Ctor_ClusterTorus(SoftDemo* pdemo,const btVector3& x,const btVector3& a,const btVector3& s=btVector3(2,2,2))
{
btSoftBody* psb=btSoftBodyHelpers::CreateFromTriMesh(pdemo->m_softBodyWorldInfo,gVertices,&gIndices[0][0],NUM_TRIANGLES);
btSoftBody::Material* pm=psb->appendMaterial();
pm->m_kLST = 1;
pm->m_flags -= btSoftBody::fMaterial::DebugDraw;
psb->generateBendingConstraints(2,pm);
psb->m_cfg.piterations = 2;
psb->m_cfg.collisions = btSoftBody::fCollision::CL_SS+
btSoftBody* psb=btSoftBodyHelpers::CreateFromTriMesh(pdemo->m_softBodyWorldInfo,gVertices,&gIndices[0][0],NUM_TRIANGLES);
btSoftBody::Material* pm=psb->appendMaterial();
pm->m_kLST = 1;
pm->m_flags -= btSoftBody::fMaterial::DebugDraw;
psb->generateBendingConstraints(2,pm);
psb->m_cfg.piterations = 2;
psb->m_cfg.collisions = btSoftBody::fCollision::CL_SS+
btSoftBody::fCollision::CL_RS;
psb->randomizeConstraints();
psb->scale(s);
psb->rotate(btQuaternion(a[0],a[1],a[2]));
psb->translate(x);
psb->setTotalMass(50,true);
psb->generateClusters(64);
pdemo->getSoftDynamicsWorld()->addSoftBody(psb);
return(psb);
psb->randomizeConstraints();
psb->scale(s);
psb->rotate(btQuaternion(a[0],a[1],a[2]));
psb->translate(x);
psb->setTotalMass(50,true);
psb->generateClusters(64);
pdemo->getSoftDynamicsWorld()->addSoftBody(psb);
return(psb);
}
//
@@ -954,12 +954,12 @@ static struct MotorControl : btSoftBody::AJoint::IControl
goal=0;
maxtorque=0;
}
btScalar Speed(btSoftBody::AJoint*,btScalar current)
btScalar Speed(btSoftBody::AJoint*,btScalar current)
{
return(current+btMin(maxtorque,btMax(-maxtorque,goal-current)));
}
btScalar goal;
btScalar maxtorque;
btScalar goal;
btScalar maxtorque;
} motorcontrol;
//
@@ -970,17 +970,17 @@ struct SteerControl : btSoftBody::AJoint::IControl
angle=0;
sign=s;
}
void Prepare(btSoftBody::AJoint* joint)
void Prepare(btSoftBody::AJoint* joint)
{
joint->m_refs[0][0]=btCos(angle*sign);
joint->m_refs[0][2]=btSin(angle*sign);
}
btScalar Speed(btSoftBody::AJoint* joint,btScalar current)
btScalar Speed(btSoftBody::AJoint* joint,btScalar current)
{
return(motorcontrol.Speed(joint,current));
}
btScalar angle;
btScalar sign;
btScalar angle;
btScalar sign;
};
static SteerControl steercontrol_f(+1);
@@ -989,41 +989,41 @@ static SteerControl steercontrol_r(-1);
//
static void Init_ClusterDeform(SoftDemo* pdemo)
{
btSoftBody* psb=Ctor_ClusterTorus(pdemo,btVector3(0,0,0),btVector3(SIMD_PI/2,0,SIMD_HALF_PI));
psb->generateClusters(8);
psb->m_cfg.kDF=1;
btSoftBody* psb=Ctor_ClusterTorus(pdemo,btVector3(0,0,0),btVector3(SIMD_PI/2,0,SIMD_HALF_PI));
psb->generateClusters(8);
psb->m_cfg.kDF=1;
}
//
static void Init_ClusterCollide1(SoftDemo* pdemo)
{
const btScalar s=8;
btSoftBody* psb=btSoftBodyHelpers::CreatePatch( pdemo->m_softBodyWorldInfo,btVector3(-s,0,-s),
const btScalar s=8;
btSoftBody* psb=btSoftBodyHelpers::CreatePatch( pdemo->m_softBodyWorldInfo,btVector3(-s,0,-s),
btVector3(+s,0,-s),
btVector3(-s,0,+s),
btVector3(+s,0,+s),
31,31,
1+2+4+8,true);
btSoftBody::Material* pm=psb->appendMaterial();
pm->m_kLST = 0.4;
pm->m_flags -= btSoftBody::fMaterial::DebugDraw;
psb->m_cfg.kDF = 1;
psb->m_cfg.kSRHR_CL = 1;
psb->m_cfg.kSR_SPLT_CL = 0;
psb->m_cfg.collisions = btSoftBody::fCollision::CL_SS+
btSoftBody::Material* pm=psb->appendMaterial();
pm->m_kLST = 0.4;
pm->m_flags -= btSoftBody::fMaterial::DebugDraw;
psb->m_cfg.kDF = 1;
psb->m_cfg.kSRHR_CL = 1;
psb->m_cfg.kSR_SPLT_CL = 0;
psb->m_cfg.collisions = btSoftBody::fCollision::CL_SS+
btSoftBody::fCollision::CL_RS;
psb->generateBendingConstraints(2,pm);
psb->setTotalMass(50);
psb->generateClusters(64);
pdemo->getSoftDynamicsWorld()->addSoftBody(psb);
psb->generateBendingConstraints(2,pm);
psb->setTotalMass(50);
psb->generateClusters(64);
pdemo->getSoftDynamicsWorld()->addSoftBody(psb);
Ctor_RbUpStack(pdemo,10);
Ctor_RbUpStack(pdemo,10);
}
//
static void Init_ClusterCollide2(SoftDemo* pdemo)
{
struct Functor
struct Functor
{
static btSoftBody* Create(SoftDemo* pdemo,const btVector3& x,const btVector3& a)
{
@@ -1052,7 +1052,7 @@ struct Functor
return(psb);
}
};
for(int i=0;i<3;++i)
for(int i=0;i<3;++i)
{
Functor::Create(pdemo,btVector3(3*i,2,0),btVector3(SIMD_PI/2*(1-(i&1)),SIMD_PI/2*(i&1),0));
}
@@ -1061,33 +1061,33 @@ for(int i=0;i<3;++i)
//
static void Init_ClusterSocket(SoftDemo* pdemo)
{
btSoftBody* psb=Ctor_ClusterTorus(pdemo,btVector3(0,0,0),btVector3(SIMD_PI/2,0,SIMD_HALF_PI));
btRigidBody* prb=Ctor_BigPlate(pdemo,50,8);
psb->m_cfg.kDF=1;
btSoftBody::LJoint::Specs lj;
lj.position = btVector3(0,5,0);
psb->appendLinearJoint(lj,prb);
btSoftBody* psb=Ctor_ClusterTorus(pdemo,btVector3(0,0,0),btVector3(SIMD_PI/2,0,SIMD_HALF_PI));
btRigidBody* prb=Ctor_BigPlate(pdemo,50,8);
psb->m_cfg.kDF=1;
btSoftBody::LJoint::Specs lj;
lj.position = btVector3(0,5,0);
psb->appendLinearJoint(lj,prb);
}
//
static void Init_ClusterHinge(SoftDemo* pdemo)
{
btSoftBody* psb=Ctor_ClusterTorus(pdemo,btVector3(0,0,0),btVector3(SIMD_PI/2,0,SIMD_HALF_PI));
btRigidBody* prb=Ctor_BigPlate(pdemo,50,8);
psb->m_cfg.kDF=1;
btSoftBody::AJoint::Specs aj;
aj.axis = btVector3(0,0,1);
psb->appendAngularJoint(aj,prb);
btSoftBody* psb=Ctor_ClusterTorus(pdemo,btVector3(0,0,0),btVector3(SIMD_PI/2,0,SIMD_HALF_PI));
btRigidBody* prb=Ctor_BigPlate(pdemo,50,8);
psb->m_cfg.kDF=1;
btSoftBody::AJoint::Specs aj;
aj.axis = btVector3(0,0,1);
psb->appendAngularJoint(aj,prb);
}
//
static void Init_ClusterCombine(SoftDemo* pdemo)
{
const btVector3 sz(2,4,2);
btSoftBody* psb0=Ctor_ClusterTorus(pdemo,btVector3(0,8,0),btVector3(SIMD_PI/2,0,SIMD_HALF_PI),sz);
btSoftBody* psb1=Ctor_ClusterTorus(pdemo,btVector3(0,8,10),btVector3(SIMD_PI/2,0,SIMD_HALF_PI),sz);
btSoftBody* psbs[]={psb0,psb1};
for(int j=0;j<2;++j)
const btVector3 sz(2,4,2);
btSoftBody* psb0=Ctor_ClusterTorus(pdemo,btVector3(0,8,0),btVector3(SIMD_PI/2,0,SIMD_HALF_PI),sz);
btSoftBody* psb1=Ctor_ClusterTorus(pdemo,btVector3(0,8,10),btVector3(SIMD_PI/2,0,SIMD_HALF_PI),sz);
btSoftBody* psbs[]={psb0,psb1};
for(int j=0;j<2;++j)
{
psbs[j]->m_cfg.kDF=1;
psbs[j]->m_cfg.kDP=0;
@@ -1095,98 +1095,98 @@ for(int j=0;j<2;++j)
psbs[j]->m_clusters[0]->m_matching = 0.05;
psbs[j]->m_clusters[0]->m_ndamping = 0.05;
}
btSoftBody::AJoint::Specs aj;
aj.axis = btVector3(0,0,1);
aj.icontrol = &motorcontrol;
psb0->appendAngularJoint(aj,psb1);
btSoftBody::AJoint::Specs aj;
aj.axis = btVector3(0,0,1);
aj.icontrol = &motorcontrol;
psb0->appendAngularJoint(aj,psb1);
btSoftBody::LJoint::Specs lj;
lj.position = btVector3(0,8,5);
psb0->appendLinearJoint(lj,psb1);
btSoftBody::LJoint::Specs lj;
lj.position = btVector3(0,8,5);
psb0->appendLinearJoint(lj,psb1);
}
//
static void Init_ClusterCar(SoftDemo* pdemo)
{
pdemo->setAzi(270);
const btVector3 origin(100,80,0);
const btQuaternion orientation(-SIMD_PI/2,0,0);
const btScalar widthf=8;
const btScalar widthr=9;
const btScalar length=8;
const btScalar height=4;
const btVector3 wheels[]= {
const btVector3 origin(100,80,0);
const btQuaternion orientation(-SIMD_PI/2,0,0);
const btScalar widthf=8;
const btScalar widthr=9;
const btScalar length=8;
const btScalar height=4;
const btVector3 wheels[]= {
btVector3(+widthf,-height,+length), // Front left
btVector3(-widthf,-height,+length), // Front right
btVector3(+widthr,-height,-length), // Rear left
btVector3(-widthr,-height,-length), // Rear right
};
btSoftBody* pa=Ctor_ClusterBunny(pdemo,btVector3(0,0,0),btVector3(0,0,0));
btSoftBody* pfl=Ctor_ClusterTorus(pdemo,wheels[0],btVector3(0,0,SIMD_HALF_PI),btVector3(2,4,2));
btSoftBody* pfr=Ctor_ClusterTorus(pdemo,wheels[1],btVector3(0,0,SIMD_HALF_PI),btVector3(2,4,2));
btSoftBody* prl=Ctor_ClusterTorus(pdemo,wheels[2],btVector3(0,0,SIMD_HALF_PI),btVector3(2,5,2));
btSoftBody* prr=Ctor_ClusterTorus(pdemo,wheels[3],btVector3(0,0,SIMD_HALF_PI),btVector3(2,5,2));
btSoftBody* pa=Ctor_ClusterBunny(pdemo,btVector3(0,0,0),btVector3(0,0,0));
btSoftBody* pfl=Ctor_ClusterTorus(pdemo,wheels[0],btVector3(0,0,SIMD_HALF_PI),btVector3(2,4,2));
btSoftBody* pfr=Ctor_ClusterTorus(pdemo,wheels[1],btVector3(0,0,SIMD_HALF_PI),btVector3(2,4,2));
btSoftBody* prl=Ctor_ClusterTorus(pdemo,wheels[2],btVector3(0,0,SIMD_HALF_PI),btVector3(2,5,2));
btSoftBody* prr=Ctor_ClusterTorus(pdemo,wheels[3],btVector3(0,0,SIMD_HALF_PI),btVector3(2,5,2));
pfl->m_cfg.kDF =
pfr->m_cfg.kDF =
prl->m_cfg.kDF =
prr->m_cfg.kDF = 1;
pfl->m_cfg.kDF =
pfr->m_cfg.kDF =
prl->m_cfg.kDF =
prr->m_cfg.kDF = 1;
btSoftBody::LJoint::Specs lspecs;
lspecs.cfm = 1;
lspecs.erp = 1;
lspecs.position = btVector3(0,0,0);
btSoftBody::LJoint::Specs lspecs;
lspecs.cfm = 1;
lspecs.erp = 1;
lspecs.position = btVector3(0,0,0);
lspecs.position=wheels[0];pa->appendLinearJoint(lspecs,pfl);
lspecs.position=wheels[1];pa->appendLinearJoint(lspecs,pfr);
lspecs.position=wheels[2];pa->appendLinearJoint(lspecs,prl);
lspecs.position=wheels[3];pa->appendLinearJoint(lspecs,prr);
lspecs.position=wheels[0];pa->appendLinearJoint(lspecs,pfl);
lspecs.position=wheels[1];pa->appendLinearJoint(lspecs,pfr);
lspecs.position=wheels[2];pa->appendLinearJoint(lspecs,prl);
lspecs.position=wheels[3];pa->appendLinearJoint(lspecs,prr);
btSoftBody::AJoint::Specs aspecs;
aspecs.cfm = 1;
aspecs.erp = 1;
aspecs.axis = btVector3(1,0,0);
btSoftBody::AJoint::Specs aspecs;
aspecs.cfm = 1;
aspecs.erp = 1;
aspecs.axis = btVector3(1,0,0);
aspecs.icontrol = &steercontrol_f;
pa->appendAngularJoint(aspecs,pfl);
pa->appendAngularJoint(aspecs,pfr);
aspecs.icontrol = &steercontrol_f;
pa->appendAngularJoint(aspecs,pfl);
pa->appendAngularJoint(aspecs,pfr);
aspecs.icontrol = &motorcontrol;
pa->appendAngularJoint(aspecs,prl);
pa->appendAngularJoint(aspecs,prr);
aspecs.icontrol = &motorcontrol;
pa->appendAngularJoint(aspecs,prl);
pa->appendAngularJoint(aspecs,prr);
pa->rotate(orientation);
pfl->rotate(orientation);
pfr->rotate(orientation);
prl->rotate(orientation);
prr->rotate(orientation);
pa->translate(origin);
pfl->translate(origin);
pfr->translate(origin);
prl->translate(origin);
prr->translate(origin);
pfl->m_cfg.piterations =
pfr->m_cfg.piterations =
prl->m_cfg.piterations =
prr->m_cfg.piterations = 1;
pfl->m_clusters[0]->m_matching =
pfr->m_clusters[0]->m_matching =
prl->m_clusters[0]->m_matching =
prr->m_clusters[0]->m_matching = 0.05;
pfl->m_clusters[0]->m_ndamping =
pfr->m_clusters[0]->m_ndamping =
prl->m_clusters[0]->m_ndamping =
prr->m_clusters[0]->m_ndamping = 0.05;
pa->rotate(orientation);
pfl->rotate(orientation);
pfr->rotate(orientation);
prl->rotate(orientation);
prr->rotate(orientation);
pa->translate(origin);
pfl->translate(origin);
pfr->translate(origin);
prl->translate(origin);
prr->translate(origin);
pfl->m_cfg.piterations =
pfr->m_cfg.piterations =
prl->m_cfg.piterations =
prr->m_cfg.piterations = 1;
pfl->m_clusters[0]->m_matching =
pfr->m_clusters[0]->m_matching =
prl->m_clusters[0]->m_matching =
prr->m_clusters[0]->m_matching = 0.05;
pfl->m_clusters[0]->m_ndamping =
pfr->m_clusters[0]->m_ndamping =
prl->m_clusters[0]->m_ndamping =
prr->m_clusters[0]->m_ndamping = 0.05;
Ctor_LinearStair(pdemo,btVector3(0,-8,0),btVector3(3,2,40),0,20);
Ctor_RbUpStack(pdemo,50);
pdemo->m_autocam=true;
Ctor_LinearStair(pdemo,btVector3(0,-8,0),btVector3(3,2,40),0,20);
Ctor_RbUpStack(pdemo,50);
pdemo->m_autocam=true;
}
//
static void Init_ClusterRobot(SoftDemo* pdemo)
{
struct Functor
struct Functor
{
static btSoftBody* CreateBall(SoftDemo* pdemo,const btVector3& pos)
{
@@ -1200,29 +1200,29 @@ struct Functor
return(psb);
}
};
const btVector3 base=btVector3(0,25,8);
btSoftBody* psb0=Functor::CreateBall(pdemo,base+btVector3(-8,0,0));
btSoftBody* psb1=Functor::CreateBall(pdemo,base+btVector3(+8,0,0));
btSoftBody* psb2=Functor::CreateBall(pdemo,base+btVector3(0,0,+8*btSqrt(2)));
const btVector3 ctr=(psb0->clusterCom(0)+psb1->clusterCom(0)+psb2->clusterCom(0))/3;
btCylinderShape* pshp=new btCylinderShape(btVector3(8,1,8));
btRigidBody* prb=pdemo->localCreateRigidBody(50,btTransform(btQuaternion(0,0,0),ctr+btVector3(0,5,0)),pshp);
btSoftBody::LJoint::Specs ls;
ls.erp=0.5f;
ls.position=psb0->clusterCom(0);psb0->appendLinearJoint(ls,prb);
ls.position=psb1->clusterCom(0);psb1->appendLinearJoint(ls,prb);
ls.position=psb2->clusterCom(0);psb2->appendLinearJoint(ls,prb);
const btVector3 base=btVector3(0,25,8);
btSoftBody* psb0=Functor::CreateBall(pdemo,base+btVector3(-8,0,0));
btSoftBody* psb1=Functor::CreateBall(pdemo,base+btVector3(+8,0,0));
btSoftBody* psb2=Functor::CreateBall(pdemo,base+btVector3(0,0,+8*btSqrt(2)));
const btVector3 ctr=(psb0->clusterCom(0)+psb1->clusterCom(0)+psb2->clusterCom(0))/3;
btCylinderShape* pshp=new btCylinderShape(btVector3(8,1,8));
btRigidBody* prb=pdemo->localCreateRigidBody(50,btTransform(btQuaternion(0,0,0),ctr+btVector3(0,5,0)),pshp);
btSoftBody::LJoint::Specs ls;
ls.erp=0.5f;
ls.position=psb0->clusterCom(0);psb0->appendLinearJoint(ls,prb);
ls.position=psb1->clusterCom(0);psb1->appendLinearJoint(ls,prb);
ls.position=psb2->clusterCom(0);psb2->appendLinearJoint(ls,prb);
btBoxShape* pbox=new btBoxShape(btVector3(20,1,40));
btRigidBody* pgrn=pdemo->localCreateRigidBody(0,btTransform(btQuaternion(0,-SIMD_HALF_PI/2,0),btVector3(0,0,0)),pbox);
btBoxShape* pbox=new btBoxShape(btVector3(20,1,40));
btRigidBody* pgrn=pdemo->localCreateRigidBody(0,btTransform(btQuaternion(0,-SIMD_HALF_PI/2,0),btVector3(0,0,0)),pbox);
pdemo->m_autocam=true;
pdemo->m_autocam=true;
}
//
static void Init_ClusterStackSoft(SoftDemo* pdemo)
{
for(int i=0;i<10;++i)
for(int i=0;i<10;++i)
{
btSoftBody* psb=Ctor_ClusterTorus(pdemo,btVector3(0,-9+8.25*i,0),btVector3(0,0,0));
psb->m_cfg.kDF=1;
@@ -1232,7 +1232,7 @@ for(int i=0;i<10;++i)
//
static void Init_ClusterStackMixed(SoftDemo* pdemo)
{
for(int i=0;i<10;++i)
for(int i=0;i<10;++i)
{
if((i+1)&1)
{
@@ -1428,7 +1428,7 @@ void SoftDemo::renderme()
idraw->drawLine(org,org-dir*rayLength*0.1,btVector3(0,0,0));
}
}
#undef RES
#undef RES
}
/* Water level */
static const btVector3 axis[]={btVector3(1,0,0),
@@ -1494,16 +1494,16 @@ void SoftDemo::keyboardCallback(unsigned char key, int x, int y)
//
void SoftDemo::mouseMotionFunc(int x,int y)
{
if(m_node&&(m_results.fraction<1.f))
if(m_node&&(m_results.fraction<1.f))
{
if(!m_drag)
{
#define SQ(_x_) (_x_)*(_x_)
#define SQ(_x_) (_x_)*(_x_)
if((SQ(x-m_lastmousepos[0])+SQ(y-m_lastmousepos[1]))>6)
{
m_drag=true;
}
#undef SQ
#undef SQ
}
if(m_drag)
{
@@ -1520,7 +1520,7 @@ if(m_node&&(m_results.fraction<1.f))
//
void SoftDemo::mouseFunc(int button, int state, int x, int y)
{
if(button==0)
if(button==0)
{
switch(state)
{
@@ -1596,7 +1596,7 @@ if(button==0)
void SoftDemo::initPhysics()
{
///create concave ground mesh
///create concave ground mesh
//reset and disable motorcontrol at the start
motorcontrol.goal = 0;

View File

@@ -23,14 +23,14 @@ typedef btAlignedObjectArray<const btDbvtNode*> tConstNodeArray;
//
struct btDbvtNodeEnumerator : btDbvt::ICollide
{
tConstNodeArray nodes;
void Process(const btDbvtNode* n) { nodes.push_back(n); }
tConstNodeArray nodes;
void Process(const btDbvtNode* n) { nodes.push_back(n); }
};
//
static DBVT_INLINE int indexof(const btDbvtNode* node)
{
return(node->parent->childs[1]==node);
return(node->parent->childs[1]==node);
}
//
@@ -38,27 +38,27 @@ static DBVT_INLINE btDbvtVolume merge( const btDbvtVolume& a,
const btDbvtVolume& b)
{
#if DBVT_MERGE_IMPL==DBVT_IMPL_SSE
DBVT_ALIGN char locals[sizeof(btDbvtAabbMm)];
btDbvtVolume& res=*(btDbvtVolume*)locals;
DBVT_ALIGN char locals[sizeof(btDbvtAabbMm)];
btDbvtVolume& res=*(btDbvtVolume*)locals;
#else
btDbvtVolume res;
btDbvtVolume res;
#endif
Merge(a,b,res);
return(res);
Merge(a,b,res);
return(res);
}
// volume+edge lengths
static DBVT_INLINE btScalar size(const btDbvtVolume& a)
{
const btVector3 edges=a.Lengths();
return( edges.x()*edges.y()*edges.z()+
const btVector3 edges=a.Lengths();
return( edges.x()*edges.y()*edges.z()+
edges.x()+edges.y()+edges.z());
}
//
static void getmaxdepth(const btDbvtNode* node,int depth,int& maxdepth)
{
if(node->isinternal())
if(node->isinternal())
{
getmaxdepth(node->childs[0],depth+1,maxdepth);
getmaxdepth(node->childs[0],depth+1,maxdepth);
@@ -69,21 +69,21 @@ if(node->isinternal())
static DBVT_INLINE void deletenode( btDbvt* pdbvt,
btDbvtNode* node)
{
btAlignedFree(pdbvt->m_free);
pdbvt->m_free=node;
btAlignedFree(pdbvt->m_free);
pdbvt->m_free=node;
}
//
static void recursedeletenode( btDbvt* pdbvt,
btDbvtNode* node)
{
if(!node->isleaf())
if(!node->isleaf())
{
recursedeletenode(pdbvt,node->childs[0]);
recursedeletenode(pdbvt,node->childs[1]);
}
if(node==pdbvt->m_root) pdbvt->m_root=0;
deletenode(pdbvt,node);
if(node==pdbvt->m_root) pdbvt->m_root=0;
deletenode(pdbvt,node);
}
//
@@ -91,15 +91,15 @@ static DBVT_INLINE btDbvtNode* createnode( btDbvt* pdbvt,
btDbvtNode* parent,
void* data)
{
btDbvtNode* node;
if(pdbvt->m_free)
btDbvtNode* node;
if(pdbvt->m_free)
{ node=pdbvt->m_free;pdbvt->m_free=0; }
else
{ node=new(btAlignedAlloc(sizeof(btDbvtNode),16)) btDbvtNode(); }
node->parent = parent;
node->data = data;
node->childs[1] = 0;
return(node);
node->parent = parent;
node->data = data;
node->childs[1] = 0;
return(node);
}
//
@@ -108,9 +108,9 @@ static DBVT_INLINE btDbvtNode* createnode( btDbvt* pdbvt,
const btDbvtVolume& volume,
void* data)
{
btDbvtNode* node=createnode(pdbvt,parent,data);
node->volume=volume;
return(node);
btDbvtNode* node=createnode(pdbvt,parent,data);
node->volume=volume;
return(node);
}
//
@@ -120,9 +120,9 @@ static DBVT_INLINE btDbvtNode* createnode( btDbvt* pdbvt,
const btDbvtVolume& volume1,
void* data)
{
btDbvtNode* node=createnode(pdbvt,parent,data);
Merge(volume0,volume1,node->volume);
return(node);
btDbvtNode* node=createnode(pdbvt,parent,data);
Merge(volume0,volume1,node->volume);
return(node);
}
//
@@ -130,7 +130,7 @@ static void insertleaf( btDbvt* pdbvt,
btDbvtNode* root,
btDbvtNode* leaf)
{
if(!pdbvt->m_root)
if(!pdbvt->m_root)
{
pdbvt->m_root = leaf;
leaf->parent = 0;
@@ -173,7 +173,7 @@ if(!pdbvt->m_root)
static btDbvtNode* removeleaf( btDbvt* pdbvt,
btDbvtNode* leaf)
{
if(leaf==pdbvt->m_root)
if(leaf==pdbvt->m_root)
{
pdbvt->m_root=0;
return(0);
@@ -215,7 +215,7 @@ static void fetchleaves(btDbvt* pdbvt,
tNodeArray& leaves,
int depth=-1)
{
if(root->isinternal()&&depth)
if(root->isinternal()&&depth)
{
fetchleaves(pdbvt,root->childs[0],leaves,depth-1);
fetchleaves(pdbvt,root->childs[1],leaves,depth-1);
@@ -234,9 +234,9 @@ static void split( const tNodeArray& leaves,
const btVector3& org,
const btVector3& axis)
{
left.resize(0);
right.resize(0);
for(int i=0,ni=leaves.size();i<ni;++i)
left.resize(0);
right.resize(0);
for(int i=0,ni=leaves.size();i<ni;++i)
{
if(dot(axis,leaves[i]->volume.Center()-org)<0)
left.push_back(leaves[i]);
@@ -249,24 +249,24 @@ for(int i=0,ni=leaves.size();i<ni;++i)
static btDbvtVolume bounds( const tNodeArray& leaves)
{
#if DBVT_MERGE_IMPL==DBVT_IMPL_SSE
DBVT_ALIGN char locals[sizeof(btDbvtVolume)];
btDbvtVolume& volume=*(btDbvtVolume*)locals;
volume=leaves[0]->volume;
DBVT_ALIGN char locals[sizeof(btDbvtVolume)];
btDbvtVolume& volume=*(btDbvtVolume*)locals;
volume=leaves[0]->volume;
#else
btDbvtVolume volume=leaves[0]->volume;
btDbvtVolume volume=leaves[0]->volume;
#endif
for(int i=1,ni=leaves.size();i<ni;++i)
for(int i=1,ni=leaves.size();i<ni;++i)
{
Merge(volume,leaves[i]->volume,volume);
}
return(volume);
return(volume);
}
//
static void bottomup( btDbvt* pdbvt,
tNodeArray& leaves)
{
while(leaves.size()>1)
while(leaves.size()>1)
{
btScalar minsize=SIMD_INFINITY;
int minidx[2]={-1,-1};
@@ -300,10 +300,10 @@ static btDbvtNode* topdown(btDbvt* pdbvt,
tNodeArray& leaves,
int bu_treshold)
{
static const btVector3 axis[]={btVector3(1,0,0),
static const btVector3 axis[]={btVector3(1,0,0),
btVector3(0,1,0),
btVector3(0,0,1)};
if(leaves.size()>1)
if(leaves.size()>1)
{
if(leaves.size()>bu_treshold)
{
@@ -362,15 +362,15 @@ if(leaves.size()>1)
return(leaves[0]);
}
}
return(leaves[0]);
return(leaves[0]);
}
//
static DBVT_INLINE btDbvtNode* sort(btDbvtNode* n,btDbvtNode*& r)
{
btDbvtNode* p=n->parent;
btAssert(n->isinternal());
if(p>n)
btDbvtNode* p=n->parent;
btAssert(n->isinternal());
if(p>n)
{
const int i=indexof(n);
const int j=1-i;
@@ -390,14 +390,14 @@ if(p>n)
btSwap(p->volume,n->volume);
return(p);
}
return(n);
return(n);
}
//
static DBVT_INLINE btDbvtNode* walkup(btDbvtNode* n,int count)
{
while(n&&(count--)) n=n->parent;
return(n);
while(n&&(count--)) n=n->parent;
return(n);
}
//
@@ -405,33 +405,33 @@ return(n);
//
//
btDbvt::btDbvt()
btDbvt::btDbvt()
{
m_root = 0;
m_free = 0;
m_lkhd = -1;
m_leaves = 0;
m_opath = 0;
m_root = 0;
m_free = 0;
m_lkhd = -1;
m_leaves = 0;
m_opath = 0;
}
//
btDbvt::~btDbvt()
btDbvt::~btDbvt()
{
clear();
clear();
}
//
void btDbvt::clear()
{
if(m_root) recursedeletenode(this,m_root);
btAlignedFree(m_free);
m_free=0;
if(m_root) recursedeletenode(this,m_root);
btAlignedFree(m_free);
m_free=0;
}
//
void btDbvt::optimizeBottomUp()
{
if(m_root)
if(m_root)
{
tNodeArray leaves;
leaves.reserve(m_leaves);
@@ -444,7 +444,7 @@ if(m_root)
//
void btDbvt::optimizeTopDown(int bu_treshold)
{
if(m_root)
if(m_root)
{
tNodeArray leaves;
leaves.reserve(m_leaves);
@@ -456,8 +456,8 @@ if(m_root)
//
void btDbvt::optimizeIncremental(int passes)
{
if(passes<0) passes=m_leaves;
if(m_root&&(passes>0))
if(passes<0) passes=m_leaves;
if(m_root&&(passes>0))
{
do {
btDbvtNode* node=m_root;
@@ -476,17 +476,17 @@ if(m_root&&(passes>0))
//
btDbvtNode* btDbvt::insert(const btDbvtVolume& volume,void* data)
{
btDbvtNode* leaf=createnode(this,0,volume,data);
insertleaf(this,m_root,leaf);
++m_leaves;
return(leaf);
btDbvtNode* leaf=createnode(this,0,volume,data);
insertleaf(this,m_root,leaf);
++m_leaves;
return(leaf);
}
//
void btDbvt::update(btDbvtNode* leaf,int lookahead)
{
btDbvtNode* root=removeleaf(this,leaf);
if(root)
btDbvtNode* root=removeleaf(this,leaf);
if(root)
{
if(lookahead>=0)
{
@@ -496,14 +496,14 @@ if(root)
}
} else root=m_root;
}
insertleaf(this,root,leaf);
insertleaf(this,root,leaf);
}
//
void btDbvt::update(btDbvtNode* leaf,const btDbvtVolume& volume)
{
btDbvtNode* root=removeleaf(this,leaf);
if(root)
btDbvtNode* root=removeleaf(this,leaf);
if(root)
{
if(m_lkhd>=0)
{
@@ -513,54 +513,54 @@ if(root)
}
} else root=m_root;
}
leaf->volume=volume;
insertleaf(this,root,leaf);
leaf->volume=volume;
insertleaf(this,root,leaf);
}
//
bool btDbvt::update(btDbvtNode* leaf,btDbvtVolume volume,const btVector3& velocity,btScalar margin)
{
if(leaf->volume.Contain(volume)) return(false);
volume.Expand(btVector3(margin,margin,margin));
volume.SignedExpand(velocity);
update(leaf,volume);
return(true);
if(leaf->volume.Contain(volume)) return(false);
volume.Expand(btVector3(margin,margin,margin));
volume.SignedExpand(velocity);
update(leaf,volume);
return(true);
}
//
bool btDbvt::update(btDbvtNode* leaf,btDbvtVolume volume,const btVector3& velocity)
{
if(leaf->volume.Contain(volume)) return(false);
volume.SignedExpand(velocity);
update(leaf,volume);
return(true);
if(leaf->volume.Contain(volume)) return(false);
volume.SignedExpand(velocity);
update(leaf,volume);
return(true);
}
//
bool btDbvt::update(btDbvtNode* leaf,btDbvtVolume volume,btScalar margin)
{
if(leaf->volume.Contain(volume)) return(false);
volume.Expand(btVector3(margin,margin,margin));
update(leaf,volume);
return(true);
if(leaf->volume.Contain(volume)) return(false);
volume.Expand(btVector3(margin,margin,margin));
update(leaf,volume);
return(true);
}
//
void btDbvt::remove(btDbvtNode* leaf)
{
removeleaf(this,leaf);
deletenode(this,leaf);
--m_leaves;
removeleaf(this,leaf);
deletenode(this,leaf);
--m_leaves;
}
//
void btDbvt::write(IWriter* iwriter) const
{
btDbvtNodeEnumerator nodes;
nodes.nodes.reserve(m_leaves*2);
enumNodes(m_root,nodes);
iwriter->Prepare(m_root,nodes.nodes.size());
for(int i=0;i<nodes.nodes.size();++i)
btDbvtNodeEnumerator nodes;
nodes.nodes.reserve(m_leaves*2);
enumNodes(m_root,nodes);
iwriter->Prepare(m_root,nodes.nodes.size());
for(int i=0;i<nodes.nodes.size();++i)
{
const btDbvtNode* n=nodes.nodes[i];
int p=-1;
@@ -581,8 +581,8 @@ for(int i=0;i<nodes.nodes.size();++i)
//
void btDbvt::clone(btDbvt& dest,IClone* iclone) const
{
dest.clear();
if(m_root!=0)
dest.clear();
if(m_root!=0)
{
btAlignedObjectArray<sStkCLN> stack;
stack.reserve(m_leaves);
@@ -612,15 +612,15 @@ if(m_root!=0)
//
int btDbvt::maxdepth(const btDbvtNode* node)
{
int depth=0;
if(node) getmaxdepth(node,1,depth);
return(depth);
int depth=0;
if(node) getmaxdepth(node,1,depth);
return(depth);
}
//
int btDbvt::countLeaves(const btDbvtNode* node)
{
if(node->isinternal())
if(node->isinternal())
return(countLeaves(node->childs[0])+countLeaves(node->childs[1]));
else
return(1);
@@ -629,7 +629,7 @@ if(node->isinternal())
//
void btDbvt::extractLeaves(const btDbvtNode* node,btAlignedObjectArray<const btDbvtNode*>& leaves)
{
if(node->isinternal())
if(node->isinternal())
{
extractLeaves(node->childs[0],leaves);
extractLeaves(node->childs[1],leaves);
@@ -657,12 +657,12 @@ q6600,2.4ghz
/W3 /nologo /c /Wp64 /Zi /errorReport:prompt
Benchmarking dbvt...
World scale: 100.000000
Extents base: 1.000000
Extents range: 4.000000
Leaves: 8192
sizeof(btDbvtVolume): 32 bytes
sizeof(btDbvtNode): 44 bytes
World scale: 100.000000
Extents base: 1.000000
Extents range: 4.000000
Leaves: 8192
sizeof(btDbvtVolume): 32 bytes
sizeof(btDbvtNode): 44 bytes
[1] btDbvtVolume intersections: 3499 ms (-1%)
[2] btDbvtVolume merges: 1934 ms (0%)
[3] btDbvt::collideTT: 5485 ms (-21%)
@@ -684,7 +684,7 @@ Benchmarking dbvt...
struct btDbvtBenchmark
{
struct NilPolicy : btDbvt::ICollide
struct NilPolicy : btDbvt::ICollide
{
NilPolicy() : m_pcount(0),m_depth(-SIMD_INFINITY),m_checksort(true) {}
void Process(const btDbvtNode*,const btDbvtNode*) { ++m_pcount; }
@@ -699,7 +699,7 @@ struct NilPolicy : btDbvt::ICollide
btScalar m_depth;
bool m_checksort;
};
struct P14 : btDbvt::ICollide
struct P14 : btDbvt::ICollide
{
struct Node
{
@@ -720,7 +720,7 @@ struct P14 : btDbvt::ICollide
}
btAlignedObjectArray<Node> m_nodes;
};
struct P15 : btDbvt::ICollide
struct P15 : btDbvt::ICollide
{
struct Node
{
@@ -742,30 +742,30 @@ struct P15 : btDbvt::ICollide
btAlignedObjectArray<Node> m_nodes;
btVector3 m_axis;
};
static btScalar RandUnit()
static btScalar RandUnit()
{
return(rand()/(btScalar)RAND_MAX);
}
static btVector3 RandVector3()
static btVector3 RandVector3()
{
return(btVector3(RandUnit(),RandUnit(),RandUnit()));
}
static btVector3 RandVector3(btScalar cs)
static btVector3 RandVector3(btScalar cs)
{
return(RandVector3()*cs-btVector3(cs,cs,cs)/2);
}
static btDbvtVolume RandVolume(btScalar cs,btScalar eb,btScalar es)
static btDbvtVolume RandVolume(btScalar cs,btScalar eb,btScalar es)
{
return(btDbvtVolume::FromCE(RandVector3(cs),btVector3(eb,eb,eb)+RandVector3()*es));
}
static btTransform RandTransform(btScalar cs)
static btTransform RandTransform(btScalar cs)
{
btTransform t;
t.setOrigin(RandVector3(cs));
t.setRotation(btQuaternion(RandUnit()*SIMD_PI*2,RandUnit()*SIMD_PI*2,RandUnit()*SIMD_PI*2).normalized());
return(t);
}
static void RandTree(btScalar cs,btScalar eb,btScalar es,int leaves,btDbvt& dbvt)
static void RandTree(btScalar cs,btScalar eb,btScalar es,int leaves,btDbvt& dbvt)
{
dbvt.clear();
for(int i=0;i<leaves;++i)
@@ -777,99 +777,99 @@ static void RandTree(btScalar cs,btScalar eb,btScalar es,int leaves,btDbvt& d
void btDbvt::benchmark()
{
static const btScalar cfgVolumeCenterScale = 100;
static const btScalar cfgVolumeExentsBase = 1;
static const btScalar cfgVolumeExentsScale = 4;
static const int cfgLeaves = 8192;
static const bool cfgEnable = true;
static const btScalar cfgVolumeCenterScale = 100;
static const btScalar cfgVolumeExentsBase = 1;
static const btScalar cfgVolumeExentsScale = 4;
static const int cfgLeaves = 8192;
static const bool cfgEnable = true;
//[1] btDbvtVolume intersections
bool cfgBenchmark1_Enable = cfgEnable;
static const int cfgBenchmark1_Iterations = 8;
static const int cfgBenchmark1_Reference = 3499;
//[2] btDbvtVolume merges
bool cfgBenchmark2_Enable = cfgEnable;
static const int cfgBenchmark2_Iterations = 4;
static const int cfgBenchmark2_Reference = 1945;
//[3] btDbvt::collideTT
bool cfgBenchmark3_Enable = cfgEnable;
static const int cfgBenchmark3_Iterations = 512;
static const int cfgBenchmark3_Reference = 5485;
//[4] btDbvt::collideTT self
bool cfgBenchmark4_Enable = cfgEnable;
static const int cfgBenchmark4_Iterations = 512;
static const int cfgBenchmark4_Reference = 2814;
//[5] btDbvt::collideTT xform
bool cfgBenchmark5_Enable = cfgEnable;
static const int cfgBenchmark5_Iterations = 512;
static const btScalar cfgBenchmark5_OffsetScale = 2;
static const int cfgBenchmark5_Reference = 7379;
//[6] btDbvt::collideTT xform,self
bool cfgBenchmark6_Enable = cfgEnable;
static const int cfgBenchmark6_Iterations = 512;
static const btScalar cfgBenchmark6_OffsetScale = 2;
static const int cfgBenchmark6_Reference = 7270;
//[7] btDbvt::rayTest
bool cfgBenchmark7_Enable = cfgEnable;
static const int cfgBenchmark7_Passes = 32;
static const int cfgBenchmark7_Iterations = 65536;
static const int cfgBenchmark7_Reference = 6307;
//[8] insert/remove
bool cfgBenchmark8_Enable = cfgEnable;
static const int cfgBenchmark8_Passes = 32;
static const int cfgBenchmark8_Iterations = 65536;
static const int cfgBenchmark8_Reference = 2105;
//[9] updates (teleport)
bool cfgBenchmark9_Enable = cfgEnable;
static const int cfgBenchmark9_Passes = 32;
static const int cfgBenchmark9_Iterations = 65536;
static const int cfgBenchmark9_Reference = 1879;
//[10] updates (jitter)
bool cfgBenchmark10_Enable = cfgEnable;
static const btScalar cfgBenchmark10_Scale = cfgVolumeCenterScale/10000;
static const int cfgBenchmark10_Passes = 32;
static const int cfgBenchmark10_Iterations = 65536;
static const int cfgBenchmark10_Reference = 1244;
//[11] optimize (incremental)
bool cfgBenchmark11_Enable = cfgEnable;
static const int cfgBenchmark11_Passes = 64;
static const int cfgBenchmark11_Iterations = 65536;
static const int cfgBenchmark11_Reference = 2510;
//[12] btDbvtVolume notequal
bool cfgBenchmark12_Enable = cfgEnable;
static const int cfgBenchmark12_Iterations = 32;
static const int cfgBenchmark12_Reference = 3677;
//[13] culling(OCL+fullsort)
bool cfgBenchmark13_Enable = cfgEnable;
static const int cfgBenchmark13_Iterations = 1024;
static const int cfgBenchmark13_Reference = 2231;
//[14] culling(OCL+qsort)
bool cfgBenchmark14_Enable = cfgEnable;
static const int cfgBenchmark14_Iterations = 8192;
static const int cfgBenchmark14_Reference = 3500;
//[15] culling(KDOP+qsort)
bool cfgBenchmark15_Enable = cfgEnable;
static const int cfgBenchmark15_Iterations = 8192;
static const int cfgBenchmark15_Reference = 1151;
//[16] insert/remove batch
bool cfgBenchmark16_Enable = cfgEnable;
static const int cfgBenchmark16_BatchCount = 256;
static const int cfgBenchmark16_Passes = 16384;
static const int cfgBenchmark16_Reference = 5138;
//[17] select
bool cfgBenchmark17_Enable = cfgEnable;
static const int cfgBenchmark17_Iterations = 4;
static const int cfgBenchmark17_Reference = 3390;
//[1] btDbvtVolume intersections
bool cfgBenchmark1_Enable = cfgEnable;
static const int cfgBenchmark1_Iterations = 8;
static const int cfgBenchmark1_Reference = 3499;
//[2] btDbvtVolume merges
bool cfgBenchmark2_Enable = cfgEnable;
static const int cfgBenchmark2_Iterations = 4;
static const int cfgBenchmark2_Reference = 1945;
//[3] btDbvt::collideTT
bool cfgBenchmark3_Enable = cfgEnable;
static const int cfgBenchmark3_Iterations = 512;
static const int cfgBenchmark3_Reference = 5485;
//[4] btDbvt::collideTT self
bool cfgBenchmark4_Enable = cfgEnable;
static const int cfgBenchmark4_Iterations = 512;
static const int cfgBenchmark4_Reference = 2814;
//[5] btDbvt::collideTT xform
bool cfgBenchmark5_Enable = cfgEnable;
static const int cfgBenchmark5_Iterations = 512;
static const btScalar cfgBenchmark5_OffsetScale = 2;
static const int cfgBenchmark5_Reference = 7379;
//[6] btDbvt::collideTT xform,self
bool cfgBenchmark6_Enable = cfgEnable;
static const int cfgBenchmark6_Iterations = 512;
static const btScalar cfgBenchmark6_OffsetScale = 2;
static const int cfgBenchmark6_Reference = 7270;
//[7] btDbvt::rayTest
bool cfgBenchmark7_Enable = cfgEnable;
static const int cfgBenchmark7_Passes = 32;
static const int cfgBenchmark7_Iterations = 65536;
static const int cfgBenchmark7_Reference = 6307;
//[8] insert/remove
bool cfgBenchmark8_Enable = cfgEnable;
static const int cfgBenchmark8_Passes = 32;
static const int cfgBenchmark8_Iterations = 65536;
static const int cfgBenchmark8_Reference = 2105;
//[9] updates (teleport)
bool cfgBenchmark9_Enable = cfgEnable;
static const int cfgBenchmark9_Passes = 32;
static const int cfgBenchmark9_Iterations = 65536;
static const int cfgBenchmark9_Reference = 1879;
//[10] updates (jitter)
bool cfgBenchmark10_Enable = cfgEnable;
static const btScalar cfgBenchmark10_Scale = cfgVolumeCenterScale/10000;
static const int cfgBenchmark10_Passes = 32;
static const int cfgBenchmark10_Iterations = 65536;
static const int cfgBenchmark10_Reference = 1244;
//[11] optimize (incremental)
bool cfgBenchmark11_Enable = cfgEnable;
static const int cfgBenchmark11_Passes = 64;
static const int cfgBenchmark11_Iterations = 65536;
static const int cfgBenchmark11_Reference = 2510;
//[12] btDbvtVolume notequal
bool cfgBenchmark12_Enable = cfgEnable;
static const int cfgBenchmark12_Iterations = 32;
static const int cfgBenchmark12_Reference = 3677;
//[13] culling(OCL+fullsort)
bool cfgBenchmark13_Enable = cfgEnable;
static const int cfgBenchmark13_Iterations = 1024;
static const int cfgBenchmark13_Reference = 2231;
//[14] culling(OCL+qsort)
bool cfgBenchmark14_Enable = cfgEnable;
static const int cfgBenchmark14_Iterations = 8192;
static const int cfgBenchmark14_Reference = 3500;
//[15] culling(KDOP+qsort)
bool cfgBenchmark15_Enable = cfgEnable;
static const int cfgBenchmark15_Iterations = 8192;
static const int cfgBenchmark15_Reference = 1151;
//[16] insert/remove batch
bool cfgBenchmark16_Enable = cfgEnable;
static const int cfgBenchmark16_BatchCount = 256;
static const int cfgBenchmark16_Passes = 16384;
static const int cfgBenchmark16_Reference = 5138;
//[17] select
bool cfgBenchmark17_Enable = cfgEnable;
static const int cfgBenchmark17_Iterations = 4;
static const int cfgBenchmark17_Reference = 3390;
btClock wallclock;
printf("Benchmarking dbvt...\r\n");
printf("\tWorld scale: %f\r\n",cfgVolumeCenterScale);
printf("\tExtents base: %f\r\n",cfgVolumeExentsBase);
printf("\tExtents range: %f\r\n",cfgVolumeExentsScale);
printf("\tLeaves: %u\r\n",cfgLeaves);
printf("\tsizeof(btDbvtVolume): %u bytes\r\n",sizeof(btDbvtVolume));
printf("\tsizeof(btDbvtNode): %u bytes\r\n",sizeof(btDbvtNode));
if(cfgBenchmark1_Enable)
btClock wallclock;
printf("Benchmarking dbvt...\r\n");
printf("\tWorld scale: %f\r\n",cfgVolumeCenterScale);
printf("\tExtents base: %f\r\n",cfgVolumeExentsBase);
printf("\tExtents range: %f\r\n",cfgVolumeExentsScale);
printf("\tLeaves: %u\r\n",cfgLeaves);
printf("\tsizeof(btDbvtVolume): %u bytes\r\n",sizeof(btDbvtVolume));
printf("\tsizeof(btDbvtNode): %u bytes\r\n",sizeof(btDbvtNode));
if(cfgBenchmark1_Enable)
{// Benchmark 1
srand(380843);
btAlignedObjectArray<btDbvtVolume> volumes;
@@ -895,7 +895,7 @@ if(cfgBenchmark1_Enable)
const int time=(int)wallclock.getTimeMilliseconds();
printf("%u ms (%i%%)\r\n",time,(time-cfgBenchmark1_Reference)*100/time);
}
if(cfgBenchmark2_Enable)
if(cfgBenchmark2_Enable)
{// Benchmark 2
srand(380843);
btAlignedObjectArray<btDbvtVolume> volumes;
@@ -921,7 +921,7 @@ if(cfgBenchmark2_Enable)
const int time=(int)wallclock.getTimeMilliseconds();
printf("%u ms (%i%%)\r\n",time,(time-cfgBenchmark2_Reference)*100/time);
}
if(cfgBenchmark3_Enable)
if(cfgBenchmark3_Enable)
{// Benchmark 3
srand(380843);
btDbvt dbvt[2];
@@ -939,7 +939,7 @@ if(cfgBenchmark3_Enable)
const int time=(int)wallclock.getTimeMilliseconds();
printf("%u ms (%i%%)\r\n",time,(time-cfgBenchmark3_Reference)*100/time);
}
if(cfgBenchmark4_Enable)
if(cfgBenchmark4_Enable)
{// Benchmark 4
srand(380843);
btDbvt dbvt;
@@ -955,7 +955,7 @@ if(cfgBenchmark4_Enable)
const int time=(int)wallclock.getTimeMilliseconds();
printf("%u ms (%i%%)\r\n",time,(time-cfgBenchmark4_Reference)*100/time);
}
if(cfgBenchmark5_Enable)
if(cfgBenchmark5_Enable)
{// Benchmark 5
srand(380843);
btDbvt dbvt[2];
@@ -979,7 +979,7 @@ if(cfgBenchmark5_Enable)
const int time=(int)wallclock.getTimeMilliseconds();
printf("%u ms (%i%%)\r\n",time,(time-cfgBenchmark5_Reference)*100/time);
}
if(cfgBenchmark6_Enable)
if(cfgBenchmark6_Enable)
{// Benchmark 6
srand(380843);
btDbvt dbvt;
@@ -1001,7 +1001,7 @@ if(cfgBenchmark6_Enable)
const int time=(int)wallclock.getTimeMilliseconds();
printf("%u ms (%i%%)\r\n",time,(time-cfgBenchmark6_Reference)*100/time);
}
if(cfgBenchmark7_Enable)
if(cfgBenchmark7_Enable)
{// Benchmark 7
srand(380843);
btDbvt dbvt;
@@ -1030,7 +1030,7 @@ if(cfgBenchmark7_Enable)
unsigned rays=cfgBenchmark7_Passes*cfgBenchmark7_Iterations;
printf("%u ms (%i%%),(%u r/s)\r\n",time,(time-cfgBenchmark7_Reference)*100/time,(rays*1000)/time);
}
if(cfgBenchmark8_Enable)
if(cfgBenchmark8_Enable)
{// Benchmark 8
srand(380843);
btDbvt dbvt;
@@ -1049,7 +1049,7 @@ if(cfgBenchmark8_Enable)
const int ir=cfgBenchmark8_Passes*cfgBenchmark8_Iterations;
printf("%u ms (%i%%),(%u ir/s)\r\n",time,(time-cfgBenchmark8_Reference)*100/time,ir*1000/time);
}
if(cfgBenchmark9_Enable)
if(cfgBenchmark9_Enable)
{// Benchmark 9
srand(380843);
btDbvt dbvt;
@@ -1071,7 +1071,7 @@ if(cfgBenchmark9_Enable)
const int up=cfgBenchmark9_Passes*cfgBenchmark9_Iterations;
printf("%u ms (%i%%),(%u u/s)\r\n",time,(time-cfgBenchmark9_Reference)*100/time,up*1000/time);
}
if(cfgBenchmark10_Enable)
if(cfgBenchmark10_Enable)
{// Benchmark 10
srand(380843);
btDbvt dbvt;
@@ -1102,7 +1102,7 @@ if(cfgBenchmark10_Enable)
const int up=cfgBenchmark10_Passes*cfgBenchmark10_Iterations;
printf("%u ms (%i%%),(%u u/s)\r\n",time,(time-cfgBenchmark10_Reference)*100/time,up*1000/time);
}
if(cfgBenchmark11_Enable)
if(cfgBenchmark11_Enable)
{// Benchmark 11
srand(380843);
btDbvt dbvt;
@@ -1118,7 +1118,7 @@ if(cfgBenchmark11_Enable)
const int op=cfgBenchmark11_Passes*cfgBenchmark11_Iterations;
printf("%u ms (%i%%),(%u o/s)\r\n",time,(time-cfgBenchmark11_Reference)*100/time,op/time*1000);
}
if(cfgBenchmark12_Enable)
if(cfgBenchmark12_Enable)
{// Benchmark 12
srand(380843);
btAlignedObjectArray<btDbvtVolume> volumes;
@@ -1144,7 +1144,7 @@ if(cfgBenchmark12_Enable)
const int time=(int)wallclock.getTimeMilliseconds();
printf("%u ms (%i%%)\r\n",time,(time-cfgBenchmark12_Reference)*100/time);
}
if(cfgBenchmark13_Enable)
if(cfgBenchmark13_Enable)
{// Benchmark 13
srand(380843);
btDbvt dbvt;
@@ -1169,7 +1169,7 @@ if(cfgBenchmark13_Enable)
const int t=cfgBenchmark13_Iterations;
printf("%u ms (%i%%),(%u t/s)\r\n",time,(time-cfgBenchmark13_Reference)*100/time,(t*1000)/time);
}
if(cfgBenchmark14_Enable)
if(cfgBenchmark14_Enable)
{// Benchmark 14
srand(380843);
btDbvt dbvt;
@@ -1196,7 +1196,7 @@ if(cfgBenchmark14_Enable)
const int t=cfgBenchmark14_Iterations;
printf("%u ms (%i%%),(%u t/s)\r\n",time,(time-cfgBenchmark14_Reference)*100/time,(t*1000)/time);
}
if(cfgBenchmark15_Enable)
if(cfgBenchmark15_Enable)
{// Benchmark 15
srand(380843);
btDbvt dbvt;
@@ -1224,7 +1224,7 @@ if(cfgBenchmark15_Enable)
const int t=cfgBenchmark15_Iterations;
printf("%u ms (%i%%),(%u t/s)\r\n",time,(time-cfgBenchmark15_Reference)*100/time,(t*1000)/time);
}
if(cfgBenchmark16_Enable)
if(cfgBenchmark16_Enable)
{// Benchmark 16
srand(380843);
btDbvt dbvt;
@@ -1250,7 +1250,7 @@ if(cfgBenchmark16_Enable)
const int ir=cfgBenchmark16_Passes*cfgBenchmark16_BatchCount;
printf("%u ms (%i%%),(%u bir/s)\r\n",time,(time-cfgBenchmark16_Reference)*100/time,int(ir*1000.0/time));
}
if(cfgBenchmark17_Enable)
if(cfgBenchmark17_Enable)
{// Benchmark 17
srand(380843);
btAlignedObjectArray<btDbvtVolume> volumes;
@@ -1284,6 +1284,6 @@ if(cfgBenchmark17_Enable)
const int time=(int)wallclock.getTimeMilliseconds();
printf("%u ms (%i%%)\r\n",time,(time-cfgBenchmark17_Reference)*100/time);
}
printf("\r\n\r\n");
printf("\r\n\r\n");
}
#endif

View File

@@ -33,10 +33,10 @@ subject to the following restrictions:
// Template implementation of ICollide
#ifdef WIN32
#if (defined (_MSC_VER) && _MSC_VER >= 1400)
#define DBVT_USE_TEMPLATE 1
#else
#define DBVT_USE_TEMPLATE 0
#if (defined (_MSC_VER) && _MSC_VER >= 1400)
#define DBVT_USE_TEMPLATE 1
#else
#define DBVT_USE_TEMPLATE 0
#endif
#else
#define DBVT_USE_TEMPLATE 0
@@ -135,43 +135,43 @@ subject to the following restrictions:
/* btDbvtAabbMm */
struct btDbvtAabbMm
{
DBVT_INLINE btVector3 Center() const { return((mi+mx)/2); }
DBVT_INLINE btVector3 Lengths() const { return(mx-mi); }
DBVT_INLINE btVector3 Extents() const { return((mx-mi)/2); }
DBVT_INLINE const btVector3& Mins() const { return(mi); }
DBVT_INLINE const btVector3& Maxs() const { return(mx); }
static inline btDbvtAabbMm FromCE(const btVector3& c,const btVector3& e);
static inline btDbvtAabbMm FromCR(const btVector3& c,btScalar r);
static inline btDbvtAabbMm FromMM(const btVector3& mi,const btVector3& mx);
static inline btDbvtAabbMm FromPoints(const btVector3* pts,int n);
static inline btDbvtAabbMm FromPoints(const btVector3** ppts,int n);
DBVT_INLINE void Expand(const btVector3& e);
DBVT_INLINE void SignedExpand(const btVector3& e);
DBVT_INLINE bool Contain(const btDbvtAabbMm& a) const;
DBVT_INLINE int Classify(const btVector3& n,btScalar o,int s) const;
DBVT_INLINE btScalar ProjectMinimum(const btVector3& v,unsigned signs) const;
DBVT_INLINE friend bool Intersect( const btDbvtAabbMm& a,
DBVT_INLINE btVector3 Center() const { return((mi+mx)/2); }
DBVT_INLINE btVector3 Lengths() const { return(mx-mi); }
DBVT_INLINE btVector3 Extents() const { return((mx-mi)/2); }
DBVT_INLINE const btVector3& Mins() const { return(mi); }
DBVT_INLINE const btVector3& Maxs() const { return(mx); }
static inline btDbvtAabbMm FromCE(const btVector3& c,const btVector3& e);
static inline btDbvtAabbMm FromCR(const btVector3& c,btScalar r);
static inline btDbvtAabbMm FromMM(const btVector3& mi,const btVector3& mx);
static inline btDbvtAabbMm FromPoints(const btVector3* pts,int n);
static inline btDbvtAabbMm FromPoints(const btVector3** ppts,int n);
DBVT_INLINE void Expand(const btVector3& e);
DBVT_INLINE void SignedExpand(const btVector3& e);
DBVT_INLINE bool Contain(const btDbvtAabbMm& a) const;
DBVT_INLINE int Classify(const btVector3& n,btScalar o,int s) const;
DBVT_INLINE btScalar ProjectMinimum(const btVector3& v,unsigned signs) const;
DBVT_INLINE friend bool Intersect( const btDbvtAabbMm& a,
const btDbvtAabbMm& b);
DBVT_INLINE friend bool Intersect( const btDbvtAabbMm& a,
DBVT_INLINE friend bool Intersect( const btDbvtAabbMm& a,
const btDbvtAabbMm& b,
const btTransform& xform);
DBVT_INLINE friend bool Intersect( const btDbvtAabbMm& a,
DBVT_INLINE friend bool Intersect( const btDbvtAabbMm& a,
const btVector3& b);
DBVT_INLINE friend btScalar Proximity( const btDbvtAabbMm& a,
DBVT_INLINE friend btScalar Proximity( const btDbvtAabbMm& a,
const btDbvtAabbMm& b);
DBVT_INLINE friend int Select( const btDbvtAabbMm& o,
DBVT_INLINE friend int Select( const btDbvtAabbMm& o,
const btDbvtAabbMm& a,
const btDbvtAabbMm& b);
DBVT_INLINE friend void Merge( const btDbvtAabbMm& a,
DBVT_INLINE friend void Merge( const btDbvtAabbMm& a,
const btDbvtAabbMm& b,
btDbvtAabbMm& r);
DBVT_INLINE friend bool NotEqual( const btDbvtAabbMm& a,
DBVT_INLINE friend bool NotEqual( const btDbvtAabbMm& a,
const btDbvtAabbMm& b);
private:
DBVT_INLINE void AddSpan(const btVector3& d,btScalar& smi,btScalar& smx) const;
DBVT_INLINE void AddSpan(const btVector3& d,btScalar& smi,btScalar& smx) const;
private:
btVector3 mi,mx;
btVector3 mi,mx;
};
// Types
@@ -195,7 +195,7 @@ struct btDbvtNode
///This btDbvt is used for soft body collision detection and for the btDbvtBroadphase. It has a fast insert, remove and update of nodes.
///Unlike the btQuantizedBvh, nodes can be dynamically moved around, which allows for change in topology of the underlying data structure.
struct btDbvt
{
{
/* Stack element */
struct sStkNN
{
@@ -283,11 +283,11 @@ struct btDbvt
static int maxdepth(const btDbvtNode* node);
static int countLeaves(const btDbvtNode* node);
static void extractLeaves(const btDbvtNode* node,btAlignedObjectArray<const btDbvtNode*>& leaves);
#if DBVT_ENABLE_BENCHMARK
#if DBVT_ENABLE_BENCHMARK
static void benchmark();
#else
#else
static void benchmark(){}
#endif
#endif
// DBVT_IPOLICY must support ICollide policy/interface
DBVT_PREFIX
static void enumNodes( const btDbvtNode* root,
@@ -359,9 +359,9 @@ struct btDbvt
return(i);
}
//
private:
private:
btDbvt(const btDbvt&) {}
};
};
//
// Inline's
@@ -370,69 +370,69 @@ struct btDbvt
//
inline btDbvtAabbMm btDbvtAabbMm::FromCE(const btVector3& c,const btVector3& e)
{
btDbvtAabbMm box;
box.mi=c-e;box.mx=c+e;
return(box);
btDbvtAabbMm box;
box.mi=c-e;box.mx=c+e;
return(box);
}
//
inline btDbvtAabbMm btDbvtAabbMm::FromCR(const btVector3& c,btScalar r)
{
return(FromCE(c,btVector3(r,r,r)));
return(FromCE(c,btVector3(r,r,r)));
}
//
inline btDbvtAabbMm btDbvtAabbMm::FromMM(const btVector3& mi,const btVector3& mx)
{
btDbvtAabbMm box;
box.mi=mi;box.mx=mx;
return(box);
btDbvtAabbMm box;
box.mi=mi;box.mx=mx;
return(box);
}
//
inline btDbvtAabbMm btDbvtAabbMm::FromPoints(const btVector3* pts,int n)
{
btDbvtAabbMm box;
box.mi=box.mx=pts[0];
for(int i=1;i<n;++i)
btDbvtAabbMm box;
box.mi=box.mx=pts[0];
for(int i=1;i<n;++i)
{
box.mi.setMin(pts[i]);
box.mx.setMax(pts[i]);
}
return(box);
return(box);
}
//
inline btDbvtAabbMm btDbvtAabbMm::FromPoints(const btVector3** ppts,int n)
{
btDbvtAabbMm box;
box.mi=box.mx=*ppts[0];
for(int i=1;i<n;++i)
btDbvtAabbMm box;
box.mi=box.mx=*ppts[0];
for(int i=1;i<n;++i)
{
box.mi.setMin(*ppts[i]);
box.mx.setMax(*ppts[i]);
}
return(box);
return(box);
}
//
DBVT_INLINE void btDbvtAabbMm::Expand(const btVector3& e)
{
mi-=e;mx+=e;
mi-=e;mx+=e;
}
//
DBVT_INLINE void btDbvtAabbMm::SignedExpand(const btVector3& e)
{
if(e.x()>0) mx.setX(mx.x()+e[0]); else mi.setX(mi.x()+e[0]);
if(e.y()>0) mx.setY(mx.y()+e[1]); else mi.setY(mi.y()+e[1]);
if(e.z()>0) mx.setZ(mx.z()+e[2]); else mi.setZ(mi.z()+e[2]);
if(e.x()>0) mx.setX(mx.x()+e[0]); else mi.setX(mi.x()+e[0]);
if(e.y()>0) mx.setY(mx.y()+e[1]); else mi.setY(mi.y()+e[1]);
if(e.z()>0) mx.setZ(mx.z()+e[2]); else mi.setZ(mi.z()+e[2]);
}
//
DBVT_INLINE bool btDbvtAabbMm::Contain(const btDbvtAabbMm& a) const
{
return( (mi.x()<=a.mi.x())&&
return( (mi.x()<=a.mi.x())&&
(mi.y()<=a.mi.y())&&
(mi.z()<=a.mi.z())&&
(mx.x()>=a.mx.x())&&
@@ -443,8 +443,8 @@ return( (mi.x()<=a.mi.x())&&
//
DBVT_INLINE int btDbvtAabbMm::Classify(const btVector3& n,btScalar o,int s) const
{
btVector3 pi,px;
switch(s)
btVector3 pi,px;
switch(s)
{
case (0+0+0): px=btVector3(mi.x(),mi.y(),mi.z());
pi=btVector3(mx.x(),mx.y(),mx.z());break;
@@ -463,25 +463,25 @@ switch(s)
case (1+2+4): px=btVector3(mx.x(),mx.y(),mx.z());
pi=btVector3(mi.x(),mi.y(),mi.z());break;
}
if((dot(n,px)+o)<0) return(-1);
if((dot(n,pi)+o)>=0) return(+1);
return(0);
if((dot(n,px)+o)<0) return(-1);
if((dot(n,pi)+o)>=0) return(+1);
return(0);
}
//
DBVT_INLINE btScalar btDbvtAabbMm::ProjectMinimum(const btVector3& v,unsigned signs) const
{
const btVector3* b[]={&mx,&mi};
const btVector3 p( b[(signs>>0)&1]->x(),
const btVector3* b[]={&mx,&mi};
const btVector3 p( b[(signs>>0)&1]->x(),
b[(signs>>1)&1]->y(),
b[(signs>>2)&1]->z());
return(dot(p,v));
return(dot(p,v));
}
//
DBVT_INLINE void btDbvtAabbMm::AddSpan(const btVector3& d,btScalar& smi,btScalar& smx) const
{
for(int i=0;i<3;++i)
for(int i=0;i<3;++i)
{
if(d[i]<0)
{ smi+=mx[i]*d[i];smx+=mi[i]*d[i]; }
@@ -495,12 +495,12 @@ DBVT_INLINE bool Intersect( const btDbvtAabbMm& a,
const btDbvtAabbMm& b)
{
#if DBVT_INT0_IMPL == DBVT_IMPL_SSE
const __m128 rt(_mm_or_ps( _mm_cmplt_ps(_mm_load_ps(b.mx),_mm_load_ps(a.mi)),
const __m128 rt(_mm_or_ps( _mm_cmplt_ps(_mm_load_ps(b.mx),_mm_load_ps(a.mi)),
_mm_cmplt_ps(_mm_load_ps(a.mx),_mm_load_ps(b.mi))));
const __int32* pu((const __int32*)&rt);
return((pu[0]|pu[1]|pu[2])==0);
const __int32* pu((const __int32*)&rt);
return((pu[0]|pu[1]|pu[2])==0);
#else
return( (a.mi.x()<=b.mx.x())&&
return( (a.mi.x()<=b.mx.x())&&
(a.mx.x()>=b.mi.x())&&
(a.mi.y()<=b.mx.y())&&
(a.mx.y()>=b.mi.y())&&
@@ -514,22 +514,22 @@ DBVT_INLINE bool Intersect( const btDbvtAabbMm& a,
const btDbvtAabbMm& b,
const btTransform& xform)
{
const btVector3 d0=xform*b.Center()-a.Center();
const btVector3 d1=d0*xform.getBasis();
btScalar s0[2]={0,0};
btScalar s1[2]={dot(xform.getOrigin(),d0),s1[0]};
a.AddSpan(d0,s0[0],s0[1]);
b.AddSpan(d1,s1[0],s1[1]);
if(s0[0]>(s1[1])) return(false);
if(s0[1]<(s1[0])) return(false);
return(true);
const btVector3 d0=xform*b.Center()-a.Center();
const btVector3 d1=d0*xform.getBasis();
btScalar s0[2]={0,0};
btScalar s1[2]={dot(xform.getOrigin(),d0),s1[0]};
a.AddSpan(d0,s0[0],s0[1]);
b.AddSpan(d1,s1[0],s1[1]);
if(s0[0]>(s1[1])) return(false);
if(s0[1]<(s1[0])) return(false);
return(true);
}
//
DBVT_INLINE bool Intersect( const btDbvtAabbMm& a,
const btVector3& b)
{
return( (b.x()>=a.mi.x())&&
return( (b.x()>=a.mi.x())&&
(b.y()>=a.mi.y())&&
(b.z()>=a.mi.z())&&
(b.x()<=a.mx.x())&&
@@ -548,8 +548,8 @@ return( (b.x()>=a.mi.x())&&
DBVT_INLINE btScalar Proximity( const btDbvtAabbMm& a,
const btDbvtAabbMm& b)
{
const btVector3 d=(a.mi+a.mx)-(b.mi+b.mx);
return(btFabs(d.x())+btFabs(d.y())+btFabs(d.z()));
const btVector3 d=(a.mi+a.mx)-(b.mi+b.mx);
return(btFabs(d.x())+btFabs(d.y())+btFabs(d.z()));
}
//
@@ -558,9 +558,9 @@ DBVT_INLINE int Select( const btDbvtAabbMm& o,
const btDbvtAabbMm& b)
{
#if DBVT_SELECT_IMPL == DBVT_IMPL_SSE
static DBVT_ALIGN const unsigned __int32 mask[]={0x7fffffff,0x7fffffff,0x7fffffff,0x7fffffff};
static DBVT_ALIGN const unsigned __int32 mask[]={0x7fffffff,0x7fffffff,0x7fffffff,0x7fffffff};
// TODO: the intrinsic version is 11% slower
#if DBVT_USE_INTRINSIC_SSE
#if DBVT_USE_INTRINSIC_SSE
__m128 omi(_mm_load_ps(o.mi));
omi=_mm_add_ps(omi,_mm_load_ps(o.mx));
__m128 ami(_mm_load_ps(a.mi));
@@ -578,7 +578,7 @@ static DBVT_ALIGN const unsigned __int32 mask[]={0x7fffffff,0x7fffffff,0x7ffffff
bmi=_mm_add_ps(bmi,t1);
bmi=_mm_add_ss(bmi,_mm_shuffle_ps(bmi,bmi,1));
return(_mm_cmple_ss(bmi,ami).m128_u32[0]&1);
#else
#else
DBVT_ALIGN __int32 r[1];
__asm
{
@@ -608,9 +608,9 @@ static DBVT_ALIGN const unsigned __int32 mask[]={0x7fffffff,0x7fffffff,0x7ffffff
movss r,xmm2
}
return(r[0]&1);
#endif
#endif
#else
return(Proximity(o,a)<Proximity(o,b)?0:1);
return(Proximity(o,a)<Proximity(o,b)?0:1);
#endif
}
@@ -620,16 +620,16 @@ DBVT_INLINE void Merge( const btDbvtAabbMm& a,
btDbvtAabbMm& r)
{
#if DBVT_MERGE_IMPL==DBVT_IMPL_SSE
__m128 ami(_mm_load_ps(a.mi));
__m128 amx(_mm_load_ps(a.mx));
__m128 bmi(_mm_load_ps(b.mi));
__m128 bmx(_mm_load_ps(b.mx));
ami=_mm_min_ps(ami,bmi);
amx=_mm_max_ps(amx,bmx);
_mm_store_ps(r.mi,ami);
_mm_store_ps(r.mx,amx);
__m128 ami(_mm_load_ps(a.mi));
__m128 amx(_mm_load_ps(a.mx));
__m128 bmi(_mm_load_ps(b.mi));
__m128 bmx(_mm_load_ps(b.mx));
ami=_mm_min_ps(ami,bmi);
amx=_mm_max_ps(amx,bmx);
_mm_store_ps(r.mi,ami);
_mm_store_ps(r.mx,amx);
#else
for(int i=0;i<3;++i)
for(int i=0;i<3;++i)
{
if(a.mi[i]<b.mi[i]) r.mi[i]=a.mi[i]; else r.mi[i]=b.mi[i];
if(a.mx[i]>b.mx[i]) r.mx[i]=a.mx[i]; else r.mx[i]=b.mx[i];
@@ -641,7 +641,7 @@ for(int i=0;i<3;++i)
DBVT_INLINE bool NotEqual( const btDbvtAabbMm& a,
const btDbvtAabbMm& b)
{
return( (a.mi.x()!=b.mi.x())||
return( (a.mi.x()!=b.mi.x())||
(a.mi.y()!=b.mi.y())||
(a.mi.z()!=b.mi.z())||
(a.mx.x()!=b.mx.x())||
@@ -658,9 +658,9 @@ DBVT_PREFIX
inline void btDbvt::enumNodes( const btDbvtNode* root,
DBVT_IPOLICY)
{
DBVT_CHECKTYPE
policy.Process(root);
if(root->isinternal())
DBVT_CHECKTYPE
policy.Process(root);
if(root->isinternal())
{
enumNodes(root->childs[0],policy);
enumNodes(root->childs[1],policy);
@@ -672,8 +672,8 @@ DBVT_PREFIX
inline void btDbvt::enumLeaves( const btDbvtNode* root,
DBVT_IPOLICY)
{
DBVT_CHECKTYPE
if(root->isinternal())
DBVT_CHECKTYPE
if(root->isinternal())
{
enumLeaves(root->childs[0],policy);
enumLeaves(root->childs[1],policy);
@@ -690,8 +690,8 @@ inline void btDbvt::collideTT( const btDbvtNode* root0,
const btDbvtNode* root1,
DBVT_IPOLICY)
{
DBVT_CHECKTYPE
if(root0&&root1)
DBVT_CHECKTYPE
if(root0&&root1)
{
btAlignedObjectArray<sStkNN> stack;
int depth=1;
@@ -755,8 +755,8 @@ inline void btDbvt::collideTT( const btDbvtNode* root0,
const btTransform& xform,
DBVT_IPOLICY)
{
DBVT_CHECKTYPE
if(root0&&root1)
DBVT_CHECKTYPE
if(root0&&root1)
{
btAlignedObjectArray<sStkNN> stack;
int depth=1;
@@ -812,8 +812,8 @@ inline void btDbvt::collideTT( const btDbvtNode* root0,
const btTransform& xform1,
DBVT_IPOLICY)
{
const btTransform xform=xform0.inverse()*xform1;
collideTT(root0,root1,xform,policy);
const btTransform xform=xform0.inverse()*xform1;
collideTT(root0,root1,xform,policy);
}
//
@@ -822,8 +822,8 @@ inline void btDbvt::collideTV( const btDbvtNode* root,
const btDbvtVolume& vol,
DBVT_IPOLICY)
{
DBVT_CHECKTYPE
if(root)
DBVT_CHECKTYPE
if(root)
{
ATTRIBUTE_ALIGNED16(btDbvtVolume) volume(vol);
btAlignedObjectArray<const btDbvtNode*> stack;
@@ -856,7 +856,7 @@ inline void btDbvt::rayTest( const btDbvtNode* root,
const btVector3& rayTo,
DBVT_IPOLICY)
{
DBVT_CHECKTYPE
DBVT_CHECKTYPE
if(root)
{
btVector3 rayDir = (rayTo-rayFrom);
@@ -915,8 +915,8 @@ inline void btDbvt::collideKDOP(const btDbvtNode* root,
int count,
DBVT_IPOLICY)
{
DBVT_CHECKTYPE
if(root)
DBVT_CHECKTYPE
if(root)
{
const int inside=(1<<count)-1;
btAlignedObjectArray<sStkNP> stack;
@@ -972,8 +972,8 @@ inline void btDbvt::collideOCL( const btDbvtNode* root,
DBVT_IPOLICY,
bool fsort)
{
DBVT_CHECKTYPE
if(root)
DBVT_CHECKTYPE
if(root)
{
const unsigned srtsgns=(sortaxis[0]>=0?1:0)+
(sortaxis[1]>=0?2:0)+
@@ -1029,20 +1029,20 @@ if(root)
/* Insert 0 */
j=nearest(&stack[0],&stock[0],nes[q].value,0,stack.size());
stack.push_back(0);
#if DBVT_USE_MEMMOVE
#if DBVT_USE_MEMMOVE
memmove(&stack[j+1],&stack[j],sizeof(int)*(stack.size()-j-1));
#else
#else
for(int k=stack.size()-1;k>j;--k) stack[k]=stack[k-1];
#endif
#endif
stack[j]=allocate(ifree,stock,nes[q]);
/* Insert 1 */
j=nearest(&stack[0],&stock[0],nes[1-q].value,j,stack.size());
stack.push_back(0);
#if DBVT_USE_MEMMOVE
#if DBVT_USE_MEMMOVE
memmove(&stack[j+1],&stack[j],sizeof(int)*(stack.size()-j-1));
#else
#else
for(int k=stack.size()-1;k>j;--k) stack[k]=stack[k-1];
#endif
#endif
stack[j]=allocate(ifree,stock,nes[1-q]);
}
else
@@ -1065,8 +1065,8 @@ DBVT_PREFIX
inline void btDbvt::collideTU( const btDbvtNode* root,
DBVT_IPOLICY)
{
DBVT_CHECKTYPE
if(root)
DBVT_CHECKTYPE
if(root)
{
btAlignedObjectArray<const btDbvtNode*> stack;
stack.reserve(SIMPLE_STACKSIZE);

View File

@@ -26,7 +26,7 @@ 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())
{
@@ -38,7 +38,7 @@ struct ProfileScope
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,23 +90,23 @@ value=zerodummy;
/* Tree collider */
struct btDbvtTreeCollider : btDbvt::ICollide
{
btDbvtBroadphase* pbp;
btDbvtProxy* proxy;
btDbvtBroadphase* pbp;
btDbvtProxy* proxy;
btDbvtTreeCollider(btDbvtBroadphase* p) : pbp(p) {}
void Process(const btDbvtNode* na,const btDbvtNode* nb)
void Process(const btDbvtNode* na,const btDbvtNode* nb)
{
if(na!=nb)
{
btDbvtProxy* pa=(btDbvtProxy*)na->data;
btDbvtProxy* pb=(btDbvtProxy*)nb->data;
#if DBVT_BP_SORTPAIRS
#if DBVT_BP_SORTPAIRS
if(pa>pb) btSwap(pa,pb);
#endif
#endif
pbp->m_paircache->addOverlappingPair(pa,pb);
++pbp->m_newpairs;
}
}
void Process(const btDbvtNode* n)
void Process(const btDbvtNode* n)
{
Process(n,proxy->leaf);
}
@@ -119,42 +119,42 @@ 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 :
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_gid = 0;
m_pid = 0;
m_cid = 0;
for(int i=0;i<=STAGECOUNT;++i)
{
m_stageRoots[i]=0;
}
#if DBVT_BP_PROFILE
clear(m_profiling);
clear(m_profiling);
#endif
}
//
btDbvtBroadphase::~btDbvtBroadphase()
{
if(m_releasepaircache)
{
if(m_releasepaircache)
{
m_paircache->~btOverlappingPairCache();
btAlignedFree(m_paircache);
}
}
}
//
@@ -167,40 +167,40 @@ btBroadphaseProxy* btDbvtBroadphase::createProxy( const btVector3& aabbMin,
btDispatcher* /*dispatcher*/,
void* /*multiSapProxy*/)
{
btDbvtProxy* proxy=new(btAlignedAlloc(sizeof(btDbvtProxy),16)) btDbvtProxy( aabbMin,aabbMax,userPtr,
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);
}
return(proxy);
return(proxy);
}
//
void btDbvtBroadphase::destroyProxy( btBroadphaseProxy* absproxy,
btDispatcher* dispatcher)
{
btDbvtProxy* proxy=(btDbvtProxy*)absproxy;
if(proxy->stage==STAGECOUNT)
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;
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
@@ -247,10 +247,10 @@ void btDbvtBroadphase::setAabb( btBroadphaseProxy* absproxy,
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;
@@ -272,11 +272,11 @@ if(NotEqual(aabb,proxy->leaf->volume))
if(delta[1]<0) velocity[1]=-velocity[1];
if(delta[2]<0) velocity[2]=-velocity[2];
if (
#ifdef DBVT_BP_MARGIN
#ifdef DBVT_BP_MARGIN
m_sets[0].update(proxy->leaf,aabb,velocity,DBVT_BP_MARGIN)
#else
#else
m_sets[0].update(proxy->leaf,aabb,velocity)
#endif
#endif
)
{
++m_updates_done;
@@ -311,9 +311,9 @@ 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;
@@ -336,31 +336,31 @@ 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);
}
/* 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
#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
#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);
@@ -370,7 +370,7 @@ if(current)
m_fixedleft=m_sets[1].m_leaves;
m_needcleanup=true;
}
/* collide dynamics */
/* collide dynamics */
{
btDbvtTreeCollider collider(this);
if(m_deferedcollide)
@@ -384,8 +384,8 @@ if(current)
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();
@@ -400,9 +400,9 @@ if(m_needcleanup)
btDbvtProxy* pb=(btDbvtProxy*)p.m_pProxy1;
if(!Intersect(pa->leaf->volume,pb->leaf->volume))
{
#if DBVT_BP_SORTPAIRS
#if DBVT_BP_SORTPAIRS
if(pa>pb) btSwap(pa,pb);
#endif
#endif
m_paircache->removeOverlappingPair(pa,pb,dispatcher);
--ni;--i;
}
@@ -410,34 +410,34 @@ if(m_needcleanup)
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[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 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();
aabbMin=bounds.Mins();
aabbMax=bounds.Maxs();
}
//
@@ -466,7 +466,7 @@ void btDbvtBroadphase::printStats()
#if DBVT_BP_ENABLE_BENCHMARK
struct btBroadphaseBenchmark
{
{
struct Experiment
{
const char* name;
@@ -506,21 +506,21 @@ struct btBroadphaseBenchmark
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},*/
};
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;

View File

@@ -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,13 +40,13 @@ 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;
@@ -60,35 +60,35 @@ 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;
@@ -96,24 +96,24 @@ struct {
unsigned long m_jobcount;
} 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

File diff suppressed because it is too large Load Diff

View File

@@ -50,8 +50,8 @@ 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;
@@ -59,7 +59,7 @@ btSoftBodyTriangleCallback::btSoftBodyTriangleCallback(btDispatcher* dispatcher
//
// create the manifold from the dispatcher 'manifold pool'
//
// m_manifoldPtr = m_dispatcher->getNewManifold(m_convexBody,m_triBody);
// m_manifoldPtr = m_dispatcher->getNewManifold(m_convexBody,m_triBody);
clearCache();
}
@@ -67,7 +67,7 @@ btSoftBodyTriangleCallback::btSoftBodyTriangleCallback(btDispatcher* dispatcher
btSoftBodyTriangleCallback::~btSoftBodyTriangleCallback()
{
clearCache();
// m_dispatcher->releaseManifold( m_manifoldPtr );
// m_dispatcher->releaseManifold( m_manifoldPtr );
}
@@ -134,14 +134,14 @@ void btSoftBodyTriangleCallback::processTriangle(btVector3* triangle,int partId,
//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,
@@ -152,7 +152,7 @@ void btSoftBodyTriangleCallback::processTriangle(btVector3* triangle,int partId,
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);
@@ -170,7 +170,7 @@ void btSoftBodyTriangleCallback::processTriangle(btVector3* triangle,int partId,
//m_resultOut->setShapeIdentifiers(-1,-1,partId,triangleIndex);
// cvxcvxalgo.setShapeIdentifiers(-1,-1,partId,triangleIndex);
// cvxcvxalgo.processCollision(m_convexBody,m_triBody,*m_dispatchInfoPtr,m_resultOut);
// 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);
@@ -233,13 +233,13 @@ void btSoftBodyConcaveCollisionAlgorithm::processCollision (btCollisionObject* b
{
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());

View File

@@ -77,9 +77,9 @@ class btSoftBodyTriangleCallback : public btTriangleCallback
btHashMap<btHashKey<btTriIndex>,btTriIndex> m_shapeCache;
public:
int m_triangleCount;
int m_triangleCount;
// btPersistentManifold* m_manifoldPtr;
// btPersistentManifold* m_manifoldPtr;
btSoftBodyTriangleCallback(btDispatcher* dispatcher,btCollisionObject* body0,btCollisionObject* body1,bool isSwapped);

View File

@@ -23,11 +23,11 @@ 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);
}
}
//
static void drawBox( btIDebugDraw* idraw,
@@ -35,7 +35,7 @@ static void drawBox( btIDebugDraw* idraw,
const btVector3& maxs,
const btVector3& color)
{
const btVector3 c[]={ btVector3(mins.x(),mins.y(),mins.z()),
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()),
@@ -43,12 +43,12 @@ const btVector3 c[]={ btVector3(mins.x(),mins.y(),mins.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);
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);
}
//
@@ -60,7 +60,7 @@ static void drawTree( btIDebugDraw* idraw,
int mindepth,
int maxdepth)
{
if(node)
if(node)
{
if(node->isinternal()&&((depth<maxdepth)||(maxdepth<0)))
{
@@ -81,8 +81,8 @@ 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)
@@ -90,14 +90,14 @@ if(items.size())
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;
}
@@ -107,7 +107,7 @@ 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;
}
@@ -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,7 +136,7 @@ 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),
@@ -150,7 +150,7 @@ static btVector3 stresscolor(btScalar stress)
const int sel=(int)stress;
const btScalar frc=stress-sel;
return(spectrum[sel]+(spectrum[sel+1]-spectrum[sel])*frc);
}
}
#endif
//
@@ -294,7 +294,7 @@ void btSoftBodyHelpers::Draw( btSoftBody* psb,
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];
@@ -302,7 +302,7 @@ void btSoftBodyHelpers::Draw( btSoftBody* psb,
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));
@@ -398,7 +398,7 @@ void btSoftBodyHelpers::DrawNodeTree( btSoftBody* psb,
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);
}
//
@@ -407,7 +407,7 @@ void btSoftBodyHelpers::DrawFaceTree( btSoftBody* psb,
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);
}
//
@@ -416,7 +416,7 @@ void btSoftBodyHelpers::DrawClusterTree( btSoftBody* psb,
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);
}
//
@@ -565,7 +565,7 @@ btSoftBody* btSoftBodyHelpers::CreatePatchUV(btSoftBodyWorldInfo& worldInfo,
float* tex_coords)
{
/*
/*
*
* corners:
*
@@ -716,7 +716,7 @@ btSoftBody* btSoftBodyHelpers::CreatePatchUV(btSoftBodyWorldInfo& worldInfo,
float btSoftBodyHelpers::CalculateUV(int resx,int resy,int ix,int iy,int id)
{
/*
/*
*
*
* node00 --- node01
@@ -741,7 +741,7 @@ float btSoftBodyHelpers::CalculateUV(int resx,int resy,int ix,int iy,int id)
*
*/
float tc=0.0f;
float tc=0.0f;
if (id == 0) {
tc = (1.0f/((resx-1))*ix);
}
@@ -754,7 +754,7 @@ 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,

View File

@@ -33,12 +33,12 @@ struct btSymMatrix
{
btSymMatrix() : dim(0) {}
btSymMatrix(int n,const T& init=T()) { resize(n,init); }
void resize(int n,const T& init=T()) { dim=n;store.resize((n*(n+1))/2,init); }
int index(int c,int r) const { if(c>r) btSwap(c,r);btAssert(r<dim);return((r*(r+1))/2+c); }
T& operator()(int c,int r) { return(store[index(c,r)]); }
const T& operator()(int c,int r) const { return(store[index(c,r)]); }
btAlignedObjectArray<T> store;
int dim;
void resize(int n,const T& init=T()) { dim=n;store.resize((n*(n+1))/2,init); }
int index(int c,int r) const { if(c>r) btSwap(c,r);btAssert(r<dim);return((r*(r+1))/2+c); }
T& operator()(int c,int r) { return(store[index(c,r)]); }
const T& operator()(int c,int r) const { return(store[index(c,r)]); }
btAlignedObjectArray<T> store;
int dim;
};
//
@@ -171,8 +171,8 @@ public:
template <typename T>
static inline void ZeroInitialize(T& value)
{
static const T zerodummy;
value=zerodummy;
static const T zerodummy;
value=zerodummy;
}
//
template <typename T>
@@ -195,17 +195,17 @@ static inline btMatrix3x3 Lerp( const btMatrix3x3& a,
const btMatrix3x3& b,
btScalar t)
{
btMatrix3x3 r;
r[0]=Lerp(a[0],b[0],t);
r[1]=Lerp(a[1],b[1],t);
r[2]=Lerp(a[2],b[2],t);
return(r);
btMatrix3x3 r;
r[0]=Lerp(a[0],b[0],t);
r[1]=Lerp(a[1],b[1],t);
r[2]=Lerp(a[2],b[2],t);
return(r);
}
//
static inline btVector3 Clamp(const btVector3& v,btScalar maxlength)
{
const btScalar sql=v.length2();
if(sql>(maxlength*maxlength))
const btScalar sql=v.length2();
if(sql>(maxlength*maxlength))
return((v*maxlength)/btSqrt(sql));
else
return(v);
@@ -233,8 +233,8 @@ static inline bool SameSign(const T& x,const T& y)
//
static inline btScalar ClusterMetric(const btVector3& x,const btVector3& y)
{
const btVector3 d=x-y;
return(btFabs(d[0])+btFabs(d[1])+btFabs(d[2]));
const btVector3 d=x-y;
return(btFabs(d[0])+btFabs(d[1])+btFabs(d[2]));
}
//
static inline btMatrix3x3 ScaleAlongAxis(const btVector3& a,btScalar s)
@@ -296,9 +296,9 @@ static inline btMatrix3x3 Mul(const btMatrix3x3& a,
//
static inline void Orthogonalize(btMatrix3x3& m)
{
m[2]=cross(m[0],m[1]).normalized();
m[1]=cross(m[2],m[0]).normalized();
m[0]=cross(m[1],m[2]).normalized();
m[2]=cross(m[0],m[1]).normalized();
m[1]=cross(m[2],m[0]).normalized();
m[0]=cross(m[1],m[2]).normalized();
}
//
static inline btMatrix3x3 MassMatrix(btScalar im,const btMatrix3x3& iwi,const btVector3& r)
@@ -321,14 +321,14 @@ static inline btMatrix3x3 ImpulseMatrix( btScalar dt,
static inline btMatrix3x3 ImpulseMatrix( btScalar ima,const btMatrix3x3& iia,const btVector3& ra,
btScalar imb,const btMatrix3x3& iib,const btVector3& rb)
{
return(Add(MassMatrix(ima,iia,ra),MassMatrix(imb,iib,rb)).inverse());
return(Add(MassMatrix(ima,iia,ra),MassMatrix(imb,iib,rb)).inverse());
}
//
static inline btMatrix3x3 AngularImpulseMatrix( const btMatrix3x3& iia,
const btMatrix3x3& iib)
{
return(Add(iia,iib).inverse());
return(Add(iia,iib).inverse());
}
//
@@ -350,9 +350,9 @@ static inline void ProjectOrigin( const btVector3& a,
btVector3& prj,
btScalar& sqd)
{
const btVector3 d=b-a;
const btScalar m2=d.length2();
if(m2>SIMD_EPSILON)
const btVector3 d=b-a;
const btScalar m2=d.length2();
if(m2>SIMD_EPSILON)
{
const btScalar t=Clamp<btScalar>(-dot(a,d)/m2,0,1);
const btVector3 p=a+d*t;
@@ -371,9 +371,9 @@ static inline void ProjectOrigin( const btVector3& a,
btVector3& prj,
btScalar& sqd)
{
const btVector3& q=cross(b-a,c-a);
const btScalar m2=q.length2();
if(m2>SIMD_EPSILON)
const btVector3& q=cross(b-a,c-a);
const btScalar m2=q.length2();
if(m2>SIMD_EPSILON)
{
const btVector3 n=q/btSqrt(m2);
const btScalar k=dot(a,n);
@@ -413,11 +413,11 @@ static inline btVector3 BaryCoord( const btVector3& a,
const btVector3& c,
const btVector3& p)
{
const btScalar w[]={ cross(a-p,b-p).length(),
const btScalar w[]={ cross(a-p,b-p).length(),
cross(b-p,c-p).length(),
cross(c-p,a-p).length()};
const btScalar isum=1/(w[0]+w[1]+w[2]);
return(btVector3(w[1]*isum,w[2]*isum,w[0]*isum));
const btScalar isum=1/(w[0]+w[1]+w[2]);
return(btVector3(w[1]*isum,w[2]*isum,w[0]*isum));
}
//
@@ -427,16 +427,16 @@ static btScalar ImplicitSolve( btSoftBody::ImplicitFn* fn,
const btScalar accuracy,
const int maxiterations=256)
{
btScalar span[2]={0,1};
btScalar values[2]={fn->Eval(a),fn->Eval(b)};
if(values[0]>values[1])
btScalar span[2]={0,1};
btScalar values[2]={fn->Eval(a),fn->Eval(b)};
if(values[0]>values[1])
{
btSwap(span[0],span[1]);
btSwap(values[0],values[1]);
}
if(values[0]>-accuracy) return(-1);
if(values[1]<+accuracy) return(-1);
for(int i=0;i<maxiterations;++i)
if(values[0]>-accuracy) return(-1);
if(values[1]<+accuracy) return(-1);
for(int i=0;i<maxiterations;++i)
{
const btScalar t=Lerp(span[0],span[1],values[0]/(values[0]-values[1]));
const btScalar v=fn->Eval(Lerp(a,b,t));
@@ -447,7 +447,7 @@ for(int i=0;i<maxiterations;++i)
else
{ span[1]=t;values[1]=v; }
}
return(-1);
return(-1);
}
//
@@ -464,18 +464,18 @@ static inline btVector3 NormalizeAny(const btVector3& v)
static inline btDbvtVolume VolumeOf( const btSoftBody::Face& f,
btScalar margin)
{
const btVector3* pts[]={ &f.m_n[0]->m_x,
const btVector3* pts[]={ &f.m_n[0]->m_x,
&f.m_n[1]->m_x,
&f.m_n[2]->m_x};
btDbvtVolume vol=btDbvtVolume::FromPoints(pts,3);
vol.Expand(btVector3(margin,margin,margin));
return(vol);
btDbvtVolume vol=btDbvtVolume::FromPoints(pts,3);
vol.Expand(btVector3(margin,margin,margin));
return(vol);
}
//
static inline btVector3 CenterOf( const btSoftBody::Face& f)
{
return((f.m_n[0]->m_x+f.m_n[1]->m_x+f.m_n[2]->m_x)/3);
return((f.m_n[0]->m_x+f.m_n[1]->m_x+f.m_n[2]->m_x)/3);
}
//
@@ -543,9 +543,9 @@ static inline int MatchEdge( const btSoftBody::Node* a,
const btSoftBody::Node* ma,
const btSoftBody::Node* mb)
{
if((a==ma)&&(b==mb)) return(0);
if((a==mb)&&(b==ma)) return(1);
return(-1);
if((a==ma)&&(b==mb)) return(0);
if((a==mb)&&(b==ma)) return(1);
return(-1);
}
//
@@ -555,7 +555,7 @@ return(-1);
//
struct btEigen
{
static int system(btMatrix3x3& a,btMatrix3x3* vectors,btVector3* values=0)
static int system(btMatrix3x3& a,btMatrix3x3* vectors,btVector3* values=0)
{
static const int maxiterations=16;
static const btScalar accuracy=(btScalar)0.0001;
@@ -588,7 +588,7 @@ static int system(btMatrix3x3& a,btMatrix3x3* vectors,btVector3* values=0)
return(iterations);
}
private:
static inline void mulTPQ(btMatrix3x3& a,btScalar c,btScalar s,int p,int q)
static inline void mulTPQ(btMatrix3x3& a,btScalar c,btScalar s,int p,int q)
{
const btScalar m[2][3]={ {a[p][0],a[p][1],a[p][2]},
{a[q][0],a[q][1],a[q][2]}};
@@ -597,7 +597,7 @@ static inline void mulTPQ(btMatrix3x3& a,btScalar c,btScalar s,int p,int q)
for(i=0;i<3;++i) a[p][i]=c*m[0][i]-s*m[1][i];
for(i=0;i<3;++i) a[q][i]=c*m[1][i]+s*m[0][i];
}
static inline void mulPQ(btMatrix3x3& a,btScalar c,btScalar s,int p,int q)
static inline void mulPQ(btMatrix3x3& a,btScalar c,btScalar s,int p,int q)
{
const btScalar m[2][3]={ {a[0][p],a[1][p],a[2][p]},
{a[0][q],a[1][q],a[2][q]}};
@@ -639,7 +639,7 @@ static inline int PolarDecompose( const btMatrix3x3& m,btMatrix3x3& q,btMatrix
q.setIdentity();
s.setIdentity();
}
return(i);
return(i);
}
//

View File

@@ -28,8 +28,8 @@ 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;

View File

@@ -28,14 +28,14 @@ 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();
}

View File

@@ -23,7 +23,7 @@ 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)
@@ -38,11 +38,11 @@ unsigned int HsiehHash(const void* pdata)
hash^=hash<<4;hash+=hash>>17;
hash^=hash<<25;hash+=hash>>6;
return(hash);
}
}
template <const int CELLSIZE>
struct btSparseSdf
{
{
//
// Inner types
//
@@ -200,7 +200,7 @@ struct btSparseSdf
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]};
const btScalar gy[]={ d[3]-d[0],d[2]-d[1],
@@ -214,9 +214,9 @@ struct btSparseSdf
normal.setZ(Lerp( Lerp(gz[0],gz[1],ix.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);