Merge remote-tracking branch 'bulletphysics/master'

This commit is contained in:
Erwin Coumans 2014-08-03 13:19:44 -07:00
commit ba5a8a450b
517 changed files with 27710 additions and 3776 deletions

17
.travis.yml Normal file
View File

@ -0,0 +1,17 @@
language: cpp
compiler:
- gcc
- clang
install:
- sudo apt-get update
- sudo apt-get install libglew-dev
script:
- echo "CXX="$CXX
- echo "CC="$CC
- cmake . -G "Unix Makefiles" #-DCMAKE_CXX_FLAGS=-Werror
- make -j8
- sudo make install
# Test again with double precision
- cmake . -G "Unix Makefiles" -DUSE_DOUBLE_PRECISION=ON #-DCMAKE_CXX_FLAGS=-Werror
- make -j8
- sudo make install

View File

@ -5,7 +5,7 @@ set(CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS true)
SET(MSVC_INCREMENTAL_DEFAULT ON)
PROJECT(BULLET_PHYSICS)
SET(BULLET_VERSION 2.82)
SET(BULLET_VERSION 2.83)
IF(COMMAND cmake_policy)
cmake_policy(SET CMP0003 NEW)
@ -22,7 +22,7 @@ SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -D_DEBUG")
OPTION(USE_DOUBLE_PRECISION "Use double precision" OFF)
OPTION(USE_GRAPHICAL_BENCHMARK "Use Graphical Benchmark" ON)
OPTION(BUILD_SHARED_LIBS "Use shared libraries" OFF)
OPTION(USE_MSVC_RUNTIME_LIBRARY_DLL "Use MSVC Runtime Library DLL (/MD or /MDd)" OFF)
OPTION(USE_MSVC_INCREMENTAL_LINKING "Use MSVC Incremental Linking" OFF)
@ -39,18 +39,20 @@ IF(MSVC)
IF (NOT USE_MSVC_INCREMENTAL_LINKING)
#MESSAGE("MSVC_INCREMENTAL_DEFAULT"+${MSVC_INCREMENTAL_DEFAULT})
SET( MSVC_INCREMENTAL_YES_FLAG "/INCREMENTAL:NO")
STRING(REPLACE "INCREMENTAL:YES" "INCREMENTAL:NO" replacementFlags ${CMAKE_EXE_LINKER_FLAGS_DEBUG})
SET(CMAKE_EXE_LINKER_FLAGS_DEBUG "/INCREMENTAL:NO ${replacementFlags}" )
MESSAGE("CMAKE_EXE_LINKER_FLAGS_DEBUG=${CMAKE_EXE_LINKER_FLAGS_DEBUG}")
# STRING(REPLACE "INCREMENTAL:YES" "INCREMENTAL:NO" replacementFlags2 ${CMAKE_EXE_LINKER_FLAGS})
# SET(CMAKE_EXE_LINKER_FLAGS ${replacementFlag2})
# STRING(REPLACE "INCREMENTAL:YES" "" replacementFlags3 ${CMAKE_EXTRA_LINK_FLAGS})
# SET(CMAKE_EXTRA_LINK_FLAGS ${replacementFlag3})
STRING(REPLACE "INCREMENTAL:YES" "INCREMENTAL:NO" replacementFlags2 ${CMAKE_EXE_LINKER_FLAGS})
SET(CMAKE_EXE_LINKER_FLAGS ${replacementFlag2})
STRING(REPLACE "INCREMENTAL:YES" "" replacementFlags3 "${CMAKE_EXTRA_LINK_FLAGS}")
SET(CMAKE_EXTRA_LINK_FLAGS ${replacementFlag3})
STRING(REPLACE "INCREMENTAL:YES" "INCREMENTAL:NO" replacementFlags3 ${CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO})
STRING(REPLACE "INCREMENTAL:YES" "INCREMENTAL:NO" replacementFlags3 "${CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO}")
SET(CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO ${replacementFlags3})
SET(CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO "/INCREMENTAL:NO ${replacementFlags3}" )
@ -179,8 +181,8 @@ ENDIF (OPENGL_FOUND)
OPTION(BUILD_OBSOLETE_DEMOS "Set when you want to build the obsolete Bullet 2 demos" OFF)
IF(BUILD_OBSOLETE_DEMOS)
OPTION(BUILD_BULLET2_DEMOS "Set when you want to build the Bullet 2 demos" ON)
IF(BUILD_BULLET2_DEMOS)
IF (USE_GLUT)
IF (MSVC)
@ -188,13 +190,13 @@ IF (USE_GLUT)
ADD_DEFINITIONS(-DBT_USE_FREEGLUT)
IF (CMAKE_CL_64)
message("Win64 using static freeglut in ObsoleteDemos/Glut/glut64.lib")
SET(GLUT_glut_LIBRARY ${BULLET_PHYSICS_SOURCE_DIR}/ObsoleteDemos/Glut/glut64.lib glu32.lib gdi32.lib winmm.lib user32.lib)
message("Win64 using static freeglut in Demos/Glut/glut64.lib")
SET(GLUT_glut_LIBRARY ${BULLET_PHYSICS_SOURCE_DIR}/Demos/Glut/glut64.lib glu32.lib gdi32.lib winmm.lib user32.lib)
ELSE(CMAKE_CL_64)
message("Win32 using static freeglut in ObsoleteDemos/Glut/glut32.lib")
SET(GLUT_glut_LIBRARY ${BULLET_PHYSICS_SOURCE_DIR}/ObsoleteDemos/Glut/glut32.lib glu32.lib gdi32.lib winmm.lib user32.lib)
message("Win32 using static freeglut in Demos/Glut/glut32.lib")
SET(GLUT_glut_LIBRARY ${BULLET_PHYSICS_SOURCE_DIR}/Demos/Glut/glut32.lib glu32.lib gdi32.lib winmm.lib user32.lib)
ENDIF (CMAKE_CL_64)
SET(GLUT_INCLUDE_DIR ${BULLET_PHYSICS_SOURCE_DIR}/ObsoleteDemos/Glut )
SET(GLUT_INCLUDE_DIR ${BULLET_PHYSICS_SOURCE_DIR}/Demos/Glut )
ELSE()
FIND_PACKAGE(GLUT)
IF (GLUT_FOUND)
@ -212,19 +214,29 @@ IF (USE_GLUT)
ENDIF (GLUT_FOUND)
ENDIF (MSVC)
IF(NOT WIN32 AND NOT APPLE)
IF(NOT WIN32 AND NOT APPLE AND NOT CMAKE_CROSSCOMPILING)
# This is added for linux. This should always work if everything is installed and working fine.
SET(GLUT_INCLUDE_DIR /usr/include /usr/local/include)
ENDIF()
ENDIF(USE_GLUT)
IF(EXISTS ${BULLET_PHYSICS_SOURCE_DIR}/ObsoleteDemos AND IS_DIRECTORY ${BULLET_PHYSICS_SOURCE_DIR}/ObsoleteDemos)
SUBDIRS(ObsoleteDemos)
IF(EXISTS ${BULLET_PHYSICS_SOURCE_DIR}/Demos AND IS_DIRECTORY ${BULLET_PHYSICS_SOURCE_DIR}/Demos)
SUBDIRS(Demos)
ENDIF()
ENDIF(BUILD_OBSOLETE_DEMOS)
ENDIF(BUILD_BULLET2_DEMOS)
OPTION(BUILD_BULLET3_DEMOS "Set when you want to build the Bullet 3 demos" ON)
IF (APPLE)
FIND_LIBRARY(COCOA_LIBRARY Cocoa)
ENDIF()
OPTION(BUILD_BULLET3 "Set when you want to build Bullet 3" ON)
IF(BUILD_BULLET3)
OPTION(BUILD_BULLET3_DEMOS "Set when you want to build the Bullet 3 demos" ON)
ELSE(BUILD_BULLET3)
unset(BUILD_BULLET3_DEMOS CACHE)
OPTION(BUILD_BULLET3_DEMOS "Set when you want to build the Bullet 3 demos" OFF)
ENDIF(BUILD_BULLET3)
IF(BUILD_BULLET3_DEMOS)
IF(EXISTS ${BULLET_PHYSICS_SOURCE_DIR}/Demos3 AND IS_DIRECTORY ${BULLET_PHYSICS_SOURCE_DIR}/Demos3)
SUBDIRS(Demos3)
@ -232,6 +244,10 @@ IF(BUILD_BULLET3_DEMOS)
ENDIF()
ENDIF(BUILD_BULLET3_DEMOS)
OPTION(BUILD_EXTRAS "Set when you want to build the extras" ON)
IF(BUILD_EXTRAS)
SUBDIRS(Extras)
ENDIF(BUILD_EXTRAS)
#Maya Dynamica plugin is moved to http://dynamica.googlecode.com
@ -266,14 +282,14 @@ IF(INSTALL_LIBS)
ENDIF(INSTALL_LIBS)
#INSTALL of other files requires CMake 2.6
#IF (${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION} GREATER 2.5)
# OPTION(INSTALL_EXTRA_LIBS "Set when you want extra libraries installed" OFF)
#ENDIF (${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION} GREATER 2.5)
IF (${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION} GREATER 2.5)
OPTION(INSTALL_EXTRA_LIBS "Set when you want extra libraries installed" OFF)
ENDIF (${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION} GREATER 2.5)
OPTION(BUILD_UNIT_TESTS "Build Unit Tests" OFF)
OPTION(BUILD_UNIT_TESTS "Build Unit Tests" ON)
IF (BUILD_UNIT_TESTS)
SUBDIRS(UnitTests)
SUBDIRS(test)
ENDIF()
set (BULLET_CONFIG_CMAKE_PATH lib${LIB_SUFFIX}/cmake/bullet )

