- removed STL from the Bullet library: replace std::vector by btAlignedObjectArray. Also removed the std::set for overlapping pair set, and turned it into an overlapping pair array. The SAP only adds objects, never removed. Removal is postponed for during traversal of overlapping pairs (duplicates and non-overlapping pairs are removed during that traversal).

- added heap sort and binary search/linear search to btAlignedObjectArray
- fixed wrong cast, thanks Hamstray, http://www.continuousphysics.com/Bullet/phpBB2/viewtopic.php?t=1015
This commit is contained in:
ejcoumans
2007-03-06 09:59:17 +00:00
parent f8b714cd42
commit 054d672592
54 changed files with 512 additions and 246 deletions

View File

@@ -117,8 +117,9 @@ void BasicDemo::initPhysics()
m_dispatcher = new btCollisionDispatcher(true);
//#define USE_SWEEP_AND_PRUNE 1
#ifdef USE_SWEEP_AND_PRUNE
#define maxProxies 8192
btVector3 worldAabbMin(-10000,-10000,-10000);
btVector3 worldAabbMax(10000,10000,10000);
m_overlappingPairCache = new btAxisSweep3(worldAabbMin,worldAabbMax,maxProxies);

View File

@@ -17,7 +17,6 @@ subject to the following restrictions:
#include "DemoApplication.h"
#include <vector>
class btCollisionShape;
class btOverlappingPairCache;
@@ -30,7 +29,7 @@ class BasicDemo : public DemoApplication
{
//keep the collision shapes, for deletion/cleanup
std::vector<btCollisionShape*> m_collisionShapes;
btAlignedObjectArray<btCollisionShape*> m_collisionShapes;
btOverlappingPairCache* m_overlappingPairCache;

View File

@@ -17,6 +17,9 @@ subject to the following restrictions:
#include "BspLoader.h"
#include "LinearMath/btVector3.h"
#include "LinearMath/btGeometryUtil.h"
#include <stdio.h>
#include <string.h>
void BspConverter::convertBsp(BspLoader& bspLoader,float scaling)
{

View File

@@ -17,7 +17,6 @@ subject to the following restrictions:
#define BSP_CONVERTER_H
class BspLoader;
#include <vector>
#include "LinearMath/btVector3.h"
#include "LinearMath/btAlignedObjectArray.h"

View File

@@ -195,9 +195,9 @@ void BspDemo::initPhysics(char* bspfilename)
void BspDemo::clientMoveAndDisplay()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
float dt = m_clock.getTimeMicroseconds() * 0.000001f;
m_clock.reset();
m_dynamicsWorld->stepSimulation(dt);
renderme();

View File

@@ -22,6 +22,8 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#include "BspLoader.h"
#include <stdio.h>
#include <string.h>
typedef struct
{
@@ -45,6 +47,20 @@ bool tokenready; // only true if UnGetToken was just called
int extrasize = 100;
BspLoader::BspLoader()
:m_num_entities(0)
{
m_Endianness = getMachineEndianness();
if (m_Endianness == BSP_BIG_ENDIAN)
{
printf("Machine is BIG_ENDIAN\n");
} else
{
printf("Machine is Little Endian\n");
}
}
bool BspLoader::loadBSPFile( void* memoryBuffer) {
BSPHeader *header = (BSPHeader*) memoryBuffer;

View File

@@ -25,6 +25,8 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#ifndef BSP_LOADER_H
#define BSP_LOADER_H
#include "LinearMath/btAlignedObjectArray.h"
#define BSPMAXTOKEN 1024
#define BSPMAX_KEY 32
#define BSPMAX_VALUE 1024
@@ -49,7 +51,6 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#define HEADER_LUMPS 17
#define MAX_QPATH 64
#include <vector>
typedef struct {
@@ -172,18 +173,8 @@ class BspLoader
public:
BspLoader()
:m_num_entities(0)
{
m_Endianness = getMachineEndianness();
if (m_Endianness == BSP_BIG_ENDIAN)
{
printf("Machine is BIG_ENDIAN\n");
} else
{
printf("Machine is Little Endian\n");
}
}
BspLoader();
bool loadBSPFile( void* memoryBuffer);
const char* getValueForKey( const BSPEntity *ent, const char *key ) const;
@@ -236,53 +227,53 @@ class BspLoader
public: //easier for conversion
int m_num_entities;
std::vector<BSPEntity> m_entities;
btAlignedObjectArray<BSPEntity> m_entities;
int m_nummodels;
std::vector<BSPModel> m_dmodels;
btAlignedObjectArray<BSPModel> m_dmodels;
int m_numShaders;
std::vector<BSPShader> m_dshaders;
btAlignedObjectArray<BSPShader> m_dshaders;
int m_entdatasize;
std::vector<char> m_dentdata;
btAlignedObjectArray<char> m_dentdata;
int m_numleafs;
std::vector<BSPLeaf> m_dleafs;
btAlignedObjectArray<BSPLeaf> m_dleafs;
int m_numplanes;
std::vector<BSPPlane> m_dplanes;
btAlignedObjectArray<BSPPlane> m_dplanes;
int m_numnodes;
std::vector<BSPNode> m_dnodes;
btAlignedObjectArray<BSPNode> m_dnodes;
int m_numleafsurfaces;
std::vector<int> m_dleafsurfaces;
btAlignedObjectArray<int> m_dleafsurfaces;
int m_numleafbrushes;
std::vector<int> m_dleafbrushes;
btAlignedObjectArray<int> m_dleafbrushes;
int m_numbrushes;
std::vector<BSPBrush> m_dbrushes;
btAlignedObjectArray<BSPBrush> m_dbrushes;
int m_numbrushsides;
std::vector<BSPBrushSide> m_dbrushsides;
btAlignedObjectArray<BSPBrushSide> m_dbrushsides;
int m_numLightBytes;
std::vector<unsigned char> m_lightBytes;
btAlignedObjectArray<unsigned char> m_lightBytes;
int m_numGridPoints;
std::vector<unsigned char> m_gridData;
btAlignedObjectArray<unsigned char> m_gridData;
int m_numVisBytes;
std::vector<unsigned char> m_visBytes;
btAlignedObjectArray<unsigned char> m_visBytes;
int m_numDrawIndexes;
std::vector<int> m_drawIndexes;
btAlignedObjectArray<int> m_drawIndexes;
int m_numDrawSurfaces;
std::vector<BSPSurface> m_drawSurfaces;
btAlignedObjectArray<BSPSurface> m_drawSurfaces;
enum
{

View File

@@ -203,6 +203,7 @@ void CcdPhysicsDemo::clientMoveAndDisplay()
#endif //USE_KINEMATIC_GROUND
float dt = m_clock.getTimeMicroseconds() * 0.000001f;
m_clock.reset();
printf("dt = %f: ",dt);

View File

@@ -747,7 +747,10 @@ void ColladaConverter::PreparePhysicsObject(struct btRigidBodyInput& input, bool
}
if (startScale.length() < 0.001)
printf("invalid scale\n");
colShape->setLocalScaling(startScale);
btRigidBody* body= createRigidBody(isDynamics,mass,startTransform,colShape);
if (body)
@@ -881,7 +884,7 @@ bool ColladaConverter::saveAs(const char* filename)
}
//some code that de-mangles the windows filename passed in as argument
char cleaned_filename[512];
char cleaned_filename[513];
char* getLastFileName()
{
return cleaned_filename;
@@ -928,7 +931,7 @@ char* fixFileName(const char* lpCmdLine)
out++;
}
cleaned_filename[i] = '\0';
cleaned_filename[i+1] = '\0';
return cleaned_filename;
}

View File

@@ -192,7 +192,6 @@ void ConcaveDemo::clientMoveAndDisplay()
float dt = m_clock.getTimeMicroseconds() * 0.000001f;
m_clock.reset();
m_dynamicsWorld->stepSimulation(dt);
renderme();

View File

@@ -172,7 +172,6 @@ void ConstraintDemo::clientMoveAndDisplay()
float dt = float(m_clock.getTimeMicroseconds()) * 0.000001f;
m_clock.reset();
//printf("dt = %f: ",dt);
{

View File

@@ -17,7 +17,7 @@ subject to the following restrictions:
#include "DemoApplication.h"
class btCollisionAlgorithmCreateFunc;
struct btCollisionAlgorithmCreateFunc;
///ConcaveDemo shows usage of static concave triangle meshes
///It also shows per-triangle material (friction/restitution) through CustomMaterialCombinerCallback

View File

@@ -1868,7 +1868,6 @@ void ConcaveDemo::clientMoveAndDisplay()
float dt = float(m_clock.getTimeMicroseconds()) * 0.000001f;
m_clock.reset();
m_dynamicsWorld->stepSimulation(dt);
renderme();

View File

@@ -900,13 +900,16 @@ void DemoApplication::clientResetScene()
{
btCollisionObject* colObj = m_dynamicsWorld->getCollisionObjectArray()[i];
btRigidBody* body = btRigidBody::upcast(colObj);
if (body && body->getMotionState())
if (body)
{
btDefaultMotionState* myMotionState = (btDefaultMotionState*)body->getMotionState();
myMotionState->m_graphicsWorldTrans = myMotionState->m_startWorldTrans;
colObj->setWorldTransform( myMotionState->m_graphicsWorldTrans );
colObj->setInterpolationWorldTransform( myMotionState->m_startWorldTrans );
colObj->activate();
if (body->getMotionState())
{
btDefaultMotionState* myMotionState = (btDefaultMotionState*)body->getMotionState();
myMotionState->m_graphicsWorldTrans = myMotionState->m_startWorldTrans;
colObj->setWorldTransform( myMotionState->m_graphicsWorldTrans );
colObj->setInterpolationWorldTransform( myMotionState->m_startWorldTrans );
colObj->activate();
}
//removed cached contact points
m_dynamicsWorld->getBroadphase()->cleanProxyFromPairs(colObj->getBroadphaseHandle());

View File

@@ -49,9 +49,8 @@ class DemoApplication
{
protected:
hidden::Clock m_clock;
btClock m_clock;
///this is the most important class
btDynamicsWorld* m_dynamicsWorld;

View File

@@ -40,6 +40,11 @@ void GLDebugDrawer::setDebugMode(int debugMode)
}
void GLDebugDrawer::reportErrorWarning(const char* warningString)
{
printf(warningString);
}
void GLDebugDrawer::drawContactPoint(const btVector3& pointOnB,const btVector3& normalOnB,btScalar distance,int lifeTime,const btVector3& color)
{
if (m_debugMode & btIDebugDraw::DBG_DrawContactPoints)

View File

@@ -19,6 +19,8 @@ public:
virtual void drawContactPoint(const btVector3& PointOnB,const btVector3& normalOnB,btScalar distance,int lifeTime,const btVector3& color);
virtual void reportErrorWarning(const char* warningString);
virtual void setDebugMode(int debugMode);
virtual int getDebugMode() const { return m_debugMode;}

View File

@@ -143,10 +143,8 @@ void UserCollisionAlgorithm::clientMoveAndDisplay()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
float dt = m_clock.getTimeMicroseconds() * 0.000001f;
m_clock.reset();
m_dynamicsWorld->stepSimulation(dt);

View File

@@ -325,7 +325,6 @@ void VehicleDemo::clientMoveAndDisplay()
float dt = m_clock.getTimeMicroseconds() * 0.000001f;
m_clock.reset();
if (m_dynamicsWorld)
{
//during idle mode, just run 1 simulation step maximum