fix compound collision (host side)
This commit is contained in:
@@ -2,6 +2,9 @@
|
|||||||
#ifndef B3_COLLIDABLE_H
|
#ifndef B3_COLLIDABLE_H
|
||||||
#define B3_COLLIDABLE_H
|
#define B3_COLLIDABLE_H
|
||||||
|
|
||||||
|
#include "Bullet3Common/b3Vector3.h"
|
||||||
|
#include "Bullet3Common/b3Quaternion.h"
|
||||||
|
|
||||||
enum b3ShapeTypes
|
enum b3ShapeTypes
|
||||||
{
|
{
|
||||||
SHAPE_HEIGHT_FIELD=1,
|
SHAPE_HEIGHT_FIELD=1,
|
||||||
@@ -34,8 +37,8 @@ struct b3CollidableNew
|
|||||||
|
|
||||||
struct b3GpuChildShape
|
struct b3GpuChildShape
|
||||||
{
|
{
|
||||||
float m_childPosition[4];
|
b3Vector3 m_childPosition;
|
||||||
float m_childOrientation[4];
|
b3Quaternion m_childOrientation;
|
||||||
int m_shapeIndex;
|
int m_shapeIndex;
|
||||||
int m_unused0;
|
int m_unused0;
|
||||||
int m_unused1;
|
int m_unused1;
|
||||||
|
|||||||
@@ -21,6 +21,10 @@ subject to the following restrictions:
|
|||||||
//#define B3_DEBUG_SAT_FACE
|
//#define B3_DEBUG_SAT_FACE
|
||||||
//#define CHECK_ON_HOST
|
//#define CHECK_ON_HOST
|
||||||
|
|
||||||
|
#ifdef CHECK_ON_HOST
|
||||||
|
//#define PERSISTENT_CONTACTS_HOST
|
||||||
|
#endif
|
||||||
|
|
||||||
int b3g_actualSATPairTests=0;
|
int b3g_actualSATPairTests=0;
|
||||||
|
|
||||||
#include "b3ConvexHullContact.h"
|
#include "b3ConvexHullContact.h"
|
||||||
@@ -560,9 +564,11 @@ void computeContactPlaneCompound(int pairIndex,
|
|||||||
const b3RigidBodyCL* rigidBodies,
|
const b3RigidBodyCL* rigidBodies,
|
||||||
const b3Collidable* collidables,
|
const b3Collidable* collidables,
|
||||||
const b3ConvexPolyhedronCL* convexShapes,
|
const b3ConvexPolyhedronCL* convexShapes,
|
||||||
|
const b3GpuChildShape* cpuChildShapes,
|
||||||
const b3Vector3* convexVertices,
|
const b3Vector3* convexVertices,
|
||||||
const int* convexIndices,
|
const int* convexIndices,
|
||||||
const b3GpuFace* faces,
|
const b3GpuFace* faces,
|
||||||
|
|
||||||
b3Contact4* globalContactsOut,
|
b3Contact4* globalContactsOut,
|
||||||
int& nGlobalContactsOut,
|
int& nGlobalContactsOut,
|
||||||
int maxContactCapacity)
|
int maxContactCapacity)
|
||||||
@@ -572,12 +578,24 @@ void computeContactPlaneCompound(int pairIndex,
|
|||||||
b3Assert(shapeTypeB == SHAPE_COMPOUND_OF_CONVEX_HULLS);
|
b3Assert(shapeTypeB == SHAPE_COMPOUND_OF_CONVEX_HULLS);
|
||||||
|
|
||||||
|
|
||||||
|
int numChildrenB = collidables[collidableIndexB].m_numChildShapes;
|
||||||
|
for (int c=0;c<numChildrenB;c++)
|
||||||
|
{
|
||||||
|
int childShapeIndexB = collidables[collidableIndexB].m_shapeIndex+c;
|
||||||
|
int childColIndexB = cpuChildShapes[childShapeIndexB].m_shapeIndex;
|
||||||
|
|
||||||
|
float4 rootPosB = rigidBodies[bodyIndexB].m_pos;
|
||||||
|
b3Quaternion rootOrnB = rigidBodies[bodyIndexB].m_quat;
|
||||||
|
b3Vector3 childPosB = cpuChildShapes[childShapeIndexB].m_childPosition;
|
||||||
|
b3Quaternion childOrnB = cpuChildShapes[childShapeIndexB].m_childOrientation;
|
||||||
|
float4 posB = b3QuatRotate(rootOrnB,childPosB)+rootPosB;
|
||||||
|
b3Quaternion ornB = rootOrnB*childOrnB;//b3QuatMul(ornB,childOrnB);
|
||||||
|
|
||||||
|
int shapeIndexB = collidables[childColIndexB].m_shapeIndex;
|
||||||
|
|
||||||
|
const b3ConvexPolyhedronCL* hullB = &convexShapes[shapeIndexB];
|
||||||
|
|
||||||
int shapeIndex = collidables[collidableIndexB].m_shapeIndex;
|
|
||||||
const b3ConvexPolyhedronCL* hullB = &convexShapes[shapeIndex];
|
|
||||||
|
|
||||||
b3Vector3 posB = rigidBodies[bodyIndexB].m_pos;
|
|
||||||
b3Quaternion ornB = rigidBodies[bodyIndexB].m_quat;
|
|
||||||
b3Vector3 posA = rigidBodies[bodyIndexA].m_pos;
|
b3Vector3 posA = rigidBodies[bodyIndexA].m_pos;
|
||||||
b3Quaternion ornA = rigidBodies[bodyIndexA].m_quat;
|
b3Quaternion ornA = rigidBodies[bodyIndexA].m_quat;
|
||||||
|
|
||||||
@@ -607,7 +625,7 @@ void computeContactPlaneCompound(int pairIndex,
|
|||||||
int hitVertex=-1;
|
int hitVertex=-1;
|
||||||
b3Vector3 hitVtx;
|
b3Vector3 hitVtx;
|
||||||
|
|
||||||
#define MAX_PLANE_CONVEX_POINTS 64
|
#define MAX_PLANE_CONVEX_POINTS 64
|
||||||
|
|
||||||
b3Vector3 contactPoints[MAX_PLANE_CONVEX_POINTS];
|
b3Vector3 contactPoints[MAX_PLANE_CONVEX_POINTS];
|
||||||
int numPoints = 0;
|
int numPoints = 0;
|
||||||
@@ -658,7 +676,7 @@ void computeContactPlaneCompound(int pairIndex,
|
|||||||
numReducedPoints = extractManifoldSequentialGlobal( contactPoints, numPoints, planeNormalInConvex, &contactIdx);
|
numReducedPoints = extractManifoldSequentialGlobal( contactPoints, numPoints, planeNormalInConvex, &contactIdx);
|
||||||
}
|
}
|
||||||
int dstIdx;
|
int dstIdx;
|
||||||
// dstIdx = nGlobalContactsOut++;//AppendInc( nGlobalContactsOut, dstIdx );
|
// dstIdx = nGlobalContactsOut++;//AppendInc( nGlobalContactsOut, dstIdx );
|
||||||
|
|
||||||
if (numReducedPoints>0)
|
if (numReducedPoints>0)
|
||||||
{
|
{
|
||||||
@@ -684,9 +702,9 @@ void computeContactPlaneCompound(int pairIndex,
|
|||||||
}//if (dstIdx < numPairs)
|
}//if (dstIdx < numPairs)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// printf("computeContactPlaneConvex\n");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -1647,9 +1665,9 @@ int computeContactConvexConvex( b3AlignedObjectArray<b3Int4>& pairs,
|
|||||||
if (numOldPoints)
|
if (numOldPoints)
|
||||||
{
|
{
|
||||||
newContact = oldContacts[pairs[pairIndex].z];
|
newContact = oldContacts[pairs[pairIndex].z];
|
||||||
#ifdef CHECK_ON_HOST
|
#ifdef PERSISTENT_CONTACTS_HOST
|
||||||
b3ContactCache::refreshContactPoints(transA,transB,newContact);
|
b3ContactCache::refreshContactPoints(transA,transB,newContact);
|
||||||
#endif //CHECK_ON_HOST
|
#endif //PERSISTENT_CONTACTS_HOST
|
||||||
}
|
}
|
||||||
numPoints = b3Contact4Data_getNumPoints(&newContact);
|
numPoints = b3Contact4Data_getNumPoints(&newContact);
|
||||||
|
|
||||||
@@ -1680,7 +1698,7 @@ int computeContactConvexConvex( b3AlignedObjectArray<b3Int4>& pairs,
|
|||||||
resultPointOnBWorld.w = distance2;
|
resultPointOnBWorld.w = distance2;
|
||||||
newContact.m_worldPosB[p] = resultPointOnBWorld;
|
newContact.m_worldPosB[p] = resultPointOnBWorld;
|
||||||
b3Vector3 resultPointOnAWorld = resultPointOnBWorld+distance2*sepAxis2;
|
b3Vector3 resultPointOnAWorld = resultPointOnBWorld+distance2*sepAxis2;
|
||||||
#ifdef CHECK_ON_HOST
|
#ifdef PERSISTENT_CONTACTS_HOST
|
||||||
newContact.m_localPosA[p] = transA.inverse()*resultPointOnAWorld;
|
newContact.m_localPosA[p] = transA.inverse()*resultPointOnAWorld;
|
||||||
newContact.m_localPosB[p] = transB.inverse()*resultPointOnBWorld;
|
newContact.m_localPosB[p] = transB.inverse()*resultPointOnBWorld;
|
||||||
#endif
|
#endif
|
||||||
@@ -1881,7 +1899,7 @@ void GpuSatCollision::computeConvexConvexContactsGPUSAT( b3OpenCLArray<b3Int4>*
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
hostContacts.resize(nPairs);
|
hostContacts.resize(maxContactCapacity);
|
||||||
|
|
||||||
for (int i=0;i<nPairs;i++)
|
for (int i=0;i<nPairs;i++)
|
||||||
{
|
{
|
||||||
@@ -1929,7 +1947,7 @@ void GpuSatCollision::computeConvexConvexContactsGPUSAT( b3OpenCLArray<b3Int4>*
|
|||||||
hostCollidables[collidableIndexB].m_shapeType == SHAPE_PLANE)
|
hostCollidables[collidableIndexB].m_shapeType == SHAPE_PLANE)
|
||||||
{
|
{
|
||||||
computeContactPlaneCompound(i,bodyIndexB,bodyIndexA,collidableIndexB,collidableIndexA,&hostBodyBuf[0],
|
computeContactPlaneCompound(i,bodyIndexB,bodyIndexA,collidableIndexB,collidableIndexA,&hostBodyBuf[0],
|
||||||
&hostCollidables[0],&hostConvexData[0],&hostVertices[0],&hostIndices[0],&hostFaces[0],&hostContacts[0],nContacts,maxContactCapacity);
|
&hostCollidables[0],&hostConvexData[0],&cpuChildShapes[0], &hostVertices[0],&hostIndices[0],&hostFaces[0],&hostContacts[0],nContacts,maxContactCapacity);
|
||||||
// printf("convex-plane\n");
|
// printf("convex-plane\n");
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -1938,7 +1956,7 @@ void GpuSatCollision::computeConvexConvexContactsGPUSAT( b3OpenCLArray<b3Int4>*
|
|||||||
hostCollidables[collidableIndexB].m_shapeType == SHAPE_COMPOUND_OF_CONVEX_HULLS)
|
hostCollidables[collidableIndexB].m_shapeType == SHAPE_COMPOUND_OF_CONVEX_HULLS)
|
||||||
{
|
{
|
||||||
computeContactPlaneCompound(i,bodyIndexA,bodyIndexB,collidableIndexA,collidableIndexB,&hostBodyBuf[0],
|
computeContactPlaneCompound(i,bodyIndexA,bodyIndexB,collidableIndexA,collidableIndexB,&hostBodyBuf[0],
|
||||||
&hostCollidables[0],&hostConvexData[0],&hostVertices[0],&hostIndices[0],&hostFaces[0],&hostContacts[0],nContacts,maxContactCapacity);
|
&hostCollidables[0],&hostConvexData[0],&cpuChildShapes[0],&hostVertices[0],&hostIndices[0],&hostFaces[0],&hostContacts[0],nContacts,maxContactCapacity);
|
||||||
// printf("plane-convex\n");
|
// printf("plane-convex\n");
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -1970,9 +1988,11 @@ void GpuSatCollision::computeConvexConvexContactsGPUSAT( b3OpenCLArray<b3Int4>*
|
|||||||
pairs->copyFromHost(hostPairs);
|
pairs->copyFromHost(hostPairs);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
hostContacts.resize(nContacts);
|
||||||
|
|
||||||
if (nContacts)
|
if (nContacts)
|
||||||
{
|
{
|
||||||
hostContacts.resize(nContacts);
|
|
||||||
contactOut->copyFromHost(hostContacts);
|
contactOut->copyFromHost(hostContacts);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user