Code-style consistency improvement:

Apply clang-format-all.sh using the _clang-format file through all the cpp/.h files.
make sure not to apply it to certain serialization structures, since some parser expects the * as part of the name, instead of type.
This commit contains no other changes aside from adding and applying clang-format-all.sh
This commit is contained in:
erwincoumans
2018-09-23 14:17:31 -07:00
parent b73b05e9fb
commit ab8f16961e
1773 changed files with 1081087 additions and 474249 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -2,7 +2,6 @@
#ifndef COMMON_RIGID_BODY_MT_BASE_H
#define COMMON_RIGID_BODY_MT_BASE_H
#include "btBulletDynamicsCommon.h"
#include "../CommonInterfaces/CommonExampleInterface.h"
#include "../CommonInterfaces/CommonGUIHelperInterface.h"
@@ -13,49 +12,57 @@
enum SolverType
{
SOLVER_TYPE_SEQUENTIAL_IMPULSE,
SOLVER_TYPE_SEQUENTIAL_IMPULSE_MT,
SOLVER_TYPE_NNCG,
SOLVER_TYPE_MLCP_PGS,
SOLVER_TYPE_MLCP_DANTZIG,
SOLVER_TYPE_MLCP_LEMKE,
SOLVER_TYPE_SEQUENTIAL_IMPULSE,
SOLVER_TYPE_SEQUENTIAL_IMPULSE_MT,
SOLVER_TYPE_NNCG,
SOLVER_TYPE_MLCP_PGS,
SOLVER_TYPE_MLCP_DANTZIG,
SOLVER_TYPE_MLCP_LEMKE,
SOLVER_TYPE_COUNT
SOLVER_TYPE_COUNT
};
inline const char* getSolverTypeName( SolverType t )
inline const char* getSolverTypeName(SolverType t)
{
switch (t)
{
case SOLVER_TYPE_SEQUENTIAL_IMPULSE: return "SequentialImpulse";
case SOLVER_TYPE_SEQUENTIAL_IMPULSE_MT: return "SequentialImpulseMt";
case SOLVER_TYPE_NNCG: return "NNCG";
case SOLVER_TYPE_MLCP_PGS: return "MLCP ProjectedGaussSeidel";
case SOLVER_TYPE_MLCP_DANTZIG: return "MLCP Dantzig";
case SOLVER_TYPE_MLCP_LEMKE: return "MLCP Lemke";
default:{}
}
btAssert( !"unhandled solver type in switch" );
return "???";
switch (t)
{
case SOLVER_TYPE_SEQUENTIAL_IMPULSE:
return "SequentialImpulse";
case SOLVER_TYPE_SEQUENTIAL_IMPULSE_MT:
return "SequentialImpulseMt";
case SOLVER_TYPE_NNCG:
return "NNCG";
case SOLVER_TYPE_MLCP_PGS:
return "MLCP ProjectedGaussSeidel";
case SOLVER_TYPE_MLCP_DANTZIG:
return "MLCP Dantzig";
case SOLVER_TYPE_MLCP_LEMKE:
return "MLCP Lemke";
default:
{
}
}
btAssert(!"unhandled solver type in switch");
return "???";
}
struct CommonRigidBodyMTBase : public CommonExampleInterface
{
//keep the collision shapes, for deletion/cleanup
btAlignedObjectArray<btCollisionShape*> m_collisionShapes;
btBroadphaseInterface* m_broadphase;
btCollisionDispatcher* m_dispatcher;
btConstraintSolver* m_solver;
//keep the collision shapes, for deletion/cleanup
btAlignedObjectArray<btCollisionShape*> m_collisionShapes;
btBroadphaseInterface* m_broadphase;
btCollisionDispatcher* m_dispatcher;
btConstraintSolver* m_solver;
btDefaultCollisionConfiguration* m_collisionConfiguration;
btDiscreteDynamicsWorld* m_dynamicsWorld;
SolverType m_solverType;
bool m_multithreadedWorld;
bool m_multithreadCapable;
SolverType m_solverType;
bool m_multithreadedWorld;
bool m_multithreadCapable;
//data for picking objects
class btRigidBody* m_pickedBody;
class btRigidBody* m_pickedBody;
class btTypedConstraint* m_pickedConstraint;
int m_savedState;
int m_savedState;
btVector3 m_oldPickingPos;
btVector3 m_hitPos;
btScalar m_oldPickingDist;
@@ -64,13 +71,12 @@ struct CommonRigidBodyMTBase : public CommonExampleInterface
CommonRigidBodyMTBase(struct GUIHelperInterface* helper);
virtual ~CommonRigidBodyMTBase();
btDiscreteDynamicsWorld* getDynamicsWorld()
btDiscreteDynamicsWorld* getDynamicsWorld()
{
return m_dynamicsWorld;
}
virtual void createDefaultParameters();
virtual void createDefaultParameters();
virtual void createEmptyDynamicsWorld();
virtual void stepSimulation(float deltaTime)
@@ -81,8 +87,8 @@ struct CommonRigidBodyMTBase : public CommonExampleInterface
}
}
virtual void drawScreenText();
virtual void renderScene();
virtual void drawScreenText();
virtual void renderScene();
virtual void physicsDebugDraw(int debugFlags);
virtual void exitPhysics()
@@ -91,15 +97,14 @@ struct CommonRigidBodyMTBase : public CommonExampleInterface
//cleanup in the reverse order of creation/initialization
//remove the rigidbodies from the dynamics world and delete them
if (m_dynamicsWorld)
{
int i;
for (i = m_dynamicsWorld->getNumConstraints() - 1; i >= 0; i--)
{
m_dynamicsWorld->removeConstraint(m_dynamicsWorld->getConstraint(i));
}
int i;
for (i = m_dynamicsWorld->getNumConstraints() - 1; i >= 0; i--)
{
m_dynamicsWorld->removeConstraint(m_dynamicsWorld->getConstraint(i));
}
for (i = m_dynamicsWorld->getNumCollisionObjects() - 1; i >= 0; i--)
{
btCollisionObject* obj = m_dynamicsWorld->getCollisionObjectArray()[i];
@@ -113,7 +118,7 @@ struct CommonRigidBodyMTBase : public CommonExampleInterface
}
}
//delete collision shapes
for (int j = 0; j<m_collisionShapes.size(); j++)
for (int j = 0; j < m_collisionShapes.size(); j++)
{
btCollisionShape* shape = m_collisionShapes[j];
delete shape;
@@ -121,84 +126,80 @@ struct CommonRigidBodyMTBase : public CommonExampleInterface
m_collisionShapes.clear();
delete m_dynamicsWorld;
m_dynamicsWorld=0;
m_dynamicsWorld = 0;
delete m_solver;
m_solver=0;
m_solver = 0;
delete m_broadphase;
m_broadphase=0;
m_broadphase = 0;
delete m_dispatcher;
m_dispatcher=0;
m_dispatcher = 0;
delete m_collisionConfiguration;
m_collisionConfiguration=0;
m_collisionConfiguration = 0;
}
virtual void debugDraw(int debugDrawFlags)
{
if (m_dynamicsWorld)
{
virtual void debugDraw(int debugDrawFlags)
{
if (m_dynamicsWorld)
{
if (m_dynamicsWorld->getDebugDrawer())
{
m_dynamicsWorld->getDebugDrawer()->setDebugMode(debugDrawFlags);
}
m_dynamicsWorld->debugDrawWorld();
}
m_dynamicsWorld->debugDrawWorld();
}
}
}
virtual bool keyboardCallback(int key, int state)
virtual bool keyboardCallback(int key, int state)
{
if ((key==B3G_F3) && state && m_dynamicsWorld)
if ((key == B3G_F3) && state && m_dynamicsWorld)
{
btDefaultSerializer* serializer = new btDefaultSerializer();
btDefaultSerializer* serializer = new btDefaultSerializer();
m_dynamicsWorld->serialize(serializer);
FILE* file = fopen("testFile.bullet","wb");
fwrite(serializer->getBufferPointer(),serializer->getCurrentBufferSize(),1, file);
FILE* file = fopen("testFile.bullet", "wb");
fwrite(serializer->getBufferPointer(), serializer->getCurrentBufferSize(), 1, file);
fclose(file);
//b3Printf("btDefaultSerializer wrote testFile.bullet");
delete serializer;
return true;
}
return false;//don't handle this key
return false; //don't handle this key
}
btVector3 getRayTo(int x,int y)
btVector3 getRayTo(int x, int y)
{
CommonRenderInterface* renderer = m_guiHelper->getRenderInterface();
if (!renderer)
{
btAssert(0);
return btVector3(0,0,0);
return btVector3(0, 0, 0);
}
float top = 1.f;
float bottom = -1.f;
float nearPlane = 1.f;
float tanFov = (top-bottom)*0.5f / nearPlane;
float tanFov = (top - bottom) * 0.5f / nearPlane;
float fov = btScalar(2.0) * btAtan(tanFov);
btVector3 camPos,camTarget;
btVector3 camPos, camTarget;
renderer->getActiveCamera()->getCameraPosition(camPos);
renderer->getActiveCamera()->getCameraTargetPosition(camTarget);
btVector3 rayFrom = camPos;
btVector3 rayForward = (camTarget-camPos);
btVector3 rayFrom = camPos;
btVector3 rayForward = (camTarget - camPos);
rayForward.normalize();
float farPlane = 10000.f;
rayForward*= farPlane;
rayForward *= farPlane;
btVector3 rightOffset;
btVector3 cameraUp=btVector3(0,0,0);
cameraUp[m_guiHelper->getAppInterface()->getUpAxis()]=1;
btVector3 cameraUp = btVector3(0, 0, 0);
cameraUp[m_guiHelper->getAppInterface()->getUpAxis()] = 1;
btVector3 vertical = cameraUp;
@@ -208,25 +209,22 @@ struct CommonRigidBodyMTBase : public CommonExampleInterface
vertical = hor.cross(rayForward);
vertical.safeNormalize();
float tanfov = tanf(0.5f*fov);
float tanfov = tanf(0.5f * fov);
hor *= 2.f * farPlane * tanfov;
vertical *= 2.f * farPlane * tanfov;
btScalar aspect;
float width = float(renderer->getScreenWidth());
float height = float (renderer->getScreenHeight());
float height = float(renderer->getScreenHeight());
aspect = width / height;
hor*=aspect;
aspect = width / height;
hor *= aspect;
btVector3 rayToCenter = rayFrom + rayForward;
btVector3 dHor = hor * 1.f/width;
btVector3 dVert = vertical * 1.f/height;
btVector3 dHor = hor * 1.f / width;
btVector3 dVert = vertical * 1.f / height;
btVector3 rayTo = rayToCenter - 0.5f * hor + 0.5f * vertical;
rayTo += btScalar(x) * dHor;
@@ -234,10 +232,10 @@ struct CommonRigidBodyMTBase : public CommonExampleInterface
return rayTo;
}
virtual bool mouseMoveCallback(float x,float y)
virtual bool mouseMoveCallback(float x, float y)
{
CommonRenderInterface* renderer = m_guiHelper->getRenderInterface();
if (!renderer)
{
btAssert(0);
@@ -247,21 +245,21 @@ struct CommonRigidBodyMTBase : public CommonExampleInterface
btVector3 rayTo = getRayTo(int(x), int(y));
btVector3 rayFrom;
renderer->getActiveCamera()->getCameraPosition(rayFrom);
movePickedBody(rayFrom,rayTo);
movePickedBody(rayFrom, rayTo);
return false;
}
virtual bool mouseButtonCallback(int button, int state, float x, float y)
virtual bool mouseButtonCallback(int button, int state, float x, float y)
{
CommonRenderInterface* renderer = m_guiHelper->getRenderInterface();
if (!renderer)
{
btAssert(0);
return false;
}
CommonWindowInterface* window = m_guiHelper->getAppInterface()->m_window;
#if 0
@@ -289,25 +287,23 @@ struct CommonRigidBodyMTBase : public CommonExampleInterface
printf("NO CONTROL pressed\n");
}
#endif
if (state==1)
if (state == 1)
{
if(button==0 && (!window->isModifierKeyPressed(B3G_ALT) && !window->isModifierKeyPressed(B3G_CONTROL) ))
if (button == 0 && (!window->isModifierKeyPressed(B3G_ALT) && !window->isModifierKeyPressed(B3G_CONTROL)))
{
btVector3 camPos;
renderer->getActiveCamera()->getCameraPosition(camPos);
btVector3 rayFrom = camPos;
btVector3 rayTo = getRayTo(int(x),int(y));
btVector3 rayTo = getRayTo(int(x), int(y));
pickBody(rayFrom, rayTo);
}
} else
}
else
{
if (button==0)
if (button == 0)
{
removePickingConstraint();
//remove p2p
@@ -318,10 +314,9 @@ struct CommonRigidBodyMTBase : public CommonExampleInterface
return false;
}
virtual bool pickBody(const btVector3& rayFromWorld, const btVector3& rayToWorld)
{
if (m_dynamicsWorld==0)
if (m_dynamicsWorld == 0)
return false;
btCollisionWorld::ClosestRayResultCallback rayCallback(rayFromWorld, rayToWorld);
@@ -329,7 +324,6 @@ struct CommonRigidBodyMTBase : public CommonExampleInterface
m_dynamicsWorld->rayTest(rayFromWorld, rayToWorld, rayCallback);
if (rayCallback.hasHit())
{
btVector3 pickPos = rayCallback.m_hitPointWorld;
btRigidBody* body = (btRigidBody*)btRigidBody::upcast(rayCallback.m_collisionObject);
if (body)
@@ -352,7 +346,6 @@ struct CommonRigidBodyMTBase : public CommonExampleInterface
}
}
// pickObject(pickPos, rayCallback.m_collisionObject);
m_oldPickingPos = rayToWorld;
m_hitPos = pickPos;
@@ -364,7 +357,7 @@ struct CommonRigidBodyMTBase : public CommonExampleInterface
}
virtual bool movePickedBody(const btVector3& rayFromWorld, const btVector3& rayToWorld)
{
if (m_pickedBody && m_pickedConstraint)
if (m_pickedBody && m_pickedConstraint)
{
btPoint2PointConstraint* pickCon = static_cast<btPoint2PointConstraint*>(m_pickedConstraint);
if (pickCon)
@@ -397,15 +390,13 @@ struct CommonRigidBodyMTBase : public CommonExampleInterface
}
}
btBoxShape* createBoxShape(const btVector3& halfExtents)
{
btBoxShape* box = new btBoxShape(halfExtents);
return box;
}
btRigidBody* createRigidBody(float mass, const btTransform& startTransform, btCollisionShape* shape, const btVector4& color = btVector4(1, 0, 0, 1))
btRigidBody* createRigidBody(float mass, const btTransform& startTransform, btCollisionShape* shape, const btVector4& color = btVector4(1, 0, 0, 1))
{
btAssert((!shape || shape->getShapeType() != INVALID_SHAPE_PROXYTYPE));
@@ -416,7 +407,7 @@ struct CommonRigidBodyMTBase : public CommonExampleInterface
if (isDynamic)
shape->calculateLocalInertia(mass, localInertia);
//using motionstate is recommended, it provides interpolation capabilities, and only synchronizes 'active' objects
//using motionstate is recommended, it provides interpolation capabilities, and only synchronizes 'active' objects
#define USE_MOTIONSTATE 1
#ifdef USE_MOTIONSTATE
@@ -430,28 +421,24 @@ struct CommonRigidBodyMTBase : public CommonExampleInterface
#else
btRigidBody* body = new btRigidBody(mass, 0, shape, localInertia);
body->setWorldTransform(startTransform);
#endif//
#endif //
body->setUserIndex(-1);
m_dynamicsWorld->addRigidBody(body);
return body;
}
btRigidBody* createKinematicBody(const btTransform& startTransform, btCollisionShape* shape)
{
btAssert( ( !shape || shape->getShapeType() != INVALID_SHAPE_PROXYTYPE ) );
btRigidBody* body = new btRigidBody( 0.0f, NULL, shape );
body->setWorldTransform( startTransform );
body->setCollisionFlags( body->getCollisionFlags() | btCollisionObject::CF_KINEMATIC_OBJECT );
body->setUserIndex( -1 );
m_dynamicsWorld->addRigidBody( body );
return body;
}
btRigidBody* createKinematicBody(const btTransform& startTransform, btCollisionShape* shape)
{
btAssert((!shape || shape->getShapeType() != INVALID_SHAPE_PROXYTYPE));
btRigidBody* body = new btRigidBody(0.0f, NULL, shape);
body->setWorldTransform(startTransform);
body->setCollisionFlags(body->getCollisionFlags() | btCollisionObject::CF_KINEMATIC_OBJECT);
body->setUserIndex(-1);
m_dynamicsWorld->addRigidBody(body);
return body;
}
};
#endif //#define COMMON_RIGID_BODY_MT_BASE_H
#endif //#define COMMON_RIGID_BODY_MT_BASE_H