View File

@ -0,0 +1,147 @@
/*
Bullet Continuous Collision Detection and Physics Library
Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/
This software is provided 'as-is', without any express or implied warranty.
In no event will the authors be held liable for any damages arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it freely,
subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
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)
///scaling of the objects (0.1 = 20 centimeter boxes )
#define SCALING 1.
#define START_POS_X -5
#define START_POS_Y -5
#define START_POS_Z -3
#include "BasicDemo.h"
#include "GlutStuff.h"
///btBulletDynamicsCommon.h is the main Bullet include file, contains most common include files.
#include "btBulletDynamicsCommon.h"
#include <stdio.h> //printf debugging
#include "GLDebugDrawer.h"
#include "LinearMath/btAabbUtil2.h"
static GLDebugDrawer gDebugDraw;
///The MyOverlapCallback is used to show how to collect object that overlap with a given bounding box defined by aabbMin and aabbMax.
///See m_physicsSetup.m_dynamicsWorld->getBroadphase()->aabbTest.
struct MyOverlapCallback : public btBroadphaseAabbCallback
{
btVector3 m_queryAabbMin;
btVector3 m_queryAabbMax;
int m_numOverlap;
MyOverlapCallback(const btVector3& aabbMin, const btVector3& aabbMax ) : m_queryAabbMin(aabbMin),m_queryAabbMax(aabbMax),m_numOverlap(0) {}
virtual bool process(const btBroadphaseProxy* proxy)
{
btVector3 proxyAabbMin,proxyAabbMax;
btCollisionObject* colObj0 = (btCollisionObject*)proxy->m_clientObject;
colObj0->getCollisionShape()->getAabb(colObj0->getWorldTransform(),proxyAabbMin,proxyAabbMax);
if (TestAabbAgainstAabb2(proxyAabbMin,proxyAabbMax,m_queryAabbMin,m_queryAabbMax))
{
m_numOverlap++;
}
return true;
}
};
void BasicDemo::clientMoveAndDisplay()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
//simple dynamics world doesn't handle fixed-time-stepping
float ms = getDeltaTimeMicroseconds();
m_physicsSetup.stepSimulation(ms/1000000.f);
m_physicsSetup.m_dynamicsWorld->debugDrawWorld();
/*
///step the simulation
if (m_physicsSetup.m_dynamicsWorld)
{
m_physicsSetup.m_dynamicsWorld->stepSimulation(ms / 1000000.f);
//optional but useful: debug drawing
m_physicsSetup.m_dynamicsWorld->debugDrawWorld();
btVector3 aabbMin(1,1,1);
btVector3 aabbMax(2,2,2);
MyOverlapCallback aabbOverlap(aabbMin,aabbMax);
m_physicsSetup.m_dynamicsWorld->getBroadphase()->aabbTest(aabbMin,aabbMax,aabbOverlap);
//if (aabbOverlap.m_numOverlap)
// printf("#aabb overlap = %d\n", aabbOverlap.m_numOverlap);
}
*/
renderme();
glFlush();
swapBuffers();
}
void BasicDemo::displayCallback(void) {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
renderme();
//optional but useful: debug drawing to detect problems
if (m_physicsSetup.m_dynamicsWorld)
m_physicsSetup.m_dynamicsWorld->debugDrawWorld();
glFlush();
swapBuffers();
}
void BasicDemo::initPhysics()
{
setTexturing(true);
setShadows(true);
setCameraDistance(btScalar(SCALING*50.));
GraphicsPhysicsBridge gfxBridge;
m_physicsSetup.initPhysics(gfxBridge);
m_dynamicsWorld = m_physicsSetup.m_dynamicsWorld;
m_dynamicsWorld->setDebugDrawer(&gDebugDraw);
}
void BasicDemo::clientResetScene()
{
exitPhysics();
initPhysics();
}
void BasicDemo::exitPhysics()
{
m_physicsSetup.exitPhysics();
}

View File

@ -24,30 +24,15 @@ subject to the following restrictions:
#endif
#include "LinearMath/btAlignedObjectArray.h"
#include "BasicDemoPhysicsSetup.h"
class btBroadphaseInterface;
class btCollisionShape;
class btOverlappingPairCache;
class btCollisionDispatcher;
class btConstraintSolver;
struct btCollisionAlgorithmCreateFunc;
class btDefaultCollisionConfiguration;
///BasicDemo is good starting point for learning the code base and porting.
class BasicDemo : public PlatformDemoApplication
{
//keep the collision shapes, for deletion/cleanup
btAlignedObjectArray<btCollisionShape*> m_collisionShapes;
btBroadphaseInterface* m_broadphase;
btCollisionDispatcher* m_dispatcher;
btConstraintSolver* m_solver;
btDefaultCollisionConfiguration* m_collisionConfiguration;
BasicDemoPhysicsSetup m_physicsSetup;
public:

View File

@ -0,0 +1,89 @@
#include "BasicDemoPhysicsSetup.h"
#include "btBulletDynamicsCommon.h"
#define ARRAY_SIZE_Y 5
#define ARRAY_SIZE_X 5
#define ARRAY_SIZE_Z 5
void BasicDemoPhysicsSetup::initPhysics(GraphicsPhysicsBridge& gfxBridge)
{
createEmptyDynamicsWorld();
///create a few basic rigid bodies
btBoxShape* groundShape = createBoxShape(btVector3(btScalar(50.),btScalar(50.),btScalar(50.)));
gfxBridge.createCollisionShapeGraphicsObject(groundShape);
//groundShape->initializePolyhedralFeatures();
// btCollisionShape* groundShape = new btStaticPlaneShape(btVector3(0,1,0),50);
m_collisionShapes.push_back(groundShape);
btTransform groundTransform;
groundTransform.setIdentity();
groundTransform.setOrigin(btVector3(0,-50,0));
{
btScalar mass(0.);
btRigidBody* body = createRigidBody(mass,groundTransform,groundShape, btVector4(0,0,1,1));
gfxBridge.createRigidBodyGraphicsObject(body, btVector3(0, 1, 0));
}
{
//create a few dynamic rigidbodies
// Re-using the same collision is better for memory usage and performance
btBoxShape* colShape = createBoxShape(btVector3(1,1,1));
gfxBridge.createCollisionShapeGraphicsObject(colShape);
//btCollisionShape* colShape = new btSphereShape(btScalar(1.));
m_collisionShapes.push_back(colShape);
/// Create Dynamic Objects
btTransform startTransform;
startTransform.setIdentity();
btScalar mass(1.f);
//rigidbody is dynamic if and only if mass is non zero, otherwise static
bool isDynamic = (mass != 0.f);
btVector3 localInertia(0,0,0);
if (isDynamic)
colShape->calculateLocalInertia(mass,localInertia);
for (int k=0;k<ARRAY_SIZE_Y;k++)
{
for (int i=0;i<ARRAY_SIZE_X;i++)
{
for(int j = 0;j<ARRAY_SIZE_Z;j++)
{
startTransform.setOrigin(btVector3(
btScalar(2.0*i),
btScalar(20+2.0*k),
btScalar(2.0*j)));
btRigidBody* body = createRigidBody(mass,startTransform,colShape);
gfxBridge.createRigidBodyGraphicsObject(body, btVector3(1, 1, 0));
}
}
}
}
}

View File

@ -0,0 +1,28 @@
#ifndef BASIC_DEMO_PHYSICS_SETUP_H
#define BASIC_DEMO_PHYSICS_SETUP_H
class btRigidBody;
class btCollisionShape;
class btBroadphaseInterface;
class btConstraintSolver;
class btCollisionDispatcher;
class btDefaultCollisionConfiguration;
class btDiscreteDynamicsWorld;
class btTransform;
class btVector3;
class btBoxShape;
#include "LinearMath/btVector3.h"
#include "LinearMath/btAlignedObjectArray.h"
#include "../CommonRigidBodySetup.h"
struct BasicDemoPhysicsSetup : public CommonRigidBodySetup
{
virtual void initPhysics(GraphicsPhysicsBridge& gfxBridge);
};
#endif //BASIC_DEMO_PHYSICS_SETUP_H

View File

@ -28,6 +28,8 @@ ADD_EXECUTABLE(AppBasicDemo
main.cpp
BasicDemo.cpp
BasicDemo.h
BasicDemoPhysicsSetup.cpp
BasicDemoPhysicsSetup.h
${BULLET_PHYSICS_SOURCE_DIR}/build3/bullet.rc
)
ELSE()
@ -35,6 +37,8 @@ ELSE()
main.cpp
BasicDemo.cpp
BasicDemo.h
BasicDemoPhysicsSetup.cpp
BasicDemoPhysicsSetup.h
)
ENDIF()
ELSE (USE_GLUT)
@ -52,6 +56,8 @@ ELSE (USE_GLUT)
Win32BasicDemo.cpp
BasicDemo.cpp
BasicDemo.h
BasicDemoPhysicsSetup.cpp
BasicDemoPhysicsSetup.h
${BULLET_PHYSICS_SOURCE_DIR}/build3/bullet.rc
)

View File

