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:
@@ -13,14 +13,13 @@ subject to the following restrictions:
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
|
||||
///create 125 (5x5x5) dynamic object
|
||||
#define ARRAY_SIZE_X 5
|
||||
#define ARRAY_SIZE_Y 5
|
||||
#define ARRAY_SIZE_Z 5
|
||||
|
||||
//maximum number of objects (and allow user to shoot additional boxes)
|
||||
#define MAX_PROXIES (ARRAY_SIZE_X*ARRAY_SIZE_Y*ARRAY_SIZE_Z + 1024)
|
||||
#define MAX_PROXIES (ARRAY_SIZE_X * ARRAY_SIZE_Y * ARRAY_SIZE_Z + 1024)
|
||||
|
||||
///scaling of the objects (0.1 = 20 centimeter boxes )
|
||||
#define SCALING 1.
|
||||
@@ -31,8 +30,7 @@ subject to the following restrictions:
|
||||
#include "RollingFrictionDemo.h"
|
||||
///btBulletDynamicsCommon.h is the main Bullet include file, contains most common include files.
|
||||
#include "btBulletDynamicsCommon.h"
|
||||
#include <stdio.h> //printf debugging
|
||||
|
||||
#include <stdio.h> //printf debugging
|
||||
|
||||
#include "../CommonInterfaces/CommonRigidBodyBase.h"
|
||||
#include "../Utils/b3ResourcePath.h"
|
||||
@@ -43,47 +41,37 @@ subject to the following restrictions:
|
||||
class RollingFrictionDemo : public CommonRigidBodyBase
|
||||
{
|
||||
public:
|
||||
|
||||
RollingFrictionDemo(struct GUIHelperInterface* helper)
|
||||
:CommonRigidBodyBase(helper)
|
||||
: CommonRigidBodyBase(helper)
|
||||
{
|
||||
}
|
||||
virtual ~RollingFrictionDemo()
|
||||
{
|
||||
|
||||
}
|
||||
void initPhysics();
|
||||
|
||||
void exitPhysics();
|
||||
|
||||
void initPhysics();
|
||||
|
||||
void exitPhysics();
|
||||
|
||||
void resetCamera()
|
||||
{
|
||||
float dist = 35;
|
||||
float pitch = -14;
|
||||
float yaw = 0;
|
||||
float targetPos[3]={0,0,0};
|
||||
m_guiHelper->resetCamera(dist,yaw,pitch,targetPos[0],targetPos[1],targetPos[2]);
|
||||
float targetPos[3] = {0, 0, 0};
|
||||
m_guiHelper->resetCamera(dist, yaw, pitch, targetPos[0], targetPos[1], targetPos[2]);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void RollingFrictionDemo::initPhysics()
|
||||
void RollingFrictionDemo::initPhysics()
|
||||
{
|
||||
|
||||
m_guiHelper->setUpAxis(2);
|
||||
|
||||
|
||||
|
||||
///collision configuration contains default setup for memory, collision setup
|
||||
m_collisionConfiguration = new btDefaultCollisionConfiguration();
|
||||
//m_collisionConfiguration->setConvexConvexMultipointIterations();
|
||||
|
||||
///use the default collision dispatcher. For parallel processing you can use a diffent dispatcher (see Extras/BulletMultiThreaded)
|
||||
m_dispatcher = new btCollisionDispatcher(m_collisionConfiguration);
|
||||
m_dispatcher = new btCollisionDispatcher(m_collisionConfiguration);
|
||||
|
||||
m_broadphase = new btDbvtBroadphase();
|
||||
|
||||
@@ -91,37 +79,35 @@ void RollingFrictionDemo::initPhysics()
|
||||
btSequentialImpulseConstraintSolver* sol = new btSequentialImpulseConstraintSolver;
|
||||
m_solver = sol;
|
||||
|
||||
m_dynamicsWorld = new btDiscreteDynamicsWorld(m_dispatcher,m_broadphase,m_solver,m_collisionConfiguration);
|
||||
// m_dynamicsWorld->getSolverInfo().m_singleAxisRollingFrictionThreshold = 0.f;//faster but lower quality
|
||||
m_dynamicsWorld->setGravity(btVector3(0,0,-10));
|
||||
m_dynamicsWorld = new btDiscreteDynamicsWorld(m_dispatcher, m_broadphase, m_solver, m_collisionConfiguration);
|
||||
// m_dynamicsWorld->getSolverInfo().m_singleAxisRollingFrictionThreshold = 0.f;//faster but lower quality
|
||||
m_dynamicsWorld->setGravity(btVector3(0, 0, -10));
|
||||
|
||||
m_guiHelper->createPhysicsDebugDrawer(m_dynamicsWorld);
|
||||
|
||||
|
||||
{
|
||||
|
||||
///create a few basic rigid bodies
|
||||
btCollisionShape* groundShape = new btBoxShape(btVector3(btScalar(10.),btScalar(5.),btScalar(25.)));
|
||||
btCollisionShape* groundShape = new btBoxShape(btVector3(btScalar(10.), btScalar(5.), btScalar(25.)));
|
||||
|
||||
|
||||
m_collisionShapes.push_back(groundShape);
|
||||
|
||||
btTransform groundTransform;
|
||||
groundTransform.setIdentity();
|
||||
groundTransform.setOrigin(btVector3(0,0,-28));
|
||||
groundTransform.setRotation(btQuaternion(btVector3(0,1,0),SIMD_PI*0.03));
|
||||
groundTransform.setOrigin(btVector3(0, 0, -28));
|
||||
groundTransform.setRotation(btQuaternion(btVector3(0, 1, 0), SIMD_PI * 0.03));
|
||||
//We can also use DemoApplication::localCreateRigidBody, but for clarity it is provided here:
|
||||
btScalar mass(0.);
|
||||
|
||||
//rigidbody is dynamic if and only if mass is non zero, otherwise static
|
||||
bool isDynamic = (mass != 0.f);
|
||||
|
||||
btVector3 localInertia(0,0,0);
|
||||
btVector3 localInertia(0, 0, 0);
|
||||
if (isDynamic)
|
||||
groundShape->calculateLocalInertia(mass,localInertia);
|
||||
groundShape->calculateLocalInertia(mass, localInertia);
|
||||
|
||||
//using motionstate is recommended, it provides interpolation capabilities, and only synchronizes 'active' objects
|
||||
btDefaultMotionState* myMotionState = new btDefaultMotionState(groundTransform);
|
||||
btRigidBody::btRigidBodyConstructionInfo rbInfo(mass,myMotionState,groundShape,localInertia);
|
||||
btRigidBody::btRigidBodyConstructionInfo rbInfo(mass, myMotionState, groundShape, localInertia);
|
||||
btRigidBody* body = new btRigidBody(rbInfo);
|
||||
body->setFriction(.5);
|
||||
|
||||
@@ -130,28 +116,27 @@ void RollingFrictionDemo::initPhysics()
|
||||
}
|
||||
|
||||
{
|
||||
|
||||
///create a few basic rigid bodies
|
||||
btCollisionShape* groundShape = new btBoxShape(btVector3(btScalar(100.),btScalar(100.),btScalar(50.)));
|
||||
|
||||
btCollisionShape* groundShape = new btBoxShape(btVector3(btScalar(100.), btScalar(100.), btScalar(50.)));
|
||||
|
||||
m_collisionShapes.push_back(groundShape);
|
||||
|
||||
btTransform groundTransform;
|
||||
groundTransform.setIdentity();
|
||||
groundTransform.setOrigin(btVector3(0,0,-54));
|
||||
groundTransform.setOrigin(btVector3(0, 0, -54));
|
||||
//We can also use DemoApplication::localCreateRigidBody, but for clarity it is provided here:
|
||||
btScalar mass(0.);
|
||||
|
||||
//rigidbody is dynamic if and only if mass is non zero, otherwise static
|
||||
bool isDynamic = (mass != 0.f);
|
||||
|
||||
btVector3 localInertia(0,0,0);
|
||||
btVector3 localInertia(0, 0, 0);
|
||||
if (isDynamic)
|
||||
groundShape->calculateLocalInertia(mass,localInertia);
|
||||
groundShape->calculateLocalInertia(mass, localInertia);
|
||||
|
||||
//using motionstate is recommended, it provides interpolation capabilities, and only synchronizes 'active' objects
|
||||
btDefaultMotionState* myMotionState = new btDefaultMotionState(groundTransform);
|
||||
btRigidBody::btRigidBodyConstructionInfo rbInfo(mass,myMotionState,groundShape,localInertia);
|
||||
btRigidBody::btRigidBodyConstructionInfo rbInfo(mass, myMotionState, groundShape, localInertia);
|
||||
btRigidBody* body = new btRigidBody(rbInfo);
|
||||
body->setFriction(.1);
|
||||
//add the body to the dynamics world
|
||||
@@ -164,62 +149,60 @@ void RollingFrictionDemo::initPhysics()
|
||||
#define NUM_SHAPES 10
|
||||
btCollisionShape* colShapes[NUM_SHAPES] = {
|
||||
new btSphereShape(btScalar(0.5)),
|
||||
new btCapsuleShape(0.25,0.5),
|
||||
new btCapsuleShapeX(0.25,0.5),
|
||||
new btCapsuleShapeZ(0.25,0.5),
|
||||
new btConeShape(0.25,0.5),
|
||||
new btConeShapeX(0.25,0.5),
|
||||
new btConeShapeZ(0.25,0.5),
|
||||
new btCylinderShape(btVector3(0.25,0.5,0.25)),
|
||||
new btCylinderShapeX(btVector3(0.5,0.25,0.25)),
|
||||
new btCylinderShapeZ(btVector3(0.25,0.25,0.5)),
|
||||
new btCapsuleShape(0.25, 0.5),
|
||||
new btCapsuleShapeX(0.25, 0.5),
|
||||
new btCapsuleShapeZ(0.25, 0.5),
|
||||
new btConeShape(0.25, 0.5),
|
||||
new btConeShapeX(0.25, 0.5),
|
||||
new btConeShapeZ(0.25, 0.5),
|
||||
new btCylinderShape(btVector3(0.25, 0.5, 0.25)),
|
||||
new btCylinderShapeX(btVector3(0.5, 0.25, 0.25)),
|
||||
new btCylinderShapeZ(btVector3(0.25, 0.25, 0.5)),
|
||||
};
|
||||
for (int i=0;i<NUM_SHAPES;i++)
|
||||
for (int i = 0; i < NUM_SHAPES; i++)
|
||||
m_collisionShapes.push_back(colShapes[i]);
|
||||
|
||||
/// Create Dynamic Objects
|
||||
btTransform startTransform;
|
||||
startTransform.setIdentity();
|
||||
|
||||
btScalar mass(1.f);
|
||||
btScalar mass(1.f);
|
||||
|
||||
//rigidbody is dynamic if and only if mass is non zero, otherwise static
|
||||
|
||||
float start_x = START_POS_X - ARRAY_SIZE_X/2;
|
||||
|
||||
float start_x = START_POS_X - ARRAY_SIZE_X / 2;
|
||||
float start_y = START_POS_Y;
|
||||
float start_z = START_POS_Z - ARRAY_SIZE_Z/2;
|
||||
float start_z = START_POS_Z - ARRAY_SIZE_Z / 2;
|
||||
|
||||
{
|
||||
int shapeIndex = 0;
|
||||
for (int k=0;k<ARRAY_SIZE_Y;k++)
|
||||
for (int k = 0; k < ARRAY_SIZE_Y; k++)
|
||||
{
|
||||
for (int i=0;i<ARRAY_SIZE_X;i++)
|
||||
for (int i = 0; i < ARRAY_SIZE_X; i++)
|
||||
{
|
||||
for(int j = 0;j<ARRAY_SIZE_Z;j++)
|
||||
for (int j = 0; j < ARRAY_SIZE_Z; j++)
|
||||
{
|
||||
startTransform.setOrigin(SCALING*btVector3(
|
||||
btScalar(2.0*i + start_x),
|
||||
btScalar(2.0*j + start_z),
|
||||
btScalar(20+2.0*k + start_y)));
|
||||
|
||||
startTransform.setOrigin(SCALING * btVector3(
|
||||
btScalar(2.0 * i + start_x),
|
||||
btScalar(2.0 * j + start_z),
|
||||
btScalar(20 + 2.0 * k + start_y)));
|
||||
|
||||
shapeIndex++;
|
||||
btCollisionShape* colShape = colShapes[shapeIndex%NUM_SHAPES];
|
||||
btCollisionShape* colShape = colShapes[shapeIndex % NUM_SHAPES];
|
||||
bool isDynamic = (mass != 0.f);
|
||||
btVector3 localInertia(0,0,0);
|
||||
btVector3 localInertia(0, 0, 0);
|
||||
|
||||
if (isDynamic)
|
||||
colShape->calculateLocalInertia(mass,localInertia);
|
||||
colShape->calculateLocalInertia(mass, localInertia);
|
||||
|
||||
//using motionstate is recommended, it provides interpolation capabilities, and only synchronizes 'active' objects
|
||||
btDefaultMotionState* myMotionState = new btDefaultMotionState(startTransform);
|
||||
btRigidBody::btRigidBodyConstructionInfo rbInfo(mass,myMotionState,colShape,localInertia);
|
||||
btRigidBody::btRigidBodyConstructionInfo rbInfo(mass, myMotionState, colShape, localInertia);
|
||||
btRigidBody* body = new btRigidBody(rbInfo);
|
||||
body->setFriction(1.f);
|
||||
body->setRollingFriction(.1);
|
||||
body->setSpinningFriction(0.1);
|
||||
body->setAnisotropicFriction(colShape->getAnisotropicRollingFrictionDirection(),btCollisionObject::CF_ANISOTROPIC_ROLLING_FRICTION);
|
||||
|
||||
body->setAnisotropicFriction(colShape->getAnisotropicRollingFrictionDirection(), btCollisionObject::CF_ANISOTROPIC_ROLLING_FRICTION);
|
||||
|
||||
m_dynamicsWorld->addRigidBody(body);
|
||||
}
|
||||
@@ -231,29 +214,26 @@ void RollingFrictionDemo::initPhysics()
|
||||
m_guiHelper->autogenerateGraphicsObjects(m_dynamicsWorld);
|
||||
|
||||
if (0)
|
||||
{
|
||||
btSerializer* s = new btDefaultSerializer;
|
||||
m_dynamicsWorld->serialize(s);
|
||||
char resourcePath[1024];
|
||||
if (b3ResourcePath::findResourcePath("slope.bullet",resourcePath,1024))
|
||||
{
|
||||
FILE* f = fopen(resourcePath,"wb");
|
||||
fwrite(s->getBufferPointer(),s->getCurrentBufferSize(),1,f);
|
||||
fclose(f);
|
||||
}
|
||||
btSerializer* s = new btDefaultSerializer;
|
||||
m_dynamicsWorld->serialize(s);
|
||||
char resourcePath[1024];
|
||||
if (b3ResourcePath::findResourcePath("slope.bullet", resourcePath, 1024))
|
||||
{
|
||||
FILE* f = fopen(resourcePath, "wb");
|
||||
fwrite(s->getBufferPointer(), s->getCurrentBufferSize(), 1, f);
|
||||
fclose(f);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void RollingFrictionDemo::exitPhysics()
|
||||
void RollingFrictionDemo::exitPhysics()
|
||||
{
|
||||
|
||||
//cleanup in the reverse order of creation/initialization
|
||||
|
||||
//remove the rigidbodies from the dynamics world and delete them
|
||||
int i;
|
||||
for (i=m_dynamicsWorld->getNumCollisionObjects()-1; i>=0 ;i--)
|
||||
for (i = m_dynamicsWorld->getNumCollisionObjects() - 1; i >= 0; i--)
|
||||
{
|
||||
btCollisionObject* obj = m_dynamicsWorld->getCollisionObjectArray()[i];
|
||||
btRigidBody* body = btRigidBody::upcast(obj);
|
||||
@@ -261,12 +241,12 @@ void RollingFrictionDemo::exitPhysics()
|
||||
{
|
||||
delete body->getMotionState();
|
||||
}
|
||||
m_dynamicsWorld->removeCollisionObject( obj );
|
||||
m_dynamicsWorld->removeCollisionObject(obj);
|
||||
delete obj;
|
||||
}
|
||||
|
||||
//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;
|
||||
@@ -274,24 +254,17 @@ void RollingFrictionDemo::exitPhysics()
|
||||
m_collisionShapes.clear();
|
||||
|
||||
delete m_dynamicsWorld;
|
||||
|
||||
|
||||
delete m_solver;
|
||||
|
||||
|
||||
delete m_broadphase;
|
||||
|
||||
|
||||
delete m_dispatcher;
|
||||
|
||||
delete m_collisionConfiguration;
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
class CommonExampleInterface* RollingFrictionCreateFunc(struct CommonExampleOptions& options)
|
||||
class CommonExampleInterface* RollingFrictionCreateFunc(struct CommonExampleOptions& options)
|
||||
{
|
||||
return new RollingFrictionDemo(options.m_guiHelper);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -15,8 +15,6 @@ subject to the following restrictions:
|
||||
#ifndef _ROLLING_FRICTION_DEMO_H
|
||||
#define _ROLLING_FRICTION_DEMO_H
|
||||
|
||||
class CommonExampleInterface* RollingFrictionCreateFunc(struct CommonExampleOptions& options);
|
||||
|
||||
|
||||
#endif //_ROLLING_FRICTION_DEMO_H
|
||||
class CommonExampleInterface* RollingFrictionCreateFunc(struct CommonExampleOptions& options);
|
||||
|
||||
#endif //_ROLLING_FRICTION_DEMO_H
|
||||
|
||||
Reference in New Issue
Block a user