From fb65c290330f0d53dc949773702be611edc0d0cf Mon Sep 17 00:00:00 2001 From: Erwin Coumans Date: Tue, 3 May 2016 12:59:21 -0700 Subject: [PATCH 01/10] use "world" to make door static (instead of using mass = 0) minor improvements to pybullet --- data/door.urdf | 11 ++- examples/pybullet/pybullet.c | 130 ++++++++++++++++++++++++++--------- 2 files changed, 105 insertions(+), 36 deletions(-) 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/examples/pybullet/pybullet.c b/examples/pybullet/pybullet.c index 24cec5b7d..9bea19d17 100644 --- a/examples/pybullet/pybullet.c +++ b/examples/pybullet/pybullet.c @@ -8,15 +8,21 @@ #endif static PyObject *SpamError; -static b3PhysicsClientHandle sm; +static b3PhysicsClientHandle sm=0; + static PyObject * -spam_step(PyObject *self, PyObject *args) +pybullet_stepSimulation(PyObject *self, PyObject *args) { + if (0==sm) + { + PyErr_SetString(SpamError, "Not connected to physics server."); + return NULL; + } { - b3SharedMemoryStatusHandle statusHandle; - int statusType; + b3SharedMemoryStatusHandle statusHandle; + int statusType; if (b3CanSubmitCommand(sm)) { @@ -29,15 +35,53 @@ return PyLong_FromLong(1); } static PyObject * -spam_loadURDF(PyObject* self, PyObject* args) +pybullet_connectPhysicsServer(PyObject *self, PyObject *args) { + if (0!=sm) + { + PyErr_SetString(SpamError, "Already connected to physics server, disconnect first."); + return NULL; + } + + { + sm = b3ConnectSharedMemory(SHARED_MEMORY_KEY); + } + + return PyLong_FromLong(1); +} + +static PyObject * +pybullet_disconnectPhysicsServer(PyObject *self, PyObject *args) +{ + if (0==sm) + { + PyErr_SetString(SpamError, "Not connected to physics server."); + return NULL; + } + { + b3DisconnectSharedMemory(sm); + sm = 0; + } + + return PyLong_FromLong(1); +} + + +static PyObject * +pybullet_loadURDF(PyObject* self, PyObject* args) +{ + if (0==sm) + { + PyErr_SetString(SpamError, "Not connected to physics server."); + return NULL; + } int size= PySequence_Size(args); int bodyIndex = -1; const char* urdfFileName=0; float startPosX =0; - float startPosY =0; - float startPosZ = 1; + float startPosY =0; + float startPosZ = 1; float startOrnX = 0; float startOrnY = 0; float startOrnZ = 0; @@ -61,29 +105,56 @@ spam_loadURDF(PyObject* self, PyObject* args) &startOrnX,&startOrnY,&startOrnZ, &startOwnW)) return NULL; } - printf("urdf filename = %s\n", urdfFileName); - b3SharedMemoryStatusHandle statusHandle; - int statusType; - b3SharedMemoryCommandHandle command = b3LoadUrdfCommandInit(sm, urdfFileName); + { + printf("urdf filename = %s\n", urdfFileName); + b3SharedMemoryStatusHandle statusHandle; + int statusType; + b3SharedMemoryCommandHandle command = b3LoadUrdfCommandInit(sm, urdfFileName); - //setting the initial position, orientation and other arguments are optional - int ret = b3LoadUrdfCommandSetStartPosition(command, startPosX,startPosY,startPosZ); - statusHandle = b3SubmitClientCommandAndWaitStatus(sm, command); - statusType = b3GetStatusType(statusHandle); - if (statusType!=CMD_URDF_LOADING_COMPLETED) - { - PyErr_SetString(SpamError, "Cannot load URDF file."); - return NULL; - } - bodyIndex = b3GetStatusBodyIndex(statusHandle); + //setting the initial position, orientation and other arguments are optional + b3LoadUrdfCommandSetStartPosition(command, startPosX,startPosY,startPosZ); + statusHandle = b3SubmitClientCommandAndWaitStatus(sm, command); + statusType = b3GetStatusType(statusHandle); + if (statusType!=CMD_URDF_LOADING_COMPLETED) + { + PyErr_SetString(SpamError, "Cannot load URDF file."); + return NULL; + } + bodyIndex = b3GetStatusBodyIndex(statusHandle); + } return PyLong_FromLong(bodyIndex); } +static PyObject * +pybullet_resetSimulation(PyObject* self, PyObject* args) +{ + if (0==sm) + { + PyErr_SetString(SpamError, "Not connected to physics server."); + return NULL; + } + + { + b3SharedMemoryStatusHandle statusHandle; + statusHandle = b3SubmitClientCommandAndWaitStatus(sm, b3InitResetSimulationCommand(sm)); +// ASSERT_EQ(b3GetStatusType(statusHandle), CMD_RESET_SIMULATION_COMPLETED); + } +} static PyMethodDef SpamMethods[] = { - {"step", spam_step, METH_VARARGS, - "Step the simulation forward."}, -{"loadURDF", spam_loadURDF, METH_VARARGS, - "Create a multibody by loading a URDF file."}, + {"loadURDF", pybullet_loadURDF, METH_VARARGS, + "Create a multibody by loading a URDF file."}, + + {"connect", pybullet_connectPhysicsServer, METH_VARARGS, + "Connect to an existing physics server (using shared memory by default)."}, + {"disconnect", pybullet_disconnectPhysicsServer, METH_VARARGS, + "Disconnect from the physics server."}, + + {"resetSimulation", pybullet_resetSimulation, METH_VARARGS, + "Reset the simulation: remove all objects and start from an empty world."}, + + {"stepSimulation", pybullet_stepSimulation, METH_VARARGS, + "Step the simulation using forward dynamics."}, + {NULL, NULL, 0, NULL} /* Sentinel */ }; @@ -92,16 +163,7 @@ PyMODINIT_FUNC initpybullet(void) { - b3PhysicsClientHandle h; - PyObject *m; -sm = b3ConnectSharedMemory(SHARED_MEMORY_KEY); - -//#ifdef __APPLE__ -//sm = b3CreateInProcessPhysicsServerAndConnectMainThread(0,0); -//#else -//sm = b3CreateInProcessPhysicsServerAndConnect(0,0); -//#endif m = Py_InitModule("pybullet", SpamMethods); if (m == NULL) return; From 709a55d5ab5378a7d3fced8940e262afde73d456 Mon Sep 17 00:00:00 2001 From: Erwin Coumans Date: Tue, 3 May 2016 13:02:06 -0700 Subject: [PATCH 02/10] add CMake support for pybullet (still preliminary) requires shared library build: cmake .. -DBUILD_SHARED_LIBS=on then create a symbolic link from libpybullet.so to pybullet.so --- examples/CMakeLists.txt | 2 +- examples/ExampleBrowser/CMakeLists.txt | 100 +++++++++++++++++-------- examples/pybullet/CMakeLists.txt | 24 ++++++ examples/pybullet/premake4.lua | 1 + 4 files changed, 93 insertions(+), 34 deletions(-) create mode 100644 examples/pybullet/CMakeLists.txt diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 4d26967f1..18c2f16c8 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -1,5 +1,5 @@ SUBDIRS( HelloWorld BasicDemo ) IF(BUILD_BULLET3) - SUBDIRS( ExampleBrowser ThirdPartyLibs/Gwen OpenGLWindow) + SUBDIRS( ExampleBrowser ThirdPartyLibs/Gwen OpenGLWindow pybullet) ENDIF() diff --git a/examples/ExampleBrowser/CMakeLists.txt b/examples/ExampleBrowser/CMakeLists.txt index 2e8de4868..8942c3ec7 100644 --- a/examples/ExampleBrowser/CMakeLists.txt +++ b/examples/ExampleBrowser/CMakeLists.txt @@ -1,21 +1,19 @@ - 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(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 +95,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 @@ -168,44 +168,76 @@ 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} ${BULLET_PHYSICS_SOURCE_DIR}/build3/bullet.rc ) +IF (WIN32) + INCLUDE_DIRECTORIES( + ${BULLET_PHYSICS_SOURCE_DIR}/examples/ThirdPartyLibs/Glew + ) + IF (BUILD_SHARED_LIBS) + TARGET_LINK_LIBRARIES( + Bullet3Common BulletSoftBody BulletDynamics BulletCollision BulletInverseDynamicsUtils + BulletInverseDynamics LinearMath OpenGLWindow gwen + ${OPENGL_gl_LIBRARY} ${OPENGL_glu_LIBRARY} + ) + ENDIF (BUILD_SHARED_LIBS) + ADD_DEFINITIONS(-DGLEW_STATIC) +ELSE(WIN32) + IF(APPLE) + find_library(COCOA NAMES Cocoa) + MESSAGE(${COCOA}) + IF (BUILD_SHARED_LIBS) + TARGET_LINK_LIBRARIES( + Bullet3Common BulletSoftBody BulletDynamics BulletCollision BulletInverseDynamicsUtils + BulletInverseDynamics LinearMath OpenGLWindow gwen + ${COCOA} ${OPENGL_gl_LIBRARY} ${OPENGL_glu_LIBRARY} + ) + ELSE(APPLE) + ENDIF (BUILD_SHARED_LIBS) + 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 ) + IF (BUILD_SHARED_LIBS) + TARGET_LINK_LIBRARIES( + Bullet3Common BulletSoftBody BulletDynamics BulletCollision BulletInverseDynamicsUtils + BulletInverseDynamics LinearMath OpenGLWindow gwen + pthread dl + ) + ENDIF(BUILD_SHARED_LIBS) + 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}) + +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,7 +261,9 @@ ENDIF(WIN32) ADD_EXECUTABLE(App_ExampleBrowser - ${App_ExampleBrowser_SRCS} + main.cpp + ExampleEntries.cpp + ExampleEntries.h ) diff --git a/examples/pybullet/CMakeLists.txt b/examples/pybullet/CMakeLists.txt new file mode 100644 index 000000000..db057eda9 --- /dev/null +++ b/examples/pybullet/CMakeLists.txt @@ -0,0 +1,24 @@ +IF (BUILD_SHARED_LIBS) + +INCLUDE_DIRECTORIES( + ${BULLET_PHYSICS_SOURCE_DIR}/src + ${BULLET_PHYSICS_SOURCE_DIR}/examples + ${BULLET_PHYSICS_SOURCE_DIR}/examples/ThirdPartyLibs + /usr/include/python2.7 + ) + +SET(pybullet_SRCS + pybullet.c + ../../examples/ExampleBrowser/ExampleEntries.cpp +) + + +ADD_LIBRARY(pybullet ${pybullet_SRCS}) + +SET_TARGET_PROPERTIES(pybullet PROPERTIES VERSION ${BULLET_VERSION}) +SET_TARGET_PROPERTIES(pybullet PROPERTIES SOVERSION ${BULLET_VERSION}) + + TARGET_LINK_LIBRARIES(pybullet BulletExampleBrowserLib BulletSoftBody BulletDynamics BulletCollision BulletInverseDynamicsUtils BulletInverseDynamics LinearMath OpenGLWindow gwen Bullet3Common) +ENDIF (BUILD_SHARED_LIBS) + + diff --git a/examples/pybullet/premake4.lua b/examples/pybullet/premake4.lua index da3da721c..39092b889 100644 --- a/examples/pybullet/premake4.lua +++ b/examples/pybullet/premake4.lua @@ -20,6 +20,7 @@ project ("pybullet") ".", "../../src", "../ThirdPartyLibs", + "/usr/include/python2.7", } From a9ef14591008a4a4347b78a104ce30d1cb047abd Mon Sep 17 00:00:00 2001 From: Erwin Coumans Date: Tue, 3 May 2016 21:27:30 -0700 Subject: [PATCH 03/10] add standalone opengl version of BasicExample for cmake, called BasicExampleGui --- examples/BasicDemo/CMakeLists.txt | 69 +++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) 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) + + From a251ff4331eacbbffcf6cb856c63752f2ad83ebc Mon Sep 17 00:00:00 2001 From: Erwin Coumans Date: Tue, 3 May 2016 21:48:28 -0700 Subject: [PATCH 04/10] add 'dl' target libs in cmake --- examples/OpenGLWindow/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/OpenGLWindow/CMakeLists.txt b/examples/OpenGLWindow/CMakeLists.txt index 1e95d87c6..f7f1db5ad 100644 --- a/examples/OpenGLWindow/CMakeLists.txt +++ b/examples/OpenGLWindow/CMakeLists.txt @@ -59,7 +59,7 @@ if (BUILD_SHARED_LIBS) else() set (CMAKE_THREAD_PREFER_PTHREAD TRUE) FIND_PACKAGE(Threads) - target_link_libraries(OpenGLWindow ${CMAKE_THREAD_LIBS_INIT}) + target_link_libraries(OpenGLWindow dl ${CMAKE_THREAD_LIBS_INIT}) endif() endif() From 7a833a7ac2528b834a7ae14b6d14e2c063e9c072 Mon Sep 17 00:00:00 2001 From: Erwin Coumans Date: Tue, 3 May 2016 22:05:30 -0700 Subject: [PATCH 05/10] fix target link libs in cmake --- examples/ExampleBrowser/CMakeLists.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/examples/ExampleBrowser/CMakeLists.txt b/examples/ExampleBrowser/CMakeLists.txt index 8942c3ec7..66fd7109f 100644 --- a/examples/ExampleBrowser/CMakeLists.txt +++ b/examples/ExampleBrowser/CMakeLists.txt @@ -187,7 +187,7 @@ IF (WIN32) ) IF (BUILD_SHARED_LIBS) TARGET_LINK_LIBRARIES( - Bullet3Common BulletSoftBody BulletDynamics BulletCollision BulletInverseDynamicsUtils + BulletExampleBrowserLib Bullet3Common BulletSoftBody BulletDynamics BulletCollision BulletInverseDynamicsUtils BulletInverseDynamics LinearMath OpenGLWindow gwen ${OPENGL_gl_LIBRARY} ${OPENGL_glu_LIBRARY} ) @@ -199,7 +199,7 @@ ELSE(WIN32) MESSAGE(${COCOA}) IF (BUILD_SHARED_LIBS) TARGET_LINK_LIBRARIES( - Bullet3Common BulletSoftBody BulletDynamics BulletCollision BulletInverseDynamicsUtils + BulletExampleBrowserLib Bullet3Common BulletSoftBody BulletDynamics BulletCollision BulletInverseDynamicsUtils BulletInverseDynamics LinearMath OpenGLWindow gwen ${COCOA} ${OPENGL_gl_LIBRARY} ${OPENGL_glu_LIBRARY} ) @@ -211,7 +211,7 @@ ELSE(WIN32) INCLUDE_DIRECTORIES( ${BULLET_PHYSICS_SOURCE_DIR}/examples/ThirdPartyLibs/Glew ) IF (BUILD_SHARED_LIBS) TARGET_LINK_LIBRARIES( - Bullet3Common BulletSoftBody BulletDynamics BulletCollision BulletInverseDynamicsUtils + BulletExampleBrowserLib Bullet3Common BulletSoftBody BulletDynamics BulletCollision BulletInverseDynamicsUtils BulletInverseDynamics LinearMath OpenGLWindow gwen pthread dl ) From 938db633dfaf377a0750bd2ddb6aeae2d30adb88 Mon Sep 17 00:00:00 2001 From: Erwin Coumans Date: Tue, 3 May 2016 23:34:48 -0700 Subject: [PATCH 06/10] fixes in build system --- examples/ExampleBrowser/CMakeLists.txt | 57 +++---- examples/ExampleBrowser/ExampleEntries.cpp | 20 +-- examples/ExampleBrowser/ExampleEntries.h | 44 ++++-- .../InProcessExampleBrowser.cpp | 141 +++++++++++++++++- examples/ExampleBrowser/main.cpp | 2 +- examples/pybullet/CMakeLists.txt | 2 +- examples/pybullet/pybullet.c | 2 + 7 files changed, 219 insertions(+), 49 deletions(-) diff --git a/examples/ExampleBrowser/CMakeLists.txt b/examples/ExampleBrowser/CMakeLists.txt index 66fd7109f..b3f06d557 100644 --- a/examples/ExampleBrowser/CMakeLists.txt +++ b/examples/ExampleBrowser/CMakeLists.txt @@ -185,44 +185,51 @@ IF (WIN32) INCLUDE_DIRECTORIES( ${BULLET_PHYSICS_SOURCE_DIR}/examples/ThirdPartyLibs/Glew ) - IF (BUILD_SHARED_LIBS) - TARGET_LINK_LIBRARIES( - BulletExampleBrowserLib Bullet3Common BulletSoftBody BulletDynamics BulletCollision BulletInverseDynamicsUtils - BulletInverseDynamics LinearMath OpenGLWindow gwen - ${OPENGL_gl_LIBRARY} ${OPENGL_glu_LIBRARY} - ) - ENDIF (BUILD_SHARED_LIBS) - ADD_DEFINITIONS(-DGLEW_STATIC) + ADD_DEFINITIONS(-DGLEW_STATIC) ELSE(WIN32) IF(APPLE) find_library(COCOA NAMES Cocoa) - MESSAGE(${COCOA}) - IF (BUILD_SHARED_LIBS) - TARGET_LINK_LIBRARIES( - BulletExampleBrowserLib Bullet3Common BulletSoftBody BulletDynamics BulletCollision BulletInverseDynamicsUtils - BulletInverseDynamics LinearMath OpenGLWindow gwen - ${COCOA} ${OPENGL_gl_LIBRARY} ${OPENGL_glu_LIBRARY} - ) - ELSE(APPLE) - ENDIF (BUILD_SHARED_LIBS) + 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 ) - IF (BUILD_SHARED_LIBS) - TARGET_LINK_LIBRARIES( - BulletExampleBrowserLib Bullet3Common BulletSoftBody BulletDynamics BulletCollision BulletInverseDynamicsUtils - BulletInverseDynamics LinearMath OpenGLWindow gwen - pthread dl - ) - ENDIF(BUILD_SHARED_LIBS) - ENDIF(APPLE) + 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( . diff --git a/examples/ExampleBrowser/ExampleEntries.cpp b/examples/ExampleBrowser/ExampleEntries.cpp index 36611663f..3ec1403d6 100644 --- a/examples/ExampleBrowser/ExampleEntries.cpp +++ b/examples/ExampleBrowser/ExampleEntries.cpp @@ -274,17 +274,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 @@ -297,7 +297,7 @@ void ExampleEntries::initOpenCLExampleEntries() #endif //B3_USE_CLEW } -void ExampleEntries::initExampleEntries() +void ExampleEntriesAll::initExampleEntries() { m_data->m_allExamples.clear(); @@ -330,33 +330,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/InProcessExampleBrowser.cpp b/examples/ExampleBrowser/InProcessExampleBrowser.cpp index d9be45726..97b0761c4 100644 --- a/examples/ExampleBrowser/InProcessExampleBrowser.cpp +++ b/examples/ExampleBrowser/InProcessExampleBrowser.cpp @@ -25,6 +25,143 @@ void* ExampleBrowserMemoryFunc(); #ifndef _WIN32 #include "../MultiThreading/b3PosixThreadSupport.h" +#include "ExampleEntries.h" +#include "LinearMath/btAlignedObjectArray.h" +#include "EmptyExample.h" + +#include "../SharedMemory/PhysicsServerExample.h" +#include "../SharedMemory/PhysicsClientExample.h" + + + + +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; +} + static b3ThreadSupportInterface* createExampleBrowserThreadSupport(int numThreads) { b3PosixThreadSupport::ThreadConstructionInfo constructionInfo("testThreads", @@ -91,7 +228,7 @@ void ExampleBrowserThreadFunc(void* userPtr,void* lsMemory) b3Clock clock; - ExampleEntries examples; + ExampleEntriesPhysicsServer examples; examples.initExampleEntries(); DefaultBrowser* exampleBrowser = new DefaultBrowser(&examples); @@ -231,7 +368,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/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/pybullet/CMakeLists.txt b/examples/pybullet/CMakeLists.txt index db057eda9..b5ee53a0e 100644 --- a/examples/pybullet/CMakeLists.txt +++ b/examples/pybullet/CMakeLists.txt @@ -18,7 +18,7 @@ ADD_LIBRARY(pybullet ${pybullet_SRCS}) SET_TARGET_PROPERTIES(pybullet PROPERTIES VERSION ${BULLET_VERSION}) SET_TARGET_PROPERTIES(pybullet PROPERTIES SOVERSION ${BULLET_VERSION}) - TARGET_LINK_LIBRARIES(pybullet BulletExampleBrowserLib BulletSoftBody BulletDynamics BulletCollision BulletInverseDynamicsUtils BulletInverseDynamics LinearMath OpenGLWindow gwen Bullet3Common) + TARGET_LINK_LIBRARIES(pybullet BulletExampleBrowserLib BulletSoftBody BulletDynamics BulletCollision BulletInverseDynamicsUtils BulletInverseDynamics LinearMath OpenGLWindow gwen Bullet3Common Python) ENDIF (BUILD_SHARED_LIBS) diff --git a/examples/pybullet/pybullet.c b/examples/pybullet/pybullet.c index 9bea19d17..f2b9c5500 100644 --- a/examples/pybullet/pybullet.c +++ b/examples/pybullet/pybullet.c @@ -138,6 +138,8 @@ pybullet_resetSimulation(PyObject* self, PyObject* args) statusHandle = b3SubmitClientCommandAndWaitStatus(sm, b3InitResetSimulationCommand(sm)); // ASSERT_EQ(b3GetStatusType(statusHandle), CMD_RESET_SIMULATION_COMPLETED); } + return PyLong_FromLong(1); + } static PyMethodDef SpamMethods[] = { From f0b9037cd2217394a82026e948dbcc6965f4412c Mon Sep 17 00:00:00 2001 From: Erwin Coumans Date: Tue, 3 May 2016 23:42:19 -0700 Subject: [PATCH 07/10] tweak cmake, add option BUILD_PYBULLET --- CMakeLists.txt | 1 + examples/CMakeLists.txt | 6 ++++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index cf653084a..7e3321091 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -191,6 +191,7 @@ 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_BULLET3) IF(APPLE) diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 18c2f16c8..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 pybullet) + SUBDIRS( ExampleBrowser ThirdPartyLibs/Gwen OpenGLWindow ) ENDIF() - +IF(BUILD_PYBULLET) + SUBDIRS(pybullet) +ENDIF(BUILD_PYBULLET) From 0d3440b3887bcc78968d2f4c4f84c3fed76231ee Mon Sep 17 00:00:00 2001 From: Erwin Coumans Date: Tue, 3 May 2016 23:46:29 -0700 Subject: [PATCH 08/10] fixes in Mac resizing example browser (if window size exceeds capability) --- .../CommonInterfaces/CommonWindowInterface.h | 4 ++- .../ExampleBrowser/OpenGLExampleBrowser.cpp | 18 ++++++----- examples/OpenGLWindow/MacOpenGLWindow.h | 3 ++ examples/OpenGLWindow/MacOpenGLWindow.mm | 19 ++++++++++-- examples/OpenGLWindow/SimpleOpenGL3App.cpp | 31 +++++++++++++------ 5 files changed, 55 insertions(+), 20 deletions(-) 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/OpenGLExampleBrowser.cpp b/examples/ExampleBrowser/OpenGLExampleBrowser.cpp index d8756f67e..c07e63a7c 100644 --- a/examples/ExampleBrowser/OpenGLExampleBrowser.cpp +++ b/examples/ExampleBrowser/OpenGLExampleBrowser.cpp @@ -695,8 +695,8 @@ bool OpenGLExampleBrowser::init(int argc, char* argv[]) } - int width = 1024; - int height=768; + int width = 1920; + int height=1080; #ifndef NO_OPENGL3 SimpleOpenGL3App* simpleApp=0; sUseOpenGL2 =args.CheckCmdLineFlag("opengl2"); @@ -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/OpenGLWindow/MacOpenGLWindow.h b/examples/OpenGLWindow/MacOpenGLWindow.h index f17102a8b..d84b031b4 100644 --- a/examples/OpenGLWindow/MacOpenGLWindow.h +++ b/examples/OpenGLWindow/MacOpenGLWindow.h @@ -101,6 +101,9 @@ public: virtual float getTimeInSeconds(); + virtual int getWidth() const; + virtual int getHeight() const; + virtual void setRenderCallback( b3RenderCallback renderCallback); diff --git a/examples/OpenGLWindow/MacOpenGLWindow.mm b/examples/OpenGLWindow/MacOpenGLWindow.mm index 818726971..d247f95b0 100644 --- a/examples/OpenGLWindow/MacOpenGLWindow.mm +++ b/examples/OpenGLWindow/MacOpenGLWindow.mm @@ -423,8 +423,8 @@ void MacOpenGLWindow::createWindow(const b3gWindowConstructionInfo& ci) [m_internalData->m_window makeKeyAndOrderFront: nil]; [m_internalData->m_myview MakeCurrent]; - //m_internalData->m_width = m_internalData->m_myview.GetWindowWidth; - //m_internalData->m_height = m_internalData->m_myview.GetWindowHeight; + m_internalData->m_width = m_internalData->m_myview.GetWindowWidth; + m_internalData->m_height = m_internalData->m_myview.GetWindowHeight; [NSApp activateIgnoringOtherApps:YES]; @@ -1132,6 +1132,21 @@ void MacOpenGLWindow::getMouseCoordinates(int& x, int& y) } +int MacOpenGLWindow::getWidth() const +{ + if (m_internalData && m_internalData->m_myview && m_internalData->m_myview.GetWindowWidth) + return m_internalData->m_myview.GetWindowWidth; + return 0; +} + +int MacOpenGLWindow::getHeight() const +{ + if (m_internalData && m_internalData->m_myview && m_internalData->m_myview.GetWindowHeight) + return m_internalData->m_myview.GetWindowHeight; + return 0; +} + + void MacOpenGLWindow::setResizeCallback(b3ResizeCallback resizeCallback) { [m_internalData->m_myview setResizeCallback:resizeCallback]; diff --git a/examples/OpenGLWindow/SimpleOpenGL3App.cpp b/examples/OpenGLWindow/SimpleOpenGL3App.cpp index 241ff7bba..d77c12bef 100644 --- a/examples/OpenGLWindow/SimpleOpenGL3App.cpp +++ b/examples/OpenGLWindow/SimpleOpenGL3App.cpp @@ -56,8 +56,11 @@ static void SimpleResizeCallback( float widthf, float heightf) { int width = (int)widthf; int height = (int)heightf; - gApp->m_instancingRenderer->resize(width,height); - gApp->m_primRenderer->setScreenSize(width,height); + if (gApp && gApp->m_instancingRenderer) + gApp->m_instancingRenderer->resize(width,height); + + if (gApp && gApp->m_primRenderer) + gApp->m_primRenderer->setScreenSize(width,height); } @@ -115,6 +118,7 @@ extern unsigned char OpenSansData[]; SimpleOpenGL3App::SimpleOpenGL3App( const char* title, int width,int height, bool allowRetina) { gApp = this; + m_data = new SimpleInternalData; m_data->m_frameDumpPngFileName = 0; m_data->m_renderTexture = 0; @@ -123,6 +127,7 @@ SimpleOpenGL3App::SimpleOpenGL3App( const char* title, int width,int height, boo m_data->m_upAxis = 1; m_window = new b3gDefaultOpenGLWindow(); + m_window->setAllowRetina(allowRetina); b3gWindowConstructionInfo ci; @@ -141,6 +146,9 @@ SimpleOpenGL3App::SimpleOpenGL3App( const char* title, int width,int height, boo 1.f); m_window->startRendering(); + width = m_window->getWidth(); + height = m_window->getHeight(); + b3Assert(glGetError() ==GL_NO_ERROR); #ifndef __APPLE__ @@ -160,17 +168,21 @@ SimpleOpenGL3App::SimpleOpenGL3App( const char* title, int width,int height, boo b3Assert(glGetError() ==GL_NO_ERROR); - m_primRenderer = new GLPrimitiveRenderer(width,height); m_parameterInterface = 0; - + b3Assert(glGetError() ==GL_NO_ERROR); m_instancingRenderer = new GLInstancingRenderer(128*1024,64*1024*1024); - m_renderer = m_instancingRenderer ; - m_instancingRenderer->init(); + m_primRenderer = new GLPrimitiveRenderer(width,height); + + m_renderer = m_instancingRenderer ; + m_window->setResizeCallback(SimpleResizeCallback); + + + m_instancingRenderer->init(); m_instancingRenderer->resize(width,height); - - b3Assert(glGetError() ==GL_NO_ERROR); + m_primRenderer->setScreenSize(width,height); + b3Assert(glGetError() ==GL_NO_ERROR); m_instancingRenderer->InitShaders(); @@ -178,8 +190,7 @@ SimpleOpenGL3App::SimpleOpenGL3App( const char* title, int width,int height, boo m_window->setMouseButtonCallback(SimpleMouseButtonCallback); m_window->setKeyboardCallback(SimpleKeyboardCallback); m_window->setWheelCallback(SimpleWheelCallback); - m_window->setResizeCallback(SimpleResizeCallback); - + TwGenerateDefaultFonts(); m_data->m_fontTextureId = BindFont(g_DefaultNormalFont); m_data->m_largeFontTextureId = BindFont(g_DefaultLargeFont); From 8360e2e66d6adb9d06077d849ca8ba480e929729 Mon Sep 17 00:00:00 2001 From: erwin coumans Date: Wed, 4 May 2016 00:16:53 -0700 Subject: [PATCH 09/10] windows fixes --- .../InProcessExampleBrowser.cpp | 63 ++++++++++--------- .../ExampleBrowser/OpenGLExampleBrowser.cpp | 4 +- examples/OpenGLWindow/Win32OpenGLWindow.cpp | 15 +++++ examples/OpenGLWindow/Win32OpenGLWindow.h | 3 + 4 files changed, 55 insertions(+), 30 deletions(-) diff --git a/examples/ExampleBrowser/InProcessExampleBrowser.cpp b/examples/ExampleBrowser/InProcessExampleBrowser.cpp index 97b0761c4..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,7 @@ void* ExampleBrowserMemoryFunc(); #include //#include "BulletMultiThreaded/PlatformDefinitions.h" -#ifndef _WIN32 -#include "../MultiThreading/b3PosixThreadSupport.h" - +#include "Bullet3Common/b3Logging.h" #include "ExampleEntries.h" #include "LinearMath/btAlignedObjectArray.h" #include "EmptyExample.h" @@ -32,6 +30,38 @@ void* ExampleBrowserMemoryFunc(); #include "../SharedMemory/PhysicsServerExample.h" #include "../SharedMemory/PhysicsClientExample.h" +#ifndef _WIN32 +#include "../MultiThreading/b3PosixThreadSupport.h" + + + +static b3ThreadSupportInterface* createExampleBrowserThreadSupport(int numThreads) +{ + b3PosixThreadSupport::ThreadConstructionInfo constructionInfo("testThreads", + ExampleBrowserThreadFunc, + ExampleBrowserMemoryFunc, + numThreads); + b3ThreadSupportInterface* threadSupport = new b3PosixThreadSupport(constructionInfo); + + return threadSupport; + +} + + + +#elif defined( _WIN32) +#include "../MultiThreading/b3Win32ThreadSupport.h" + +b3ThreadSupportInterface* createExampleBrowserThreadSupport(int numThreads) +{ + b3Win32ThreadSupport::Win32ThreadConstructionInfo threadConstructionInfo("testThreads",ExampleBrowserThreadFunc,ExampleBrowserMemoryFunc,numThreads); + b3Win32ThreadSupport* threadSupport = new b3Win32ThreadSupport(threadConstructionInfo); + return threadSupport; + +} +#endif + + @@ -162,30 +192,6 @@ const char* ExampleEntriesPhysicsServer::getExampleDescription(int index) return m_data->m_allExamples[index].m_description; } -static b3ThreadSupportInterface* createExampleBrowserThreadSupport(int numThreads) -{ - b3PosixThreadSupport::ThreadConstructionInfo constructionInfo("testThreads", - ExampleBrowserThreadFunc, - ExampleBrowserMemoryFunc, - numThreads); - b3ThreadSupportInterface* threadSupport = new b3PosixThreadSupport(constructionInfo); - - return threadSupport; - -} - - -#elif defined( _WIN32) -#include "../MultiThreading/b3Win32ThreadSupport.h" - -b3ThreadSupportInterface* createExampleBrowserThreadSupport(int numThreads) -{ - b3Win32ThreadSupport::Win32ThreadConstructionInfo threadConstructionInfo("testThreads",ExampleBrowserThreadFunc,ExampleBrowserMemoryFunc,numThreads); - b3Win32ThreadSupport* threadSupport = new b3Win32ThreadSupport(threadConstructionInfo); - return threadSupport; - -} -#endif @@ -284,6 +290,7 @@ struct btInProcessExampleBrowserInternalData }; + btInProcessExampleBrowserInternalData* btCreateInProcessExampleBrowser(int argc,char** argv2) { diff --git a/examples/ExampleBrowser/OpenGLExampleBrowser.cpp b/examples/ExampleBrowser/OpenGLExampleBrowser.cpp index c07e63a7c..5804c2c65 100644 --- a/examples/ExampleBrowser/OpenGLExampleBrowser.cpp +++ b/examples/ExampleBrowser/OpenGLExampleBrowser.cpp @@ -695,8 +695,8 @@ bool OpenGLExampleBrowser::init(int argc, char* argv[]) } - int width = 1920; - int height=1080; + int width = 1024; + int height=768; #ifndef NO_OPENGL3 SimpleOpenGL3App* simpleApp=0; sUseOpenGL2 =args.CheckCmdLineFlag("opengl2"); diff --git a/examples/OpenGLWindow/Win32OpenGLWindow.cpp b/examples/OpenGLWindow/Win32OpenGLWindow.cpp index d7571bf98..0e076b92c 100644 --- a/examples/OpenGLWindow/Win32OpenGLWindow.cpp +++ b/examples/OpenGLWindow/Win32OpenGLWindow.cpp @@ -180,6 +180,21 @@ int Win32OpenGLWindow::fileOpenDialog(char* fileName, int maxFileNameLength) //return 0; } +int Win32OpenGLWindow::getWidth() const +{ + if (m_data) + return m_data->m_openglViewportWidth; + return 0; +} + +int Win32OpenGLWindow::getHeight() const +{ + if (m_data) + return m_data->m_openglViewportHeight; + return 0; +} + + #endif diff --git a/examples/OpenGLWindow/Win32OpenGLWindow.h b/examples/OpenGLWindow/Win32OpenGLWindow.h index bf8a0f5eb..901ce6518 100644 --- a/examples/OpenGLWindow/Win32OpenGLWindow.h +++ b/examples/OpenGLWindow/Win32OpenGLWindow.h @@ -53,6 +53,9 @@ public: virtual float getRetinaScale() const {return 1.f;} virtual void setAllowRetina(bool /*allowRetina*/) {}; + virtual int getWidth() const; + virtual int getHeight() const; + virtual int fileOpenDialog(char* fileName, int maxFileNameLength); }; From 194009f46e4697a1bc89ca3f31124d554472e8b2 Mon Sep 17 00:00:00 2001 From: "Erwin Coumans (Google)" Date: Wed, 4 May 2016 00:17:39 -0700 Subject: [PATCH 10/10] linux fixes --- examples/OpenGLWindow/X11OpenGLWindow.cpp | 14 ++++++++++++++ examples/OpenGLWindow/X11OpenGLWindow.h | 7 ++++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/examples/OpenGLWindow/X11OpenGLWindow.cpp b/examples/OpenGLWindow/X11OpenGLWindow.cpp index e6d0f666d..f2a077145 100644 --- a/examples/OpenGLWindow/X11OpenGLWindow.cpp +++ b/examples/OpenGLWindow/X11OpenGLWindow.cpp @@ -1076,6 +1076,20 @@ b3KeyboardCallback X11OpenGLWindow::getKeyboardCallback() return m_data->m_keyboardCallback; } +int X11OpenGLWindow::getWidth() const +{ + if (m_data) + return m_data->m_glWidth; + return 0; +} +int X11OpenGLWindow::getHeight() const +{ + if (m_data) + return m_data->m_glHeight; + return 0; +} + + #include int X11OpenGLWindow::fileOpenDialog(char* filename, int maxNameLength) diff --git a/examples/OpenGLWindow/X11OpenGLWindow.h b/examples/OpenGLWindow/X11OpenGLWindow.h index cc28aae1a..fd88689bc 100644 --- a/examples/OpenGLWindow/X11OpenGLWindow.h +++ b/examples/OpenGLWindow/X11OpenGLWindow.h @@ -54,7 +54,7 @@ public: virtual void setResizeCallback(b3ResizeCallback resizeCallback); virtual void setWheelCallback(b3WheelCallback wheelCallback); virtual void setKeyboardCallback( b3KeyboardCallback keyboardCallback); - + virtual b3MouseMoveCallback getMouseMoveCallback(); virtual b3MouseButtonCallback getMouseButtonCallback(); virtual b3ResizeCallback getResizeCallback(); @@ -65,9 +65,14 @@ public: virtual void setWindowTitle(const char* title); + virtual int getWidth() const; + + virtual int getHeight() const; + int fileOpenDialog(char* filename, int maxNameLength); }; + #endif