@ -4,8 +4,8 @@ Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/
This software is provided 'as-is', without any express or implied warranty.
In no event will the authors be held liable for any damages arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it freely,
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it freely,
subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
@ -60,7 +60,7 @@ public:
{
///perhaps we can do something special with entities (isEntity)
///like adding a collision Triggering (as example)
if (vertices.size() > 0)
{
float mass = 0.f;
@ -69,7 +69,7 @@ public:
startTransform.setIdentity();
startTransform.setOrigin(btVector3(0,0,-10.f));
//this create an internal copy of the vertices
btCollisionShape* shape = new btConvexHullShape(&(vertices[0].getX()),vertices.size());
m_demoApp->m_collisionShapes.push_back(shape);
@ -134,7 +134,7 @@ BspDemo::~BspDemo()
void BspDemo::initPhysics()
{
const char* bspfilename = "BspDemo.bsp";
initPhysics(bspfilename);
}
@ -144,7 +144,7 @@ void BspDemo::initPhysics(const char* bspfilename)
{
setTexturing(true);
setShadows(false);
m_cameraUp = btVector3(0,0,1);
m_forwardAxis = 1;
@ -170,31 +170,23 @@ void BspDemo::initPhysics(const char* bspfilename)
#ifdef QUAKE_BSP_IMPORTING
void* memoryBuffer = 0;
FILE* file = fopen(bspfilename,"r");
if (!file)
{
//try again other path,
//sight... visual studio leaves the current working directory in the projectfiles folder
//instead of executable folder. who wants this default behaviour?!?
bspfilename = "../../BspDemo.bsp";
file = fopen(bspfilename,"r");
}
if (!file)
{
//try again other path, cmake needs 4 levels deep back...
bspfilename = "../../../../BspDemo.bsp";
file = fopen(bspfilename,"r");
}
if (!file)
{
//try again other path,
//sight... visual studio leaves the current working directory in the projectfiles folder
//instead of executable folder. who wants this default behaviour?!?
bspfilename = "BspDemo.bsp";
file = fopen(bspfilename,"r");
}
const char* filename = "BspDemo.bsp";
const char* prefix[]={"./","../","../../","../../../","../../../../", "BspDemo/", "Demos/BspDemo/",
"../Demos/BspDemo/","../../Demos/BspDemo/"};
int numPrefixes = sizeof(prefix)/sizeof(const char*);
char relativeFileName[1024];
FILE* file=0;
for (int i=0;i<numPrefixes;i++)
{
sprintf(relativeFileName,"%s%s",prefix[i],filename);
file = fopen(relativeFileName,"r");
if (file)
break;
}
if (file)
{
@ -229,9 +221,9 @@ void BspDemo::initPhysics(const char* bspfilename)
void BspDemo::clientMoveAndDisplay()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
float dt = getDeltaTimeMicroseconds() * 0.000001f;
m_dynamicsWorld->stepSimulation(dt);
//optional but useful: debug drawing
@ -248,7 +240,7 @@ void BspDemo::clientMoveAndDisplay()
void BspDemo::displayCallback(void) {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
renderme();
@ -295,7 +287,7 @@ char* makeExeToBspFilename(const char* lpCmdLine)
// If we hit a null or a quote, stop copying. This will get just the first filename.
if(i && (in[0] == '.') && (in[1] == 'e') && (in[2] == 'x') && (in[3] == 'e'))
break;
// If we hit a null or a quote, stop copying. This will get just the first filename.
if(*in == '\0' || *in == '\"')
break;
@ -316,6 +308,6 @@ char* makeExeToBspFilename(const char* lpCmdLine)
*(out++) = 's';
*(out++) = 'p';
*(out++) = 0;
return cleaned_filename;
}

View File

@ -35,7 +35,7 @@ IF (NOT INTERNAL_CREATE_DISTRIBUTABLE_MSVC_PROJECTFILES)
ADD_CUSTOM_COMMAND(
TARGET AppBspPhysicsDemo
POST_BUILD
COMMAND ${CMAKE_COMMAND} ARGS -E copy_if_different ${BULLET_PHYSICS_SOURCE_DIR}/ObsoleteDemos/BspDemo/BspDemo.bsp ${CMAKE_CURRENT_BINARY_DIR}
COMMAND ${CMAKE_COMMAND} ARGS -E copy_if_different ${BULLET_PHYSICS_SOURCE_DIR}/Demos/BspDemo/BspDemo.bsp ${CMAKE_CURRENT_BINARY_DIR}
)
ENDIF (NOT INTERNAL_CREATE_DISTRIBUTABLE_MSVC_PROJECTFILES)
@ -43,4 +43,4 @@ IF (INTERNAL_ADD_POSTFIX_EXECUTABLE_NAMES)
SET_TARGET_PROPERTIES(AppBspPhysicsDemo PROPERTIES DEBUG_POSTFIX "_Debug")
SET_TARGET_PROPERTIES(AppBspPhysicsDemo PROPERTIES MINSIZEREL_POSTFIX "_MinsizeRel")
SET_TARGET_PROPERTIES(AppBspPhysicsDemo PROPERTIES RELWITHDEBINFO_POSTFIX "_RelWithDebugInfo")
ENDIF(INTERNAL_ADD_POSTFIX_EXECUTABLE_NAMES)
ENDIF(INTERNAL_ADD_POSTFIX_EXECUTABLE_NAMES)

View File

@ -4,8 +4,8 @@ Copyright (c) 2003-2010 Erwin Coumans http://continuousphysics.com/Bullet/
This software is provided 'as-is', without any express or implied warranty.
In no event will the authors be held liable for any damages arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it freely,
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it freely,
subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
@ -38,16 +38,36 @@ void BulletXmlImportDemo::initPhysics()
setTexturing(true);
setShadows(true);
setupEmptyDynamicsWorld();
m_dynamicsWorld->setDebugDrawer(&gDebugDrawer);
btBulletXmlWorldImporter* importer = new btBulletXmlWorldImporter(m_dynamicsWorld);
importer->loadFile("bullet_basic.xml");
static const char* filename = "bullet_basic.xml";
const char* prefix[]={"./","../","../../","../../../","../../../../", "BulletXmlImportDemo/", "Demos/BulletXmlImportDemo/",
"../Demos/BulletXmlImportDemo/","../../Demos/BulletXmlImportDemo/"};
int numPrefixes = sizeof(prefix)/sizeof(const char*);
char relativeFileName[1024];
bool fileFound = false;
for (int i=0;i<numPrefixes;i++)
{
sprintf(relativeFileName,"%s%s",prefix[i],filename);
FILE* f = fopen(relativeFileName,"r");
if (f)
{
fclose(f);
fileFound = true;
break;
}
}
importer->loadFile(relativeFileName);
// importer->loadFile("bulletser.xml");
// importer->loadFile("bullet_constraints.xml");
@ -55,21 +75,21 @@ void BulletXmlImportDemo::initPhysics()
void BulletXmlImportDemo::clientMoveAndDisplay()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
//simple dynamics world doesn't handle fixed-time-stepping
float ms = getDeltaTimeMicroseconds();
///step the simulation
if (m_dynamicsWorld)
{
m_dynamicsWorld->stepSimulation(ms / 1000000.f);
m_dynamicsWorld->debugDrawWorld();
}
renderme();
renderme();
glFlush();
@ -81,8 +101,8 @@ void BulletXmlImportDemo::clientMoveAndDisplay()
void BulletXmlImportDemo::displayCallback(void) {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
renderme();
@ -105,7 +125,7 @@ void BulletXmlImportDemo::setupEmptyDynamicsWorld()
btGImpactCollisionAlgorithm::registerAlgorithm(m_dispatcher);
m_broadphase = new btDbvtBroadphase();
///the default constraint solver. For parallel processing you can use a different solver (see Extras/BulletMultiThreaded)
btSequentialImpulseConstraintSolver* sol = new btSequentialImpulseConstraintSolver;
m_solver = sol;
@ -113,7 +133,7 @@ void BulletXmlImportDemo::setupEmptyDynamicsWorld()
//btGImpactCollisionAlgorithm::registerAlgorithm((btCollisionDispatcher*)m_dynamicsWorld->getDispatcher());
}
@ -122,8 +142,6 @@ void BulletXmlImportDemo::setupEmptyDynamicsWorld()
BulletXmlImportDemo::~BulletXmlImportDemo()
{
m_fileLoader->deleteAllData();
delete m_fileLoader;
exitPhysics();
}
@ -163,16 +181,16 @@ void BulletXmlImportDemo::exitPhysics()
m_collisionShapes.clear();
delete m_dynamicsWorld;
delete m_solver;
delete m_broadphase;
delete m_dispatcher;
delete m_collisionConfiguration;
}

View File

@ -49,8 +49,6 @@ class BulletXmlImportDemo : public PlatformDemoApplication
btDefaultCollisionConfiguration* m_collisionConfiguration;
class btBulletWorldImporter* m_fileLoader;
public:
BulletXmlImportDemo()

View File

@ -18,6 +18,7 @@ ${BULLET_PHYSICS_SOURCE_DIR}/src
${BULLET_PHYSICS_SOURCE_DIR}/Extras/Serialize/BulletFileLoader
${BULLET_PHYSICS_SOURCE_DIR}/Extras/Serialize/BulletWorldImporter
${BULLET_PHYSICS_SOURCE_DIR}/Extras/Serialize/BulletXmlWorldImporter
${GLUT_INCLUDE_DIR}
)
ADD_DEFINITIONS(-DDESERIALIZE_SOFT_BODIES)

View File

@ -5,12 +5,12 @@ SUBDIRS( HelloWorld )
IF (USE_GLUT)
IF (GLUT_FOUND)
IF(BUILD_CPU_DEMOS)
# IF(BUILD_EXTRAS)
# SUBDIRS( BulletXmlImportDemo ConcaveDemo ConstraintDemo ConvexDecompositionDemo SerializeDemo )
# ENDIF()
IF(BUILD_EXTRAS)
SUBDIRS( BulletXmlImportDemo ConcaveDemo ConvexDecompositionDemo SerializeDemo )
ENDIF()
SET(SharedDemoSubdirs
OpenGL
CcdPhysicsDemo SliderConstraintDemo GenericJointDemo Raytracer
CcdPhysicsDemo ConstraintDemo SliderConstraintDemo GenericJointDemo Raytracer
RagdollDemo ForkLiftDemo BasicDemo FeatherstoneMultiBodyDemo RollingFrictionDemo RaytestDemo VoronoiFractureDemo
GyroscopicDemo FractureDemo Box2dDemo BspDemo MovingConcaveDemo VehicleDemo
UserCollisionAlgorithm CharacterDemo SoftDemo

View File

@ -25,12 +25,17 @@ IF (WIN32)
ADD_EXECUTABLE(AppCcdPhysicsDemo
main.cpp
CcdPhysicsDemo.cpp
CcdPhysicsSetup.h
CcdPhysicsSetup.cpp
${BULLET_PHYSICS_SOURCE_DIR}/build3/bullet.rc
)
ELSE()
ADD_EXECUTABLE(AppCcdPhysicsDemo
main.cpp
CcdPhysicsDemo.cpp
CcdPhysicsSetup.h
CcdPhysicsSetup.cpp
)
ENDIF()

View File

@ -167,26 +167,11 @@ void CcdPhysicsDemo::initPhysics()
m_ShootBoxInitialSpeed = 4000.f;
m_defaultContactProcessingThreshold = 0.f;
///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->registerCollisionCreateFunc(BOX_SHAPE_PROXYTYPE,BOX_SHAPE_PROXYTYPE,m_collisionConfiguration->getCollisionAlgorithmCreateFunc(CONVEX_SHAPE_PROXYTYPE,CONVEX_SHAPE_PROXYTYPE));
m_broadphase = new btDbvtBroadphase();
///the default constraint solver. For parallel processing you can use a different solver (see Extras/BulletMultiThreaded)
btSequentialImpulseConstraintSolver* sol = new btSequentialImpulseConstraintSolver;
m_solver = sol;
m_dynamicsWorld = new btDiscreteDynamicsWorld(m_dispatcher,m_broadphase,m_solver,m_collisionConfiguration);
GraphicsPhysicsBridge bridge;
m_physicsSetup.initPhysics(bridge);
m_dynamicsWorld = m_physicsSetup.m_dynamicsWorld;
m_dynamicsWorld->getSolverInfo().m_solverMode |=SOLVER_USE_2_FRICTION_DIRECTIONS|SOLVER_RANDMIZE_ORDER;
m_dynamicsWorld ->setDebugDrawer(&sDebugDrawer);
//m_dynamicsWorld->getSolverInfo().m_splitImpulse=false;
@ -203,108 +188,6 @@ void CcdPhysicsDemo::initPhysics()
m_dynamicsWorld->setGravity(btVector3(0,-10,0));
///create a few basic rigid bodies
btBoxShape* box = new btBoxShape(btVector3(btScalar(110.),btScalar(1.),btScalar(110.)));
// box->initializePolyhedralFeatures();
btCollisionShape* groundShape = box;
// btCollisionShape* groundShape = new btStaticPlaneShape(btVector3(0,1,0),50);
m_collisionShapes.push_back(groundShape);
//m_collisionShapes.push_back(new btCylinderShape (btVector3(CUBE_HALF_EXTENTS,CUBE_HALF_EXTENTS,CUBE_HALF_EXTENTS)));
m_collisionShapes.push_back(new btBoxShape (btVector3(CUBE_HALF_EXTENTS,CUBE_HALF_EXTENTS,CUBE_HALF_EXTENTS)));
btTransform groundTransform;
groundTransform.setIdentity();
//groundTransform.setOrigin(btVector3(5,5,5));
//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);
if (isDynamic)
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* body = new btRigidBody(rbInfo);
body->setFriction(0.5);
//body->setRollingFriction(0.3);
//add the body to the dynamics world
m_dynamicsWorld->addRigidBody(body);
}
{
//create a few dynamic rigidbodies
// Re-using the same collision is better for memory usage and performance
btCollisionShape* colShape = new btBoxShape(btVector3(1,1,1));
//btCollisionShape* colShape = new btSphereShape(btScalar(1.));
m_collisionShapes.push_back(colShape);
/// Create Dynamic Objects
btTransform startTransform;
startTransform.setIdentity();
btScalar mass(1.f);
//rigidbody is dynamic if and only if mass is non zero, otherwise static
bool isDynamic = (mass != 0.f);
btVector3 localInertia(0,0,0);
if (isDynamic)
colShape->calculateLocalInertia(mass,localInertia);
int gNumObjects = 120;//120;
int i;
for (i=0;i<gNumObjects;i++)
{
btCollisionShape* shape = m_collisionShapes[1];
btTransform trans;
trans.setIdentity();
//stack them
int colsize = 10;
int row = (i*CUBE_HALF_EXTENTS*2)/(colsize*2*CUBE_HALF_EXTENTS);
int row2 = row;
int col = (i)%(colsize)-colsize/2;
if (col>3)
{
col=11;
row2 |=1;
}
btVector3 pos(col*2*CUBE_HALF_EXTENTS + (row2%2)*CUBE_HALF_EXTENTS,
row*2*CUBE_HALF_EXTENTS+CUBE_HALF_EXTENTS+EXTRA_HEIGHT,0);
trans.setOrigin(pos);
float mass = 1.f;
btRigidBody* body = localCreateRigidBody(mass,trans,shape);
body->setAnisotropicFriction(shape->getAnisotropicRollingFrictionDirection(),btCollisionObject::CF_ANISOTROPIC_ROLLING_FRICTION);
body->setFriction(0.5);
//body->setRollingFriction(.3);
///when using m_ccdMode
if (m_ccdMode==USE_CCD)
{
body->setCcdMotionThreshold(CUBE_HALF_EXTENTS);
body->setCcdSweptSphereRadius(0.9*CUBE_HALF_EXTENTS);
}
}
}
}
void CcdPhysicsDemo::clientResetScene()
@ -381,40 +264,8 @@ void CcdPhysicsDemo::shootBox(const btVector3& destination)
void CcdPhysicsDemo::exitPhysics()
{
m_physicsSetup.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--)
{
btCollisionObject* obj = m_dynamicsWorld->getCollisionObjectArray()[i];
btRigidBody* body = btRigidBody::upcast(obj);
if (body && body->getMotionState())
{
delete body->getMotionState();
}
m_dynamicsWorld->removeCollisionObject( obj );
delete obj;
}
//delete collision shapes
for (int j=0;j<m_collisionShapes.size();j++)
{
btCollisionShape* shape = m_collisionShapes[j];
delete shape;
}
m_collisionShapes.clear();
delete m_dynamicsWorld;
delete m_solver;
delete m_broadphase;
delete m_dispatcher;
delete m_collisionConfiguration;
}

