Merge remote-tracking branch 'bulletphysics/master'
This commit is contained in:
17
.travis.yml
Normal file
17
.travis.yml
Normal 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
|
||||||
@@ -5,7 +5,7 @@ set(CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS true)
|
|||||||
SET(MSVC_INCREMENTAL_DEFAULT ON)
|
SET(MSVC_INCREMENTAL_DEFAULT ON)
|
||||||
|
|
||||||
PROJECT(BULLET_PHYSICS)
|
PROJECT(BULLET_PHYSICS)
|
||||||
SET(BULLET_VERSION 2.82)
|
SET(BULLET_VERSION 2.83)
|
||||||
|
|
||||||
IF(COMMAND cmake_policy)
|
IF(COMMAND cmake_policy)
|
||||||
cmake_policy(SET CMP0003 NEW)
|
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_DOUBLE_PRECISION "Use double precision" OFF)
|
||||||
OPTION(USE_GRAPHICAL_BENCHMARK "Use Graphical Benchmark" ON)
|
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_RUNTIME_LIBRARY_DLL "Use MSVC Runtime Library DLL (/MD or /MDd)" OFF)
|
||||||
OPTION(USE_MSVC_INCREMENTAL_LINKING "Use MSVC Incremental Linking" OFF)
|
OPTION(USE_MSVC_INCREMENTAL_LINKING "Use MSVC Incremental Linking" OFF)
|
||||||
@@ -44,13 +44,15 @@ IF(MSVC)
|
|||||||
SET(CMAKE_EXE_LINKER_FLAGS_DEBUG "/INCREMENTAL:NO ${replacementFlags}" )
|
SET(CMAKE_EXE_LINKER_FLAGS_DEBUG "/INCREMENTAL:NO ${replacementFlags}" )
|
||||||
MESSAGE("CMAKE_EXE_LINKER_FLAGS_DEBUG=${CMAKE_EXE_LINKER_FLAGS_DEBUG}")
|
MESSAGE("CMAKE_EXE_LINKER_FLAGS_DEBUG=${CMAKE_EXE_LINKER_FLAGS_DEBUG}")
|
||||||
|
|
||||||
# STRING(REPLACE "INCREMENTAL:YES" "INCREMENTAL:NO" replacementFlags2 ${CMAKE_EXE_LINKER_FLAGS})
|
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_EXE_LINKER_FLAGS ${replacementFlag2})
|
||||||
# SET(CMAKE_EXTRA_LINK_FLAGS ${replacementFlag3})
|
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 ${replacementFlags3})
|
||||||
SET(CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO "/INCREMENTAL:NO ${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)
|
OPTION(BUILD_BULLET2_DEMOS "Set when you want to build the Bullet 2 demos" ON)
|
||||||
IF(BUILD_OBSOLETE_DEMOS)
|
IF(BUILD_BULLET2_DEMOS)
|
||||||
|
|
||||||
IF (USE_GLUT)
|
IF (USE_GLUT)
|
||||||
IF (MSVC)
|
IF (MSVC)
|
||||||
@@ -188,13 +190,13 @@ IF (USE_GLUT)
|
|||||||
ADD_DEFINITIONS(-DBT_USE_FREEGLUT)
|
ADD_DEFINITIONS(-DBT_USE_FREEGLUT)
|
||||||
|
|
||||||
IF (CMAKE_CL_64)
|
IF (CMAKE_CL_64)
|
||||||
message("Win64 using static freeglut in ObsoleteDemos/Glut/glut64.lib")
|
message("Win64 using static freeglut in Demos/Glut/glut64.lib")
|
||||||
SET(GLUT_glut_LIBRARY ${BULLET_PHYSICS_SOURCE_DIR}/ObsoleteDemos/Glut/glut64.lib glu32.lib gdi32.lib winmm.lib user32.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)
|
ELSE(CMAKE_CL_64)
|
||||||
message("Win32 using static freeglut in ObsoleteDemos/Glut/glut32.lib")
|
message("Win32 using static freeglut in Demos/Glut/glut32.lib")
|
||||||
SET(GLUT_glut_LIBRARY ${BULLET_PHYSICS_SOURCE_DIR}/ObsoleteDemos/Glut/glut32.lib glu32.lib gdi32.lib winmm.lib user32.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)
|
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()
|
ELSE()
|
||||||
FIND_PACKAGE(GLUT)
|
FIND_PACKAGE(GLUT)
|
||||||
IF (GLUT_FOUND)
|
IF (GLUT_FOUND)
|
||||||
@@ -212,19 +214,29 @@ IF (USE_GLUT)
|
|||||||
ENDIF (GLUT_FOUND)
|
ENDIF (GLUT_FOUND)
|
||||||
ENDIF (MSVC)
|
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.
|
# 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)
|
SET(GLUT_INCLUDE_DIR /usr/include /usr/local/include)
|
||||||
ENDIF()
|
ENDIF()
|
||||||
ENDIF(USE_GLUT)
|
ENDIF(USE_GLUT)
|
||||||
|
|
||||||
|
|
||||||
IF(EXISTS ${BULLET_PHYSICS_SOURCE_DIR}/ObsoleteDemos AND IS_DIRECTORY ${BULLET_PHYSICS_SOURCE_DIR}/ObsoleteDemos)
|
IF(EXISTS ${BULLET_PHYSICS_SOURCE_DIR}/Demos AND IS_DIRECTORY ${BULLET_PHYSICS_SOURCE_DIR}/Demos)
|
||||||
SUBDIRS(ObsoleteDemos)
|
SUBDIRS(Demos)
|
||||||
ENDIF()
|
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(BUILD_BULLET3_DEMOS)
|
||||||
IF(EXISTS ${BULLET_PHYSICS_SOURCE_DIR}/Demos3 AND IS_DIRECTORY ${BULLET_PHYSICS_SOURCE_DIR}/Demos3)
|
IF(EXISTS ${BULLET_PHYSICS_SOURCE_DIR}/Demos3 AND IS_DIRECTORY ${BULLET_PHYSICS_SOURCE_DIR}/Demos3)
|
||||||
SUBDIRS(Demos3)
|
SUBDIRS(Demos3)
|
||||||
@@ -232,6 +244,10 @@ IF(BUILD_BULLET3_DEMOS)
|
|||||||
ENDIF()
|
ENDIF()
|
||||||
ENDIF(BUILD_BULLET3_DEMOS)
|
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
|
#Maya Dynamica plugin is moved to http://dynamica.googlecode.com
|
||||||
@@ -266,14 +282,14 @@ IF(INSTALL_LIBS)
|
|||||||
ENDIF(INSTALL_LIBS)
|
ENDIF(INSTALL_LIBS)
|
||||||
|
|
||||||
#INSTALL of other files requires CMake 2.6
|
#INSTALL of other files requires CMake 2.6
|
||||||
#IF (${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)
|
OPTION(INSTALL_EXTRA_LIBS "Set when you want extra libraries installed" OFF)
|
||||||
#ENDIF (${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION} GREATER 2.5)
|
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)
|
IF (BUILD_UNIT_TESTS)
|
||||||
SUBDIRS(UnitTests)
|
SUBDIRS(test)
|
||||||
ENDIF()
|
ENDIF()
|
||||||
|
|
||||||
set (BULLET_CONFIG_CMAKE_PATH lib${LIB_SUFFIX}/cmake/bullet )
|
set (BULLET_CONFIG_CMAKE_PATH lib${LIB_SUFFIX}/cmake/bullet )
|
||||||
|
|||||||
147
Demos/BasicDemo/BasicDemo.cpp
Normal file
147
Demos/BasicDemo/BasicDemo.cpp
Normal 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();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -24,30 +24,15 @@ subject to the following restrictions:
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "LinearMath/btAlignedObjectArray.h"
|
#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.
|
///BasicDemo is good starting point for learning the code base and porting.
|
||||||
|
|
||||||
class BasicDemo : public PlatformDemoApplication
|
class BasicDemo : public PlatformDemoApplication
|
||||||
{
|
{
|
||||||
|
|
||||||
//keep the collision shapes, for deletion/cleanup
|
BasicDemoPhysicsSetup m_physicsSetup;
|
||||||
btAlignedObjectArray<btCollisionShape*> m_collisionShapes;
|
|
||||||
|
|
||||||
btBroadphaseInterface* m_broadphase;
|
|
||||||
|
|
||||||
btCollisionDispatcher* m_dispatcher;
|
|
||||||
|
|
||||||
btConstraintSolver* m_solver;
|
|
||||||
|
|
||||||
btDefaultCollisionConfiguration* m_collisionConfiguration;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
89
Demos/BasicDemo/BasicDemoPhysicsSetup.cpp
Normal file
89
Demos/BasicDemo/BasicDemoPhysicsSetup.cpp
Normal 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));
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
28
Demos/BasicDemo/BasicDemoPhysicsSetup.h
Normal file
28
Demos/BasicDemo/BasicDemoPhysicsSetup.h
Normal 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
|
||||||
@@ -28,6 +28,8 @@ ADD_EXECUTABLE(AppBasicDemo
|
|||||||
main.cpp
|
main.cpp
|
||||||
BasicDemo.cpp
|
BasicDemo.cpp
|
||||||
BasicDemo.h
|
BasicDemo.h
|
||||||
|
BasicDemoPhysicsSetup.cpp
|
||||||
|
BasicDemoPhysicsSetup.h
|
||||||
${BULLET_PHYSICS_SOURCE_DIR}/build3/bullet.rc
|
${BULLET_PHYSICS_SOURCE_DIR}/build3/bullet.rc
|
||||||
)
|
)
|
||||||
ELSE()
|
ELSE()
|
||||||
@@ -35,6 +37,8 @@ ELSE()
|
|||||||
main.cpp
|
main.cpp
|
||||||
BasicDemo.cpp
|
BasicDemo.cpp
|
||||||
BasicDemo.h
|
BasicDemo.h
|
||||||
|
BasicDemoPhysicsSetup.cpp
|
||||||
|
BasicDemoPhysicsSetup.h
|
||||||
)
|
)
|
||||||
ENDIF()
|
ENDIF()
|
||||||
ELSE (USE_GLUT)
|
ELSE (USE_GLUT)
|
||||||
@@ -52,6 +56,8 @@ ELSE (USE_GLUT)
|
|||||||
Win32BasicDemo.cpp
|
Win32BasicDemo.cpp
|
||||||
BasicDemo.cpp
|
BasicDemo.cpp
|
||||||
BasicDemo.h
|
BasicDemo.h
|
||||||
|
BasicDemoPhysicsSetup.cpp
|
||||||
|
BasicDemoPhysicsSetup.h
|
||||||
${BULLET_PHYSICS_SOURCE_DIR}/build3/bullet.rc
|
${BULLET_PHYSICS_SOURCE_DIR}/build3/bullet.rc
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -171,31 +171,23 @@ void BspDemo::initPhysics(const char* bspfilename)
|
|||||||
|
|
||||||
void* memoryBuffer = 0;
|
void* memoryBuffer = 0;
|
||||||
|
|
||||||
FILE* file = fopen(bspfilename,"r");
|
const char* filename = "BspDemo.bsp";
|
||||||
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...
|
const char* prefix[]={"./","../","../../","../../../","../../../../", "BspDemo/", "Demos/BspDemo/",
|
||||||
bspfilename = "../../../../BspDemo.bsp";
|
"../Demos/BspDemo/","../../Demos/BspDemo/"};
|
||||||
file = fopen(bspfilename,"r");
|
int numPrefixes = sizeof(prefix)/sizeof(const char*);
|
||||||
}
|
char relativeFileName[1024];
|
||||||
if (!file)
|
FILE* file=0;
|
||||||
|
|
||||||
|
for (int i=0;i<numPrefixes;i++)
|
||||||
{
|
{
|
||||||
//try again other path,
|
sprintf(relativeFileName,"%s%s",prefix[i],filename);
|
||||||
//sight... visual studio leaves the current working directory in the projectfiles folder
|
file = fopen(relativeFileName,"r");
|
||||||
//instead of executable folder. who wants this default behaviour?!?
|
if (file)
|
||||||
bspfilename = "BspDemo.bsp";
|
break;
|
||||||
file = fopen(bspfilename,"r");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (file)
|
if (file)
|
||||||
{
|
{
|
||||||
BspLoader bspLoader;
|
BspLoader bspLoader;
|
||||||
@@ -35,7 +35,7 @@ IF (NOT INTERNAL_CREATE_DISTRIBUTABLE_MSVC_PROJECTFILES)
|
|||||||
ADD_CUSTOM_COMMAND(
|
ADD_CUSTOM_COMMAND(
|
||||||
TARGET AppBspPhysicsDemo
|
TARGET AppBspPhysicsDemo
|
||||||
POST_BUILD
|
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)
|
ENDIF (NOT INTERNAL_CREATE_DISTRIBUTABLE_MSVC_PROJECTFILES)
|
||||||
|
|
||||||
@@ -47,7 +47,27 @@ void BulletXmlImportDemo::initPhysics()
|
|||||||
|
|
||||||
|
|
||||||
btBulletXmlWorldImporter* importer = new btBulletXmlWorldImporter(m_dynamicsWorld);
|
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("bulletser.xml");
|
||||||
// importer->loadFile("bullet_constraints.xml");
|
// importer->loadFile("bullet_constraints.xml");
|
||||||
|
|
||||||
@@ -122,8 +142,6 @@ void BulletXmlImportDemo::setupEmptyDynamicsWorld()
|
|||||||
|
|
||||||
BulletXmlImportDemo::~BulletXmlImportDemo()
|
BulletXmlImportDemo::~BulletXmlImportDemo()
|
||||||
{
|
{
|
||||||
m_fileLoader->deleteAllData();
|
|
||||||
delete m_fileLoader;
|
|
||||||
exitPhysics();
|
exitPhysics();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -49,8 +49,6 @@ class BulletXmlImportDemo : public PlatformDemoApplication
|
|||||||
|
|
||||||
btDefaultCollisionConfiguration* m_collisionConfiguration;
|
btDefaultCollisionConfiguration* m_collisionConfiguration;
|
||||||
|
|
||||||
class btBulletWorldImporter* m_fileLoader;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
BulletXmlImportDemo()
|
BulletXmlImportDemo()
|
||||||
@@ -18,6 +18,7 @@ ${BULLET_PHYSICS_SOURCE_DIR}/src
|
|||||||
${BULLET_PHYSICS_SOURCE_DIR}/Extras/Serialize/BulletFileLoader
|
${BULLET_PHYSICS_SOURCE_DIR}/Extras/Serialize/BulletFileLoader
|
||||||
${BULLET_PHYSICS_SOURCE_DIR}/Extras/Serialize/BulletWorldImporter
|
${BULLET_PHYSICS_SOURCE_DIR}/Extras/Serialize/BulletWorldImporter
|
||||||
${BULLET_PHYSICS_SOURCE_DIR}/Extras/Serialize/BulletXmlWorldImporter
|
${BULLET_PHYSICS_SOURCE_DIR}/Extras/Serialize/BulletXmlWorldImporter
|
||||||
|
${GLUT_INCLUDE_DIR}
|
||||||
)
|
)
|
||||||
|
|
||||||
ADD_DEFINITIONS(-DDESERIALIZE_SOFT_BODIES)
|
ADD_DEFINITIONS(-DDESERIALIZE_SOFT_BODIES)
|
||||||
@@ -5,12 +5,12 @@ SUBDIRS( HelloWorld )
|
|||||||
IF (USE_GLUT)
|
IF (USE_GLUT)
|
||||||
IF (GLUT_FOUND)
|
IF (GLUT_FOUND)
|
||||||
IF(BUILD_CPU_DEMOS)
|
IF(BUILD_CPU_DEMOS)
|
||||||
# IF(BUILD_EXTRAS)
|
IF(BUILD_EXTRAS)
|
||||||
# SUBDIRS( BulletXmlImportDemo ConcaveDemo ConstraintDemo ConvexDecompositionDemo SerializeDemo )
|
SUBDIRS( BulletXmlImportDemo ConcaveDemo ConvexDecompositionDemo SerializeDemo )
|
||||||
# ENDIF()
|
ENDIF()
|
||||||
SET(SharedDemoSubdirs
|
SET(SharedDemoSubdirs
|
||||||
OpenGL
|
OpenGL
|
||||||
CcdPhysicsDemo SliderConstraintDemo GenericJointDemo Raytracer
|
CcdPhysicsDemo ConstraintDemo SliderConstraintDemo GenericJointDemo Raytracer
|
||||||
RagdollDemo ForkLiftDemo BasicDemo FeatherstoneMultiBodyDemo RollingFrictionDemo RaytestDemo VoronoiFractureDemo
|
RagdollDemo ForkLiftDemo BasicDemo FeatherstoneMultiBodyDemo RollingFrictionDemo RaytestDemo VoronoiFractureDemo
|
||||||
GyroscopicDemo FractureDemo Box2dDemo BspDemo MovingConcaveDemo VehicleDemo
|
GyroscopicDemo FractureDemo Box2dDemo BspDemo MovingConcaveDemo VehicleDemo
|
||||||
UserCollisionAlgorithm CharacterDemo SoftDemo
|
UserCollisionAlgorithm CharacterDemo SoftDemo
|
||||||
@@ -25,12 +25,17 @@ IF (WIN32)
|
|||||||
ADD_EXECUTABLE(AppCcdPhysicsDemo
|
ADD_EXECUTABLE(AppCcdPhysicsDemo
|
||||||
main.cpp
|
main.cpp
|
||||||
CcdPhysicsDemo.cpp
|
CcdPhysicsDemo.cpp
|
||||||
|
CcdPhysicsSetup.h
|
||||||
|
CcdPhysicsSetup.cpp
|
||||||
${BULLET_PHYSICS_SOURCE_DIR}/build3/bullet.rc
|
${BULLET_PHYSICS_SOURCE_DIR}/build3/bullet.rc
|
||||||
)
|
)
|
||||||
ELSE()
|
ELSE()
|
||||||
ADD_EXECUTABLE(AppCcdPhysicsDemo
|
ADD_EXECUTABLE(AppCcdPhysicsDemo
|
||||||
main.cpp
|
main.cpp
|
||||||
CcdPhysicsDemo.cpp
|
CcdPhysicsDemo.cpp
|
||||||
|
CcdPhysicsSetup.h
|
||||||
|
CcdPhysicsSetup.cpp
|
||||||
|
|
||||||
)
|
)
|
||||||
ENDIF()
|
ENDIF()
|
||||||
|
|
||||||
@@ -167,26 +167,11 @@ void CcdPhysicsDemo::initPhysics()
|
|||||||
m_ShootBoxInitialSpeed = 4000.f;
|
m_ShootBoxInitialSpeed = 4000.f;
|
||||||
|
|
||||||
m_defaultContactProcessingThreshold = 0.f;
|
m_defaultContactProcessingThreshold = 0.f;
|
||||||
|
GraphicsPhysicsBridge bridge;
|
||||||
///collision configuration contains default setup for memory, collision setup
|
m_physicsSetup.initPhysics(bridge);
|
||||||
m_collisionConfiguration = new btDefaultCollisionConfiguration();
|
m_dynamicsWorld = m_physicsSetup.m_dynamicsWorld;
|
||||||
// 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);
|
|
||||||
m_dynamicsWorld->getSolverInfo().m_solverMode |=SOLVER_USE_2_FRICTION_DIRECTIONS|SOLVER_RANDMIZE_ORDER;
|
m_dynamicsWorld->getSolverInfo().m_solverMode |=SOLVER_USE_2_FRICTION_DIRECTIONS|SOLVER_RANDMIZE_ORDER;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
m_dynamicsWorld ->setDebugDrawer(&sDebugDrawer);
|
m_dynamicsWorld ->setDebugDrawer(&sDebugDrawer);
|
||||||
|
|
||||||
//m_dynamicsWorld->getSolverInfo().m_splitImpulse=false;
|
//m_dynamicsWorld->getSolverInfo().m_splitImpulse=false;
|
||||||
@@ -203,108 +188,6 @@ void CcdPhysicsDemo::initPhysics()
|
|||||||
|
|
||||||
m_dynamicsWorld->setGravity(btVector3(0,-10,0));
|
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()
|
void CcdPhysicsDemo::clientResetScene()
|
||||||
@@ -381,40 +264,8 @@ void CcdPhysicsDemo::shootBox(const btVector3& destination)
|
|||||||
|
|
||||||
void CcdPhysicsDemo::exitPhysics()
|
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;
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -33,19 +33,14 @@ class btConstraintSolver;
|
|||||||
struct btCollisionAlgorithmCreateFunc;
|
struct btCollisionAlgorithmCreateFunc;
|
||||||
class btDefaultCollisionConfiguration;
|
class btDefaultCollisionConfiguration;
|
||||||
|
|
||||||
|
#include "CcdPhysicsSetup.h"
|
||||||
|
|
||||||
///CcdPhysicsDemo is good starting point for learning the code base and porting.
|
///CcdPhysicsDemo is good starting point for learning the code base and porting.
|
||||||
|
|
||||||
class CcdPhysicsDemo : public PlatformDemoApplication
|
class CcdPhysicsDemo : public PlatformDemoApplication
|
||||||
{
|
{
|
||||||
|
|
||||||
//keep the collision shapes, for deletion/cleanup
|
CcdPhysicsSetup m_physicsSetup;
|
||||||
btAlignedObjectArray<btCollisionShape*> m_collisionShapes;
|
|
||||||
|
|
||||||
btBroadphaseInterface* m_broadphase;
|
|
||||||
|
|
||||||
btCollisionDispatcher* m_dispatcher;
|
|
||||||
|
|
||||||
btConstraintSolver* m_solver;
|
|
||||||
|
|
||||||
enum
|
enum
|
||||||
{
|
{
|
||||||
@@ -54,7 +49,6 @@ class CcdPhysicsDemo : public PlatformDemoApplication
|
|||||||
};
|
};
|
||||||
int m_ccdMode;
|
int m_ccdMode;
|
||||||
|
|
||||||
btDefaultCollisionConfiguration* m_collisionConfiguration;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
179
Demos/CcdPhysicsDemo/CcdPhysicsSetup.cpp
Normal file
179
Demos/CcdPhysicsDemo/CcdPhysicsSetup.cpp
Normal 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
23
Demos/CcdPhysicsDemo/CcdPhysicsSetup.h
Normal file
23
Demos/CcdPhysicsDemo/CcdPhysicsSetup.h
Normal 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
|
||||||
@@ -46,7 +46,7 @@ IF (NOT INTERNAL_CREATE_DISTRIBUTABLE_MSVC_PROJECTFILES)
|
|||||||
ADD_CUSTOM_COMMAND(
|
ADD_CUSTOM_COMMAND(
|
||||||
TARGET AppCharacterDemo
|
TARGET AppCharacterDemo
|
||||||
POST_BUILD
|
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)
|
ENDIF (NOT INTERNAL_CREATE_DISTRIBUTABLE_MSVC_PROJECTFILES)
|
||||||
|
|
||||||
@@ -101,35 +101,30 @@ void CharacterDemo::initPhysics()
|
|||||||
btTransform tr;
|
btTransform tr;
|
||||||
tr.setIdentity();
|
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;
|
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)
|
if (file)
|
||||||
{
|
{
|
||||||
BspLoader bspLoader;
|
BspLoader bspLoader;
|
||||||
int size=0;
|
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 */
|
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
|
} else
|
||||||
{
|
{
|
||||||
//how to detect file size?
|
//how to detect file size?
|
||||||
41
Demos/CommonParameterInterface.h
Normal file
41
Demos/CommonParameterInterface.h
Normal 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
|
||||||
67
Demos/CommonPhysicsSetup.h
Normal file
67
Demos/CommonPhysicsSetup.h
Normal 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
|
||||||
|
|
||||||
|
|
||||||
247
Demos/CommonRigidBodySetup.h
Normal file
247
Demos/CommonRigidBodySetup.h
Normal 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
|
||||||
|
|
||||||
@@ -16,6 +16,8 @@ IF (USE_GLUT)
|
|||||||
../OpenGL
|
../OpenGL
|
||||||
${BULLET_PHYSICS_SOURCE_DIR}/Extras/Serialize/BulletFileLoader
|
${BULLET_PHYSICS_SOURCE_DIR}/Extras/Serialize/BulletFileLoader
|
||||||
${BULLET_PHYSICS_SOURCE_DIR}/Extras/Serialize/BulletWorldImporter
|
${BULLET_PHYSICS_SOURCE_DIR}/Extras/Serialize/BulletWorldImporter
|
||||||
|
${GLUT_INCLUDE_DIR}
|
||||||
|
|
||||||
)
|
)
|
||||||
|
|
||||||
LINK_LIBRARIES(
|
LINK_LIBRARIES(
|
||||||
@@ -14,14 +14,14 @@
|
|||||||
INCLUDE_DIRECTORIES(
|
INCLUDE_DIRECTORIES(
|
||||||
${BULLET_PHYSICS_SOURCE_DIR}/src
|
${BULLET_PHYSICS_SOURCE_DIR}/src
|
||||||
../OpenGL
|
../OpenGL
|
||||||
${BULLET_PHYSICS_SOURCE_DIR}/Extras/Serialize/BulletFileLoader
|
${GLUT_INCLUDE_DIR}
|
||||||
${BULLET_PHYSICS_SOURCE_DIR}/Extras/Serialize/BulletWorldImporter
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
IF (USE_GLUT)
|
IF (USE_GLUT)
|
||||||
LINK_LIBRARIES(
|
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
|
ADD_EXECUTABLE(AppConstraintDemo
|
||||||
@@ -31,7 +31,7 @@ IF (USE_GLUT)
|
|||||||
)
|
)
|
||||||
ELSE (USE_GLUT)
|
ELSE (USE_GLUT)
|
||||||
LINK_LIBRARIES(
|
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
|
ADD_EXECUTABLE(AppConstraintDemo
|
||||||
70
Demos/ConstraintDemo/ConstraintPhysicsSetup.cpp
Normal file
70
Demos/ConstraintDemo/ConstraintPhysicsSetup.cpp
Normal 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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
16
Demos/ConstraintDemo/ConstraintPhysicsSetup.h
Normal file
16
Demos/ConstraintDemo/ConstraintPhysicsSetup.h
Normal 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
|
||||||
@@ -1,3 +1,4 @@
|
|||||||
|
|
||||||
# This is basically the overall name of the project in Visual Studio this is the name of the Solution File
|
# 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/ConvexDecomposition
|
||||||
${BULLET_PHYSICS_SOURCE_DIR}/Extras/Serialize/BulletFileLoader
|
${BULLET_PHYSICS_SOURCE_DIR}/Extras/Serialize/BulletFileLoader
|
||||||
${BULLET_PHYSICS_SOURCE_DIR}/Extras/Serialize/BulletWorldImporter
|
${BULLET_PHYSICS_SOURCE_DIR}/Extras/Serialize/BulletWorldImporter
|
||||||
|
${GLUT_INCLUDE_DIR}
|
||||||
|
|
||||||
)
|
)
|
||||||
|
|
||||||
IF (USE_GLUT)
|
IF (USE_GLUT)
|
||||||
@@ -53,7 +56,7 @@ IF (NOT INTERNAL_CREATE_DISTRIBUTABLE_MSVC_PROJECTFILES)
|
|||||||
TARGET AppConvexDecompositionDemo
|
TARGET AppConvexDecompositionDemo
|
||||||
POST_BUILD
|
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}/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)
|
ENDIF (NOT INTERNAL_CREATE_DISTRIBUTABLE_MSVC_PROJECTFILES)
|
||||||
|
|
||||||
@@ -178,20 +178,19 @@ void ConvexDecompositionDemo::initPhysics(const char* filename)
|
|||||||
|
|
||||||
ConvexDecomposition::WavefrontObj wo;
|
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];
|
||||||
|
|
||||||
if (!tcount)
|
for (int i=0;i<numPrefixes;i++)
|
||||||
{
|
{
|
||||||
//when running this app from visual studio, the default starting folder is different, so make a second attempt...
|
sprintf(relativeFileName,"%s%s",prefix[i],filename);
|
||||||
tcount = wo.loadObj("../../file.obj");
|
tcount = wo.loadObj(relativeFileName);
|
||||||
|
if (tcount)
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
if (!tcount)
|
|
||||||
{
|
|
||||||
//cmake generated msvc files need 4 levels deep back... so make a 3rd attempt...
|
|
||||||
tcount = wo.loadObj("../../../../file.obj");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user