Permalink
Browse files

add scaling option for concave trimeshes

  • Loading branch information...
1 parent aec16d7 commit 430a4a042d96214f5aa7ed98f2e27ad1058aba86 @erwincoumans committed Jul 21, 2012
@@ -210,7 +210,7 @@ int btGpuNarrowphaseAndSolver::allocateCollidable()
return curSize;
}
-int btGpuNarrowphaseAndSolver::registerConcaveMeshShape(class objLoader* obj,btCollidable& col)
+int btGpuNarrowphaseAndSolver::registerConcaveMeshShape(class objLoader* obj,btCollidable& col, const float* scaling)
{
m_internalData->m_convexData->resize(m_internalData->m_numAcceleratedShapes+1);
@@ -236,9 +236,9 @@ int btGpuNarrowphaseAndSolver::registerConcaveMeshShape(class objLoader* obj,btC
{
obj_face* face = obj->faceList[i];
- btVector3 vert0(obj->vertexList[face->vertex_index[0]]->e[0],obj->vertexList[face->vertex_index[0]]->e[1],obj->vertexList[face->vertex_index[0]]->e[2]);
- btVector3 vert1(obj->vertexList[face->vertex_index[1]]->e[0],obj->vertexList[face->vertex_index[1]]->e[1],obj->vertexList[face->vertex_index[1]]->e[2]);
- btVector3 vert2(obj->vertexList[face->vertex_index[2]]->e[0],obj->vertexList[face->vertex_index[2]]->e[1],obj->vertexList[face->vertex_index[2]]->e[2]);
+ btVector3 vert0(obj->vertexList[face->vertex_index[0]]->e[0]*scaling[0],obj->vertexList[face->vertex_index[0]]->e[1]*scaling[1],obj->vertexList[face->vertex_index[0]]->e[2]*scaling[2]);
+ btVector3 vert1(obj->vertexList[face->vertex_index[1]]->e[0]*scaling[0],obj->vertexList[face->vertex_index[1]]->e[1]*scaling[1],obj->vertexList[face->vertex_index[1]]->e[2]*scaling[2]);
+ btVector3 vert2(obj->vertexList[face->vertex_index[2]]->e[0]*scaling[0],obj->vertexList[face->vertex_index[2]]->e[1]*scaling[1],obj->vertexList[face->vertex_index[2]]->e[2]*scaling[2]);
btVector3 normal = ((vert1-vert0).cross(vert2-vert0)).normalize();
btScalar c = -(normal.dot(vert0));
@@ -264,7 +264,7 @@ int btGpuNarrowphaseAndSolver::registerConcaveMeshShape(class objLoader* obj,btC
m_internalData->m_convexVertices.resize(vertexOffset+convex.m_numVertices);
for (int i=0;i<obj->vertexCount;i++)
{
- btVector3 vert(obj->vertexList[i]->e[0],obj->vertexList[i]->e[1],obj->vertexList[i]->e[2]);
+ btVector3 vert(obj->vertexList[i]->e[0]*scaling[0],obj->vertexList[i]->e[1]*scaling[1],obj->vertexList[i]->e[2]*scaling[2]);
m_internalData->m_convexVertices[vertexOffset+i] = vert;
}
@@ -75,7 +75,7 @@ class btGpuNarrowphaseAndSolver
virtual ~btGpuNarrowphaseAndSolver(void);
- int registerConcaveMeshShape(class objLoader* obj, btCollidable& col);
+ int registerConcaveMeshShape(class objLoader* obj, btCollidable& col, const float* scaling);
int registerConvexHullShape(class btConvexUtility* convexPtr, btCollidable& col);
int registerConvexHeightfield(class ConvexHeightField* convexShape,btCollidable& col);
int registerRigidBody(int collidableIndex, float mass, const float* position, const float* orientation, const float* aabbMin, const float* aabbMax,bool writeToGpu);
@@ -272,6 +272,9 @@ void createSceneProgrammatically(GLInstancingRenderer& renderer,CLPhysicsDemo& p
#else
char* fileName = "../../bin/wavefront/plane.obj";
//char* fileName = "../../bin/wavefront/triangle.obj";
+ //char* fileName = "../../bin/wavefront/cornell_box.obj";
+
+
#endif
bool loadFile = false;
@@ -288,7 +291,7 @@ void createSceneProgrammatically(GLInstancingRenderer& renderer,CLPhysicsDemo& p
int shapeIndex = renderer.registerShape(gfxShape->m_vertices,gfxShape->m_numvertices,gfxShape->m_indices,gfxShape->m_numIndices);
float groundPos[4] = {0,0,0,0};
renderer.registerGraphicsInstance(shapeIndex,groundPos,rotOrn,color,meshScaling);
- int colShape = physicsSim.registerConcaveMesh(objData);
+ int colShape = physicsSim.registerConcaveMesh(objData, meshScaling);
physicsSim.registerPhysicsInstance(0.f,groundPos, orn, colShape,colShape);
@@ -196,13 +196,13 @@ void CLPhysicsDemo::writeBodiesToGpu()
}
-int CLPhysicsDemo::registerConcaveMesh(objLoader* obj)
+int CLPhysicsDemo::registerConcaveMesh(objLoader* obj,const float* scaling)
{
int collidableIndex = narrowphaseAndSolver->allocateCollidable();
btCollidable& col = narrowphaseAndSolver->getCollidableCpu(collidableIndex);
col.m_shapeType = CollisionShape::SHAPE_CONCAVE_TRIMESH;
- col.m_shapeIndex = narrowphaseAndSolver->registerConcaveMeshShape(obj,col);
+ col.m_shapeIndex = narrowphaseAndSolver->registerConcaveMeshShape(obj,col,scaling);
@@ -212,7 +212,7 @@ int CLPhysicsDemo::registerConcaveMesh(objLoader* obj)
for (int i=0;i<obj->vertexCount;i++)
{
- btVector3 vtx(obj->vertexList[i]->e[0],obj->vertexList[i]->e[1],obj->vertexList[i]->e[2]);
+ btVector3 vtx(obj->vertexList[i]->e[0]*scaling[0],obj->vertexList[i]->e[1]*scaling[1],obj->vertexList[i]->e[2]*scaling[2]);
myAabbMin.setMin(vtx);
myAabbMax.setMax(vtx);
}
@@ -60,7 +60,7 @@ struct CLPhysicsDemo
int registerCollisionShape(const float* vertices, int strideInBytes, int numVertices, const float* scaling, bool noHeightField);
int registerConvexShape(class btConvexUtility* utilPtr , bool noHeightField);
- int registerConcaveMesh(class objLoader* obj);
+ int registerConcaveMesh(class objLoader* obj, const float* scaling);
int registerPhysicsInstance(float mass, const float* position, const float* orientation, int collisionShapeIndex, int userPointer);

0 comments on commit 430a4a0

Please sign in to comment.