View File

@ -33,19 +33,14 @@ class btConstraintSolver;
struct btCollisionAlgorithmCreateFunc;
class btDefaultCollisionConfiguration;
#include "CcdPhysicsSetup.h"
///CcdPhysicsDemo is good starting point for learning the code base and porting.
class CcdPhysicsDemo : public PlatformDemoApplication
{
//keep the collision shapes, for deletion/cleanup
btAlignedObjectArray<btCollisionShape*> m_collisionShapes;
btBroadphaseInterface* m_broadphase;
btCollisionDispatcher* m_dispatcher;
btConstraintSolver* m_solver;
CcdPhysicsSetup m_physicsSetup;
enum
{
@ -54,7 +49,6 @@ class CcdPhysicsDemo : public PlatformDemoApplication
};
int m_ccdMode;
btDefaultCollisionConfiguration* m_collisionConfiguration;
public:

View File

@ -0,0 +1,179 @@
#include "CcdPhysicsSetup.h"
#include "btBulletDynamicsCommon.h"
#define CUBE_HALF_EXTENTS 1.f
#define EXTRA_HEIGHT 1.f
void KinematicObjectSetup::initPhysics(GraphicsPhysicsBridge& gfxBridge)
{
createEmptyDynamicsWorld();
{
btBoxShape* box = new btBoxShape(btVector3(btScalar(10.), btScalar(1.), btScalar(10.)));
gfxBridge.createCollisionShapeGraphicsObject(box);
btTransform startTrans;
startTrans.setIdentity();
startTrans.setOrigin(btVector3(0, -1, 0));
btRigidBody* body = createRigidBody(0, startTrans, box);
body->setMotionState(0);
body->setFriction(1);
body->setCollisionFlags(body->getCollisionFlags() | btCollisionObject::CF_KINEMATIC_OBJECT);
body->setActivationState(DISABLE_DEACTIVATION);
gfxBridge.createRigidBodyGraphicsObject(body, btVector3(0,1,0));
}
{
btBoxShape* box = new btBoxShape(btVector3(btScalar(1.), btScalar(1.), btScalar(1.)));
gfxBridge.createCollisionShapeGraphicsObject(box);
btTransform startTrans;
startTrans.setIdentity();
startTrans.setOrigin(btVector3(0, 1, 0));
btRigidBody* body = createRigidBody(1, startTrans, box);
body->setFriction(1);
body->setActivationState(DISABLE_DEACTIVATION);
gfxBridge.createRigidBodyGraphicsObject(body, btVector3(1, 1, 0));
}
}
void KinematicObjectSetup::stepSimulation(float deltaTime)
{
if (m_dynamicsWorld)
{
btCollisionObject* colObj = m_dynamicsWorld->getCollisionObjectArray()[0];
btRigidBody* body = btRigidBody::upcast(colObj);
if (body)
{
btMotionState* ms = body->getMotionState();
btTransform startTrans;
startTrans.setIdentity();
static float time = 0.f;
time += 0.01f;
static float xPos = 0.f;
xPos = sinf(time)*10.f;
startTrans.setOrigin(btVector3(xPos, -1, 0));
if (ms)
{
ms->setWorldTransform(startTrans);
}
else
{
body->setWorldTransform(startTrans);
}
}
m_dynamicsWorld->stepSimulation(deltaTime);
}
}
void CcdPhysicsSetup::initPhysics(GraphicsPhysicsBridge& gfxBridge)
{
createEmptyDynamicsWorld();
///create a few basic rigid bodies
btBoxShape* box = new btBoxShape(btVector3(btScalar(110.), btScalar(1.), btScalar(110.)));
gfxBridge.createCollisionShapeGraphicsObject(box);
// box->initializePolyhedralFeatures();
btCollisionShape* groundShape = box;
m_collisionShapes.push_back(groundShape);
//m_collisionShapes.push_back(new btCylinderShape (btVector3(CUBE_HALF_EXTENTS,CUBE_HALF_EXTENTS,CUBE_HALF_EXTENTS)));
m_collisionShapes.push_back(new btBoxShape(btVector3(CUBE_HALF_EXTENTS, CUBE_HALF_EXTENTS, CUBE_HALF_EXTENTS)));
btTransform groundTransform;
groundTransform.setIdentity();
//groundTransform.setOrigin(btVector3(5,5,5));
//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);
if (isDynamic)
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* body = new btRigidBody(rbInfo);
gfxBridge.createRigidBodyGraphicsObject(body, btVector3(0, 1, 0));
body->setFriction(0.5);
//body->setRollingFriction(0.3);
//add the body to the dynamics world
m_dynamicsWorld->addRigidBody(body);
}
{
//create a few dynamic rigidbodies
// Re-using the same collision is better for memory usage and performance
btCollisionShape* colShape = new btBoxShape(btVector3(1, 1, 1));
gfxBridge.createCollisionShapeGraphicsObject(colShape);
//btCollisionShape* colShape = new btSphereShape(btScalar(1.));
m_collisionShapes.push_back(colShape);
/// Create Dynamic Objects
btTransform startTransform;
startTransform.setIdentity();
btScalar mass(1.f);
//rigidbody is dynamic if and only if mass is non zero, otherwise static
bool isDynamic = (mass != 0.f);
btVector3 localInertia(0, 0, 0);
if (isDynamic)
colShape->calculateLocalInertia(mass, localInertia);
int gNumObjects = 120;//120;
int i;
for (i = 0; i<gNumObjects; i++)
{
btCollisionShape* shape = colShape;// m_collisionShapes[1];
btTransform trans;
trans.setIdentity();
//stack them
int colsize = 10;
int row = (i*CUBE_HALF_EXTENTS * 2) / (colsize * 2 * CUBE_HALF_EXTENTS);
int row2 = row;
int col = (i) % (colsize)-colsize / 2;
if (col>3)
{
col = 11;
row2 |= 1;
}
btVector3 pos(col * 2 * CUBE_HALF_EXTENTS + (row2 % 2)*CUBE_HALF_EXTENTS,
row * 2 * CUBE_HALF_EXTENTS + CUBE_HALF_EXTENTS + EXTRA_HEIGHT, 0);
trans.setOrigin(pos);
float mass = 1.f;
btRigidBody* body = createRigidBody(mass, trans, shape);
gfxBridge.createRigidBodyGraphicsObject(body, btVector3(1, 1, 0));
body->setAnisotropicFriction(shape->getAnisotropicRollingFrictionDirection(), btCollisionObject::CF_ANISOTROPIC_ROLLING_FRICTION);
body->setFriction(0.5);
//body->setRollingFriction(.3);
///when using m_ccdMode
//if (m_ccdMode == USE_CCD)
{
body->setCcdMotionThreshold(CUBE_HALF_EXTENTS);
body->setCcdSweptSphereRadius(0.9*CUBE_HALF_EXTENTS);
}
}
}
}

