27 #ifdef PFX_USE_FREE_VECTORMATH
28 #include "vecmath/vmInclude.h"
31 #endif //PFX_USE_FREE_VECTORMATH
47 #define TMP_BUFF_BYTES (15*1024*1024)
111 vmVector3 dVA = deltaLinearVelocityA +
cross(deltaAngularVelocityA,rA);
112 vmVector3 dVB = deltaLinearVelocityB +
cross(deltaAngularVelocityB,rB);
117 deltaLinearVelocityA += deltaImpulse * massInvA * normal;
118 deltaAngularVelocityA += deltaImpulse * inertiaInvA *
cross(rA,normal);
119 deltaLinearVelocityB -= deltaImpulse * massInvB * normal;
120 deltaAngularVelocityB -= deltaImpulse * inertiaInvB *
cross(rB,normal);
178 for(
int k=0;k<iteration+1;k++) {
183 if(batchId%numTasks == taskId && numPairs > 0) {
191 PfxSolverBody &solverBodyA = iA != 65535 ? offsetSolverBodies[iA] : staticBody;
192 PfxSolverBody &solverBodyB = iB != 65535 ? offsetSolverBodies[iB] : staticBody;
201 for (i=0;i<numRows;i++)
218 if(batchId%numTasks == taskId && numPairs > 0) {
227 btConstraintRow* contactConstraintRows = &offsetContactConstraintRows[contactIndex*12];
258 contactConstraintRows[j*3],
259 contactConstraintRows[j*3+1],
260 contactConstraintRows[j*3+2],
284 for(
uint32_t i=0;i<numRigidBodies;i++) {
302 if(fabsf(n[2]) > 0.707f) {
304 float a = n[1]*n[1] + n[2]*n[2];
305 float k = 1.0f/sqrtf(a);
316 float a = n[0]*n[0] + n[1]*n[1];
317 float k = 1.0f/sqrtf(a);
330 #define PFX_CONTACT_SLOP 0.001f
336 float penetrationDepth,
365 vmVector3 vABrestitution = vArestitution-vBrestitution;
383 float denom =
dot(K*normal,normal);
385 constraintResponse.
m_rhs = -(1.0f+restitution)*
dot(vAB,normal);
387 constraintResponse.
m_rhs /= denom;
398 float denom =
dot(K*normal,normal);
401 constraintFriction1.
m_rhs = -
dot(vAB,normal);
412 float denom =
dot(K*normal,normal);
415 constraintFriction2.
m_rhs = -
dot(vAB,normal);
434 for(
uint32_t i=0;i<numContactPairs;i++) {
446 btConstraintRow* contactConstraintRows = &offsetContactConstraintRows[
id*12];
448 TrbState &stateA = offsetRigStates[iA];
452 TrbState &stateB = offsetRigStates[iB];
481 if (rbB && (rbB->getInvMass()>0.f))
483 linVelB = rbB->getLinearVelocity();
484 angVelB = rbB->getAngularVelocity();
494 contactConstraintRows[j*3],
495 contactConstraintRows[j*3+1],
496 contactConstraintRows[j*3+2],
529 for(
uint32_t i=0;i<numContactPairs;i++) {
537 btConstraintRow* contactConstraintRows = &offsetContactConstraintRows[
id*12];
593 criticalsection->
lock();
601 int nextStart = start + batch;
603 int nextBatch = (rest > batch)?batch:rest;
608 criticalsection->
unlock();
635 criticalsection->
lock();
643 int nextStart = start + batch;
645 int nextBatch = (rest > batch)?batch:rest;
650 criticalsection->
unlock();
687 float separationBias,
697 int div = (int)maxTasks * 4;
698 int batch = ((int)numContactPairs + div - 1) / div;
700 BulletPE2ConstraintSolverSpursSupport* spursThread = (BulletPE2ConstraintSolverSpursSupport*) threadSupport;
709 spursThread->setSharedParam(0,0);
710 spursThread->setSharedParam(1,
btMin(batch,64));
714 for(
int t=0;t<maxTasks;t++) {
728 io[t].
barrierAddr2 = (
unsigned int)spursThread->getBarrierAddress();
734 #ifdef SEQUENTIAL_SETUP
735 CustomSetupContactConstraintsTask(contactPairs1,numContactPairs,offsetContactManifolds,offsetRigStates,offsetSolverBodies,numRigidBodies,separationBias,timeStep);
741 #ifndef SEQUENTIAL_SETUP
742 unsigned int arg0,arg1;
743 for(
int t=0;t<maxTasks;t++) {
747 #endif //SEQUENTIAL_SETUP
761 HeapManager pool((
unsigned char*)poolBuff,poolBytes);
764 int bufSize =
sizeof(
uint8_t)*numRigidBodies;
765 bufSize = ((bufSize+127)>>7)<<7;
770 size_t allocSize =
sizeof(
uint32_t)*((numPairs+31)/32);
772 memset(pairTable,0,allocSize);
785 bool startIndexCheck =
true;
792 memset(bodyTable,0xff,bufSize);
794 for(batchId=0;i<numPairs&&totalCount<numPairs&&batchId<maxBatches;batchId++) {
800 for(;i<numPairs&&pairCount<targetCount;i++) {
805 if(pairTable[idxP] & maskP) {
818 pairTable[idxP] |= maskP;
824 if( (bodyTable[idxA] != batchId && bodyTable[idxA] != 0xff) ||
825 (bodyTable[idxB] != batchId && bodyTable[idxB] != 0xff) ) {
826 startIndexCheck =
false;
833 bodyTable[idxA] = batchId;
835 bodyTable[idxB] = batchId;
840 pairTable[idxP] |= maskP;
847 totalCount += pairCount;
881 HeapManager pool((
unsigned char*)poolBuf,poolBytes);
890 void *tmpBuff = pool.
allocate(tmpBytes);
894 CustomSplitConstraints(contactPairs,numContactPairs,*cgroup,cbatches,maxTasks,numRigidBodies,tmpBuff,tmpBytes);
895 CustomSplitConstraints(jointPairs,numJointPairs,*jgroup,jbatches,maxTasks,numRigidBodies,tmpBuff,tmpBytes);
899 BT_PROFILE(
"PFX_CONSTRAINT_SOLVER_CMD_SOLVE_CONSTRAINTS");
901 #ifdef SOLVE_SEQUENTIAL
902 CustomSolveConstraintsTask(
920 for(
int t=0;t<maxTasks;t++) {
942 BulletPE2ConstraintSolverSpursSupport* spursThread = (BulletPE2ConstraintSolverSpursSupport*) threadSupport;
943 io[t].
barrierAddr2 = (
unsigned int) spursThread->getBarrierAddress();
950 unsigned int arg0,arg1;
951 for(
int t=0;t<maxTasks;t++) {
961 BT_PROFILE(
"PFX_CONSTRAINT_SOLVER_CMD_POST_SOLVER");
962 int batch = ((int)numRigidBodies + maxTasks - 1) / maxTasks;
963 int rest = (int)numRigidBodies;
966 for(
int t=0;t<maxTasks;t++) {
967 int num = (rest - batch ) > 0 ? batch : rest;
974 BulletPE2ConstraintSolverSpursSupport* spursThread = (BulletPE2ConstraintSolverSpursSupport*) threadSupport;
975 io[t].
barrierAddr2 = (
unsigned int)spursThread->getBarrierAddress();
979 #ifdef SOLVE_SEQUENTIAL
988 unsigned int arg0,arg1;
989 for(
int t=0;t<maxTasks;t++) {
990 #ifndef SOLVE_SEQUENTIAL
1004 TrbState* states,
int numRigidBodies,
1021 for(
uint32_t i=0;i<numJoints;i++) {
1046 #ifdef SEQUENTIAL_SETUP
1047 CustomSetupContactConstraintsSeqNew(
1058 offsetContactManifolds,
1059 offsetContactConstraintRows,
1065 solverThreadSupport,
1066 criticalSection,solverIO,
1070 #endif //SEQUENTIAL_SETUP
1078 CustomSolveConstraintsSeq(
1080 jointPairs,numJoints,
1090 jointPairs,numJoints,
1091 offsetContactManifolds,
1092 offsetContactConstraintRows,
1093 offsetSolverConstraints,
1097 solverIO, solverThreadSupport,
1112 offsetContactManifolds,
1113 offsetContactConstraintRows,
1119 solverThreadSupport,
1120 criticalSection,solverIO,
1185 BT_PROFILE(
"create states and solver bodies");
1186 for (
int i=0;i<numRigidBodies;i++)
1247 int totalPoints = 0;
1248 #ifndef USE_C_ARRAYS
1253 #endif//USE_C_ARRAYS
1255 int actualNumManifolds= 0;
1258 for (
int i1=0;i1<numManifolds;i1++)
1260 if (manifoldPtr[i1]->getNumContacts()>0)
1268 if (!obAisActive && !obBisActive)
1296 totalPoints+=numPosPoints;
1304 int contactId = m-offsetContactManifolds;
1307 btAssert(contactId<dispatcher->getInternalManifoldPool()->getMaxCount());
1311 actualNumManifolds++;
1319 int actualNumJoints=0;
1330 int totalNumRows = 0;
1335 for (i=0;i<numConstraints;i++)
1348 for (i=0;i<numConstraints;i++)
1393 info2.
cfm = ¤tConstraintRow->
m_cfm;
1442 rel_vel = vel1Dotn+vel2Dotn;
1446 btScalar velocityError = restitution - rel_vel;
1449 solverConstraint.
m_rhs = penetrationImpulse+velocityImpulse;
1471 int id = currentConstraintRow-offsetSolverConstraints;
1484 float separateBias=0.1;
1496 int totalContacts =0;
1498 for (
int i=0;i<actualNumManifolds;i++)
1511 BT_PROFILE(
"BPE_customConstraintSolverSequentialNew");
1512 if (numRigidBodies>0 && (actualNumManifolds+actualNumJoints)>0)
1523 offsetContactManifolds,
1527 jointPairs,actualNumJoints,
1528 offsetSolverConstraints,
1529 separateBias,timeStep,iteration,
1537 for (
int i=0;i<numRigidBodies;i++)