diff --git a/demo/gpudemo/GpuDemo.h b/demo/gpudemo/GpuDemo.h index c62028709..019177c4d 100644 --- a/demo/gpudemo/GpuDemo.h +++ b/demo/gpudemo/GpuDemo.h @@ -38,9 +38,9 @@ public: :useOpenCL(true), preferredOpenCLPlatformIndex(-1), preferredOpenCLDeviceIndex(-1), - arraySizeX(11), - arraySizeY(11), - arraySizeZ(11), + arraySizeX(1), + arraySizeY(1), + arraySizeZ(1), m_useConcaveMesh(false), gapX(14.3), gapY(14.0), diff --git a/demo/gpudemo/main_opengl3core.cpp b/demo/gpudemo/main_opengl3core.cpp index 6f6e70834..32b09a127 100644 --- a/demo/gpudemo/main_opengl3core.cpp +++ b/demo/gpudemo/main_opengl3core.cpp @@ -65,6 +65,8 @@ btAlignedObjectArray demoNames; int selectedDemo = 0; GpuDemo::CreateFunc* allDemos[]= { + GpuConvexPlaneScene::MyCreateFunc, + GpuConvexScene::MyCreateFunc, ConcaveCompoundScene::MyCreateFunc, ConcaveSphereScene::MyCreateFunc, @@ -74,7 +76,7 @@ GpuDemo::CreateFunc* allDemos[]= GpuSphereScene::MyCreateFunc, - GpuConvexScene::MyCreateFunc, + GpuCompoundScene::MyCreateFunc, PairBench::MyCreateFunc, diff --git a/demo/gpudemo/rigidbody/GpuConvexScene.cpp b/demo/gpudemo/rigidbody/GpuConvexScene.cpp index a37b6ec6e..5c0f0afb7 100644 --- a/demo/gpudemo/rigidbody/GpuConvexScene.cpp +++ b/demo/gpudemo/rigidbody/GpuConvexScene.cpp @@ -21,30 +21,21 @@ void GpuConvexScene::setupScene(const ConstructionInfo& ci) { + + createStaticEnvironment(ci); + int strideInBytes = 9*sizeof(float); int numVertices = sizeof(cube_vertices)/strideInBytes; int numIndices = sizeof(cube_indices)/sizeof(int); - //int shapeId = ci.m_instancingRenderer->registerShape(&cube_vertices[0],numVertices,cube_indices,numIndices); + int shapeId = ci.m_instancingRenderer->registerShape(&cube_vertices[0],numVertices,cube_indices,numIndices); + //int shapeId = ci.m_instancingRenderer->registerShape(&cube_vertices[0],numVertices,cube_indices,numIndices); int group=1; int mask=1; int index=10; - { - btVector4 scaling(400,1,400,1); - int colIndex = m_data->m_np->registerConvexHullShape(&cube_vertices[0],strideInBytes,numVertices, scaling); - btVector3 position(0,0,0); - btQuaternion orn(0,0,0,1); - - btVector4 color(0,0,1,1); - - int id = ci.m_instancingRenderer->registerGraphicsInstance(shapeId,position,orn,color,scaling); - int pid = m_data->m_rigidBodyPipeline->registerPhysicsInstance(0.f,position,orn,colIndex,index); - - index++; - } - + { @@ -59,6 +50,7 @@ void GpuConvexScene::setupScene(const ConstructionInfo& ci) int curColor = 0; float scaling[4] = {1,1,1,1}; int colIndex = m_data->m_np->registerConvexHullShape(&cube_vertices[0],strideInBytes,numVertices, scaling); + //int colIndex = m_data->m_np->registerSphereShape(1); for (int i=0;isetCameraTargetPosition(camPos); - m_instancingRenderer->setCameraDistance(120); + m_instancingRenderer->setCameraDistance(40); char msg[1024]; int numInstances = index; sprintf(msg,"Num objects = %d",numInstances); ci.m_gui->setStatusBarMessage(msg,true); +} + + + + +void GpuConvexScene::createStaticEnvironment(const ConstructionInfo& ci) +{ + int strideInBytes = 9*sizeof(float); + int numVertices = sizeof(cube_vertices)/strideInBytes; + int numIndices = sizeof(cube_indices)/sizeof(int); + int shapeId = ci.m_instancingRenderer->registerShape(&cube_vertices[0],numVertices,cube_indices,numIndices); + int group=1; + int mask=1; + int index=0; + + + { + btVector4 scaling(400,1,400,1); + int colIndex = m_data->m_np->registerConvexHullShape(&cube_vertices[0],strideInBytes,numVertices, scaling); + btVector3 position(0,0,0); + btQuaternion orn(0,0,0,1); + + btVector4 color(0,0,1,1); + + int id = ci.m_instancingRenderer->registerGraphicsInstance(shapeId,position,orn,color,scaling); + int pid = m_data->m_rigidBodyPipeline->registerPhysicsInstance(0.f,position,orn,colIndex,index); + + } +} + +void GpuConvexPlaneScene::createStaticEnvironment(const ConstructionInfo& ci) +{ + int index=0; + btVector3 normal(0,1,0); + float constant=0.f; + int colIndex = m_data->m_np->registerPlaneShape(normal,constant);//>registerConvexHullShape(&cube_vertices[0],strideInBytes,numVertices, scaling); + btVector3 position(0,0,0); + btQuaternion orn(0,0,0,1); + // btQuaternion orn(btVector3(1,0,0),0.3); + btVector4 color(0,0,1,1); + btVector4 scaling(100,0.0001,100,1); + int strideInBytes = 9*sizeof(float); + int numVertices = sizeof(cube_vertices)/strideInBytes; + int numIndices = sizeof(cube_indices)/sizeof(int); + int shapeId = ci.m_instancingRenderer->registerShape(&cube_vertices[0],numVertices,cube_indices,numIndices); + + + int id = ci.m_instancingRenderer->registerGraphicsInstance(shapeId,position,orn,color,scaling); + int pid = m_data->m_rigidBodyPipeline->registerPhysicsInstance(0.f,position,orn,colIndex,index); + } \ No newline at end of file diff --git a/demo/gpudemo/rigidbody/GpuConvexScene.h b/demo/gpudemo/rigidbody/GpuConvexScene.h index c7106ada4..6b1a3c6a6 100644 --- a/demo/gpudemo/rigidbody/GpuConvexScene.h +++ b/demo/gpudemo/rigidbody/GpuConvexScene.h @@ -22,6 +22,30 @@ public: virtual void setupScene(const ConstructionInfo& ci); + virtual void createStaticEnvironment(const ConstructionInfo& ci); + +}; + + +class GpuConvexPlaneScene : public GpuConvexScene +{ +public: + + GpuConvexPlaneScene(){} + virtual ~GpuConvexPlaneScene(){} + virtual const char* getName() + { + return "GRBConvexPlane"; + } + + static GpuDemo* MyCreateFunc() + { + GpuDemo* demo = new GpuConvexPlaneScene; + return demo; + } + + virtual void createStaticEnvironment(const ConstructionInfo& ci); + }; #endif //GPU_CONVEX_SCENE_H diff --git a/opencl/gpu_sat/host/ConvexHullContact.cpp b/opencl/gpu_sat/host/ConvexHullContact.cpp index ca5d55610..0e1da0936 100644 --- a/opencl/gpu_sat/host/ConvexHullContact.cpp +++ b/opencl/gpu_sat/host/ConvexHullContact.cpp @@ -291,6 +291,125 @@ inline bool IsPointInPolygon(const float4& p, return true; } +void computeContactPlaneConvex(int pairIndex, + int bodyIndexA, int bodyIndexB, + int collidableIndexA, int collidableIndexB, + const btRigidBodyCL* rigidBodies, + const btCollidable* collidables, + const btConvexPolyhedronCL* convexShapes, + const btVector3* convexVertices, + const int* convexIndices, + const btGpuFace* faces, + btContact4* globalContactsOut, + int& nGlobalContactsOut, + int maxContactCapacity) +{ + + int shapeIndex = collidables[collidableIndexB].m_shapeIndex; + const btConvexPolyhedronCL* hullB = &convexShapes[shapeIndex]; + + btVector3 posB = rigidBodies[bodyIndexB].m_pos; + btQuaternion ornB = rigidBodies[bodyIndexB].m_quat; + btVector3 posA = rigidBodies[bodyIndexA].m_pos; + btQuaternion ornA = rigidBodies[bodyIndexA].m_quat; + + int numContactsOut = 0; + int numWorldVertsB1= 0; + + btVector3 planeEq = faces[collidables[collidableIndexA].m_shapeIndex].m_plane; + btVector3 planeNormal(planeEq.x,planeEq.y,planeEq.z); + float planeConstant = planeEq.w; + btTransform convexWorldTransform; + convexWorldTransform.setIdentity(); + convexWorldTransform.setOrigin(posB); + convexWorldTransform.setRotation(ornB); + btTransform planeTransform; + planeTransform.setIdentity(); + planeTransform.setOrigin(posA); + planeTransform.setRotation(ornA); + + btTransform planeInConvex; + planeInConvex= convexWorldTransform.inverse() * planeTransform; + + btVector3 planeNormalInConvex = planeInConvex.getBasis()*-planeNormal; + float maxDot = -1e30; + int hitVertex=-1; + btVector3 hitVtx; + for (int i=0;im_numVertices;i++) + { + btVector3 vtx = convexVertices[hullB->m_vertexOffset+i]; + float curDot = vtx.dot(planeNormalInConvex); + if (curDot>maxDot) + { + hitVertex=i; + maxDot=curDot; + hitVtx = vtx; + } + } + + btVector3 hitVtxWorld = convexWorldTransform*hitVtx; + float dist = 0; + + int dstIdx; +// dstIdx = nGlobalContactsOut++;//AppendInc( nGlobalContactsOut, dstIdx ); + + if (nGlobalContactsOut < maxContactCapacity) + { + dstIdx=nGlobalContactsOut; + nGlobalContactsOut++; + + btContact4* c = &globalContactsOut[dstIdx]; + c->m_worldNormal = -planeNormalInConvex; + c->setFrictionCoeff(0.7); + c->setRestituitionCoeff(0.f); + + c->m_batchIdx = pairIndex; + c->m_bodyAPtrAndSignBit = rigidBodies[bodyIndexA].m_invMass==0?-bodyIndexA:bodyIndexA; + c->m_bodyBPtrAndSignBit = rigidBodies[bodyIndexB].m_invMass==0?-bodyIndexB:bodyIndexB; + btVector3 pOnB1 = hitVtxWorld; + pOnB1[3] = -0.01f; + c->m_worldPos[0] = pOnB1; + int numPoints = 1; + c->m_worldNormal[3] = numPoints; + }//if (dstIdx < numPairs) + + /* + + int closestFaceB=-1; + float dmax = -FLT_MAX; + + { + for(int face=0;facem_numFaces;face++) + { + const float4 Normal = make_float4(faces[hullB->m_faceOffset+face].m_plane.x, + faces[hullB->m_faceOffset+face].m_plane.y, faces[hullB->m_faceOffset+face].m_plane.z,0.f); + const float4 WorldNormal = quatRotate(ornB, Normal); + float d = dot3F4(WorldNormal,separatingNormal); + if (d > dmax) + { + dmax = d; + closestFaceB = face; + } + } + } + + { + const btGpuFace polyB = faces[hullB->m_faceOffset+closestFaceB]; + const int numVertices = polyB.m_numIndices; + for(int e0=0;e0m_vertexOffset+indices[polyB.m_indexOffset+e0]]; + worldVertsB1[pairIndex*capacityWorldVerts+numWorldVertsB1++] = transform(b,posB,ornB); + } + } + + + */ + + + + printf("computeContactPlaneConvex\n"); +} void computeContactSphereConvex(int pairIndex, int bodyIndexA, int bodyIndexB, @@ -478,7 +597,7 @@ void GpuSatCollision::computeConvexConvexContactsGPUSAT( const btOpenCLArray hostAabbs; clAabbsWS.copyToHost(hostAabbs); @@ -542,6 +661,24 @@ void GpuSatCollision::computeConvexConvexContactsGPUSAT( const btOpenCLArray