View File

@ -0,0 +1,23 @@
#ifndef CCD_PHYSICS_SETUP_H
#define CCD_PHYSICS_SETUP_H
#include "../CommonRigidBodySetup.h"
struct CcdPhysicsSetup : public CommonRigidBodySetup
{
virtual void initPhysics(GraphicsPhysicsBridge& gfxBridge);
};
struct KinematicObjectSetup : public CommonRigidBodySetup
{
virtual void initPhysics(GraphicsPhysicsBridge& gfxBridge);
virtual void stepSimulation(float deltaTime);
};
#endif //CCD_PHYSICS_SETUP_H

View File

@ -46,7 +46,7 @@ IF (NOT INTERNAL_CREATE_DISTRIBUTABLE_MSVC_PROJECTFILES)
ADD_CUSTOM_COMMAND(
TARGET AppCharacterDemo
POST_BUILD
COMMAND ${CMAKE_COMMAND} ARGS -E copy_if_different ${BULLET_PHYSICS_SOURCE_DIR}/ObsoleteDemos/BspDemo/BspDemo.bsp ${CMAKE_CURRENT_BINARY_DIR}
COMMAND ${CMAKE_COMMAND} ARGS -E copy_if_different ${BULLET_PHYSICS_SOURCE_DIR}/Demos/BspDemo/BspDemo.bsp ${CMAKE_CURRENT_BINARY_DIR}
)
ENDIF (NOT INTERNAL_CREATE_DISTRIBUTABLE_MSVC_PROJECTFILES)

View File

