From 9303891468b136421e60f71c3405626ee2ce3c1c Mon Sep 17 00:00:00 2001 From: erwincoumans Date: Thu, 5 Oct 2017 09:02:33 -0700 Subject: [PATCH] Allow to configure Y=up, default is Z=up, using pybullet.configureDebugVisualizer(COV_ENABLE_Y_AXIS_UP,0/1) Implement pybullet.getConnectionInfo, returns [isConnected, connectionMethod], where isConnected=0 or 1 --- .../ExampleBrowser/OpenGLExampleBrowser.cpp | 7 ++++ examples/SharedMemory/PhysicsClientC_API.h | 6 +-- .../StandaloneMain/hellovr_opengl_main.cpp | 9 +++- examples/pybullet/pybullet.c | 41 +++++++++++++++++-- 4 files changed, 55 insertions(+), 8 deletions(-) diff --git a/examples/ExampleBrowser/OpenGLExampleBrowser.cpp b/examples/ExampleBrowser/OpenGLExampleBrowser.cpp index 6c7ac6be2..d0d14b200 100644 --- a/examples/ExampleBrowser/OpenGLExampleBrowser.cpp +++ b/examples/ExampleBrowser/OpenGLExampleBrowser.cpp @@ -377,6 +377,13 @@ void OpenGLExampleBrowser::registerFileImporter(const char* extension, CommonExa void OpenGLExampleBrowserVisualizerFlagCallback(int flag, bool enable) { + if (flag == COV_ENABLE_Y_AXIS_UP) + { + //either Y = up or Z + int upAxis = enable? 1:2; + s_app->setUpAxis(upAxis); + } + if (flag == COV_ENABLE_RENDERING) { gEnableRenderLoop = (enable!=0); diff --git a/examples/SharedMemory/PhysicsClientC_API.h b/examples/SharedMemory/PhysicsClientC_API.h index f2dba0e30..a5723c589 100644 --- a/examples/SharedMemory/PhysicsClientC_API.h +++ b/examples/SharedMemory/PhysicsClientC_API.h @@ -323,10 +323,8 @@ B3_SHARED_API int b3GetStatusJacobian(b3SharedMemoryStatusHandle statusHandle, double* angularJacobian); B3_SHARED_API b3SharedMemoryCommandHandle b3CalculateMassMatrixCommandInit(b3PhysicsClientHandle physClient, int bodyIndex, const double* jointPositionsQ); -B3_SHARED_API int b3GetStatusMassMatrix(b3SharedMemoryStatusHandle statusHandle, - int* dofCount, - double* massMatrix); - +///the mass matrix is stored in column-major layout of size dofCount*dofCount +B3_SHARED_API int b3GetStatusMassMatrix(b3PhysicsClientHandle physClient, b3SharedMemoryStatusHandle statusHandle, int* dofCount, double* massMatrix); ///compute the joint positions to move the end effector to a desired target using inverse kinematics diff --git a/examples/StandaloneMain/hellovr_opengl_main.cpp b/examples/StandaloneMain/hellovr_opengl_main.cpp index 1e48f879f..3a98e6a87 100644 --- a/examples/StandaloneMain/hellovr_opengl_main.cpp +++ b/examples/StandaloneMain/hellovr_opengl_main.cpp @@ -376,10 +376,16 @@ void MyKeyboardCallback(int key, int state) extern bool useShadowMap; static bool gEnableVRRenderControllers=true; static bool gEnableVRRendering = true; - +static int gUpAxis = 2; void VRPhysicsServerVisualizerFlagCallback(int flag, bool enable) { + if (flag == COV_ENABLE_Y_AXIS_UP) + { + //either Y = up or Z + gUpAxis = enable? 1:2; + } + if (flag == COV_ENABLE_SHADOWS) { useShadowMap = enable; @@ -890,6 +896,7 @@ void CMainApplication::RunMainLoop() while ( !bQuit && !m_app->m_window->requestedExit()) { + this->m_app->setUpAxis(gUpAxis); b3ChromeUtilsEnableProfiling(); if (gEnableVRRendering) { diff --git a/examples/pybullet/pybullet.c b/examples/pybullet/pybullet.c index cea0302ce..f08b4c4d4 100644 --- a/examples/pybullet/pybullet.c +++ b/examples/pybullet/pybullet.c @@ -503,6 +503,36 @@ void b3pybulletExitFunc(void) } +static PyObject* pybullet_getConnectionInfo(PyObject* self, PyObject* args, PyObject* keywds) +{ + int physicsClientId = 0; + int isConnected=0; + int method=0; + PyObject* pylist = 0; + b3PhysicsClientHandle sm = 0; + static char* kwlist[] = {"physicsClientId", NULL}; + if (!PyArg_ParseTupleAndKeywords(args, keywds, "|i", kwlist, &physicsClientId)) + { + return NULL; + } + sm = getPhysicsClient(physicsClientId); + if (sm != 0) + { + if (b3CanSubmitCommand(sm)) + { + isConnected = 1; + method = sPhysicsClientsGUI[physicsClientId]; + } + } + + pylist = PyTuple_New(2); + PyTuple_SetItem(pylist, 0, PyInt_FromLong(isConnected)); + PyTuple_SetItem(pylist, 1, PyInt_FromLong(method)); + return pylist; + +} + + static PyObject* pybullet_saveWorld(PyObject* self, PyObject* args, PyObject* keywds) { const char* worldFileName = ""; @@ -7314,13 +7344,14 @@ static PyObject* pybullet_calculateMassMatrix(PyObject* self, PyObject* args, Py if (statusType == CMD_CALCULATED_MASS_MATRIX_COMPLETED) { int dofCount; - b3GetStatusMassMatrix(statusHandle, &dofCount, NULL); + b3GetStatusMassMatrix(sm, statusHandle, &dofCount, NULL); if (dofCount) { - pyResultList = PyTuple_New(dofCount); int byteSizeDofCount = sizeof(double) * dofCount; + pyResultList = PyTuple_New(dofCount); + massMatrix = (double*)malloc(dofCount * byteSizeDofCount); - b3GetStatusMassMatrix(statusHandle, NULL, massMatrix); + b3GetStatusMassMatrix(sm, statusHandle, NULL, massMatrix); if (massMatrix) { int r; @@ -7372,6 +7403,10 @@ static PyMethodDef SpamMethods[] = { "disconnect(physicsClientId=0)\n" "Disconnect from the physics server."}, + {"getConnectionInfo", (PyCFunction)pybullet_getConnectionInfo, METH_VARARGS | METH_KEYWORDS, + "getConnectionInfo(physicsClientId=0)\n" + "Return if a given client id is connected, and using what method."}, + {"resetSimulation", (PyCFunction)pybullet_resetSimulation, METH_VARARGS | METH_KEYWORDS, "resetSimulation(physicsClientId=0)\n" "Reset the simulation: remove all objects and start from an empty world."},