Some changes in rendering, to get shadows for trimeshes
Add dynamic aabb tree (btDbvt) optimization for btCompoundShape/btCompoundCollisionAlgorithm Add btTransformAabb util, todo: deploy it throughout the codebase
This commit is contained in:
@@ -45,7 +45,7 @@ subject to the following restrictions:
|
||||
#include "GlutStuff.h"
|
||||
|
||||
|
||||
btVector3 centroid;
|
||||
btVector3 centroid=btVector3(0,0,0);
|
||||
btVector3 convexDecompositionObjectOffset(10,0,0);
|
||||
|
||||
#define CUBE_HALF_EXTENTS 4
|
||||
@@ -100,6 +100,7 @@ void ConvexDecompositionDemo::initPhysics(const char* filename)
|
||||
#endif//USE_PARALLEL_DISPATCHER
|
||||
|
||||
|
||||
convexDecompositionObjectOffset.setValue(10,0,0);
|
||||
|
||||
btVector3 worldAabbMin(-10000,-10000,-10000);
|
||||
btVector3 worldAabbMax(10000,10000,10000);
|
||||
@@ -124,10 +125,13 @@ void ConvexDecompositionDemo::initPhysics(const char* filename)
|
||||
|
||||
class MyConvexDecomposition : public ConvexDecomposition::ConvexDecompInterface
|
||||
{
|
||||
|
||||
ConvexDecompositionDemo* m_convexDemo;
|
||||
|
||||
public:
|
||||
|
||||
btAlignedObjectArray<btConvexHullShape*> m_convexShapes;
|
||||
btAlignedObjectArray<btVector3> m_convexCentroids;
|
||||
|
||||
MyConvexDecomposition (FILE* outputFile,ConvexDecompositionDemo* demo)
|
||||
:m_convexDemo(demo),
|
||||
mBaseCount(0),
|
||||
@@ -162,6 +166,7 @@ void ConvexDecompositionDemo::initPhysics(const char* filename)
|
||||
|
||||
//calc centroid, to shift vertices around center of mass
|
||||
centroid.setValue(0,0,0);
|
||||
|
||||
btAlignedObjectArray<btVector3> vertices;
|
||||
if ( 1 )
|
||||
{
|
||||
@@ -245,29 +250,17 @@ void ConvexDecompositionDemo::initPhysics(const char* filename)
|
||||
btGeometryUtil::getVerticesFromPlaneEquations(shiftedPlaneEquations,shiftedVertices);
|
||||
|
||||
|
||||
btCollisionShape* convexShape = new btConvexHullShape(&(shiftedVertices[0].getX()),shiftedVertices.size());
|
||||
btConvexHullShape* convexShape = new btConvexHullShape(&(shiftedVertices[0].getX()),shiftedVertices.size());
|
||||
|
||||
#else //SHRINK_OBJECT_INWARDS
|
||||
|
||||
#ifdef USE_PARALLEL_DISPATCHER
|
||||
//SPU/multi threaded version only supports convex hull with contiguous vertices at the moment
|
||||
btCollisionShape* convexShape = new btConvexHullShape(&(vertices[0].getX()),vertices.size());
|
||||
#else
|
||||
btCollisionShape* convexShape = new btConvexTriangleMeshShape(trimesh);
|
||||
#endif //USE_PARALLEL_DISPATCHER
|
||||
|
||||
btConvexHullShape* convexShape = new btConvexHullShape(&(vertices[0].getX()),vertices.size());
|
||||
#endif
|
||||
|
||||
convexShape->setMargin(0.01);
|
||||
|
||||
m_convexShapes.push_back(convexShape);
|
||||
m_convexCentroids.push_back(centroid);
|
||||
m_convexDemo->m_collisionShapes.push_back(convexShape);
|
||||
|
||||
btTransform trans;
|
||||
trans.setIdentity();
|
||||
trans.setOrigin(centroid-convexDecompositionObjectOffset);
|
||||
|
||||
//btRigidBody* body = m_convexDemo->localCreateRigidBody( mass, trans,convexShape);
|
||||
m_convexDemo->localCreateRigidBody( mass, trans,convexShape);
|
||||
mBaseCount+=result.mHullVcount; // advance the 'base index' counter.
|
||||
|
||||
|
||||
@@ -394,6 +387,34 @@ void ConvexDecompositionDemo::initPhysics(const char* filename)
|
||||
|
||||
ConvexBuilder cb(desc.mCallback);
|
||||
cb.process(desc);
|
||||
//now create some bodies
|
||||
|
||||
{
|
||||
btCompoundShape* compound = new btCompoundShape();
|
||||
m_collisionShapes.push_back (compound);
|
||||
|
||||
btTransform trans;
|
||||
trans.setIdentity();
|
||||
for (int i=0;i<convexDecomposition.m_convexShapes.size();i++)
|
||||
{
|
||||
|
||||
btVector3 centroid = convexDecomposition.m_convexCentroids[i];
|
||||
trans.setOrigin(centroid);
|
||||
btConvexHullShape* convexShape = convexDecomposition.m_convexShapes[i];
|
||||
compound->addChildShape(trans,convexShape);
|
||||
}
|
||||
btScalar mass=10.f;
|
||||
trans.setOrigin(-convexDecompositionObjectOffset);
|
||||
localCreateRigidBody( mass, trans,compound);
|
||||
convexDecompositionObjectOffset.setZ(6);
|
||||
trans.setOrigin(-convexDecompositionObjectOffset);
|
||||
localCreateRigidBody( mass, trans,compound);
|
||||
convexDecompositionObjectOffset.setZ(-6);
|
||||
trans.setOrigin(-convexDecompositionObjectOffset);
|
||||
localCreateRigidBody( mass, trans,compound);
|
||||
|
||||
}
|
||||
|
||||
|
||||
if (outputFile)
|
||||
fclose(outputFile);
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -166,7 +166,7 @@ void OGL_displaylist_register_shape(btCollisionShape * shape)
|
||||
|
||||
glNewList(dlist.m_dlist,GL_COMPILE);
|
||||
|
||||
glEnable(GL_CULL_FACE);
|
||||
// glEnable(GL_CULL_FACE);
|
||||
|
||||
glCullFace(GL_BACK);
|
||||
|
||||
@@ -177,7 +177,7 @@ void OGL_displaylist_register_shape(btCollisionShape * shape)
|
||||
concaveMesh->processAllTriangles(&drawCallback,aabbMin,aabbMax);
|
||||
}
|
||||
|
||||
glDisable(GL_CULL_FACE);
|
||||
// glDisable(GL_CULL_FACE);
|
||||
|
||||
glEndList();
|
||||
}
|
||||
@@ -237,12 +237,16 @@ public:
|
||||
} else
|
||||
{
|
||||
glBegin(GL_TRIANGLES);
|
||||
glColor3f(1, 1, 1);
|
||||
//glColor3f(1, 1, 1);
|
||||
|
||||
|
||||
glVertex3d(triangle[0].getX(), triangle[0].getY(), triangle[0].getZ());
|
||||
//glColor3f(0, 1, 0);
|
||||
glVertex3d(triangle[1].getX(), triangle[1].getY(), triangle[1].getZ());
|
||||
//glColor3f(0, 0, 1);
|
||||
glVertex3d(triangle[2].getX(), triangle[2].getY(), triangle[2].getZ());
|
||||
|
||||
glVertex3d(triangle[2].getX(), triangle[2].getY(), triangle[2].getZ());
|
||||
glVertex3d(triangle[1].getX(), triangle[1].getY(), triangle[1].getZ());
|
||||
glVertex3d(triangle[0].getX(), triangle[0].getY(), triangle[0].getZ());
|
||||
glEnd();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user