@ -69,11 +69,11 @@ void CharacterDemo::initPhysics()
m_constraintSolver = new btSequentialImpulseConstraintSolver();
m_dynamicsWorld = new btDiscreteDynamicsWorld(m_dispatcher,m_overlappingPairCache,m_constraintSolver,m_collisionConfiguration);
m_dynamicsWorld->getDispatchInfo().m_allowedCcdPenetration=0.0001f;
#ifdef DYNAMIC_CHARACTER_CONTROLLER
m_character = new DynamicCharacterController ();
#else
btTransform startTransform;
startTransform.setIdentity ();
//startTransform.setOrigin (btVector3(0.0, 4.0, 0.0));
@ -101,35 +101,30 @@ void CharacterDemo::initPhysics()
btTransform tr;
tr.setIdentity();
const char* bspfilename = "BspDemo.bsp";
const char* filename = "BspDemo.bsp";
const char* prefix[]={"./","../","../../","../../../","../../../../", "BspDemo/", "Demos/BspDemo/",
"../Demos/BspDemo/","../../Demos/BspDemo/"};
int numPrefixes = sizeof(prefix)/sizeof(const char*);
char relativeFileName[1024];
FILE* file=0;
for (int i=0;i<numPrefixes;i++)
{
sprintf(relativeFileName,"%s%s",prefix[i],filename);
file = fopen(relativeFileName,"r");
if (file)
break;
}
void* memoryBuffer = 0;
FILE* file = fopen(bspfilename,"r");
if (!file)
{
//cmake generated visual studio projects need 4 levels back
bspfilename = "../../../../BspDemo.bsp";
file = fopen(bspfilename,"r");
}
if (!file)
{
//visual studio leaves the current working directory in the projectfiles folder
bspfilename = "../../BspDemo.bsp";
file = fopen(bspfilename,"r");
}
if (!file)
{
//visual studio leaves the current working directory in the projectfiles folder
bspfilename = "BspDemo.bsp";
file = fopen(bspfilename,"r");
}
if (file)
{
BspLoader bspLoader;
int size=0;
if (fseek(file, 0, SEEK_END) || (size = ftell(file)) == EOF || fseek(file, 0, SEEK_SET)) { /* File operations denied? ok, just close and return failure */
printf("Error: cannot get filesize from %s\n", bspfilename);
printf("Error: cannot get filesize from %s\n", filename);
} else
{
//how to detect file size?
@ -183,7 +178,7 @@ void CharacterDemo::debugDrawContacts()
manifoldArray.clear();
const btBroadphasePair& pair = pairArray[i];
btBroadphasePair* collisionPair = m_overlappingPairCache->getOverlappingPairCache()->findPair(pair.m_pProxy0,pair.m_pProxy1);
if (!collisionPair)
continue;
@ -217,7 +212,7 @@ void CharacterDemo::clientMoveAndDisplay()
/* Character stuff &*/
if (m_character)
{
}
debugDrawContacts();
@ -265,7 +260,7 @@ void CharacterDemo::clientMoveAndDisplay()
walkDirection += forwardDir;
if (gBackward)
walkDirection -= forwardDir;
walkDirection -= forwardDir;
m_character->setWalkDirection(walkDirection*walkSpeed);
@ -344,7 +339,7 @@ void CharacterDemo::clientResetScene()
m_character->reset (m_dynamicsWorld);
///WTF
m_character->warp (btVector3(10.210001,-2.0306311,16.576973));
}
void CharacterDemo::specialKeyboardUp(int key, int x, int y)
@ -444,7 +439,7 @@ void CharacterDemo::updateCamera()
m_cameraTargetPosition = characterWorldTrans.getOrigin();
m_cameraPosition = m_cameraTargetPosition + up * 10.0 + backward * 12.0;
//use the convex sweep test to find a safe position for the camera (not blocked by static geometry)
btSphereShape cameraSphere(0.2f);
btTransform cameraFrom,cameraTo;
@ -452,10 +447,10 @@ void CharacterDemo::updateCamera()
cameraFrom.setOrigin(characterWorldTrans.getOrigin());
cameraTo.setIdentity();
cameraTo.setOrigin(m_cameraPosition);
btCollisionWorld::ClosestConvexResultCallback cb( characterWorldTrans.getOrigin(), cameraTo.getOrigin() );
cb.m_collisionFilterMask = btBroadphaseProxy::StaticFilter;
m_dynamicsWorld->convexSweepTest(&cameraSphere,cameraFrom,cameraTo,cb);
if (cb.hasHit())
{

View File

@ -0,0 +1,41 @@
#ifndef PARAM_INTERFACE_H
#define PARAM_INTERFACE_H
#pragma once
typedef void (*SliderParamChangedCallback) (float newVal);
#include "LinearMath/btScalar.h"
struct SliderParams
{
const char* m_name;
float m_minVal;
float m_maxVal;
SliderParamChangedCallback m_callback;
btScalar* m_paramValuePointer;
void* m_userPointer;
bool m_clampToNotches;
SliderParams(const char* name, btScalar* targetValuePointer)
:m_name(name),
m_minVal(-100),
m_maxVal(100),
m_callback(0),
m_paramValuePointer(targetValuePointer),
m_userPointer(0),
m_clampToNotches(false)
{
}
};
struct CommonParameterInterface
{
virtual void registerSliderFloatParameter(SliderParams& params)=0;
virtual void syncParameters()=0;
virtual void removeAllParameters()=0;
};
#endif //PARAM_INTERFACE_H

View File

@ -0,0 +1,67 @@
#ifndef COMMON_PHYSICS_SETUP_H
#define COMMON_PHYSICS_SETUP_H
class btRigidBody;
class btBoxShape;
class btTransform;
class btCollisionShape;
#include "LinearMath/btVector3.h"
#include "CommonParameterInterface.h"
class btDiscreteDynamicsWorld;
///The GraphicsPhysicsBridge let's the graphics engine create graphics representation and synchronize
struct GraphicsPhysicsBridge
{
virtual void createRigidBodyGraphicsObject(btRigidBody* body,const btVector3& color)
{
}
virtual void createCollisionShapeGraphicsObject(btCollisionShape* collisionShape)
{
}
virtual void syncPhysicsToGraphics(const btDiscreteDynamicsWorld* rbWorld)
{
}
virtual void createPhysicsDebugDrawer( btDiscreteDynamicsWorld* rbWorld)
{
}
virtual CommonParameterInterface* getParameterInterface()
{
return 0;
}
};
struct CommonPhysicsSetup
{
public:
virtual ~CommonPhysicsSetup() {}
virtual void initPhysics(GraphicsPhysicsBridge& gfxBridge) = 0;
virtual void exitPhysics()=0;
virtual void stepSimulation(float deltaTime)=0;
virtual void debugDraw()=0;
virtual bool pickBody(const btVector3& rayFromWorld, const btVector3& rayToWorld) = 0;
virtual bool movePickedBody(const btVector3& rayFromWorld, const btVector3& rayToWorld)=0;
virtual void removePickingConstraint() = 0;
virtual void syncPhysicsToGraphics(GraphicsPhysicsBridge& gfxBridge) = 0;
virtual btRigidBody* createRigidBody(float mass, const btTransform& startTransform,btCollisionShape* shape, const btVector4& color=btVector4(1,0,0,1))=0;
virtual btBoxShape* createBoxShape(const btVector3& halfExtents)=0;
};
#endif //COMMON_PHYSICS_SETUP_H

View File

@ -0,0 +1,247 @@
#ifndef COMMON_RIGID_BODY_SETUP_H
#define COMMON_RIGID_BODY_SETUP_H
//todo: replace this 'btBulletDynamicsCommon.h' header with specific used header files
#include "btBulletDynamicsCommon.h"
#include "CommonPhysicsSetup.h"
struct CommonRigidBodySetup : public CommonPhysicsSetup
{
//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;
//data for picking objects
class btRigidBody* m_pickedBody;
class btTypedConstraint* m_pickedConstraint;
btVector3 m_oldPickingPos;
btVector3 m_hitPos;
btScalar m_oldPickingDist;
CommonRigidBodySetup()
:m_broadphase(0),
m_dispatcher(0),
m_solver(0),
m_collisionConfiguration(0),
m_dynamicsWorld(0),
m_pickedBody(0),
m_pickedConstraint(0)
{
}
virtual void createEmptyDynamicsWorld()
{
///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_broadphase = new btDbvtBroadphase();
///the default constraint solver. For parallel processing you can use a different solver (see Extras/BulletMultiThreaded)
btSequentialImpulseConstraintSolver* sol = new btSequentialImpulseConstraintSolver;
m_solver = sol;
m_dynamicsWorld = new btDiscreteDynamicsWorld(m_dispatcher, m_broadphase, m_solver, m_collisionConfiguration);
m_dynamicsWorld->setGravity(btVector3(0, -10, 0));
}
virtual void stepSimulation(float deltaTime)
{
if (m_dynamicsWorld)
{
m_dynamicsWorld->stepSimulation(deltaTime);
}
}
virtual void exitPhysics()
{
removePickingConstraint();
//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));
}
for (i = m_dynamicsWorld->getNumCollisionObjects() - 1; i >= 0; i--)
{
btCollisionObject* obj = m_dynamicsWorld->getCollisionObjectArray()[i];
btRigidBody* body = btRigidBody::upcast(obj);
if (body && body->getMotionState())
{
delete body->getMotionState();
}
m_dynamicsWorld->removeCollisionObject(obj);
delete obj;
}
}
//delete collision shapes
for (int j = 0; j<m_collisionShapes.size(); j++)
{
btCollisionShape* shape = m_collisionShapes[j];
delete shape;
}
m_collisionShapes.clear();
delete m_dynamicsWorld;
delete m_solver;
delete m_broadphase;
delete m_dispatcher;
delete m_collisionConfiguration;
}
virtual void syncPhysicsToGraphics(GraphicsPhysicsBridge& gfxBridge)
{
if (m_dynamicsWorld)
{
gfxBridge.syncPhysicsToGraphics(m_dynamicsWorld);
}
}
virtual void debugDraw()
{
if (m_dynamicsWorld)
{
m_dynamicsWorld->debugDrawWorld();
}
}
virtual bool pickBody(const btVector3& rayFromWorld, const btVector3& rayToWorld)
{
if (m_dynamicsWorld==0)
return false;
btCollisionWorld::ClosestRayResultCallback rayCallback(rayFromWorld, rayToWorld);
m_dynamicsWorld->rayTest(rayFromWorld, rayToWorld, rayCallback);
if (rayCallback.hasHit())
{
btVector3 pickPos = rayCallback.m_hitPointWorld;
btRigidBody* body = (btRigidBody*)btRigidBody::upcast(rayCallback.m_collisionObject);
if (body)
{
//other exclusions?
if (!(body->isStaticObject() || body->isKinematicObject()))
{
m_pickedBody = body;
m_pickedBody->setActivationState(DISABLE_DEACTIVATION);
//printf("pickPos=%f,%f,%f\n",pickPos.getX(),pickPos.getY(),pickPos.getZ());
btVector3 localPivot = body->getCenterOfMassTransform().inverse() * pickPos;
btPoint2PointConstraint* p2p = new btPoint2PointConstraint(*body, localPivot);
m_dynamicsWorld->addConstraint(p2p, true);
m_pickedConstraint = p2p;
btScalar mousePickClamping = 30.f;
p2p->m_setting.m_impulseClamp = mousePickClamping;
//very weak constraint for picking
p2p->m_setting.m_tau = 0.001f;
}
}
// pickObject(pickPos, rayCallback.m_collisionObject);
m_oldPickingPos = rayToWorld;
m_hitPos = pickPos;
m_oldPickingDist = (pickPos - rayFromWorld).length();
// printf("hit !\n");
//add p2p
}
return false;
}
virtual bool movePickedBody(const btVector3& rayFromWorld, const btVector3& rayToWorld)
{
if (m_pickedBody && m_pickedConstraint)
{
btPoint2PointConstraint* pickCon = static_cast<btPoint2PointConstraint*>(m_pickedConstraint);
if (pickCon)
{
//keep it at the same picking distance
btVector3 newPivotB;
btVector3 dir = rayToWorld - rayFromWorld;
dir.normalize();
dir *= m_oldPickingDist;
newPivotB = rayFromWorld + dir;
pickCon->setPivotB(newPivotB);
return true;
}
}
return false;
}
virtual void removePickingConstraint()
{
if (m_pickedConstraint)
{
m_dynamicsWorld->removeConstraint(m_pickedConstraint);
delete m_pickedConstraint;
m_pickedConstraint = 0;
m_pickedBody = 0;
}
}
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))
{
btAssert((!shape || shape->getShapeType() != INVALID_SHAPE_PROXYTYPE));
//rigidbody is dynamic if and only if mass is non zero, otherwise static
bool isDynamic = (mass != 0.f);
btVector3 localInertia(0, 0, 0);
if (isDynamic)
shape->calculateLocalInertia(mass, localInertia);
//using motionstate is recommended, it provides interpolation capabilities, and only synchronizes 'active' objects
#define USE_MOTIONSTATE 1
#ifdef USE_MOTIONSTATE
btDefaultMotionState* myMotionState = new btDefaultMotionState(startTransform);
btRigidBody::btRigidBodyConstructionInfo cInfo(mass, myMotionState, shape, localInertia);
btRigidBody* body = new btRigidBody(cInfo);
//body->setContactProcessingThreshold(m_defaultContactProcessingThreshold);
#else
btRigidBody* body = new btRigidBody(mass, 0, shape, localInertia);
body->setWorldTransform(startTransform);
#endif//
body->setUserIndex(-1);
m_dynamicsWorld->addRigidBody(body);
return body;
}
};
#endif //COMMON_RIGID_BODY_SETUP_H

View File