View File

@@ -20,11 +20,9 @@ subject to the following restrictions:
#include "btBulletCollisionCommon.h"
#include "LinearMath/btAlignedObjectArray.h"
#include <stdio.h> //printf debugging
#include <stdio.h> //printf debugging
#include <algorithm>
static btScalar gSliderStackRows = 1.0f;
static btScalar gSliderStackColumns = 1.0f;
static btScalar gSliderStackHeight = 15.0f;
@@ -35,101 +33,101 @@ static btScalar gSliderGroundTilt = 0.0f;
static btScalar gSliderRollingFriction = 0.0f;
static bool gSpheresNotBoxes = false;
static void boolPtrButtonCallback( int buttonId, bool buttonState, void* userPointer )
static void boolPtrButtonCallback(int buttonId, bool buttonState, void* userPointer)
{
if ( bool* val = static_cast<bool*>( userPointer ) )
{
*val = !*val;
}
if (bool* val = static_cast<bool*>(userPointer))
{
*val = !*val;
}
}
/// MultiThreadedDemo shows how to setup and use multithreading
class MultiThreadedDemo : public CommonRigidBodyMTBase
class MultiThreadedDemo : public CommonRigidBodyMTBase
{
static const int kUpAxis = 1;
static const int kUpAxis = 1;
btRigidBody* localCreateRigidBody(btScalar mass, const btTransform& worldTransform, btCollisionShape* colSape);
btVector3 m_cameraTargetPos;
float m_cameraPitch;
float m_cameraYaw;
float m_cameraDist;
btRigidBody* m_groundBody;
btTransform m_groundStartXf;
float m_groundMovePhase;
float m_prevRollingFriction;
btVector3 m_cameraTargetPos;
float m_cameraPitch;
float m_cameraYaw;
float m_cameraDist;
btRigidBody* m_groundBody;
btTransform m_groundStartXf;
float m_groundMovePhase;
float m_prevRollingFriction;
void createStack( const btTransform& trans, btCollisionShape* boxShape, const btVector3& halfBoxSize, int size, int width );
void createSceneObjects();
void destroySceneObjects();
void createStack(const btTransform& trans, btCollisionShape* boxShape, const btVector3& halfBoxSize, int size, int width);
void createSceneObjects();
void destroySceneObjects();
public:
BT_DECLARE_ALIGNED_ALLOCATOR();
BT_DECLARE_ALIGNED_ALLOCATOR();
MultiThreadedDemo( struct GUIHelperInterface* helper );
MultiThreadedDemo(struct GUIHelperInterface* helper);
virtual ~MultiThreadedDemo() {}
btQuaternion getGroundRotation() const
{
btScalar tilt = gSliderGroundTilt * SIMD_2_PI / 360.0f;
return btQuaternion( btVector3( 1.0f, 0.0f, 0.0f ), tilt );
}
struct TestSumBody : public btIParallelSumBody
{
virtual btScalar sumLoop( int iBegin, int iEnd ) const BT_OVERRIDE
{
btScalar sum = 0.0f;
for (int i = iBegin; i < iEnd; ++i)
{
if (i > 0)
{
sum += 1.0f / btScalar(i);
}
}
return sum;
}
};
virtual void stepSimulation( float deltaTime ) BT_OVERRIDE
{
if ( m_dynamicsWorld )
{
if ( m_prevRollingFriction != gSliderRollingFriction )
{
m_prevRollingFriction = gSliderRollingFriction;
btCollisionObjectArray& objArray = m_dynamicsWorld->getCollisionObjectArray();
for ( int i = 0; i < objArray.size(); ++i )
{
btCollisionObject* obj = objArray[ i ];
obj->setRollingFriction( gSliderRollingFriction );
}
}
if (m_groundBody)
{
// update ground
const float cyclesPerSecond = 1.0f;
m_groundMovePhase += cyclesPerSecond * deltaTime;
m_groundMovePhase -= floor( m_groundMovePhase ); // keep phase between 0 and 1
btTransform xf = m_groundStartXf;
float gndHOffset = btSin(m_groundMovePhase * SIMD_2_PI) * gSliderGroundHorizontalAmplitude;
float gndHVel = btCos(m_groundMovePhase * SIMD_2_PI) * gSliderGroundHorizontalAmplitude * cyclesPerSecond * SIMD_2_PI; // d(gndHOffset)/dt
float gndVOffset = btSin(m_groundMovePhase * SIMD_2_PI) * gSliderGroundVerticalAmplitude;
float gndVVel = btCos(m_groundMovePhase * SIMD_2_PI) * gSliderGroundVerticalAmplitude * cyclesPerSecond * SIMD_2_PI; // d(gndVOffset)/dt
btVector3 offset(0,0,0);
btVector3 vel(0,0,0);
int horizAxis = 2;
offset[horizAxis] = gndHOffset;
vel[horizAxis] = gndHVel;
offset[kUpAxis] = gndVOffset;
vel[kUpAxis] = gndVVel;
xf.setOrigin(xf.getOrigin() + offset);
xf.setRotation( getGroundRotation() );
m_groundBody->setWorldTransform( xf );
m_groundBody->setLinearVelocity( vel );
}
// always step by 1/60 for benchmarking
m_dynamicsWorld->stepSimulation( 1.0f / 60.0f, 0 );
}
btQuaternion getGroundRotation() const
{
btScalar tilt = gSliderGroundTilt * SIMD_2_PI / 360.0f;
return btQuaternion(btVector3(1.0f, 0.0f, 0.0f), tilt);
}
struct TestSumBody : public btIParallelSumBody
{
virtual btScalar sumLoop(int iBegin, int iEnd) const BT_OVERRIDE
{
btScalar sum = 0.0f;
for (int i = iBegin; i < iEnd; ++i)
{
if (i > 0)
{
sum += 1.0f / btScalar(i);
}
}
return sum;
}
};
virtual void stepSimulation(float deltaTime) BT_OVERRIDE
{
if (m_dynamicsWorld)
{
if (m_prevRollingFriction != gSliderRollingFriction)
{
m_prevRollingFriction = gSliderRollingFriction;
btCollisionObjectArray& objArray = m_dynamicsWorld->getCollisionObjectArray();
for (int i = 0; i < objArray.size(); ++i)
{
btCollisionObject* obj = objArray[i];
obj->setRollingFriction(gSliderRollingFriction);
}
}
if (m_groundBody)
{
// update ground
const float cyclesPerSecond = 1.0f;
m_groundMovePhase += cyclesPerSecond * deltaTime;
m_groundMovePhase -= floor(m_groundMovePhase); // keep phase between 0 and 1
btTransform xf = m_groundStartXf;
float gndHOffset = btSin(m_groundMovePhase * SIMD_2_PI) * gSliderGroundHorizontalAmplitude;
float gndHVel = btCos(m_groundMovePhase * SIMD_2_PI) * gSliderGroundHorizontalAmplitude * cyclesPerSecond * SIMD_2_PI; // d(gndHOffset)/dt
float gndVOffset = btSin(m_groundMovePhase * SIMD_2_PI) * gSliderGroundVerticalAmplitude;
float gndVVel = btCos(m_groundMovePhase * SIMD_2_PI) * gSliderGroundVerticalAmplitude * cyclesPerSecond * SIMD_2_PI; // d(gndVOffset)/dt
btVector3 offset(0, 0, 0);
btVector3 vel(0, 0, 0);
int horizAxis = 2;
offset[horizAxis] = gndHOffset;
vel[horizAxis] = gndHVel;
offset[kUpAxis] = gndVOffset;
vel[kUpAxis] = gndVVel;
xf.setOrigin(xf.getOrigin() + offset);
xf.setRotation(getGroundRotation());
m_groundBody->setWorldTransform(xf);
m_groundBody->setLinearVelocity(vel);
}
// always step by 1/60 for benchmarking
m_dynamicsWorld->stepSimulation(1.0f / 60.0f, 0);
}
#if 0
{
// test parallelSum
@@ -138,221 +136,212 @@ public:
printf( "sum = %f\n", testSum );
}
#endif
}
virtual void initPhysics() BT_OVERRIDE;
virtual void resetCamera() BT_OVERRIDE
{
m_guiHelper->resetCamera( m_cameraDist,
m_cameraYaw,
m_cameraPitch,
m_cameraTargetPos.x(),
m_cameraTargetPos.y(),
m_cameraTargetPos.z()
);
}
virtual void initPhysics() BT_OVERRIDE;
virtual void resetCamera() BT_OVERRIDE
{
m_guiHelper->resetCamera(m_cameraDist,
m_cameraYaw,
m_cameraPitch,
m_cameraTargetPos.x(),
m_cameraTargetPos.y(),
m_cameraTargetPos.z());
}
};
MultiThreadedDemo::MultiThreadedDemo(struct GUIHelperInterface* helper)
: CommonRigidBodyMTBase( helper )
: CommonRigidBodyMTBase(helper)
{
m_groundBody = NULL;
m_groundMovePhase = 0.0f;
m_cameraTargetPos = btVector3( 0.0f, 0.0f, 0.0f );
m_cameraPitch = -30.0f;
m_cameraYaw = 90.0f;
m_cameraDist = 48.0f;
m_prevRollingFriction = -1.0f;
helper->setUpAxis( kUpAxis );
m_groundBody = NULL;
m_groundMovePhase = 0.0f;
m_cameraTargetPos = btVector3(0.0f, 0.0f, 0.0f);
m_cameraPitch = -30.0f;
m_cameraYaw = 90.0f;
m_cameraDist = 48.0f;
m_prevRollingFriction = -1.0f;
helper->setUpAxis(kUpAxis);
}
void MultiThreadedDemo::initPhysics()
{
createEmptyDynamicsWorld();
createEmptyDynamicsWorld();
m_dynamicsWorld->setGravity( btVector3( 0, -10, 0 ) );
m_dynamicsWorld->setGravity(btVector3(0, -10, 0));
{
SliderParams slider( "Stack height", &gSliderStackHeight );
slider.m_minVal = 1.0f;
slider.m_maxVal = 30.0f;
slider.m_clampToIntegers = true;
m_guiHelper->getParameterInterface()->registerSliderFloatParameter( slider );
}
{
SliderParams slider( "Stack width", &gSliderStackWidth );
slider.m_minVal = 1.0f;
slider.m_maxVal = 30.0f;
slider.m_clampToIntegers = true;
m_guiHelper->getParameterInterface()->registerSliderFloatParameter( slider );
}
{
SliderParams slider( "Stack rows", &gSliderStackRows );
slider.m_minVal = 1.0f;
slider.m_maxVal = 20.0f;
slider.m_clampToIntegers = true;
m_guiHelper->getParameterInterface()->registerSliderFloatParameter( slider );
}
{
SliderParams slider( "Stack columns", &gSliderStackColumns );
slider.m_minVal = 1.0f;
slider.m_maxVal = 20.0f;
slider.m_clampToIntegers = true;
m_guiHelper->getParameterInterface()->registerSliderFloatParameter( slider );
}
{
// horizontal ground shake
SliderParams slider( "Ground horiz amp", &gSliderGroundHorizontalAmplitude );
slider.m_minVal = 0.0f;
slider.m_maxVal = 1.0f;
slider.m_clampToNotches = false;
m_guiHelper->getParameterInterface()->registerSliderFloatParameter( slider );
}
{
// vertical ground shake
SliderParams slider( "Ground vert amp", &gSliderGroundVerticalAmplitude );
slider.m_minVal = 0.0f;
slider.m_maxVal = 1.0f;
slider.m_clampToNotches = false;
m_guiHelper->getParameterInterface()->registerSliderFloatParameter( slider );
}
{
// ground tilt
SliderParams slider( "Ground tilt", &gSliderGroundTilt );
slider.m_minVal = -45.0f;
slider.m_maxVal = 45.0f;
slider.m_clampToNotches = false;
m_guiHelper->getParameterInterface()->registerSliderFloatParameter( slider );
}
{
// rolling friction
SliderParams slider( "Rolling friction", &gSliderRollingFriction );
slider.m_minVal = 0.0f;
slider.m_maxVal = 1.0f;
slider.m_clampToNotches = false;
m_guiHelper->getParameterInterface()->registerSliderFloatParameter( slider );
}
{
ButtonParams button( "Spheres not boxes", 0, false );
button.m_initialState = gSpheresNotBoxes;
button.m_userPointer = &gSpheresNotBoxes;
button.m_callback = boolPtrButtonCallback;
m_guiHelper->getParameterInterface()->registerButtonParameter( button );
}
{
SliderParams slider("Stack height", &gSliderStackHeight);
slider.m_minVal = 1.0f;
slider.m_maxVal = 30.0f;
slider.m_clampToIntegers = true;
m_guiHelper->getParameterInterface()->registerSliderFloatParameter(slider);
}
{
SliderParams slider("Stack width", &gSliderStackWidth);
slider.m_minVal = 1.0f;
slider.m_maxVal = 30.0f;
slider.m_clampToIntegers = true;
m_guiHelper->getParameterInterface()->registerSliderFloatParameter(slider);
}
{
SliderParams slider("Stack rows", &gSliderStackRows);
slider.m_minVal = 1.0f;
slider.m_maxVal = 20.0f;
slider.m_clampToIntegers = true;
m_guiHelper->getParameterInterface()->registerSliderFloatParameter(slider);
}
{
SliderParams slider("Stack columns", &gSliderStackColumns);
slider.m_minVal = 1.0f;
slider.m_maxVal = 20.0f;
slider.m_clampToIntegers = true;
m_guiHelper->getParameterInterface()->registerSliderFloatParameter(slider);
}
{
// horizontal ground shake
SliderParams slider("Ground horiz amp", &gSliderGroundHorizontalAmplitude);
slider.m_minVal = 0.0f;
slider.m_maxVal = 1.0f;
slider.m_clampToNotches = false;
m_guiHelper->getParameterInterface()->registerSliderFloatParameter(slider);
}
{
// vertical ground shake
SliderParams slider("Ground vert amp", &gSliderGroundVerticalAmplitude);
slider.m_minVal = 0.0f;
slider.m_maxVal = 1.0f;
slider.m_clampToNotches = false;
m_guiHelper->getParameterInterface()->registerSliderFloatParameter(slider);
}
{
// ground tilt
SliderParams slider("Ground tilt", &gSliderGroundTilt);
slider.m_minVal = -45.0f;
slider.m_maxVal = 45.0f;
slider.m_clampToNotches = false;
m_guiHelper->getParameterInterface()->registerSliderFloatParameter(slider);
}
{
// rolling friction
SliderParams slider("Rolling friction", &gSliderRollingFriction);
slider.m_minVal = 0.0f;
slider.m_maxVal = 1.0f;
slider.m_clampToNotches = false;
m_guiHelper->getParameterInterface()->registerSliderFloatParameter(slider);
}
{
ButtonParams button("Spheres not boxes", 0, false);
button.m_initialState = gSpheresNotBoxes;
button.m_userPointer = &gSpheresNotBoxes;
button.m_callback = boolPtrButtonCallback;
m_guiHelper->getParameterInterface()->registerButtonParameter(button);
}
createSceneObjects();
createSceneObjects();
m_guiHelper->createPhysicsDebugDrawer( m_dynamicsWorld );
m_guiHelper->createPhysicsDebugDrawer(m_dynamicsWorld);
}
btRigidBody* MultiThreadedDemo::localCreateRigidBody(btScalar mass, const btTransform& startTransform, btCollisionShape* shape)
{
btRigidBody* body = createRigidBody(mass, startTransform, shape);
if ( mass > 0.0f )
{
// prevent bodies from sleeping to make profiling/benchmarking easier
body->forceActivationState( DISABLE_DEACTIVATION );
}
return body;
btRigidBody* body = createRigidBody(mass, startTransform, shape);
if (mass > 0.0f)
{
// prevent bodies from sleeping to make profiling/benchmarking easier
body->forceActivationState(DISABLE_DEACTIVATION);
}
return body;
}
void MultiThreadedDemo::createStack( const btTransform& parentTrans, btCollisionShape* boxShape, const btVector3& halfBoxSize, int height, int width )
void MultiThreadedDemo::createStack(const btTransform& parentTrans, btCollisionShape* boxShape, const btVector3& halfBoxSize, int height, int width)
{
btTransform trans;
trans.setIdentity();
trans.setRotation( parentTrans.getRotation() );
float halfBoxHeight = halfBoxSize.y();
float halfBoxWidth = halfBoxSize.x();
btTransform trans;
trans.setIdentity();
trans.setRotation(parentTrans.getRotation());
float halfBoxHeight = halfBoxSize.y();
float halfBoxWidth = halfBoxSize.x();
btVector3 offset = btVector3( 0, 0, -halfBoxSize.z() * (width - 1) );
for ( int iZ = 0; iZ < width; iZ++ )
{
offset += btVector3( 0, 0, halfBoxSize.z()*2.0f );
for ( int iY = 0; iY < height; iY++ )
{
// This constructs a row, from left to right
int rowSize = height - iY;
for ( int iX = 0; iX < rowSize; iX++ )
{
btVector3 pos = offset + btVector3( halfBoxWidth*( 1 + iX * 2 - rowSize ),
halfBoxHeight * ( 1 + iY * 2 ),
0.0f
);
btVector3 offset = btVector3(0, 0, -halfBoxSize.z() * (width - 1));
for (int iZ = 0; iZ < width; iZ++)
{
offset += btVector3(0, 0, halfBoxSize.z() * 2.0f);
for (int iY = 0; iY < height; iY++)
{
// This constructs a row, from left to right
int rowSize = height - iY;
for (int iX = 0; iX < rowSize; iX++)
{
btVector3 pos = offset + btVector3(halfBoxWidth * (1 + iX * 2 - rowSize),
halfBoxHeight * (1 + iY * 2),
0.0f);
trans.setOrigin( parentTrans(pos) );
btScalar mass = 1.f;
trans.setOrigin(parentTrans(pos));
btScalar mass = 1.f;
btRigidBody* body = localCreateRigidBody( mass, trans, boxShape );
body->setFriction( 1.0f );
body->setRollingFriction( gSliderRollingFriction );
}
}
}
btRigidBody* body = localCreateRigidBody(mass, trans, boxShape);
body->setFriction(1.0f);
body->setRollingFriction(gSliderRollingFriction);
}
}
}
}
void MultiThreadedDemo::createSceneObjects()
{
{
// create ground box
m_groundStartXf.setOrigin( btVector3( 0.f, -3.f, 0.f ) );
m_groundStartXf.setRotation( getGroundRotation() );
{
// create ground box
m_groundStartXf.setOrigin(btVector3(0.f, -3.f, 0.f));
m_groundStartXf.setRotation(getGroundRotation());
//either use heightfield or triangle mesh
//either use heightfield or triangle mesh
btVector3 groundExtents( 400, 400, 400 );
groundExtents[ kUpAxis ] = 3;
btCollisionShape* groundShape = new btBoxShape( groundExtents );
m_collisionShapes.push_back( groundShape );
btVector3 groundExtents(400, 400, 400);
groundExtents[kUpAxis] = 3;
btCollisionShape* groundShape = new btBoxShape(groundExtents);
m_collisionShapes.push_back(groundShape);
//create ground object
m_groundBody = createKinematicBody( m_groundStartXf, groundShape );
m_groundBody->forceActivationState( DISABLE_DEACTIVATION );
m_groundBody->setFriction(1.0f);
}
//create ground object
m_groundBody = createKinematicBody(m_groundStartXf, groundShape);
m_groundBody->forceActivationState(DISABLE_DEACTIVATION);
m_groundBody->setFriction(1.0f);
}
{
// create walls of cubes
const btVector3 halfExtents = btVector3( 0.5f, 0.25f, 0.5f );
int numStackRows = btMax(1, int(gSliderStackRows));
int numStackCols = btMax(1, int(gSliderStackColumns));
int stackHeight = int(gSliderStackHeight);
int stackWidth = int( gSliderStackWidth );
float stackZSpacing = 2.0f + stackWidth*halfExtents.x()*2.0f;
float stackXSpacing = 20.0f;
{
// create walls of cubes
const btVector3 halfExtents = btVector3(0.5f, 0.25f, 0.5f);
int numStackRows = btMax(1, int(gSliderStackRows));
int numStackCols = btMax(1, int(gSliderStackColumns));
int stackHeight = int(gSliderStackHeight);
int stackWidth = int(gSliderStackWidth);
float stackZSpacing = 2.0f + stackWidth * halfExtents.x() * 2.0f;
float stackXSpacing = 20.0f;
btBoxShape* boxShape = new btBoxShape( halfExtents );
m_collisionShapes.push_back( boxShape );
btBoxShape* boxShape = new btBoxShape(halfExtents);
m_collisionShapes.push_back(boxShape);
btSphereShape* sphereShape = new btSphereShape( 0.5f );
m_collisionShapes.push_back( sphereShape );
btSphereShape* sphereShape = new btSphereShape(0.5f);
m_collisionShapes.push_back(sphereShape);
btCollisionShape* shape = boxShape;
if ( gSpheresNotBoxes )
{
shape = sphereShape;
}
btCollisionShape* shape = boxShape;
if (gSpheresNotBoxes)
{
shape = sphereShape;
}
btTransform groundTrans;
groundTrans.setIdentity();
groundTrans.setRotation( getGroundRotation() );
for ( int iX = 0; iX < numStackCols; ++iX )
{
for ( int iZ = 0; iZ < numStackRows; ++iZ )
{
btVector3 center = btVector3( iX * stackXSpacing, 0.0f, ( iZ - numStackRows / 2 ) * stackZSpacing );
btTransform trans = groundTrans;
trans.setOrigin( groundTrans( center ) );
createStack( trans, shape, halfExtents, stackHeight, stackWidth );
}
}
}
btTransform groundTrans;
groundTrans.setIdentity();
groundTrans.setRotation(getGroundRotation());
for (int iX = 0; iX < numStackCols; ++iX)
{
for (int iZ = 0; iZ < numStackRows; ++iZ)
{
btVector3 center = btVector3(iX * stackXSpacing, 0.0f, (iZ - numStackRows / 2) * stackZSpacing);
btTransform trans = groundTrans;
trans.setOrigin(groundTrans(center));
createStack(trans, shape, halfExtents, stackHeight, stackWidth);
}
}
}
#if 0
if ( false )
{
@@ -366,13 +355,10 @@ void MultiThreadedDemo::createSceneObjects()
ballBody->setLinearVelocity( btVector3( 0, 0, -10 ) );
}
#endif
m_guiHelper->autogenerateGraphicsObjects( m_dynamicsWorld );
m_guiHelper->autogenerateGraphicsObjects(m_dynamicsWorld);
}
CommonExampleInterface* MultiThreadedDemoCreateFunc( struct CommonExampleOptions& options )
CommonExampleInterface* MultiThreadedDemoCreateFunc(struct CommonExampleOptions& options)
{
return new MultiThreadedDemo(options.m_guiHelper);
}

View File

@@ -15,8 +15,6 @@ subject to the following restrictions:
#ifndef MULTITHREADED_DEMO_H
#define MULTITHREADED_DEMO_H
class CommonExampleInterface* MultiThreadedDemoCreateFunc(struct CommonExampleOptions& options);
#endif // MULTITHREADED_DEMO_H
class CommonExampleInterface* MultiThreadedDemoCreateFunc(struct CommonExampleOptions& options);
#endif // MULTITHREADED_DEMO_H