diff --git a/CMakeLists.txt b/CMakeLists.txt index cf653084a..b34c7f996 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -191,6 +191,17 @@ IF (APPLE) ENDIF() OPTION(BUILD_BULLET3 "Set when you want to build Bullet 3" ON) +OPTION(BUILD_PYBULLET "Set when you want to build pybullet (experimental Python bindings for Bullet)" OFF) + +IF(BUILD_PYBULLET) + IF(WIN32) + FIND_PACKAGE(PythonLibs 3.4 REQUIRED) + SET(BUILD_SHARED_LIBS OFF CACHE BOOL "Shared Libs" FORCE) + ELSE(WIN32) + FIND_PACKAGE(PythonLibs 2.7 REQUIRED) + SET(BUILD_SHARED_LIBS ON CACHE BOOL "Shared Libs" FORCE) + ENDIF(WIN32) +ENDIF(BUILD_PYBULLET) IF(BUILD_BULLET3) IF(APPLE) diff --git a/build3/premake4.lua b/build3/premake4.lua index 7f60a1d0e..31ca45afa 100644 --- a/build3/premake4.lua +++ b/build3/premake4.lua @@ -73,6 +73,14 @@ description = "Enable Lua scipting support in Example Browser" } + newoption + { + trigger = "python", + description = "Enable Python scripting (experimental, use Physics Server in Example Browser). " + } + + + newoption { trigger = "targetdir", value = "path such as ../bin", @@ -181,16 +189,20 @@ include "../examples/OpenGLWindow" include "../examples/ThirdPartyLibs/Gwen" include "../examples/SimpleOpenGL3" + include "../examples/TinyRenderer" include "../examples/HelloWorld" include "../examples/BasicDemo" - + include "../examples/InverseDynamics" include "../examples/SharedMemory" include "../examples/MultiThreading" if _OPTIONS["lua"] then include "../examples/ThirdPartyLibs/lua-5.2.3" end + if _OPTIONS["python"] then + include "../examples/pybullet" + end if not _OPTIONS["no-test"] then include "../test/SharedMemory" diff --git a/data/door.urdf b/data/door.urdf index 7b0cb2eae..012597d07 100644 --- a/data/door.urdf +++ b/data/door.urdf @@ -1,10 +1,17 @@ + + + + + + + - - + + diff --git a/data/floor.mtl b/data/floor.mtl new file mode 100644 index 000000000..8a67048e1 --- /dev/null +++ b/data/floor.mtl @@ -0,0 +1,13 @@ +newmtl floor + Ns 10.0000 + Ni 1.5000 + d 1.0000 + Tr 0.0000 + Tf 1.0000 1.0000 1.0000 + illum 2 + Ka 0.0000 0.0000 0.0000 + Kd 0.5880 0.5880 0.5880 + Ks 0.0000 0.0000 0.0000 + Ke 0.0000 0.0000 0.0000 + map_Ka floor_diffuse.jpg + map_Kd floor_diffuse.jpg diff --git a/data/floor.obj b/data/floor.obj new file mode 100644 index 000000000..42e145867 --- /dev/null +++ b/data/floor.obj @@ -0,0 +1,18 @@ +o +mtllib floor.mtl +v -1 -1 -1 +v 1 -1 -1 +v 1 -1 1 +v -1 -1 1 + +vt 0 0 +vt 1 0 +vt 1 1 +vt 0 1 + +vn 0 1 0 +usemtl floor + +f 3/3/1 2/2/1 1/1/1 +f 4/4/1 3/3/1 1/1/1 + diff --git a/data/floor_diffuse.jpg b/data/floor_diffuse.jpg new file mode 100644 index 000000000..36a26252d Binary files /dev/null and b/data/floor_diffuse.jpg differ diff --git a/data/floor_diffuse.tga b/data/floor_diffuse.tga new file mode 100644 index 000000000..7bb70dd10 Binary files /dev/null and b/data/floor_diffuse.tga differ diff --git a/data/floor_nm_tangent.tga b/data/floor_nm_tangent.tga new file mode 100644 index 000000000..3b8474e8f Binary files /dev/null and b/data/floor_nm_tangent.tga differ diff --git a/data/multibody.bullet b/data/multibody.bullet index 04455f0d5..1074b55dc 100644 Binary files a/data/multibody.bullet and b/data/multibody.bullet differ diff --git a/data/two_cubes.sdf b/data/two_cubes.sdf new file mode 100644 index 000000000..24c0854bd --- /dev/null +++ b/data/two_cubes.sdf @@ -0,0 +1,239 @@ + + + + 99.2 + 1 + 0 0 10 0 -0 0 + 0.8 0.8 0.8 1 + 0.2 0.2 0.2 1 + + 1000 + 0.9 + 0.01 + 0.001 + + -0.5 0.1 -0.9 + + + 1 + + + + + 1 2 3 + 100 100 + + + + + 65535 + + + + + 100 + 50 + + + + + + + + 10 + + + 0 + + + 4 5 6 + 100 100 + + + + + + + 0 + 0 + 1 + + + 0 0 -9.8 + 6e-06 2.3e-05 -4.2e-05 + + + 0.001 + 1 + 1000 + + + 0.4 0.4 0.4 1 + 0.7 0.7 0.7 1 + 1 + + + + EARTH_WGS84 + 0 + 0 + 0 + 0 + + + 0.512455 -1.58317 0.5 0 -0 0 + + + 1 + + 0.166667 + 0 + 0 + 0.166667 + 0 + 0.166667 + + + + + + 1 1 1 + + + 10 + + + + + + + + + + + + + + + + + 1 1 1 + + + + + + + 0 + 0 + 1 + + + + 0.105158 -4.55002 0.499995 -2.89297 -0.988287 -3.14159 + + + 1 + + 0.166667 + 0 + 0 + 0.166667 + 0 + 0.166667 + + + + + + 1 1 1 + + + 10 + + + + + + + + + + + + + + + + + 1 1 1 + + + + + + + 0 + 0 + 1 + + + + 0 0 + 0 0 + 1462824251 956472000 + 0 + + 0 0 0 0 -0 0 + 1 1 1 + + 0 0 0 0 -0 0 + 0 0 0 0 -0 0 + 0 0 0 0 -0 0 + 0 0 0 0 -0 0 + + + + 0.223196 -1.84719 0.499995 -2.89297 -0.988287 -3.14159 + 1 1 1 + + 0.223196 -1.84719 0.499995 -2.89297 -0.988287 -3.14159 + 0.004896 3e-06 -0.004891 -6e-06 0.009793 -0 + 0.010615 0.006191 -9.78231 -0.012424 0.021225 -1.8e-05 + 0.010615 0.006191 -9.78231 0 -0 0 + + + + 0.105158 -4.55002 0.499995 -2.89297 -0.988287 -3.14159 + 1 1 1 + + 0.105158 -4.55002 0.499995 -2.89297 -0.988287 -3.14159 + 0 0 0 0 -0 0 + 0 0 0 0 -0 0 + 0 0 0 0 -0 0 + + + + 0 0 10 0 -0 0 + + + + + 8.0562 -8.87312 3.07529 0 0.205021 2.5208 + orbit + perspective + + + + diff --git a/examples/BasicDemo/BasicExample.cpp b/examples/BasicDemo/BasicExample.cpp index d501b5109..f5bd9486c 100644 --- a/examples/BasicDemo/BasicExample.cpp +++ b/examples/BasicDemo/BasicExample.cpp @@ -52,7 +52,7 @@ void BasicExample::initPhysics() m_guiHelper->setUpAxis(1); createEmptyDynamicsWorld(); - + //m_dynamicsWorld->setGravity(btVector3(0,0,0)); m_guiHelper->createPhysicsDebugDrawer(m_dynamicsWorld); if (m_dynamicsWorld->getDebugDrawer()) @@ -63,7 +63,7 @@ void BasicExample::initPhysics() //groundShape->initializePolyhedralFeatures(); -// btCollisionShape* groundShape = new btStaticPlaneShape(btVector3(0,1,0),50); + //btCollisionShape* groundShape = new btStaticPlaneShape(btVector3(0,1,0),50); m_collisionShapes.push_back(groundShape); @@ -140,7 +140,11 @@ void BasicExample::renderScene() CommonExampleInterface* BasicExampleCreateFunc(CommonExampleOptions& options) { return new BasicExample(options.m_guiHelper); + } +B3_STANDALONE_EXAMPLE(BasicExampleCreateFunc) + + diff --git a/examples/BasicDemo/CMakeLists.txt b/examples/BasicDemo/CMakeLists.txt index 716c3a064..7286d93f9 100644 --- a/examples/BasicDemo/CMakeLists.txt +++ b/examples/BasicDemo/CMakeLists.txt @@ -29,3 +29,72 @@ IF (INTERNAL_ADD_POSTFIX_EXECUTABLE_NAMES) SET_TARGET_PROPERTIES(App_BasicExample PROPERTIES MINSIZEREL_POSTFIX "_MinsizeRel") SET_TARGET_PROPERTIES(App_BasicExample PROPERTIES RELWITHDEBINFO_POSTFIX "_RelWithDebugInfo") ENDIF(INTERNAL_ADD_POSTFIX_EXECUTABLE_NAMES) + + + + + +################# +# Standalone BasicExampleGui using OpenGL (but not the example browser) + + +INCLUDE_DIRECTORIES( + ${BULLET_PHYSICS_SOURCE_DIR}/src + ${BULLET_PHYSICS_SOURCE_DIR}/btgui + ${BULLET_PHYSICS_SOURCE_DIR}/examples + ${BULLET_PHYSICS_SOURCE_DIR}/examples/ThirdPartyLibs/Glew +) + + +SET(AppBasicExampleGui_SRCS + BasicExample.cpp + ${BULLET_PHYSICS_SOURCE_DIR}/build3/bullet.rc + ../StandaloneMain/main_opengl_single_example.cpp + ../ExampleBrowser/OpenGLGuiHelper.cpp + ../ExampleBrowser/GL_ShapeDrawer.cpp +) + +#this define maps StandaloneExampleCreateFunc to the right 'CreateFunc' +ADD_DEFINITIONS(-DB3_USE_STANDALONE_EXAMPLE) + +LINK_LIBRARIES( + BulletDynamics BulletCollision LinearMath OpenGLWindow Bullet3Common ${OPENGL_gl_LIBRARY} ${OPENGL_glu_LIBRARY} +) + +#some code to support OpenGL and Glew cross platform +IF (WIN32) + INCLUDE_DIRECTORIES( + ${BULLET_PHYSICS_SOURCE_DIR}/btgui/OpenGLWindow/GlewWindows + ) + ADD_DEFINITIONS(-DGLEW_STATIC) +ELSE(WIN32) + IF(APPLE) + find_library(COCOA NAMES Cocoa) + MESSAGE(${COCOA}) + link_libraries(${COCOA}) + + ELSE(APPLE) + INCLUDE_DIRECTORIES( + ${BULLET_PHYSICS_SOURCE_DIR}/btgui/OpenGLWindow/GlewWindows + ) + ADD_DEFINITIONS("-DGLEW_INIT_OPENGL11_FUNCTIONS=1") + ADD_DEFINITIONS("-DGLEW_STATIC") + ADD_DEFINITIONS("-DGLEW_DYNAMIC_LOAD_ALL_GLX_FUNCTIONS=1") + + LINK_LIBRARIES( X11 pthread dl Xext) + ENDIF(APPLE) +ENDIF(WIN32) + + +ADD_EXECUTABLE(AppBasicExampleGui + ${AppBasicExampleGui_SRCS} +) + + +IF (INTERNAL_ADD_POSTFIX_EXECUTABLE_NAMES) + SET_TARGET_PROPERTIES(AppBasicExampleGui PROPERTIES DEBUG_POSTFIX "_Debug") + SET_TARGET_PROPERTIES(AppBasicExampleGui PROPERTIES MINSIZEREL_POSTFIX "_MinsizeRel") + SET_TARGET_PROPERTIES(AppBasicExampleGui PROPERTIES RELWITHDEBINFO_POSTFIX "_RelWithDebugInfo") +ENDIF(INTERNAL_ADD_POSTFIX_EXECUTABLE_NAMES) + + diff --git a/examples/BasicDemo/main.cpp b/examples/BasicDemo/main.cpp index c6039fc63..9ee7222d6 100644 --- a/examples/BasicDemo/main.cpp +++ b/examples/BasicDemo/main.cpp @@ -18,8 +18,13 @@ subject to the following restrictions: #include "../CommonInterfaces/CommonExampleInterface.h" #include "../CommonInterfaces/CommonGUIHelperInterface.h" +#include "BulletCollision/CollisionDispatch/btCollisionObject.h" +#include "BulletCollision/CollisionShapes/btCollisionShape.h" +#include "BulletDynamics/Dynamics/btDiscreteDynamicsWorld.h" +#include "LinearMath/btTransform.h" +#include "LinearMath/btHashMap.h" int main(int argc, char* argv[]) @@ -39,3 +44,4 @@ int main(int argc, char* argv[]) return 0; } + diff --git a/examples/BasicDemo/premake4.lua b/examples/BasicDemo/premake4.lua index b4901e92b..2b2a7d45f 100644 --- a/examples/BasicDemo/premake4.lua +++ b/examples/BasicDemo/premake4.lua @@ -20,3 +20,82 @@ files { "**.h", } + +project "App_BasicExampleGui" + +if _OPTIONS["ios"] then + kind "WindowedApp" +else + kind "ConsoleApp" +end +defines {"B3_USE_STANDALONE_EXAMPLE"} + +includedirs {"../../src"} + +links { + "BulletDynamics","BulletCollision", "LinearMath", "OpenGL_Window","Bullet3Common" +} + + initOpenGL() + initGlew() + + +language "C++" + +files { + "BasicExample.cpp", + "*.h", + "../StandaloneMain/main_opengl_single_example.cpp", + "../ExampleBrowser/OpenGLGuiHelper.cpp", + "../ExampleBrowser/GL_ShapeDrawer.cpp", +} + +if os.is("Linux") then initX11() end + +if os.is("MacOSX") then + links{"Cocoa.framework"} +end + + + +project "App_BasicExampleGuiWithSoftwareRenderer" + +if _OPTIONS["ios"] then + kind "WindowedApp" +else + kind "ConsoleApp" +end +defines {"B3_USE_STANDALONE_EXAMPLE"} + +includedirs {"../../src"} + +links { + "BulletDynamics","BulletCollision", "LinearMath", "OpenGL_Window","Bullet3Common" +} + + initOpenGL() + initGlew() + + +language "C++" + +files { + "BasicExample.cpp", + "*.h", + "../StandaloneMain/main_sw_tinyrenderer_single_example.cpp", + "../ExampleBrowser/OpenGLGuiHelper.cpp", + "../ExampleBrowser/GL_ShapeDrawer.cpp", + "../TinyRenderer/geometry.cpp", + "../TinyRenderer/model.cpp", + "../TinyRenderer/tgaimage.cpp", + "../TinyRenderer/our_gl.cpp", + "../TinyRenderer/TinyRenderer.cpp", + "../Utils/b3ResourcePath.cpp" +} + +if os.is("Linux") then initX11() end + +if os.is("MacOSX") then + links{"Cocoa.framework"} +end + \ No newline at end of file diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 4d26967f1..8a974c55b 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -1,5 +1,7 @@ SUBDIRS( HelloWorld BasicDemo ) IF(BUILD_BULLET3) - SUBDIRS( ExampleBrowser ThirdPartyLibs/Gwen OpenGLWindow) + SUBDIRS( ExampleBrowser ThirdPartyLibs/Gwen OpenGLWindow ) ENDIF() - +IF(BUILD_PYBULLET) + SUBDIRS(pybullet) +ENDIF(BUILD_PYBULLET) diff --git a/examples/CommonInterfaces/CommonExampleInterface.h b/examples/CommonInterfaces/CommonExampleInterface.h index 71ced8fca..28859f99e 100644 --- a/examples/CommonInterfaces/CommonExampleInterface.h +++ b/examples/CommonInterfaces/CommonExampleInterface.h @@ -48,6 +48,17 @@ public: }; +CommonExampleInterface* StandaloneExampleCreateFunc(CommonExampleOptions& options); + +#ifdef B3_USE_STANDALONE_EXAMPLE + #define B3_STANDALONE_EXAMPLE(ExampleFunc) CommonExampleInterface* StandaloneExampleCreateFunc(CommonExampleOptions& options)\ + {\ + return ExampleFunc(options);\ + } +#else//B3_USE_STANDALONE_EXAMPLE + #define B3_STANDALONE_EXAMPLE(ExampleFunc) +#endif //B3_USE_STANDALONE_EXAMPLE + #endif //COMMON_EXAMPLE_INTERFACE_H diff --git a/examples/CommonInterfaces/CommonRenderInterface.h b/examples/CommonInterfaces/CommonRenderInterface.h index a3d1d0f8b..e1d6170ef 100644 --- a/examples/CommonInterfaces/CommonRenderInterface.h +++ b/examples/CommonInterfaces/CommonRenderInterface.h @@ -43,7 +43,11 @@ struct CommonRenderInterface virtual void drawPoint(const double* position, const double color[4], double pointDrawSize)=0; virtual int registerShape(const float* vertices, int numvertices, const int* indices, int numIndices,int primitiveType=B3_GL_TRIANGLES, int textureIndex=-1)=0; virtual void updateShape(int shapeIndex, const float* vertices)=0; - virtual int registerTexture(const unsigned char* texels, int width, int height)=0; + + virtual int registerTexture(const unsigned char* texels, int width, int height)=0; + virtual void updateTexture(int textureIndex, const unsigned char* texels)=0; + virtual void activateTexture(int textureIndex)=0; + virtual void writeSingleInstanceTransformToCPU(const float* position, const float* orientation, int srcIndex)=0; virtual void writeSingleInstanceTransformToCPU(const double* position, const double* orientation, int srcIndex)=0; virtual void writeSingleInstanceColorToCPU(float* color, int srcIndex)=0; diff --git a/examples/CommonInterfaces/CommonWindowInterface.h b/examples/CommonInterfaces/CommonWindowInterface.h index fb3b574e9..346fdac72 100644 --- a/examples/CommonInterfaces/CommonWindowInterface.h +++ b/examples/CommonInterfaces/CommonWindowInterface.h @@ -119,7 +119,9 @@ class CommonWindowInterface virtual float getRetinaScale() const =0; virtual void setAllowRetina(bool allow) =0; - + + virtual int getWidth() const = 0; + virtual int getHeight() const = 0; virtual int fileOpenDialog(char* fileName, int maxFileNameLength) = 0; diff --git a/examples/ExampleBrowser/CMakeLists.txt b/examples/ExampleBrowser/CMakeLists.txt index 2e8de4868..0a1c172f0 100644 --- a/examples/ExampleBrowser/CMakeLists.txt +++ b/examples/ExampleBrowser/CMakeLists.txt @@ -1,21 +1,27 @@ - INCLUDE_DIRECTORIES( . ${BULLET_PHYSICS_SOURCE_DIR}/src ${BULLET_PHYSICS_SOURCE_DIR}/examples/ThirdPartyLibs ) -FILE(GLOB ExampleBrowser_SRCS "*" "GwenGUISupport/*" ) -FILE(GLOB ExampleBrowser_HDRS "*" "GwenGUISupport/*" ) +FILE(GLOB GwenGUISupport_SRCS "GwenGUISupport/*" ) +FILE(GLOB GwenGUISupport_HDRS "GwenGUISupport/*" ) +SET(ExtendedTutorialsSources + ../ExtendedTutorials/SimpleBox.cpp + ../ExtendedTutorials/MultipleBoxes.cpp + ../ExtendedTutorials/SimpleJoint.cpp + ../ExtendedTutorials/SimpleCloth.cpp + ../ExtendedTutorials/Chain.cpp + ../ExtendedTutorials/Bridge.cpp + ../ExtendedTutorials/RigidBodyFromObj.cpp +) - - -SET(App_ExampleBrowser_SRCS - main.cpp - ExampleEntries.cpp - ExampleEntries.h +SET(BulletExampleBrowser_SRCS + OpenGLExampleBrowser.cpp + OpenGLGuiHelper.cpp InProcessExampleBrowser.cpp + GL_ShapeDrawer.cpp ../SharedMemory/PhysicsServer.cpp ../SharedMemory/PhysicsClientSharedMemory.cpp ../SharedMemory/PhysicsClient.cpp @@ -97,8 +103,10 @@ SET(App_ExampleBrowser_SRCS ../../Extras/Serialize/BulletWorldImporter/btWorldImporter.cpp ../../Extras/Serialize/BulletWorldImporter/btBulletWorldImporter.cpp -../../Extras/Serialize/BulletFileLoader/bChunk.cpp ../../Extras/Serialize/BulletFileLoader/bFile.cpp -../../Extras/Serialize/BulletFileLoader/bDNA.cpp ../../Extras/Serialize/BulletFileLoader/btBulletFile.cpp + ../../Extras/Serialize/BulletFileLoader/bChunk.cpp + ../../Extras/Serialize/BulletFileLoader/bFile.cpp + ../../Extras/Serialize/BulletFileLoader/bDNA.cpp + ../../Extras/Serialize/BulletFileLoader/btBulletFile.cpp ../Importers/ImportBsp/BspLoader.h ../Importers/ImportBsp/ImportBspExample.h @@ -124,6 +132,7 @@ SET(App_ExampleBrowser_SRCS ../Importers/ImportObjDemo/LoadMeshFromObj.cpp ../Importers/ImportObjDemo/Wavefront2GLInstanceGraphicsShape.cpp ../Importers/ImportSTLDemo/ImportSTLSetup.cpp + ../Importers/ImportSDFDemo/ImportSDFSetup.cpp ../Importers/ImportURDFDemo/ImportURDFSetup.cpp ../Importers/ImportURDFDemo/URDF2Bullet.cpp ../Importers/ImportURDFDemo/MyMultiBodyCreator.cpp @@ -168,44 +177,84 @@ SET(App_ExampleBrowser_SRCS ../ThirdPartyLibs/tinyxml/tinyxmlerror.cpp ../ThirdPartyLibs/tinyxml/tinyxmlparser.cpp - - ../ThirdPartyLibs/urdf/urdfdom/urdf_parser/src/pose.cpp - ../ThirdPartyLibs/urdf/urdfdom/urdf_parser/src/model.cpp - ../ThirdPartyLibs/urdf/urdfdom/urdf_parser/src/link.cpp - ../ThirdPartyLibs/urdf/urdfdom/urdf_parser/src/joint.cpp - ../ThirdPartyLibs/urdf/urdfdom/urdf_parser/include/urdf_parser/urdf_parser.h - ../ThirdPartyLibs/urdf/urdfdom_headers/urdf_exception/include/urdf_exception/exception.h - ../ThirdPartyLibs/urdf/urdfdom_headers/urdf_model/include/urdf_model/pose.h - ../ThirdPartyLibs/urdf/urdfdom_headers/urdf_model/include/urdf_model/model.h - ../ThirdPartyLibs/urdf/urdfdom_headers/urdf_model/include/urdf_model/link.h - ../ThirdPartyLibs/urdf/urdfdom_headers/urdf_model/include/urdf_model/joint.h ../ThirdPartyLibs/tinyxml/tinystr.cpp ../ThirdPartyLibs/tinyxml/tinyxml.cpp ../ThirdPartyLibs/tinyxml/tinyxmlerror.cpp ../ThirdPartyLibs/tinyxml/tinyxmlparser.cpp - ../ThirdPartyLibs/urdf/boost_replacement/lexical_cast.h - ../ThirdPartyLibs/urdf/boost_replacement/shared_ptr.h - ../ThirdPartyLibs/urdf/boost_replacement/printf_console.cpp - ../ThirdPartyLibs/urdf/boost_replacement/printf_console.h - ../ThirdPartyLibs/urdf/boost_replacement/string_split.cpp - ../ThirdPartyLibs/urdf/boost_replacement/string_split.h ../Utils/b3Clock.cpp ../Utils/b3Clock.h ../Utils/b3ResourcePath.cpp ../Utils/b3ResourcePath.h - ${ExampleBrowser_SRCS} - ${ExampleBrowser_HDRS} + ${GwenGUISupport_SRCS} + ${GwenGUISupport_HDRS} + ${ExtendedTutorialsSources} ${BULLET_PHYSICS_SOURCE_DIR}/build3/bullet.rc ) +IF (WIN32) + INCLUDE_DIRECTORIES( + ${BULLET_PHYSICS_SOURCE_DIR}/examples/ThirdPartyLibs/Glew + ) + ADD_DEFINITIONS(-DGLEW_STATIC) +ELSE(WIN32) + IF(APPLE) + find_library(COCOA NAMES Cocoa) + ELSE(APPLE) + ADD_DEFINITIONS("-DGLEW_INIT_OPENGL11_FUNCTIONS=1") + ADD_DEFINITIONS("-DGLEW_STATIC") + ADD_DEFINITIONS("-DGLEW_DYNAMIC_LOAD_ALL_GLX_FUNCTIONS=1") + INCLUDE_DIRECTORIES( ${BULLET_PHYSICS_SOURCE_DIR}/examples/ThirdPartyLibs/Glew ) + ENDIF(APPLE) +ENDIF(WIN32) + + +ADD_LIBRARY(BulletExampleBrowserLib ${BulletExampleBrowser_SRCS} ) +SET_TARGET_PROPERTIES(BulletExampleBrowserLib PROPERTIES VERSION ${BULLET_VERSION}) +SET_TARGET_PROPERTIES(BulletExampleBrowserLib PROPERTIES SOVERSION ${BULLET_VERSION}) +IF (BUILD_SHARED_LIBS) + IF (WIN32) + TARGET_LINK_LIBRARIES( + BulletExampleBrowserLib Bullet3Common BulletSoftBody BulletDynamics BulletCollision BulletInverseDynamicsUtils + BulletInverseDynamics LinearMath OpenGLWindow gwen + ${OPENGL_gl_LIBRARY} ${OPENGL_glu_LIBRARY} + ) + ELSE(WIN32) + IF(APPLE) + TARGET_LINK_LIBRARIES( + BulletExampleBrowserLib Bullet3Common BulletSoftBody BulletDynamics BulletCollision BulletInverseDynamicsUtils + BulletInverseDynamics LinearMath OpenGLWindow gwen + ${COCOA} ${OPENGL_gl_LIBRARY} ${OPENGL_glu_LIBRARY} + ) + ELSE(APPLE) + TARGET_LINK_LIBRARIES( + BulletExampleBrowserLib Bullet3Common BulletSoftBody BulletDynamics BulletCollision BulletInverseDynamicsUtils + BulletInverseDynamics LinearMath OpenGLWindow gwen + pthread dl + ) + ENDIF(APPLE) + ENDIF(WIN32) +ENDIF(BUILD_SHARED_LIBS) + +#################### +# +# Bullet Example Browser main app +# +#################### + +INCLUDE_DIRECTORIES( + . + ${BULLET_PHYSICS_SOURCE_DIR}/src + ${BULLET_PHYSICS_SOURCE_DIR}/examples/ThirdPartyLibs +) + + LINK_LIBRARIES( - Bullet3Common BulletSoftBody BulletDynamics BulletCollision BulletInverseDynamicsUtils BulletInverseDynamics LinearMath OpenGLWindow gwen + BulletExampleBrowserLib Bullet3Common BulletSoftBody BulletDynamics BulletCollision BulletInverseDynamicsUtils BulletInverseDynamics LinearMath OpenGLWindow gwen ) IF (WIN32) - SET(App_ExampleBrowser_SRCS ${App_ExampleBrowser_SRCS} ) INCLUDE_DIRECTORIES( - ${BULLET_PHYSICS_SOURCE_DIR}/examples/ThirdPartyLibs/Glew + ${BULLET_PHYSICS_SOURCE_DIR}/examples/ThirdPartyLibs/Glew ) LINK_LIBRARIES( ${OPENGL_gl_LIBRARY} ${OPENGL_glu_LIBRARY} @@ -229,9 +278,19 @@ ENDIF(WIN32) ADD_EXECUTABLE(App_ExampleBrowser - ${App_ExampleBrowser_SRCS} + main.cpp + ExampleEntries.cpp + ExampleEntries.h ) +FILE( MAKE_DIRECTORY "${PROJECT_BINARY_DIR}/data" ) + +ADD_CUSTOM_COMMAND( + TARGET App_ExampleBrowser + POST_BUILD + COMMAND ${CMAKE_COMMAND} ARGS -E copy_directory ${BULLET_PHYSICS_SOURCE_DIR}/data ${PROJECT_BINARY_DIR}/data + ) + IF (INTERNAL_ADD_POSTFIX_EXECUTABLE_NAMES) SET_TARGET_PROPERTIES(App_ExampleBrowser PROPERTIES DEBUG_POSTFIX "_Debug") diff --git a/examples/ExampleBrowser/ExampleEntries.cpp b/examples/ExampleBrowser/ExampleEntries.cpp index c8377c7fb..6d8b86bea 100644 --- a/examples/ExampleBrowser/ExampleEntries.cpp +++ b/examples/ExampleBrowser/ExampleEntries.cpp @@ -9,13 +9,12 @@ #include "../BasicDemo/BasicExample.h" #include "../Planar2D/Planar2D.h" #include "../Benchmarks/BenchmarkDemo.h" -#ifdef ENABLE_URDF_OBJ #include "../Importers/ImportObjDemo/ImportObjExample.h" -#endif #include "../Importers/ImportBsp/ImportBspExample.h" #include "../Importers/ImportColladaDemo/ImportColladaSetup.h" #include "../Importers/ImportSTLDemo/ImportSTLSetup.h" #include "../Importers/ImportURDFDemo/ImportURDFSetup.h" +#include "../Importers/ImportSDFDemo/ImportSDFSetup.h" #include "../Collision/CollisionTutorialBullet2.h" #include "../GyroscopicDemo/GyroscopicSetup.h" #include "../Constraints/Dof6Spring2Setup.h" @@ -56,7 +55,14 @@ #endif #endif //B3_USE_CLEW - +//Extended Tutorial Includes Added by Mobeen +#include "../ExtendedTutorials/SimpleBox.h" +#include "../ExtendedTutorials/MultipleBoxes.h" +#include "../ExtendedTutorials/SimpleJoint.h" +#include "../ExtendedTutorials/SimpleCloth.h" +#include "../ExtendedTutorials/Chain.h" +#include "../ExtendedTutorials/Bridge.h" +#include "../ExtendedTutorials/RigidBodyFromObj.h" struct ExampleEntry { @@ -80,13 +86,12 @@ struct ExampleEntry static ExampleEntry gDefaultExamples[]= { - - - - + ExampleEntry(0,"API"), + ExampleEntry(1,"Basic Example","Create some rigid bodies using box collision shapes. This is a good example to familiarize with the basic initialization of Bullet. The Basic Example can also be compiled without graphical user interface, as a console application. Press W for wireframe, A to show AABBs, I to suspend/restart physics simulation. Press D to toggle auto-deactivation of the simulation. ", BasicExampleCreateFunc), + ExampleEntry(1,"Rolling Friction", "Damping is often not good enough to keep rounded objects from rolling down a sloped surface. Instead, you can set the rolling friction of a rigid body. Generally it is best to leave the rolling friction to zero, to avoid artifacts.", RollingFrictionCreateFunc), ExampleEntry(1,"Constraints","Show the use of the various constraints in Bullet. Press the L key to visualize the constraint limits. Press the C key to visualize the constraint frames.", @@ -122,7 +127,6 @@ static ExampleEntry gDefaultExamples[]= ExampleEntry(1,"Inverse Dynamics URDF", "Create a btMultiBody from URDF. Create an inverse MultiBodyTree model from that. Use either decoupled PD control or computed torque control using the inverse model to track joint position targets", InverseDynamicsExampleCreateFunc,BT_ID_LOAD_URDF), ExampleEntry(1,"Inverse Dynamics Prog", "Create a btMultiBody programatically. Create an inverse MultiBodyTree model from that. Use either decoupled PD control or computed torque control using the inverse model to track joint position targets", InverseDynamicsExampleCreateFunc,BT_ID_PROGRAMMATICALLY), - ExampleEntry(0,"Tutorial"), ExampleEntry(1,"Constant Velocity","Free moving rigid body, without external or constraint forces", TutorialCreateFunc,TUT_VELOCITY), ExampleEntry(1,"Gravity Acceleration","Motion of a free falling rigid body under constant gravitational acceleration", TutorialCreateFunc,TUT_ACCELERATION), @@ -194,9 +198,11 @@ static ExampleEntry gDefaultExamples[]= ExampleEntry(0,"Importers"), ExampleEntry(1,"Import .bullet", "Load a binary .bullet file. The serialization mechanism can deal with versioning, differences in endianess, 32 and 64bit, double/single precision. It is easy to save a .bullet file, see the examples/Importers/ImportBullet/SerializeDemo.cpp for a code example how to export a .bullet file.", SerializeBulletCreateFunc), -#ifdef ENABLE_URDF_OBJ ExampleEntry(1,"Wavefront Obj", "Import a Wavefront .obj file", ImportObjCreateFunc, 0), -#endif + ExampleEntry(1,"Obj2RigidBody (Show Obj)", "Load a triangle mesh from Wavefront .obj and turn it in a convex hull collision shape, connected to a rigid body. We can use the original .obj mesh data to visualize the rigid body. In 'debug' wireframe mode (press 'w' to toggle) we still see the convex hull data.", ET_RigidBodyFromObjCreateFunc), + ExampleEntry(1,"Obj2RigidBody (Show Hull)", "Load a triangle mesh from Wavefront .obj and turn it in a convex hull collision shape, connected to a rigid body", ET_RigidBodyFromObjCreateFunc,ObjUseConvexHullForRendering), + ExampleEntry(1,"Obj2RigidBody Optimize", "Load a triangle mesh from Wavefront .obj, remove the vertices that are not on the convex hull", ET_RigidBodyFromObjCreateFunc,OptimizeConvexObj), + ExampleEntry(1,"Quake BSP", "Import a Quake .bsp file", ImportBspCreateFunc, 0), ExampleEntry(1,"COLLADA dae", "Import the geometric mesh data from a COLLADA file. This is used as part of the URDF importer. This loader can also be used to import collision geometry in general. ", ImportColladaCreateFunc, 0), @@ -204,7 +210,8 @@ static ExampleEntry gDefaultExamples[]= ExampleEntry(1,"URDF (RigidBody)", "Import a URDF file, and create rigid bodies (btRigidBody) connected by constraints.", ImportURDFCreateFunc, 0), ExampleEntry(1,"URDF (MultiBody)", "Import a URDF file and create a single multibody (btMultiBody) with tree hierarchy of links (mobilizers).", ImportURDFCreateFunc, 1), - + ExampleEntry(1,"SDF (MultiBody)", "Import an SDF file, create multiple multibodies etc", ImportSDFCreateFunc), + ExampleEntry(0,"Vehicles"), ExampleEntry(1,"Hinge2 Vehicle", "A rigid body chassis with 4 rigid body wheels attached by a btHinge2Constraint",Hinge2VehicleCreateFunc), ExampleEntry(1,"ForkLift","Simulate a fork lift vehicle with a working fork lift that can be moved using the cursor keys. The wheels collision is simplified using ray tests." @@ -220,13 +227,6 @@ static ExampleEntry gDefaultExamples[]= ExampleEntry(0,"Experiments"), -// ExampleEntry(1,"Robot Control (Velocity)", "Perform some robot control tasks, using physics server and client that communicate over shared memory", -// RobotControlExampleCreateFunc,ROBOT_VELOCITY_CONTROL), -// ExampleEntry(1,"Robot Control (PD)", "Perform some robot control tasks, using physics server and client that communicate over shared memory", -// RobotControlExampleCreateFunc,ROBOT_PD_CONTROL), -// ExampleEntry(1,"Robot Joint Feedback", "Apply some small ping-pong target velocity jitter, and read the joint reaction forces, using physics server and client that communicate over shared memory.", - // RobotControlExampleCreateFunc,ROBOT_PING_PONG_JOINT_FEEDBACK), - ExampleEntry(1,"Physics Server", "Create a physics server that communicates with a physics client over shared memory", PhysicsServerCreateFunc), ExampleEntry(1,"Physics Server (Logging)", "Create a physics server that communicates with a physics client over shared memory. It will log all commands to a file.", @@ -254,8 +254,22 @@ static ExampleEntry gDefaultExamples[]= ExampleEntry(0,"Rendering"), ExampleEntry(1,"Instanced Rendering", "Simple example of fast instanced rendering, only active when using OpenGL3+.",RenderInstancingCreateFunc), ExampleEntry(1,"CoordinateSystemDemo","Show the axis and positive rotation direction around the axis.", CoordinateSystemCreateFunc), - ExampleEntry(1,"Time Series", "Render some value(s) in a 2D graph window, shifting to the left", TimeSeriesCreateFunc) + ExampleEntry(1,"Time Series", "Render some value(s) in a 2D graph window, shifting to the left", TimeSeriesCreateFunc), + //Extended Tutorials Added by Mobeen + ExampleEntry(0,"Extended Tutorials"), + ExampleEntry(1,"Simple Box", "Simplest possible demo creating a single box rigid body that falls under gravity", ET_SimpleBoxCreateFunc), + ExampleEntry(1,"Multiple Boxes", "Adding multiple box rigid bodies that fall under gravity", ET_MultipleBoxesCreateFunc), + ExampleEntry(1,"Simple Joint", "Creating a single distance constraint between two box rigid bodies", ET_SimpleJointCreateFunc), + ExampleEntry(1,"Simple Cloth", "Creating a simple piece of cloth", ET_SimpleClothCreateFunc), + ExampleEntry(1,"Simple Chain", "Creating a simple chain using a pair of point2point/distance constraints. You may click and drag any box to see the chain respond.", ET_ChainCreateFunc), + ExampleEntry(1,"Simple Bridge", "Creating a simple bridge using a pair of point2point/distance constraints. You may click and drag any plank to see the bridge respond.", ET_BridgeCreateFunc), + + //todo: create a category/tutorial about advanced topics, such as optimizations, using different collision detection algorithm, different constraint solvers etc. + //ExampleEntry(0,"Advanced"), + //ExampleEntry(1,"Obj2RigidBody Add Features", "Load a triangle mesh from Wavefront .obj and create polyhedral features to perform the separating axis test (instead of GJK/MPR). It is best to combine optimization and polyhedral feature generation.", ET_RigidBodyFromObjCreateFunc,OptimizeConvexObj+ComputePolyhedralFeatures), + + }; #ifdef B3_USE_CLEW @@ -278,17 +292,17 @@ struct ExampleEntriesInternalData btAlignedObjectArray m_allExamples; }; -ExampleEntries::ExampleEntries() +ExampleEntriesAll::ExampleEntriesAll() { m_data = new ExampleEntriesInternalData; } -ExampleEntries::~ExampleEntries() +ExampleEntriesAll::~ExampleEntriesAll() { delete m_data; } -void ExampleEntries::initOpenCLExampleEntries() +void ExampleEntriesAll::initOpenCLExampleEntries() { #ifdef B3_USE_CLEW #ifndef NO_OPENGL3 @@ -301,7 +315,7 @@ void ExampleEntries::initOpenCLExampleEntries() #endif //B3_USE_CLEW } -void ExampleEntries::initExampleEntries() +void ExampleEntriesAll::initExampleEntries() { m_data->m_allExamples.clear(); @@ -334,33 +348,33 @@ void ExampleEntries::initExampleEntries() } -void ExampleEntries::registerExampleEntry(int menuLevel, const char* name,const char* description, CommonExampleInterface::CreateFunc* createFunc, int option) +void ExampleEntriesAll::registerExampleEntry(int menuLevel, const char* name,const char* description, CommonExampleInterface::CreateFunc* createFunc, int option) { ExampleEntry e( menuLevel,name,description, createFunc, option); gAdditionalRegisteredExamples.push_back(e); } -int ExampleEntries::getNumRegisteredExamples() +int ExampleEntriesAll::getNumRegisteredExamples() { return m_data->m_allExamples.size(); } -CommonExampleInterface::CreateFunc* ExampleEntries::getExampleCreateFunc(int index) +CommonExampleInterface::CreateFunc* ExampleEntriesAll::getExampleCreateFunc(int index) { return m_data->m_allExamples[index].m_createFunc; } -int ExampleEntries::getExampleOption(int index) +int ExampleEntriesAll::getExampleOption(int index) { return m_data->m_allExamples[index].m_option; } -const char* ExampleEntries::getExampleName(int index) +const char* ExampleEntriesAll::getExampleName(int index) { return m_data->m_allExamples[index].m_name; } -const char* ExampleEntries::getExampleDescription(int index) +const char* ExampleEntriesAll::getExampleDescription(int index) { return m_data->m_allExamples[index].m_description; } diff --git a/examples/ExampleBrowser/ExampleEntries.h b/examples/ExampleBrowser/ExampleEntries.h index f6d661adb..286e73f57 100644 --- a/examples/ExampleBrowser/ExampleEntries.h +++ b/examples/ExampleBrowser/ExampleEntries.h @@ -6,32 +6,56 @@ - class ExampleEntries +{ + +public: + + virtual ~ExampleEntries() {} + + + virtual void initExampleEntries()=0; + + virtual void initOpenCLExampleEntries()=0; + + virtual int getNumRegisteredExamples()=0; + + virtual CommonExampleInterface::CreateFunc* getExampleCreateFunc(int index)=0; + + virtual const char* getExampleName(int index)=0; + + virtual const char* getExampleDescription(int index)=0; + + virtual int getExampleOption(int index)=0; + +}; + + +class ExampleEntriesAll : public ExampleEntries { struct ExampleEntriesInternalData* m_data; public: - ExampleEntries(); - virtual ~ExampleEntries(); + ExampleEntriesAll(); + virtual ~ExampleEntriesAll(); static void registerExampleEntry(int menuLevel, const char* name,const char* description, CommonExampleInterface::CreateFunc* createFunc, int option=0); - void initExampleEntries(); + virtual void initExampleEntries(); - void initOpenCLExampleEntries(); + virtual void initOpenCLExampleEntries(); - int getNumRegisteredExamples(); + virtual int getNumRegisteredExamples(); - CommonExampleInterface::CreateFunc* getExampleCreateFunc(int index); + virtual CommonExampleInterface::CreateFunc* getExampleCreateFunc(int index); - const char* getExampleName(int index); + virtual const char* getExampleName(int index); - const char* getExampleDescription(int index); + virtual const char* getExampleDescription(int index); - int getExampleOption(int index); + virtual int getExampleOption(int index); }; diff --git a/examples/ExampleBrowser/GwenGUISupport/GwenParameterInterface.cpp b/examples/ExampleBrowser/GwenGUISupport/GwenParameterInterface.cpp index 5032a1cdb..fee07bc94 100644 --- a/examples/ExampleBrowser/GwenGUISupport/GwenParameterInterface.cpp +++ b/examples/ExampleBrowser/GwenGUISupport/GwenParameterInterface.cpp @@ -27,17 +27,19 @@ struct MyButtonEventHandler : public Gwen::Event::Handler template struct MySliderEventHandler : public Gwen::Event::Handler { + SliderParamChangedCallback m_callback; Gwen::Controls::TextBox* m_label; Gwen::Controls::Slider* m_pSlider; char m_variableName[1024]; T* m_targetValue; bool m_showValue; - MySliderEventHandler(const char* varName, Gwen::Controls::TextBox* label, Gwen::Controls::Slider* pSlider,T* target) + MySliderEventHandler(const char* varName, Gwen::Controls::TextBox* label, Gwen::Controls::Slider* pSlider,T* target,SliderParamChangedCallback callback) :m_label(label), m_pSlider(pSlider), m_targetValue(target), - m_showValue(true) + m_showValue(true), + m_callback(callback) { memcpy(m_variableName,varName,strlen(varName)+1); } @@ -51,6 +53,11 @@ struct MySliderEventHandler : public Gwen::Event::Handler T v = T(bla); SetValue(v); + if (m_callback) + { + (*m_callback)(v); + } + } void SetValue(T v) @@ -219,7 +226,7 @@ void GwenParameterInterface::registerSliderFloatParameter(SliderParams& params) pSlider->SetValue( *params.m_paramValuePointer);//dimensions[i] ); char labelName[1024]; sprintf(labelName,"%s",params.m_name);//axisNames[0]); - MySliderEventHandler* handler = new MySliderEventHandler(labelName,label,pSlider,params.m_paramValuePointer); + MySliderEventHandler* handler = new MySliderEventHandler(labelName,label,pSlider,params.m_paramValuePointer,params.m_callback); handler->m_showValue = params.m_showValues; m_paramInternalData->m_sliderEventHandlers.push_back(handler); diff --git a/examples/ExampleBrowser/InProcessExampleBrowser.cpp b/examples/ExampleBrowser/InProcessExampleBrowser.cpp index d9be45726..1f03b7e92 100644 --- a/examples/ExampleBrowser/InProcessExampleBrowser.cpp +++ b/examples/ExampleBrowser/InProcessExampleBrowser.cpp @@ -13,7 +13,7 @@ #include "../Utils/b3Clock.h" #include "ExampleEntries.h" -#include "Bullet3Common/b3Logging.h" +#include "Bullet3Common/b3Scalar.h" #include "../SharedMemory/InProcessMemory.h" void ExampleBrowserThreadFunc(void* userPtr,void* lsMemory); @@ -22,9 +22,19 @@ void* ExampleBrowserMemoryFunc(); #include //#include "BulletMultiThreaded/PlatformDefinitions.h" +#include "Bullet3Common/b3Logging.h" +#include "ExampleEntries.h" +#include "LinearMath/btAlignedObjectArray.h" +#include "EmptyExample.h" + +#include "../SharedMemory/PhysicsServerExample.h" +#include "../SharedMemory/PhysicsClientExample.h" + #ifndef _WIN32 #include "../MultiThreading/b3PosixThreadSupport.h" + + static b3ThreadSupportInterface* createExampleBrowserThreadSupport(int numThreads) { b3PosixThreadSupport::ThreadConstructionInfo constructionInfo("testThreads", @@ -38,6 +48,7 @@ static b3ThreadSupportInterface* createExampleBrowserThreadSupport(int numThread } + #elif defined( _WIN32) #include "../MultiThreading/b3Win32ThreadSupport.h" @@ -52,6 +63,138 @@ b3ThreadSupportInterface* createExampleBrowserThreadSupport(int numThreads) + + +class ExampleEntriesPhysicsServer : public ExampleEntries +{ + + struct ExampleEntriesInternalData2* m_data; + +public: + + ExampleEntriesPhysicsServer(); + virtual ~ExampleEntriesPhysicsServer(); + + static void registerExampleEntry(int menuLevel, const char* name,const char* description, CommonExampleInterface::CreateFunc* createFunc, int option=0); + + virtual void initExampleEntries(); + + virtual void initOpenCLExampleEntries(); + + virtual int getNumRegisteredExamples(); + + virtual CommonExampleInterface::CreateFunc* getExampleCreateFunc(int index); + + virtual const char* getExampleName(int index); + + virtual const char* getExampleDescription(int index); + + virtual int getExampleOption(int index); + +}; + + +struct ExampleEntryPhysicsServer +{ + int m_menuLevel; + const char* m_name; + const char* m_description; + CommonExampleInterface::CreateFunc* m_createFunc; + int m_option; + + ExampleEntryPhysicsServer(int menuLevel, const char* name) + :m_menuLevel(menuLevel), m_name(name), m_description(0), m_createFunc(0), m_option(0) + { + } + + ExampleEntryPhysicsServer(int menuLevel, const char* name,const char* description, CommonExampleInterface::CreateFunc* createFunc, int option=0) + :m_menuLevel(menuLevel), m_name(name), m_description(description), m_createFunc(createFunc), m_option(option) + { + } +}; + +struct ExampleEntriesInternalData2 +{ + btAlignedObjectArray m_allExamples; +}; + +static ExampleEntryPhysicsServer gDefaultExamplesPhysicsServer[]= +{ + + ExampleEntryPhysicsServer(0,"Robotics Control"), + + ExampleEntryPhysicsServer(1,"Physics Server", "Create a physics server that communicates with a physics client over shared memory", + PhysicsServerCreateFunc), + ExampleEntryPhysicsServer(1,"Physics Server (Logging)", "Create a physics server that communicates with a physics client over shared memory. It will log all commands to a file.", + PhysicsServerCreateFunc,PHYSICS_SERVER_ENABLE_COMMAND_LOGGING), + ExampleEntryPhysicsServer(1,"Physics Server (Replay Log)", "Create a physics server that replay a command log from disk.", + PhysicsServerCreateFunc,PHYSICS_SERVER_REPLAY_FROM_COMMAND_LOG), + + ExampleEntryPhysicsServer(1, "Physics Client", "Create a physics client that can communicate with a physics server over shared memory", PhysicsClientCreateFunc), + +}; + + +ExampleEntriesPhysicsServer::ExampleEntriesPhysicsServer() +{ + m_data = new ExampleEntriesInternalData2; +} + +ExampleEntriesPhysicsServer::~ExampleEntriesPhysicsServer() +{ + delete m_data; +} + +void ExampleEntriesPhysicsServer::initOpenCLExampleEntries() +{ +} + +void ExampleEntriesPhysicsServer::initExampleEntries() +{ + m_data->m_allExamples.clear(); + + + + int numDefaultEntries = sizeof(gDefaultExamplesPhysicsServer)/sizeof(ExampleEntryPhysicsServer); + for (int i=0;im_allExamples.push_back(gDefaultExamplesPhysicsServer[i]); + } + +} + +void ExampleEntriesPhysicsServer::registerExampleEntry(int menuLevel, const char* name,const char* description, CommonExampleInterface::CreateFunc* createFunc, int option) +{ +} + +int ExampleEntriesPhysicsServer::getNumRegisteredExamples() +{ + return m_data->m_allExamples.size(); +} + +CommonExampleInterface::CreateFunc* ExampleEntriesPhysicsServer::getExampleCreateFunc(int index) +{ + return m_data->m_allExamples[index].m_createFunc; +} + +int ExampleEntriesPhysicsServer::getExampleOption(int index) +{ + return m_data->m_allExamples[index].m_option; +} + +const char* ExampleEntriesPhysicsServer::getExampleName(int index) +{ + return m_data->m_allExamples[index].m_name; +} + +const char* ExampleEntriesPhysicsServer::getExampleDescription(int index) +{ + return m_data->m_allExamples[index].m_description; +} + + + + struct ExampleBrowserArgs { ExampleBrowserArgs() @@ -91,7 +234,7 @@ void ExampleBrowserThreadFunc(void* userPtr,void* lsMemory) b3Clock clock; - ExampleEntries examples; + ExampleEntriesPhysicsServer examples; examples.initExampleEntries(); DefaultBrowser* exampleBrowser = new DefaultBrowser(&examples); @@ -147,6 +290,7 @@ struct btInProcessExampleBrowserInternalData }; + btInProcessExampleBrowserInternalData* btCreateInProcessExampleBrowser(int argc,char** argv2) { @@ -231,7 +375,7 @@ void btShutDownExampleBrowser(btInProcessExampleBrowserInternalData* data) struct btInProcessExampleBrowserMainThreadInternalData { - ExampleEntries m_examples; + ExampleEntriesPhysicsServer m_examples; DefaultBrowser* m_exampleBrowser; SharedMemoryInterface* m_sharedMem; b3Clock m_clock; diff --git a/examples/ExampleBrowser/OpenGLExampleBrowser.cpp b/examples/ExampleBrowser/OpenGLExampleBrowser.cpp index d8756f67e..5804c2c65 100644 --- a/examples/ExampleBrowser/OpenGLExampleBrowser.cpp +++ b/examples/ExampleBrowser/OpenGLExampleBrowser.cpp @@ -723,6 +723,8 @@ bool OpenGLExampleBrowser::init(int argc, char* argv[]) char title[1024]; sprintf(title,"%s using OpenGL3+. %s", appTitle,optMode); simpleApp = new SimpleOpenGL3App(title,width,height, gAllowRetina); + + s_app = simpleApp; } #endif @@ -734,7 +736,11 @@ bool OpenGLExampleBrowser::init(int argc, char* argv[]) #endif s_instancingRenderer = s_app->m_renderer; - s_window = s_app->m_window; + s_window = s_app->m_window; + + width = s_window->getWidth(); + height = s_window->getHeight(); + prevMouseMoveCallback = s_window->getMouseMoveCallback(); s_window->setMouseMoveCallback(MyMouseMoveCallback); @@ -817,9 +823,7 @@ bool OpenGLExampleBrowser::init(int argc, char* argv[]) ///add some demos to the gAllExamples - - - + int numDemos = gAllExamples->getNumRegisteredExamples(); //char nodeText[1024]; @@ -924,7 +928,7 @@ bool OpenGLExampleBrowser::init(int argc, char* argv[]) gui->registerFileOpenCallback(fileOpenCallback); gui->registerQuitCallback(quitCallback); - + return true; } diff --git a/examples/ExampleBrowser/OpenGLGuiHelper.cpp b/examples/ExampleBrowser/OpenGLGuiHelper.cpp index 19d392758..5dd62fcdd 100644 --- a/examples/ExampleBrowser/OpenGLGuiHelper.cpp +++ b/examples/ExampleBrowser/OpenGLGuiHelper.cpp @@ -437,7 +437,7 @@ void OpenGLGuiHelper::createCollisionShapeGraphicsObject(btCollisionShape* colli if (vertices.size() && indices.size()) { - int shapeId = m_data->m_glApp->m_renderer->registerShape(&vertices[0].xyzw[0],vertices.size(),&indices[0],indices.size()); + int shapeId = registerGraphicsShape(&vertices[0].xyzw[0],vertices.size(),&indices[0],indices.size()); collisionShape->setUserIndex(shapeId); } @@ -501,6 +501,7 @@ CommonParameterInterface* OpenGLGuiHelper::getParameterInterface() void OpenGLGuiHelper::setUpAxis(int axis) { m_data->m_glApp->setUpAxis(axis); + } void OpenGLGuiHelper::resetCamera(float camDist, float pitch, float yaw, float camPosX,float camPosY, float camPosZ) diff --git a/examples/ExampleBrowser/main.cpp b/examples/ExampleBrowser/main.cpp index c3442de73..65b82021b 100644 --- a/examples/ExampleBrowser/main.cpp +++ b/examples/ExampleBrowser/main.cpp @@ -22,7 +22,7 @@ int main(int argc, char* argv[]) b3Clock clock; - ExampleEntries examples; + ExampleEntriesAll examples; examples.initExampleEntries(); ExampleBrowserInterface* exampleBrowser = new DefaultBrowser(&examples); diff --git a/examples/ExampleBrowser/premake4.lua b/examples/ExampleBrowser/premake4.lua index d13b30228..5bbbf51f7 100644 --- a/examples/ExampleBrowser/premake4.lua +++ b/examples/ExampleBrowser/premake4.lua @@ -46,6 +46,8 @@ project "App_BulletExampleBrowser" files {"../LuaDemo/LuaPhysicsSetup.cpp"} end + defines {"INCLUDE_CLOTH_DEMOS"} + files { "main.cpp", "ExampleEntries.cpp", @@ -78,7 +80,6 @@ project "BulletExampleBrowserLib" "../../src", "../ThirdPartyLibs", } - defines {"ENABLE_URDF_OBJ"} if _OPTIONS["lua"] then includedirs{"../ThirdPartyLibs/lua-5.2.3/src"} @@ -135,6 +136,7 @@ project "BulletExampleBrowserLib" "../InverseDynamics/InverseDynamicsExample.h", "../BasicDemo/BasicExample.*", "../Tutorial/*", + "../ExtendedTutorials/*", "../Collision/*", "../Collision/Internal/*", "../Benchmarks/*", diff --git a/examples/ExtendedTutorials/Bridge.cpp b/examples/ExtendedTutorials/Bridge.cpp new file mode 100644 index 000000000..269b5c4d0 --- /dev/null +++ b/examples/ExtendedTutorials/Bridge.cpp @@ -0,0 +1,150 @@ +/* +Bullet Continuous Collision Detection and Physics Library +Copyright (c) 2015 Google Inc. http://bulletphysics.org + +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. +*/ + + + +#include "Bridge.h" + +#include "btBulletDynamicsCommon.h" +#include "LinearMath/btVector3.h" +#include "LinearMath/btAlignedObjectArray.h" +#include "../CommonInterfaces/CommonRigidBodyBase.h" + +const int TOTAL_PLANKS = 10; +struct BridgeExample : public CommonRigidBodyBase +{ + BridgeExample(struct GUIHelperInterface* helper) + :CommonRigidBodyBase(helper) + { + } + virtual ~BridgeExample(){} + virtual void initPhysics(); + virtual void renderScene(); + void resetCamera() + { + float dist = 41; + float pitch = 52; + float yaw = 35; + float targetPos[3]={0,0.46,0}; + m_guiHelper->resetCamera(dist,pitch,yaw,targetPos[0],targetPos[1],targetPos[2]); + } +}; + +void BridgeExample::initPhysics() +{ + m_guiHelper->setUpAxis(1); + + createEmptyDynamicsWorld(); + + m_guiHelper->createPhysicsDebugDrawer(m_dynamicsWorld); + + if (m_dynamicsWorld->getDebugDrawer()) + m_dynamicsWorld->getDebugDrawer()->setDebugMode(btIDebugDraw::DBG_DrawWireframe+btIDebugDraw::DBG_DrawContactPoints); + + ///create a few basic rigid bodies + btBoxShape* groundShape = createBoxShape(btVector3(btScalar(50.),btScalar(50.),btScalar(50.))); + m_collisionShapes.push_back(groundShape); + + btTransform groundTransform; + groundTransform.setIdentity(); + groundTransform.setOrigin(btVector3(0,-50,0)); + { + btScalar mass(0.); + createRigidBody(mass,groundTransform,groundShape, btVector4(0,0,1,1)); + } + + //create two fixed boxes to hold the planks + + + + { + //create a few dynamic rigidbodies + // Re-using the same collision is better for memory usage and performance + btScalar plankWidth = 0.4; + btScalar plankHeight = 0.2; + btScalar plankBreadth = 1; + btScalar plankOffset = plankWidth; //distance between two planks + btScalar bridgeWidth = plankWidth*TOTAL_PLANKS + plankOffset*(TOTAL_PLANKS-1); + btScalar bridgeHeight = 5; + btScalar halfBridgeWidth = bridgeWidth*0.5f; + + btBoxShape* colShape = createBoxShape(btVector3(plankWidth,plankHeight,plankBreadth)); + + 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); + + //create a set of boxes to represent bridge + btAlignedObjectArray boxes; + int lastBoxIndex = TOTAL_PLANKS-1; + for(int i=0;iaddConstraint(leftSpring); + + btPoint2PointConstraint* rightSpring = new btPoint2PointConstraint(*b1, *b2, btVector3(-0.5,0,0.5), btVector3(0.5,0,0.5)); + m_dynamicsWorld->addConstraint(rightSpring); + } + } + + m_guiHelper->autogenerateGraphicsObjects(m_dynamicsWorld); +} + + +void BridgeExample::renderScene() +{ + CommonRigidBodyBase::renderScene(); +} + + + + + + + +CommonExampleInterface* ET_BridgeCreateFunc(CommonExampleOptions& options) +{ + return new BridgeExample(options.m_guiHelper); +} + + + diff --git a/examples/ExtendedTutorials/Bridge.h b/examples/ExtendedTutorials/Bridge.h new file mode 100644 index 000000000..5f8331183 --- /dev/null +++ b/examples/ExtendedTutorials/Bridge.h @@ -0,0 +1,22 @@ +/* +Bullet Continuous Collision Detection and Physics Library +Copyright (c) 2015 Google Inc. http://bulletphysics.org + +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. +*/ + +#ifndef ET_BRIDGE_EXAMPLE_H +#define ET_BRIDGE_EXAMPLE_H + +class CommonExampleInterface* ET_BridgeCreateFunc(struct CommonExampleOptions& options); + + +#endif //ET_BRIDGE_EXAMPLE_H diff --git a/examples/ExtendedTutorials/Chain.cpp b/examples/ExtendedTutorials/Chain.cpp new file mode 100644 index 000000000..e78952db9 --- /dev/null +++ b/examples/ExtendedTutorials/Chain.cpp @@ -0,0 +1,137 @@ +/* +Bullet Continuous Collision Detection and Physics Library +Copyright (c) 2015 Google Inc. http://bulletphysics.org + +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. +*/ + + + +#include "Chain.h" + +#include "btBulletDynamicsCommon.h" +#include "LinearMath/btVector3.h" +#include "LinearMath/btAlignedObjectArray.h" +#include "../CommonInterfaces/CommonRigidBodyBase.h" + +const int TOTAL_BOXES = 10; +struct ChainExample : public CommonRigidBodyBase +{ + ChainExample(struct GUIHelperInterface* helper) + :CommonRigidBodyBase(helper) + { + } + virtual ~ChainExample(){} + virtual void initPhysics(); + virtual void renderScene(); + void resetCamera() + { + float dist = 41; + float pitch = 52; + float yaw = 35; + float targetPos[3]={0,0.46,0}; + m_guiHelper->resetCamera(dist,pitch,yaw,targetPos[0],targetPos[1],targetPos[2]); + } +}; + +void ChainExample::initPhysics() +{ + m_guiHelper->setUpAxis(1); + + createEmptyDynamicsWorld(); + + m_guiHelper->createPhysicsDebugDrawer(m_dynamicsWorld); + + if (m_dynamicsWorld->getDebugDrawer()) + m_dynamicsWorld->getDebugDrawer()->setDebugMode(btIDebugDraw::DBG_DrawWireframe+btIDebugDraw::DBG_DrawContactPoints); + + ///create a few basic rigid bodies + btBoxShape* groundShape = createBoxShape(btVector3(btScalar(50.),btScalar(50.),btScalar(50.))); + m_collisionShapes.push_back(groundShape); + + btTransform groundTransform; + groundTransform.setIdentity(); + groundTransform.setOrigin(btVector3(0,-50,0)); + { + btScalar mass(0.); + createRigidBody(mass,groundTransform,groundShape, btVector4(0,0,1,1)); + } + + + { + //create a few dynamic rigidbodies + // Re-using the same collision is better for memory usage and performance + btBoxShape* colShape = createBoxShape(btVector3(1,1,0.25)); + + 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); + + btAlignedObjectArray boxes; + int lastBoxIndex = TOTAL_BOXES-1; + for(int i=0;iaddConstraint(leftSpring); + + btPoint2PointConstraint* rightSpring = new btPoint2PointConstraint(*b1, *b2, btVector3(0.5,1,0), btVector3(0.5,-1,0)); + + m_dynamicsWorld->addConstraint(rightSpring); + } + } + + m_guiHelper->autogenerateGraphicsObjects(m_dynamicsWorld); +} + + +void ChainExample::renderScene() +{ + CommonRigidBodyBase::renderScene(); +} + + + + + + + +CommonExampleInterface* ET_ChainCreateFunc(CommonExampleOptions& options) +{ + return new ChainExample(options.m_guiHelper); +} + + + diff --git a/examples/ExtendedTutorials/Chain.h b/examples/ExtendedTutorials/Chain.h new file mode 100644 index 000000000..b9cea1195 --- /dev/null +++ b/examples/ExtendedTutorials/Chain.h @@ -0,0 +1,22 @@ +/* +Bullet Continuous Collision Detection and Physics Library +Copyright (c) 2015 Google Inc. http://bulletphysics.org + +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. +*/ + +#ifndef ET_CHAIN_EXAMPLE_H +#define ET_CHAIN_EXAMPLE_H + +class CommonExampleInterface* ET_ChainCreateFunc(struct CommonExampleOptions& options); + + +#endif //ET_CHAIN_EXAMPLE_H diff --git a/examples/ExtendedTutorials/MultipleBoxes.cpp b/examples/ExtendedTutorials/MultipleBoxes.cpp new file mode 100644 index 000000000..c9555936a --- /dev/null +++ b/examples/ExtendedTutorials/MultipleBoxes.cpp @@ -0,0 +1,120 @@ +/* +Bullet Continuous Collision Detection and Physics Library +Copyright (c) 2015 Google Inc. http://bulletphysics.org + +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. +*/ + + + +#include "MultipleBoxes.h" + +#include "btBulletDynamicsCommon.h" +#include "LinearMath/btVector3.h" +#include "LinearMath/btAlignedObjectArray.h" +#include "../CommonInterfaces/CommonRigidBodyBase.h" + +const int TOTAL_BOXES = 10; +struct MultipleBoxesExample : public CommonRigidBodyBase +{ + MultipleBoxesExample(struct GUIHelperInterface* helper) + :CommonRigidBodyBase(helper) + { + } + virtual ~MultipleBoxesExample(){} + virtual void initPhysics(); + virtual void renderScene(); + void resetCamera() + { + float dist = 41; + float pitch = 52; + float yaw = 35; + float targetPos[3]={0,0.46,0}; + m_guiHelper->resetCamera(dist,pitch,yaw,targetPos[0],targetPos[1],targetPos[2]); + } +}; + +void MultipleBoxesExample::initPhysics() +{ + m_guiHelper->setUpAxis(1); + + createEmptyDynamicsWorld(); + + m_guiHelper->createPhysicsDebugDrawer(m_dynamicsWorld); + + if (m_dynamicsWorld->getDebugDrawer()) + m_dynamicsWorld->getDebugDrawer()->setDebugMode(btIDebugDraw::DBG_DrawWireframe+btIDebugDraw::DBG_DrawContactPoints); + + ///create a few basic rigid bodies + btBoxShape* groundShape = createBoxShape(btVector3(btScalar(50.),btScalar(50.),btScalar(50.))); + m_collisionShapes.push_back(groundShape); + + btTransform groundTransform; + groundTransform.setIdentity(); + groundTransform.setOrigin(btVector3(0,-50,0)); + { + btScalar mass(0.); + createRigidBody(mass,groundTransform,groundShape, btVector4(0,0,1,1)); + } + + + { + //create a few dynamic rigidbodies + // Re-using the same collision is better for memory usage and performance + btBoxShape* colShape = createBoxShape(btVector3(1,1,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 i=0;iautogenerateGraphicsObjects(m_dynamicsWorld); +} + + +void MultipleBoxesExample::renderScene() +{ + CommonRigidBodyBase::renderScene(); +} + + + + + + + +CommonExampleInterface* ET_MultipleBoxesCreateFunc(CommonExampleOptions& options) +{ + return new MultipleBoxesExample(options.m_guiHelper); +} + + + diff --git a/examples/ExtendedTutorials/MultipleBoxes.h b/examples/ExtendedTutorials/MultipleBoxes.h new file mode 100644 index 000000000..56e28b61d --- /dev/null +++ b/examples/ExtendedTutorials/MultipleBoxes.h @@ -0,0 +1,22 @@ +/* +Bullet Continuous Collision Detection and Physics Library +Copyright (c) 2015 Google Inc. http://bulletphysics.org + +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. +*/ + +#ifndef ET_MULTIPLE_BOXES_EXAMPLE_H +#define ET_MULTIPLE_BOXES_EXAMPLE_H + +class CommonExampleInterface* ET_MultipleBoxesCreateFunc(struct CommonExampleOptions& options); + + +#endif //ET_MULTIPLE_BOXES_EXAMPLE_H diff --git a/examples/ExtendedTutorials/RigidBodyFromObj.cpp b/examples/ExtendedTutorials/RigidBodyFromObj.cpp new file mode 100644 index 000000000..1a8835dfd --- /dev/null +++ b/examples/ExtendedTutorials/RigidBodyFromObj.cpp @@ -0,0 +1,159 @@ +/* +Bullet Continuous Collision Detection and Physics Library +Copyright (c) 2015 Google Inc. http://bulletphysics.org + +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. +*/ + + + +#include "RigidBodyFromObj.h" + +#include "btBulletDynamicsCommon.h" +#include "LinearMath/btVector3.h" +#include "LinearMath/btAlignedObjectArray.h" +#include "../CommonInterfaces/CommonRigidBodyBase.h" + +#include "../Utils/b3ResourcePath.h" +#include "Bullet3Common/b3FileUtils.h" +#include "../Importers/ImportObjDemo/LoadMeshFromObj.h" +#include "../OpenGLWindow/GLInstanceGraphicsShape.h" + + +struct RigidBodyFromObjExample : public CommonRigidBodyBase +{ + int m_options; + + RigidBodyFromObjExample(struct GUIHelperInterface* helper, int options) + :CommonRigidBodyBase(helper), + m_options(options) + { + } + virtual ~RigidBodyFromObjExample(){} + virtual void initPhysics(); + virtual void renderScene(); + void resetCamera() + { + float dist = 41; + float pitch = 52; + float yaw = 35; + float targetPos[3]={0,0.46,0}; + m_guiHelper->resetCamera(dist,pitch,yaw,targetPos[0],targetPos[1],targetPos[2]); + } +}; + +void RigidBodyFromObjExample::initPhysics() +{ + m_guiHelper->setUpAxis(1); + + createEmptyDynamicsWorld(); + + m_guiHelper->createPhysicsDebugDrawer(m_dynamicsWorld); + + //if (m_dynamicsWorld->getDebugDrawer()) + // m_dynamicsWorld->getDebugDrawer()->setDebugMode(btIDebugDraw::DBG_DrawWireframe+btIDebugDraw::DBG_DrawContactPoints); + + ///create a few basic rigid bodies + btBoxShape* groundShape = createBoxShape(btVector3(btScalar(50.),btScalar(50.),btScalar(50.))); + m_collisionShapes.push_back(groundShape); + + btTransform groundTransform; + groundTransform.setIdentity(); + groundTransform.setOrigin(btVector3(0,-50,0)); + { + btScalar mass(0.); + createRigidBody(mass,groundTransform,groundShape, btVector4(0,0,1,1)); + } + + //load our obj mesh + const char* fileName = "teddy.obj";//sphere8.obj";//sponza_closed.obj";//sphere8.obj"; + char relativeFileName[1024]; + if (b3ResourcePath::findResourcePath(fileName, relativeFileName, 1024)) + { + char pathPrefix[1024]; + b3FileUtils::extractPath(relativeFileName, pathPrefix, 1024); + } + + GLInstanceGraphicsShape* glmesh = LoadMeshFromObj(relativeFileName, ""); + printf("[INFO] Obj loaded: Extracted %d verticed from obj file [%s]\n", glmesh->m_numvertices, fileName); + + const GLInstanceVertex& v = glmesh->m_vertices->at(0); + btConvexHullShape* shape = new btConvexHullShape((const btScalar*)(&(v.xyzw[0])), glmesh->m_numvertices, sizeof(GLInstanceVertex)); + + shape->setLocalScaling(btVector3(0.1,0.1,0.1)); + + if (m_options & OptimizeConvexObj) + { + shape->optimizeConvexHull(); + } + + if (m_options & ComputePolyhedralFeatures) + { + shape->initializePolyhedralFeatures(); + } + + + + //shape->setMargin(0.001); + m_collisionShapes.push_back(shape); + + btTransform startTransform; + startTransform.setIdentity(); + + btScalar mass(1.f); + bool isDynamic = (mass != 0.f); + btVector3 localInertia(0,0,0); + if (isDynamic) + shape->calculateLocalInertia(mass,localInertia); + + btVector3 position(0,20,0); + startTransform.setOrigin(position); + btRigidBody* body = createRigidBody(mass,startTransform,shape); + + btVector3 color(1,1,1); + btVector3 scaling(0.1,0.1,0.1); + bool useConvexHullForRendering = ((m_options & ObjUseConvexHullForRendering)!=0); + + + if (!useConvexHullForRendering) + { + int shapeId = m_guiHelper->getRenderInterface()->registerShape(&glmesh->m_vertices->at(0).xyzw[0], + glmesh->m_numvertices, + &glmesh->m_indices->at(0), + glmesh->m_numIndices, + B3_GL_TRIANGLES,-1); + shape->setUserIndex(shapeId); + int renderInstance = m_guiHelper->getRenderInterface()->registerGraphicsInstance(shapeId,position,startTransform.getRotation(),color,scaling); + body->setUserIndex(renderInstance); + } + + m_guiHelper->autogenerateGraphicsObjects(m_dynamicsWorld); +} + + +void RigidBodyFromObjExample::renderScene() +{ + CommonRigidBodyBase::renderScene(); +} + + + + + + + +CommonExampleInterface* ET_RigidBodyFromObjCreateFunc(CommonExampleOptions& options) +{ + return new RigidBodyFromObjExample(options.m_guiHelper,options.m_option); +} + + + diff --git a/examples/ExtendedTutorials/RigidBodyFromObj.h b/examples/ExtendedTutorials/RigidBodyFromObj.h new file mode 100644 index 000000000..829e9e14a --- /dev/null +++ b/examples/ExtendedTutorials/RigidBodyFromObj.h @@ -0,0 +1,28 @@ +/* +Bullet Continuous Collision Detection and Physics Library +Copyright (c) 2015 Google Inc. http://bulletphysics.org + +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. +*/ + +#ifndef ET_RIGIDBODYFROMOBJ_EXAMPLE_H +#define ET_RIGIDBODYFROMOBJ_EXAMPLE_H + +enum ObjToRigidBodyOptionsEnum +{ + ObjUseConvexHullForRendering=1, + OptimizeConvexObj=2, + ComputePolyhedralFeatures=4, +}; +class CommonExampleInterface* ET_RigidBodyFromObjCreateFunc(struct CommonExampleOptions& options); + + +#endif //ET_RIGIDBODYFROMOBJ_EXAMPLE_H diff --git a/examples/ExtendedTutorials/SimpleBox.cpp b/examples/ExtendedTutorials/SimpleBox.cpp new file mode 100644 index 000000000..474a507f0 --- /dev/null +++ b/examples/ExtendedTutorials/SimpleBox.cpp @@ -0,0 +1,118 @@ +/* +Bullet Continuous Collision Detection and Physics Library +Copyright (c) 2015 Google Inc. http://bulletphysics.org + +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. +*/ + + + +#include "SimpleBox.h" + +#include "btBulletDynamicsCommon.h" +#include "LinearMath/btVector3.h" +#include "LinearMath/btAlignedObjectArray.h" +#include "../CommonInterfaces/CommonRigidBodyBase.h" + + +struct SimpleBoxExample : public CommonRigidBodyBase +{ + SimpleBoxExample(struct GUIHelperInterface* helper) + :CommonRigidBodyBase(helper) + { + } + virtual ~SimpleBoxExample(){} + virtual void initPhysics(); + virtual void renderScene(); + void resetCamera() + { + float dist = 41; + float pitch = 52; + float yaw = 35; + float targetPos[3]={0,0.46,0}; + m_guiHelper->resetCamera(dist,pitch,yaw,targetPos[0],targetPos[1],targetPos[2]); + } +}; + +void SimpleBoxExample::initPhysics() +{ + m_guiHelper->setUpAxis(1); + + createEmptyDynamicsWorld(); + + m_guiHelper->createPhysicsDebugDrawer(m_dynamicsWorld); + + if (m_dynamicsWorld->getDebugDrawer()) + m_dynamicsWorld->getDebugDrawer()->setDebugMode(btIDebugDraw::DBG_DrawWireframe+btIDebugDraw::DBG_DrawContactPoints); + + ///create a few basic rigid bodies + btBoxShape* groundShape = createBoxShape(btVector3(btScalar(50.),btScalar(50.),btScalar(50.))); + m_collisionShapes.push_back(groundShape); + + btTransform groundTransform; + groundTransform.setIdentity(); + groundTransform.setOrigin(btVector3(0,-50,0)); + { + btScalar mass(0.); + createRigidBody(mass,groundTransform,groundShape, btVector4(0,0,1,1)); + } + + + { + //create a few dynamic rigidbodies + // Re-using the same collision is better for memory usage and performance + btBoxShape* colShape = createBoxShape(btVector3(1,1,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); + + + startTransform.setOrigin(btVector3( + btScalar(0), + btScalar(20), + btScalar(0))); + createRigidBody(mass,startTransform,colShape); + } + + m_guiHelper->autogenerateGraphicsObjects(m_dynamicsWorld); +} + + +void SimpleBoxExample::renderScene() +{ + CommonRigidBodyBase::renderScene(); +} + + + + + + + +CommonExampleInterface* ET_SimpleBoxCreateFunc(CommonExampleOptions& options) +{ + return new SimpleBoxExample(options.m_guiHelper); +} + + + diff --git a/examples/ExtendedTutorials/SimpleBox.h b/examples/ExtendedTutorials/SimpleBox.h new file mode 100644 index 000000000..494b3fd03 --- /dev/null +++ b/examples/ExtendedTutorials/SimpleBox.h @@ -0,0 +1,22 @@ +/* +Bullet Continuous Collision Detection and Physics Library +Copyright (c) 2015 Google Inc. http://bulletphysics.org + +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. +*/ + +#ifndef ET_SIMPLE_BOX_EXAMPLE_H +#define ET_SIMPLE_BOX_EXAMPLE_H + +class CommonExampleInterface* ET_SimpleBoxCreateFunc(struct CommonExampleOptions& options); + + +#endif //ET_SIMPLE_BOX_EXAMPLE_H diff --git a/examples/ExtendedTutorials/SimpleCloth.cpp b/examples/ExtendedTutorials/SimpleCloth.cpp new file mode 100644 index 000000000..33a3815b1 --- /dev/null +++ b/examples/ExtendedTutorials/SimpleCloth.cpp @@ -0,0 +1,162 @@ +/* +Bullet Continuous Collision Detection and Physics Library +Copyright (c) 2015 Google Inc. http://bulletphysics.org + +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. +*/ + + + +#include "SimpleCloth.h" + +#include "btBulletDynamicsCommon.h" +#include "LinearMath/btVector3.h" +#include "LinearMath/btAlignedObjectArray.h" +#include "../CommonInterfaces/CommonRigidBodyBase.h" + +#include "BulletSoftBody/btSoftRigidDynamicsWorld.h" +#include "BulletSoftBody/btSoftBodyHelpers.h" +#include "BulletSoftBody/btSoftBodyRigidBodyCollisionConfiguration.h" + +struct SimpleClothExample : public CommonRigidBodyBase +{ + SimpleClothExample(struct GUIHelperInterface* helper) + :CommonRigidBodyBase(helper) + { + } + virtual ~SimpleClothExample(){} + virtual void initPhysics(); + virtual void renderScene(); + void createEmptyDynamicsWorld() + { + m_collisionConfiguration = new btSoftBodyRigidBodyCollisionConfiguration(); + m_dispatcher = new btCollisionDispatcher(m_collisionConfiguration); + + m_broadphase = new btDbvtBroadphase(); + + m_solver = new btSequentialImpulseConstraintSolver; + + m_dynamicsWorld = new btSoftRigidDynamicsWorld(m_dispatcher, m_broadphase, m_solver, m_collisionConfiguration); + m_dynamicsWorld->setGravity(btVector3(0, -10, 0)); + + softBodyWorldInfo.m_broadphase = m_broadphase; + softBodyWorldInfo.m_dispatcher = m_dispatcher; + softBodyWorldInfo.m_gravity = m_dynamicsWorld->getGravity(); + softBodyWorldInfo.m_sparsesdf.Initialize(); + } + virtual btSoftRigidDynamicsWorld* getSoftDynamicsWorld() + { + ///just make it a btSoftRigidDynamicsWorld please + ///or we will add type checking + return (btSoftRigidDynamicsWorld*) m_dynamicsWorld; + } + void resetCamera() + { + float dist = 41; + float pitch = 52; + float yaw = 35; + float targetPos[3]={0,0.46,0}; + m_guiHelper->resetCamera(dist,pitch,yaw,targetPos[0],targetPos[1],targetPos[2]); + } + + void createSoftBody(const btScalar size, const int num_x, const int num_z, const int fixed=1+2); + btSoftBodyWorldInfo softBodyWorldInfo; +}; + +void SimpleClothExample::initPhysics() +{ + m_guiHelper->setUpAxis(1); + + createEmptyDynamicsWorld(); + + m_guiHelper->createPhysicsDebugDrawer(m_dynamicsWorld); + + if (m_dynamicsWorld->getDebugDrawer()) + m_dynamicsWorld->getDebugDrawer()->setDebugMode(btIDebugDraw::DBG_DrawWireframe+btIDebugDraw::DBG_DrawContactPoints); + + ///create a few basic rigid bodies + btBoxShape* groundShape = createBoxShape(btVector3(btScalar(50.),btScalar(50.),btScalar(50.))); + m_collisionShapes.push_back(groundShape); + + btTransform groundTransform; + groundTransform.setIdentity(); + groundTransform.setOrigin(btVector3(0,-50,0)); + { + btScalar mass(0.); + createRigidBody(mass,groundTransform,groundShape, btVector4(0,0,1,1)); + } + + + { + const btScalar s=4; //size of cloth patch + const int NUM_X=31; //vertices on X axis + const int NUM_Z=31; //vertices on Z axis + createSoftBody(s,NUM_X, NUM_Z); + } + + m_guiHelper->autogenerateGraphicsObjects(m_dynamicsWorld); +} + +void SimpleClothExample::createSoftBody(const btScalar s, + const int numX, + const int numY, + const int fixed) { + + + + btSoftBody* cloth=btSoftBodyHelpers::CreatePatch(softBodyWorldInfo, + btVector3(-s/2,s+1,0), + btVector3(+s/2,s+1,0), + btVector3(-s/2,s+1,+s), + btVector3(+s/2,s+1,+s), + numX,numY, + fixed,true); + + cloth->getCollisionShape()->setMargin(0.001f); + cloth->generateBendingConstraints(2,cloth->appendMaterial()); + cloth->setTotalMass(10); + //cloth->m_cfg.citerations = 10; +// cloth->m_cfg.diterations = 10; + cloth->m_cfg.piterations = 5; + cloth->m_cfg.kDP = 0.005f; + getSoftDynamicsWorld()->addSoftBody(cloth); + +} + +void SimpleClothExample::renderScene() +{ + CommonRigidBodyBase::renderScene(); + btSoftRigidDynamicsWorld* softWorld = getSoftDynamicsWorld(); + + for ( int i=0;igetSoftBodyArray().size();i++) + { + btSoftBody* psb=(btSoftBody*)softWorld->getSoftBodyArray()[i]; + //if (softWorld->getDebugDrawer() && !(softWorld->getDebugDrawer()->getDebugMode() & (btIDebugDraw::DBG_DrawWireframe))) + { + btSoftBodyHelpers::DrawFrame(psb,softWorld->getDebugDrawer()); + btSoftBodyHelpers::Draw(psb,softWorld->getDebugDrawer(),softWorld->getDrawFlags()); + } + } +} + + + + + + + +CommonExampleInterface* ET_SimpleClothCreateFunc(CommonExampleOptions& options) +{ + return new SimpleClothExample(options.m_guiHelper); +} + + + diff --git a/examples/ExtendedTutorials/SimpleCloth.h b/examples/ExtendedTutorials/SimpleCloth.h new file mode 100644 index 000000000..d956833e9 --- /dev/null +++ b/examples/ExtendedTutorials/SimpleCloth.h @@ -0,0 +1,22 @@ +/* +Bullet Continuous Collision Detection and Physics Library +Copyright (c) 2015 Google Inc. http://bulletphysics.org + +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. +*/ + +#ifndef ET_SIMPLE_CLOTH_EXAMPLE_H +#define ET_SIMPLE_CLOTH_EXAMPLE_H + +class CommonExampleInterface* ET_SimpleClothCreateFunc(struct CommonExampleOptions& options); + + +#endif //ET_SIMPLE_CLOTH_EXAMPLE_H diff --git a/examples/ExtendedTutorials/SimpleJoint.cpp b/examples/ExtendedTutorials/SimpleJoint.cpp new file mode 100644 index 000000000..da30449b4 --- /dev/null +++ b/examples/ExtendedTutorials/SimpleJoint.cpp @@ -0,0 +1,133 @@ +/* +Bullet Continuous Collision Detection and Physics Library +Copyright (c) 2015 Google Inc. http://bulletphysics.org + +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. +*/ + + + +#include "SimpleJoint.h" + +#include "btBulletDynamicsCommon.h" +#include "LinearMath/btVector3.h" +#include "LinearMath/btAlignedObjectArray.h" +#include "../CommonInterfaces/CommonRigidBodyBase.h" + + +struct SimpleJointExample : public CommonRigidBodyBase +{ + SimpleJointExample(struct GUIHelperInterface* helper) + :CommonRigidBodyBase(helper) + { + } + virtual ~SimpleJointExample(){} + virtual void initPhysics(); + virtual void renderScene(); + void resetCamera() + { + float dist = 41; + float pitch = 52; + float yaw = 35; + float targetPos[3]={0,0.46,0}; + m_guiHelper->resetCamera(dist,pitch,yaw,targetPos[0],targetPos[1],targetPos[2]); + } +}; + +void SimpleJointExample::initPhysics() +{ + m_guiHelper->setUpAxis(1); + + createEmptyDynamicsWorld(); + + m_guiHelper->createPhysicsDebugDrawer(m_dynamicsWorld); + + if (m_dynamicsWorld->getDebugDrawer()) + m_dynamicsWorld->getDebugDrawer()->setDebugMode(btIDebugDraw::DBG_DrawWireframe+btIDebugDraw::DBG_DrawContactPoints); + + ///create a few basic rigid bodies + btBoxShape* groundShape = createBoxShape(btVector3(btScalar(50.),btScalar(50.),btScalar(50.))); + m_collisionShapes.push_back(groundShape); + + btTransform groundTransform; + groundTransform.setIdentity(); + groundTransform.setOrigin(btVector3(0,-50,0)); + { + btScalar mass(0.); + createRigidBody(mass,groundTransform,groundShape, btVector4(0,0,1,1)); + } + + + { + //create a few dynamic rigidbodies + // Re-using the same collision is better for memory usage and performance + btBoxShape* colShape = createBoxShape(btVector3(1,1,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); + + + startTransform.setOrigin(btVector3( + btScalar(0), + btScalar(10), + btScalar(0))); + btRigidBody* dynamicBox = createRigidBody(mass,startTransform,colShape); + + //create a static rigid body + mass = 0; + startTransform.setOrigin(btVector3( + btScalar(0), + btScalar(20), + btScalar(0))); + + btRigidBody* staticBox = createRigidBody(mass,startTransform,colShape); + + //create a simple p2pjoint constraint + btPoint2PointConstraint* p2p = new btPoint2PointConstraint(*dynamicBox, *staticBox, btVector3(0,3,0), btVector3(0,0,0)); + p2p->m_setting.m_damping = 0.0625; + p2p->m_setting.m_impulseClamp = 0.95; + m_dynamicsWorld->addConstraint(p2p); + } + + m_guiHelper->autogenerateGraphicsObjects(m_dynamicsWorld); +} + + +void SimpleJointExample::renderScene() +{ + CommonRigidBodyBase::renderScene(); +} + + + + + + + +CommonExampleInterface* ET_SimpleJointCreateFunc(CommonExampleOptions& options) +{ + return new SimpleJointExample(options.m_guiHelper); +} + + + diff --git a/examples/ExtendedTutorials/SimpleJoint.h b/examples/ExtendedTutorials/SimpleJoint.h new file mode 100644 index 000000000..a3d245a23 --- /dev/null +++ b/examples/ExtendedTutorials/SimpleJoint.h @@ -0,0 +1,22 @@ +/* +Bullet Continuous Collision Detection and Physics Library +Copyright (c) 2015 Google Inc. http://bulletphysics.org + +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. +*/ + +#ifndef ET_SIMPLE_JOINT_EXAMPLE_H +#define ET_SIMPLE_JOINT_EXAMPLE_H + +class CommonExampleInterface* ET_SimpleJointCreateFunc(struct CommonExampleOptions& options); + + +#endif //ET_SIMPLE_JOINT_EXAMPLE_H diff --git a/examples/HelloWorld/HelloWorld.cpp b/examples/HelloWorld/HelloWorld.cpp index f7a195746..e51e6d541 100644 --- a/examples/HelloWorld/HelloWorld.cpp +++ b/examples/HelloWorld/HelloWorld.cpp @@ -44,20 +44,24 @@ int main(int argc, char** argv) ///-----initialization_end----- - ///create a few basic rigid bodies - btCollisionShape* groundShape = new btBoxShape(btVector3(btScalar(50.),btScalar(50.),btScalar(50.))); - //keep track of the shapes, we release memory at exit. //make sure to re-use collision shapes among rigid bodies whenever possible! btAlignedObjectArray collisionShapes; - collisionShapes.push_back(groundShape); - btTransform groundTransform; - groundTransform.setIdentity(); - groundTransform.setOrigin(btVector3(0,-56,0)); + ///create a few basic rigid bodies + //the ground is a cube of side 100 at position y = -56. + //the sphere will hit it at y = -6, with center at -5 { + btCollisionShape* groundShape = new btBoxShape(btVector3(btScalar(50.),btScalar(50.),btScalar(50.))); + + collisionShapes.push_back(groundShape); + + btTransform groundTransform; + groundTransform.setIdentity(); + groundTransform.setOrigin(btVector3(0,-56,0)); + btScalar mass(0.); //rigidbody is dynamic if and only if mass is non zero, otherwise static @@ -113,7 +117,7 @@ int main(int argc, char** argv) ///-----stepsimulation_start----- - for (i=0;i<100;i++) + for (i=0;i<150;i++) { dynamicsWorld->stepSimulation(1.f/60.f,10); @@ -178,9 +182,5 @@ int main(int argc, char** argv) //next line is optional: it will be cleared by the destructor when the array goes out of scope collisionShapes.clear(); - - ///-----cleanup_end----- - printf("Press a key to exit\n"); - getchar(); } diff --git a/examples/Importers/ImportColladaDemo/LoadMeshFromCollada.cpp b/examples/Importers/ImportColladaDemo/LoadMeshFromCollada.cpp index f5a70a0cf..b9a9479e0 100644 --- a/examples/Importers/ImportColladaDemo/LoadMeshFromCollada.cpp +++ b/examples/Importers/ImportColladaDemo/LoadMeshFromCollada.cpp @@ -20,7 +20,7 @@ subject to the following restrictions: #include //fopen #include "Bullet3Common/b3AlignedObjectArray.h" #include -#include "tinyxml/tinyxml.h" +#include "../../ThirdPartyLibs/tinyxml/tinyxml.h" #include "Bullet3Common/b3FileUtils.h" #include "LinearMath/btHashMap.h" diff --git a/examples/Importers/ImportColladaDemo/LoadMeshFromCollada.h b/examples/Importers/ImportColladaDemo/LoadMeshFromCollada.h index c65666f8b..2e939b575 100644 --- a/examples/Importers/ImportColladaDemo/LoadMeshFromCollada.h +++ b/examples/Importers/ImportColladaDemo/LoadMeshFromCollada.h @@ -21,7 +21,7 @@ subject to the following restrictions: #include "LinearMath/btAlignedObjectArray.h" #include "LinearMath/btTransform.h" -#include "../OpenGLWindow/GLInstanceGraphicsShape.h" +#include "../../OpenGLWindow/GLInstanceGraphicsShape.h" #include "ColladaGraphicsInstance.h" diff --git a/examples/Importers/ImportObjDemo/ImportObjExample.cpp b/examples/Importers/ImportObjDemo/ImportObjExample.cpp index db6ef97e0..26b0e95e8 100644 --- a/examples/Importers/ImportObjDemo/ImportObjExample.cpp +++ b/examples/Importers/ImportObjDemo/ImportObjExample.cpp @@ -101,7 +101,7 @@ void ImportObjSetup::initPhysics() const char* filename = shape.material.diffuse_texname.c_str(); const unsigned char* image=0; - const char* prefix[]={"./","./data/","../data/","../../data/","../../../data/","../../../../data/"}; + const char* prefix[]={ pathPrefix,"./","./data/","../data/","../../data/","../../../data/","../../../../data/"}; int numprefix = sizeof(prefix)/sizeof(const char*); for (int i=0;!image && i //fopen #include "Bullet3Common/b3AlignedObjectArray.h" #include diff --git a/examples/Importers/ImportObjDemo/Wavefront2GLInstanceGraphicsShape.cpp b/examples/Importers/ImportObjDemo/Wavefront2GLInstanceGraphicsShape.cpp index c1b417ec9..c57dabf8b 100644 --- a/examples/Importers/ImportObjDemo/Wavefront2GLInstanceGraphicsShape.cpp +++ b/examples/Importers/ImportObjDemo/Wavefront2GLInstanceGraphicsShape.cpp @@ -1,12 +1,12 @@ #include "Wavefront2GLInstanceGraphicsShape.h" -#include "../OpenGLWindow/GLInstancingRenderer.h" -#include "../OpenGLWindow/GLInstanceGraphicsShape.h" +#include "../../OpenGLWindow/GLInstancingRenderer.h" +#include "../../OpenGLWindow/GLInstanceGraphicsShape.h" #include "btBulletDynamicsCommon.h" -#include "../OpenGLWindow/SimpleOpenGL3App.h" +#include "../../OpenGLWindow/SimpleOpenGL3App.h" #include "Wavefront2GLInstanceGraphicsShape.h" -#include "../OpenGLWindow/GLInstancingRenderer.h" -#include "../OpenGLWindow/GLInstanceGraphicsShape.h" +#include "../../OpenGLWindow/GLInstancingRenderer.h" +#include "../../OpenGLWindow/GLInstanceGraphicsShape.h" GLInstanceGraphicsShape* btgCreateGraphicsShapeFromWavefrontObj(std::vector& shapes) { diff --git a/examples/Importers/ImportObjDemo/Wavefront2GLInstanceGraphicsShape.h b/examples/Importers/ImportObjDemo/Wavefront2GLInstanceGraphicsShape.h index c93d1c465..a2b129bea 100644 --- a/examples/Importers/ImportObjDemo/Wavefront2GLInstanceGraphicsShape.h +++ b/examples/Importers/ImportObjDemo/Wavefront2GLInstanceGraphicsShape.h @@ -1,7 +1,7 @@ #ifndef WAVEFRONT2GRAPHICS_H #define WAVEFRONT2GRAPHICS_H -#include"Wavefront/tiny_obj_loader.h" +#include"../../ThirdPartyLibs/Wavefront/tiny_obj_loader.h" #include struct GLInstanceGraphicsShape* btgCreateGraphicsShapeFromWavefrontObj(std::vector& shapes); diff --git a/examples/Importers/ImportSDFDemo/ImportSDFSetup.cpp b/examples/Importers/ImportSDFDemo/ImportSDFSetup.cpp new file mode 100644 index 000000000..b95f528a9 --- /dev/null +++ b/examples/Importers/ImportSDFDemo/ImportSDFSetup.cpp @@ -0,0 +1,302 @@ + +#include "ImportSDFSetup.h" +#include "BulletDynamics/ConstraintSolver/btGeneric6DofSpring2Constraint.h" + + +#include "BulletDynamics/Featherstone/btMultiBodyLinkCollider.h" +#include "Bullet3Common/b3FileUtils.h" + +#include "BulletDynamics/Featherstone/btMultiBodyJointMotor.h" +#include "BulletDynamics/Featherstone/btMultiBodyDynamicsWorld.h" +#include "../CommonInterfaces/CommonParameterInterface.h" +#include "../../Utils/b3ResourcePath.h" + +#include "../ImportURDFDemo/BulletUrdfImporter.h" + + +#include "../ImportURDFDemo/URDF2Bullet.h" + + +//#include "urdf_samples.h" + + + + + +#include "../CommonInterfaces/CommonMultiBodyBase.h" + +#include "../ImportURDFDemo/MyMultiBodyCreator.h" + + +class ImportSDFSetup : public CommonMultiBodyBase +{ + char m_fileName[1024]; + + struct ImportSDFInternalData* m_data; + bool m_useMultiBody; + + //todo(erwincoumans) we need a name memory for each model + btAlignedObjectArray m_nameMemory; + +public: + ImportSDFSetup(struct GUIHelperInterface* helper, int option, const char* fileName); + virtual ~ImportSDFSetup(); + + virtual void initPhysics(); + virtual void stepSimulation(float deltaTime); + + void setFileName(const char* urdfFileName); + + virtual void resetCamera() + { + float dist = 3.5; + float pitch = -136; + float yaw = 28; + float targetPos[3]={0.47,0,-0.64}; + m_guiHelper->resetCamera(dist,pitch,yaw,targetPos[0],targetPos[1],targetPos[2]); + } +}; + + +static btAlignedObjectArray gFileNameArray; + + +#define MAX_NUM_MOTORS 1024 + +struct ImportSDFInternalData +{ + ImportSDFInternalData() + :m_numMotors(0) + { + for (int i=0;i=numFileNames) + { + count=0; + } + sprintf(m_fileName,"%s",gFileNameArray[count++].c_str()); + } +} + +ImportSDFSetup::~ImportSDFSetup() +{ + for (int i=0;isetUpAxis(upAxis); + + this->createEmptyDynamicsWorld(); + //m_dynamicsWorld->getSolverInfo().m_numIterations = 100; + m_guiHelper->createPhysicsDebugDrawer(m_dynamicsWorld); + m_dynamicsWorld->getDebugDrawer()->setDebugMode( + btIDebugDraw::DBG_DrawConstraints + +btIDebugDraw::DBG_DrawContactPoints + +btIDebugDraw::DBG_DrawAabb + );//+btIDebugDraw::DBG_DrawConstraintLimits); + + + btVector3 gravity(0,0,0); + gravity[upAxis]=-9.8; + + m_dynamicsWorld->setGravity(gravity); + + BulletURDFImporter u2b(m_guiHelper); + + bool loadOk = u2b.loadSDF(m_fileName); + + + if (loadOk) + { + //printTree(u2b,u2b.getRootLinkIndex()); + + //u2b.printTree(); + + btTransform identityTrans; + identityTrans.setIdentity(); + + + + for (int m =0; m