@ -16,6 +16,8 @@ IF (USE_GLUT)
../OpenGL
${BULLET_PHYSICS_SOURCE_DIR}/Extras/Serialize/BulletFileLoader
${BULLET_PHYSICS_SOURCE_DIR}/Extras/Serialize/BulletWorldImporter
${GLUT_INCLUDE_DIR}
)
LINK_LIBRARIES(

View File

@ -14,14 +14,14 @@
INCLUDE_DIRECTORIES(
${BULLET_PHYSICS_SOURCE_DIR}/src
../OpenGL
${BULLET_PHYSICS_SOURCE_DIR}/Extras/Serialize/BulletFileLoader
${BULLET_PHYSICS_SOURCE_DIR}/Extras/Serialize/BulletWorldImporter
${GLUT_INCLUDE_DIR}
)
IF (USE_GLUT)
LINK_LIBRARIES(
OpenGLSupport BulletWorldImporter BulletDynamics BulletCollision LinearMath BulletFileLoader ${GLUT_glut_LIBRARY} ${OPENGL_gl_LIBRARY} ${OPENGL_glu_LIBRARY}
OpenGLSupport BulletDynamics BulletCollision LinearMath ${GLUT_glut_LIBRARY}
${OPENGL_gl_LIBRARY} ${OPENGL_glu_LIBRARY}
)
ADD_EXECUTABLE(AppConstraintDemo
@ -31,7 +31,7 @@ IF (USE_GLUT)
)
ELSE (USE_GLUT)
LINK_LIBRARIES(
OpenGLSupport BulletWorldImporter BulletDynamics BulletCollision LinearMath BulletFileLoader ${OPENGL_gl_LIBRARY} ${OPENGL_glu_LIBRARY}
OpenGLSupport BulletDynamics BulletCollision LinearMath ${OPENGL_gl_LIBRARY} ${OPENGL_glu_LIBRARY}
)
ADD_EXECUTABLE(AppConstraintDemo

View File

@ -0,0 +1,70 @@
#include "ConstraintPhysicsSetup.h"
ConstraintPhysicsSetup::ConstraintPhysicsSetup()
{
}
ConstraintPhysicsSetup::~ConstraintPhysicsSetup()
{
}
btScalar val;
btHingeAccumulatedAngleConstraint* spDoorHinge=0;
void ConstraintPhysicsSetup::stepSimulation(float deltaTime)
{
val=spDoorHinge->getAccumulatedHingeAngle()*SIMD_DEGS_PER_RAD;// spDoorHinge->getHingeAngle()*SIMD_DEGS_PER_RAD;
if (m_dynamicsWorld)
{
m_dynamicsWorld->stepSimulation(deltaTime);
}
}
void ConstraintPhysicsSetup::initPhysics(GraphicsPhysicsBridge& gfxBridge)
{
createEmptyDynamicsWorld();
gfxBridge.createPhysicsDebugDrawer(m_dynamicsWorld);
int mode = btIDebugDraw::DBG_DrawWireframe
+btIDebugDraw::DBG_DrawConstraints
+btIDebugDraw::DBG_DrawConstraintLimits;
m_dynamicsWorld->getDebugDrawer()->setDebugMode(mode);
val=1.f;
SliderParams slider("hinge angle",&val);
slider.m_minVal=-720;
slider.m_maxVal=720;
gfxBridge.getParameterInterface()->registerSliderFloatParameter(slider);
{ // create a door using hinge constraint attached to the world
btCollisionShape* pDoorShape = new btBoxShape(btVector3(2.0f, 5.0f, 0.2f));
m_collisionShapes.push_back(pDoorShape);
btTransform doorTrans;
doorTrans.setIdentity();
doorTrans.setOrigin(btVector3(-5.0f, -2.0f, 0.0f));
btRigidBody* pDoorBody = createRigidBody( 1.0, doorTrans, pDoorShape);
pDoorBody->setActivationState(DISABLE_DEACTIVATION);
const btVector3 btPivotA(10.f + 2.1f, -2.0f, 0.0f ); // right next to the door slightly outside
btVector3 btAxisA( 0.0f, 1.0f, 0.0f ); // pointing upwards, aka Y-axis
spDoorHinge = new btHingeAccumulatedAngleConstraint( *pDoorBody, btPivotA, btAxisA );
// spDoorHinge->setLimit( 0.0f, SIMD_PI_2 );
// test problem values
// spDoorHinge->setLimit( -SIMD_PI, SIMD_PI*0.8f);
// spDoorHinge->setLimit( 1.f, -1.f);
// spDoorHinge->setLimit( -SIMD_PI*0.8f, SIMD_PI);
// spDoorHinge->setLimit( -SIMD_PI*0.8f, SIMD_PI, 0.9f, 0.3f, 0.0f);
// spDoorHinge->setLimit( -SIMD_PI*0.8f, SIMD_PI, 0.9f, 0.01f, 0.0f); // "sticky limits"
// spDoorHinge->setLimit( -SIMD_PI * 0.25f, SIMD_PI * 0.25f );
// spDoorHinge->setLimit( 0.0f, 0.0f );
m_dynamicsWorld->addConstraint(spDoorHinge);
spDoorHinge->setDbgDrawSize(btScalar(5.f));
//doorTrans.setOrigin(btVector3(-5.0f, 2.0f, 0.0f));
//btRigidBody* pDropBody = localCreateRigidBody( 10.0, doorTrans, shape);
}
}

View File

@ -0,0 +1,16 @@
#ifndef CONSTAINT_PHYSICS_SETUP_H
#define CONSTAINT_PHYSICS_SETUP_H
#include "../CommonRigidBodySetup.h"
struct ConstraintPhysicsSetup : public CommonRigidBodySetup
{
ConstraintPhysicsSetup();
virtual ~ConstraintPhysicsSetup();
virtual void initPhysics(GraphicsPhysicsBridge& gfxBridge);
virtual void stepSimulation(float deltaTime);
};
#endif //CONSTAINT_PHYSICS_SETUP_H

View File

@ -1,3 +1,4 @@
# This is basically the overall name of the project in Visual Studio this is the name of the Solution File
@ -18,6 +19,8 @@ ${BULLET_PHYSICS_SOURCE_DIR}/Extras/HACD
${BULLET_PHYSICS_SOURCE_DIR}/Extras/ConvexDecomposition
${BULLET_PHYSICS_SOURCE_DIR}/Extras/Serialize/BulletFileLoader
${BULLET_PHYSICS_SOURCE_DIR}/Extras/Serialize/BulletWorldImporter
${GLUT_INCLUDE_DIR}
)
IF (USE_GLUT)
@ -53,7 +56,7 @@ IF (NOT INTERNAL_CREATE_DISTRIBUTABLE_MSVC_PROJECTFILES)
TARGET AppConvexDecompositionDemo
POST_BUILD
COMMAND ${CMAKE_COMMAND} ARGS -E copy_if_different ${BULLET_PHYSICS_SOURCE_DIR}/Demos/SerializeDemo/testFile.bullet ${CMAKE_CURRENT_BINARY_DIR}/testFile.bullet
COMMAND ${CMAKE_COMMAND} ARGS -E copy_if_different ${BULLET_PHYSICS_SOURCE_DIR}/file.obj ${CMAKE_CURRENT_BINARY_DIR}
COMMAND ${CMAKE_COMMAND} ARGS -E copy_if_different ${BULLET_PHYSICS_SOURCE_DIR}/Demos/ConvexDecompositionDemo/file.obj ${CMAKE_CURRENT_BINARY_DIR}
)
ENDIF (NOT INTERNAL_CREATE_DISTRIBUTABLE_MSVC_PROJECTFILES)

View File

@ -4,8 +4,8 @@ Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/
This software is provided 'as-is', without any express or implied warranty.
In no event will the authors be held liable for any damages arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it freely,
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it freely,
subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
@ -178,23 +178,22 @@ void ConvexDecompositionDemo::initPhysics(const char* filename)
ConvexDecomposition::WavefrontObj wo;
tcount = wo.loadObj(filename);
tcount = 0;
const char* prefix[]={"./","../","../../","../../../","../../../../", "ConvexDecompositionDemo/", "Demos/ConvexDecompositionDemo/",
"../Demos/ConvexDecompositionDemo/","../../Demos/ConvexDecompositionDemo/"};
int numPrefixes = sizeof(prefix)/sizeof(const char*);
char relativeFileName[1024];
for (int i=0;i<numPrefixes;i++)
{
sprintf(relativeFileName,"%s%s",prefix[i],filename);
tcount = wo.loadObj(relativeFileName);
if (tcount)
break;
}
if (!tcount)
{
//when running this app from visual studio, the default starting folder is different, so make a second attempt...
tcount = wo.loadObj("../../file.obj");
}
if (!tcount)
{
//cmake generated msvc files need 4 levels deep back... so make a 3rd attempt...
tcount = wo.loadObj("../../../../file.obj");
}
btTransform startTransform;
startTransform.setIdentity();
startTransform.setOrigin(btVector3(0,-4.5,0));
@ -206,7 +205,7 @@ void ConvexDecompositionDemo::initPhysics(const char* filename)
class MyConvexDecomposition : public ConvexDecomposition::ConvexDecompInterface
{
ConvexDecompositionDemo* m_convexDemo;
public:
btAlignedObjectArray<btConvexHullShape*> m_convexShapes;
@ -220,7 +219,7 @@ void ConvexDecompositionDemo::initPhysics(const char* filename)
{
}
virtual void ConvexDecompResult(ConvexDecomposition::ConvexResult &result)
{
@ -256,7 +255,7 @@ void ConvexDecompositionDemo::initPhysics(const char* filename)
btVector3 vertex(result.mHullVertices[i*3],result.mHullVertices[i*3+1],result.mHullVertices[i*3+2]);
vertex *= localScaling;
centroid += vertex;
}
}
@ -273,8 +272,8 @@ void ConvexDecompositionDemo::initPhysics(const char* filename)
vertices.push_back(vertex);
}
}
if ( 1 )
{
@ -292,7 +291,7 @@ void ConvexDecompositionDemo::initPhysics(const char* filename)
vertex0 *= localScaling;
vertex1 *= localScaling;
vertex2 *= localScaling;
vertex0 -= centroid;
vertex1 -= centroid;
vertex2 -= centroid;
@ -303,20 +302,20 @@ void ConvexDecompositionDemo::initPhysics(const char* filename)
index0+=mBaseCount;
index1+=mBaseCount;
index2+=mBaseCount;
fprintf(mOutputFile,"f %d %d %d\r\n", index0+1, index1+1, index2+1 );
}
}
// float mass = 1.f;
//this is a tools issue: due to collision margin, convex objects overlap, compensate for it here:
//#define SHRINK_OBJECT_INWARDS 1
#ifdef SHRINK_OBJECT_INWARDS
float collisionMargin = 0.01f;
btAlignedObjectArray<btVector3> planeEquations;
btGeometryUtil::getPlaneEquationsFromVertices(vertices,planeEquations);
@ -330,13 +329,13 @@ void ConvexDecompositionDemo::initPhysics(const char* filename)
btAlignedObjectArray<btVector3> shiftedVertices;
btGeometryUtil::getVerticesFromPlaneEquations(shiftedPlaneEquations,shiftedVertices);
btConvexHullShape* convexShape = new btConvexHullShape(&(shiftedVertices[0].getX()),shiftedVertices.size());
#else //SHRINK_OBJECT_INWARDS
btConvexHullShape* convexShape = new btConvexHullShape(&(vertices[0].getX()),vertices.size());
#endif
#endif
if (sEnableSAT)
convexShape->initializePolyhedralFeatures();
convexShape->setMargin(0.01f);
@ -361,7 +360,7 @@ void ConvexDecompositionDemo::initPhysics(const char* filename)
m_trimeshes.push_back(trimesh);
btVector3 localScaling(6.f,6.f,6.f);
int i;
for ( i=0;i<wo.mTriCount;i++)
{
@ -372,7 +371,7 @@ void ConvexDecompositionDemo::initPhysics(const char* filename)
btVector3 vertex0(wo.mVertices[index0*3], wo.mVertices[index0*3+1],wo.mVertices[index0*3+2]);
btVector3 vertex1(wo.mVertices[index1*3], wo.mVertices[index1*3+1],wo.mVertices[index1*3+2]);
btVector3 vertex2(wo.mVertices[index2*3], wo.mVertices[index2*3+1],wo.mVertices[index2*3+2]);
vertex0 *= localScaling;
vertex1 *= localScaling;
vertex2 *= localScaling;
@ -380,13 +379,13 @@ void ConvexDecompositionDemo::initPhysics(const char* filename)
trimesh->addTriangle(vertex0,vertex1,vertex2);
}
btConvexShape* tmpConvexShape = new btConvexTriangleMeshShape(trimesh);
printf("old numTriangles= %d\n",wo.mTriCount);
printf("old numIndices = %d\n",wo.mTriCount*3);
printf("old numVertices = %d\n",wo.mVertexCount);
printf("reducing vertices by creating a convex hull\n");
//create a hull approximation
@ -394,18 +393,18 @@ void ConvexDecompositionDemo::initPhysics(const char* filename)
btScalar margin = tmpConvexShape->getMargin();
hull->buildHull(margin);
tmpConvexShape->setUserPointer(hull);
printf("new numTriangles = %d\n", hull->numTriangles ());
printf("new numIndices = %d\n", hull->numIndices ());
printf("new numVertices = %d\n", hull->numVertices ());
btConvexHullShape* convexShape = new btConvexHullShape();
bool updateLocalAabb = false;
for (i=0;i<hull->numVertices();i++)
{
convexShape->addPoint(hull->getVertexPointer()[i],updateLocalAabb);
convexShape->addPoint(hull->getVertexPointer()[i],updateLocalAabb);
}
convexShape->recalcLocalAabb();
@ -419,13 +418,13 @@ void ConvexDecompositionDemo::initPhysics(const char* filename)
m_collisionShapes.push_back(convexShape);
float mass = 1.f;
btTransform startTransform;
startTransform.setIdentity();
startTransform.setOrigin(btVector3(0,2,14));
localCreateRigidBody(mass, startTransform,convexShape);
bool useQuantization = true;
btCollisionShape* concaveShape = new btBvhTriangleMeshShape(trimesh,useQuantization);
startTransform.setOrigin(convexDecompositionObjectOffset);
@ -434,7 +433,7 @@ void ConvexDecompositionDemo::initPhysics(const char* filename)
m_collisionShapes.push_back (concaveShape);
}
if (tcount)
{
@ -445,11 +444,11 @@ void ConvexDecompositionDemo::initPhysics(const char* filename)
char outputFileName[512];
strcpy(outputFileName,filename);
char *dot = strstr(outputFileName,".");
if ( dot )
if ( dot )
*dot = 0;
strcat(outputFileName,"_convex.obj");
FILE* outputFile = fopen(outputFileName,"wb");
unsigned int depth = 5;
float cpercent = 5;
float ppercent = 15;
@ -479,7 +478,7 @@ void ConvexDecompositionDemo::initPhysics(const char* filename)
std::vector< HACD::Vec3<HACD::Real> > points;
std::vector< HACD::Vec3<long> > triangles;
for(int i=0; i<wo.mVertexCount; i++ )
for(int i=0; i<wo.mVertexCount; i++ )
{
int index = i*3;
HACD::Vec3<HACD::Real> vertex(wo.mVertices[index], wo.mVertices[index+1],wo.mVertices[index+2]);
@ -509,17 +508,17 @@ void ConvexDecompositionDemo::initPhysics(const char* filename)
bool invert = false;
bool addExtraDistPoints = false;
bool addNeighboursDistPoints = false;
bool addFacesPoints = false;
bool addFacesPoints = false;
myHACD.SetNClusters(nClusters); // minimum number of clusters
myHACD.SetNVerticesPerCH(100); // max of 100 vertices per convex-hull
myHACD.SetConcavity(concavity); // maximum concavity
myHACD.SetAddExtraDistPoints(addExtraDistPoints);
myHACD.SetAddNeighboursDistPoints(addNeighboursDistPoints);
myHACD.SetAddFacesPoints(addFacesPoints);
myHACD.SetAddExtraDistPoints(addExtraDistPoints);
myHACD.SetAddNeighboursDistPoints(addNeighboursDistPoints);
myHACD.SetAddFacesPoints(addFacesPoints);
myHACD.Compute();
nClusters = myHACD.GetNClusters();
nClusters = myHACD.GetNClusters();
myHACD.Save("output.wrl", false);
@ -529,7 +528,7 @@ void ConvexDecompositionDemo::initPhysics(const char* filename)
// ConvexBuilder cb(desc.mCallback);
// cb.process(desc);
//now create some bodies
if (1)
{
btCompoundShape* compound = new btCompoundShape();
@ -546,7 +545,7 @@ void ConvexDecompositionDemo::initPhysics(const char* filename)
float* vertices = new float[nPoints*3];
unsigned int* triangles = new unsigned int[nTriangles*3];
HACD::Vec3<HACD::Real> * pointsCH = new HACD::Vec3<HACD::Real>[nPoints];
HACD::Vec3<long> * trianglesCH = new HACD::Vec3<long>[nTriangles];
myHACD.GetCH(c, pointsCH, trianglesCH);
@ -585,7 +584,7 @@ void ConvexDecompositionDemo::initPhysics(const char* filename)
}
/* 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];
@ -613,7 +612,7 @@ void ConvexDecompositionDemo::initPhysics(const char* filename)
#endif
}
if (outputFile)
fclose(outputFile);
@ -623,13 +622,13 @@ void ConvexDecompositionDemo::initPhysics(const char* filename)
#ifdef TEST_SERIALIZATION
//test serializing this
//test serializing this
int maxSerializeBufferSize = 1024*1024*5;
btDefaultSerializer* serializer = new btDefaultSerializer(maxSerializeBufferSize);
m_dynamicsWorld->serialize(serializer);
FILE* f2 = fopen("testFile.bullet","wb");
fwrite(serializer->getBufferPointer(),serializer->getCurrentBufferSize(),1,f2);
fclose(f2);
@ -651,17 +650,17 @@ void ConvexDecompositionDemo::initPhysics(const char* filename)
//fileLoader->loadFile("testFile64Double.bullet");
//fileLoader->loadFile("testFile64Single.bullet");
//fileLoader->loadFile("testFile32Single.bullet");
#endif //TEST_SERIALIZATION
}
void ConvexDecompositionDemo::clientMoveAndDisplay()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
float dt = getDeltaTimeMicroseconds() * 0.000001f;
@ -681,7 +680,7 @@ void ConvexDecompositionDemo::clientMoveAndDisplay()
void ConvexDecompositionDemo::displayCallback(void) {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
if (m_dynamicsWorld)
@ -749,7 +748,7 @@ void ConvexDecompositionDemo::exitPhysics()
delete m_collisionConfiguration;
}
@ -768,7 +767,7 @@ void ConvexDecompositionDemo::keyboardCallback(unsigned char key, int x, int y)
{
printf("SAT enabled after the next restart of the demo\n");
} else
{
{
printf("SAT disabled after the next restart of the demo\n");
}
} else
@ -776,4 +775,4 @@ void ConvexDecompositionDemo::keyboardCallback(unsigned char key, int x, int y)
PlatformDemoApplication::keyboardCallback(key,x,y);
}
}
}

Some files were not shown because too many files have changed in this diff Show More