From 2302709e2da56ad50ed1ce1141a4349fc71fd77c Mon Sep 17 00:00:00 2001 From: erwin coumans Date: Mon, 18 Jul 2016 23:13:46 -0700 Subject: [PATCH 1/3] OpenVR support: track multiple controllers and buttons --- .../SharedMemory/PhysicsServerExample.cpp | 6 +- .../StandaloneMain/hellovr_opengl_main.cpp | 85 +++++++++---------- 2 files changed, 44 insertions(+), 47 deletions(-) diff --git a/examples/SharedMemory/PhysicsServerExample.cpp b/examples/SharedMemory/PhysicsServerExample.cpp index 6ae9a654d..75e475738 100644 --- a/examples/SharedMemory/PhysicsServerExample.cpp +++ b/examples/SharedMemory/PhysicsServerExample.cpp @@ -140,11 +140,11 @@ void MotionThreadFunc(void* userPtr,void* lsMemory) btVector3 from = args->m_pos; btMatrix3x3 mat(args->m_orn); - + btScalar pickDistance = 100.; btVector3 toX = args->m_pos+mat.getColumn(0); btVector3 toY = args->m_pos+mat.getColumn(1); - btVector3 toZ = args->m_pos+mat.getColumn(2)*50.; - + btVector3 toZ = args->m_pos+mat.getColumn(2)*pickDistance; + if (args->m_isPicking) { diff --git a/examples/StandaloneMain/hellovr_opengl_main.cpp b/examples/StandaloneMain/hellovr_opengl_main.cpp index 630c2d3e8..e85b8af0e 100644 --- a/examples/StandaloneMain/hellovr_opengl_main.cpp +++ b/examples/StandaloneMain/hellovr_opengl_main.cpp @@ -30,11 +30,14 @@ int gSharedMemoryKey = -1; #include "pathtools.h" CommonExampleInterface* sExample; -int sIsPressed=-1; + int sPrevPacketNum=0; GUIHelperInterface* sGuiPtr = 0; +static vr::VRControllerState_t sPrevStates[vr::k_unMaxTrackedDeviceCount] = { 0 }; + + #if defined(POSIX) #include "unistd.h" #endif @@ -663,63 +666,57 @@ bool CMainApplication::HandleInput() vr::VRControllerState_t state; if( m_pHMD->GetControllerState( unDevice, &state ) ) { - uint64_t trigger = vr::ButtonMaskFromId(vr::k_EButton_SteamVR_Trigger); - - if (sPrevPacketNum != state.unPacketNum) + //we need to have the 'move' events, so no early out here + //if (sPrevStates[unDevice].unPacketNum != state.unPacketNum) { - - static int counter=0; - sPrevPacketNum = state.unPacketNum; - //b3Printf("."); - bool isTrigger = (state.ulButtonPressed&trigger)!=0; - if (isTrigger) + sPrevStates[unDevice].unPacketNum = state.unPacketNum; + + for (int button = 0; button < vr::k_EButton_Max; button++) { - //printf("unDevice=%d\n",unDevice); - b3Transform tr; - getControllerTransform(unDevice,tr); - float pos[3] = {tr.getOrigin()[0],tr.getOrigin()[1],tr.getOrigin()[2]}; - b3Quaternion born = tr.getRotation(); - float orn[4] = {born[0],born[1],born[2],born[3]}; - + uint64_t trigger = vr::ButtonMaskFromId((vr::EVRButtonId)button); - if (sIsPressed!=unDevice) + bool isTrigger = (state.ulButtonPressed&trigger) != 0; + if (isTrigger) { - b3Printf("trigger pressed %d, %d\n",counter++, unDevice); - sIsPressed=unDevice; - sExample->vrControllerButtonCallback(unDevice,1,1,pos, orn); - - // - //virtual void vrControllerMoveCallback(int controllerId, float pos[4], float orientation[4]) {} - //virtual void vrControllerButtonCallback(int controllerId, int button, int state, float pos[4], float orientation[4]){} - - //sExample->start - } else - { - sExample->vrControllerMoveCallback(unDevice,pos,orn); - } - //sExample->exitPhysics(); - //m_app->m_instancingRenderer->removeAllInstances(); - ///sExample->initPhysics(); - } else - { - if (unDevice==sIsPressed) - { b3Transform tr; - getControllerTransform(unDevice,tr); - float pos[3] = {tr.getOrigin()[0],tr.getOrigin()[1],tr.getOrigin()[2]}; + getControllerTransform(unDevice, tr); + float pos[3] = { tr.getOrigin()[0], tr.getOrigin()[1], tr.getOrigin()[2] }; b3Quaternion born = tr.getRotation(); - float orn[4] = {born[0],born[1],born[2],born[3]}; + float orn[4] = { born[0], born[1], born[2], born[3] }; - sIsPressed=-1; - printf("device released: %d",unDevice); - sExample->vrControllerButtonCallback(unDevice,1,0,pos, orn); + //pressed now, not pressed before -> raise a button down event + if ((sPrevStates[unDevice].ulButtonPressed&trigger)==0) + { +// printf("Device PRESSED: %d, button %d\n", unDevice, button); + sExample->vrControllerButtonCallback(unDevice, button, 1, pos, orn); + } + else + { +// printf("Device MOVED: %d\n", unDevice); + sExample->vrControllerMoveCallback(unDevice, pos, orn); + } + } + else + { + //not pressed now, but pressed before -> raise a button up event + if ((sPrevStates[unDevice].ulButtonPressed&trigger) != 0) + { + b3Transform tr; + getControllerTransform(unDevice, tr); + float pos[3] = { tr.getOrigin()[0], tr.getOrigin()[1], tr.getOrigin()[2] }; + b3Quaternion born = tr.getRotation(); + float orn[4] = { born[0], born[1], born[2], born[3] }; +// printf("Device RELEASED: %d, button %d\n", unDevice,button); + sExample->vrControllerButtonCallback(unDevice, button, 0, pos, orn); + } } } } m_rbShowTrackedDevice[ unDevice ] = state.ulButtonPressed == 0; } + sPrevStates[unDevice] = state; } return bRet; From 0ae252fa35fde063a9480a338ca9c2f1ca6179f5 Mon Sep 17 00:00:00 2001 From: Erwin Coumans Date: Tue, 19 Jul 2016 15:53:16 -0700 Subject: [PATCH 2/3] fix issue, use bodyUniqueId/b3JointControlCommandInit2 --- examples/RoboticsLearning/b3RobotSimAPI.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/examples/RoboticsLearning/b3RobotSimAPI.cpp b/examples/RoboticsLearning/b3RobotSimAPI.cpp index 235861913..b29e0e429 100644 --- a/examples/RoboticsLearning/b3RobotSimAPI.cpp +++ b/examples/RoboticsLearning/b3RobotSimAPI.cpp @@ -556,7 +556,7 @@ void b3RobotSimAPI::setJointMotorControl(int bodyUniqueId, int jointIndex, const { case CONTROL_MODE_VELOCITY: { - b3SharedMemoryCommandHandle command = b3JointControlCommandInit( m_data->m_physicsClient, CONTROL_MODE_VELOCITY); + b3SharedMemoryCommandHandle command = b3JointControlCommandInit2( m_data->m_physicsClient, bodyUniqueId, CONTROL_MODE_VELOCITY); b3JointInfo jointInfo; b3GetJointInfo(m_data->m_physicsClient, bodyUniqueId, jointIndex, &jointInfo); int uIndex = jointInfo.m_uIndex; @@ -567,7 +567,7 @@ void b3RobotSimAPI::setJointMotorControl(int bodyUniqueId, int jointIndex, const } case CONTROL_MODE_POSITION_VELOCITY_PD: { - b3SharedMemoryCommandHandle command = b3JointControlCommandInit( m_data->m_physicsClient, CONTROL_MODE_POSITION_VELOCITY_PD); + b3SharedMemoryCommandHandle command = b3JointControlCommandInit2( m_data->m_physicsClient, bodyUniqueId, CONTROL_MODE_POSITION_VELOCITY_PD); b3JointInfo jointInfo; b3GetJointInfo(m_data->m_physicsClient, bodyUniqueId, jointIndex, &jointInfo); int uIndex = jointInfo.m_uIndex; @@ -583,7 +583,7 @@ void b3RobotSimAPI::setJointMotorControl(int bodyUniqueId, int jointIndex, const } case CONTROL_MODE_TORQUE: { - b3SharedMemoryCommandHandle command = b3JointControlCommandInit( m_data->m_physicsClient, CONTROL_MODE_TORQUE); + b3SharedMemoryCommandHandle command = b3JointControlCommandInit2( m_data->m_physicsClient, bodyUniqueId, CONTROL_MODE_TORQUE); b3JointInfo jointInfo; b3GetJointInfo(m_data->m_physicsClient, bodyUniqueId, jointIndex, &jointInfo); int uIndex = jointInfo.m_uIndex; From 25a1714754572ce07b458e0cbaa6b84932619140 Mon Sep 17 00:00:00 2001 From: erwin coumans Date: Tue, 19 Jul 2016 15:55:52 -0700 Subject: [PATCH 3/3] disable CProfileManager, might reduce some multi-threading conflicts --- .../Collision/CollisionTutorialBullet2.cpp | 5 +++- .../GwenGUISupport/GwenProfileWindow.cpp | 7 ++++-- src/LinearMath/btQuickprof.cpp | 8 +++--- src/LinearMath/btQuickprof.h | 25 +++++++++++-------- 4 files changed, 27 insertions(+), 18 deletions(-) diff --git a/examples/Collision/CollisionTutorialBullet2.cpp b/examples/Collision/CollisionTutorialBullet2.cpp index 1198f9e5d..0479a73e8 100644 --- a/examples/Collision/CollisionTutorialBullet2.cpp +++ b/examples/Collision/CollisionTutorialBullet2.cpp @@ -265,8 +265,9 @@ public: virtual void stepSimulation(float deltaTime) { +#ifndef BT_NO_PROFILE CProfileManager::Reset(); - +#endif @@ -314,7 +315,9 @@ public: m_app->m_renderer->writeTransforms(); +#ifndef BT_NO_PROFILE CProfileManager::Increment_Frame_Counter(); +#endif } virtual void renderScene() { diff --git a/examples/ExampleBrowser/GwenGUISupport/GwenProfileWindow.cpp b/examples/ExampleBrowser/GwenGUISupport/GwenProfileWindow.cpp index 597ff834d..4991ee04e 100644 --- a/examples/ExampleBrowser/GwenGUISupport/GwenProfileWindow.cpp +++ b/examples/ExampleBrowser/GwenGUISupport/GwenProfileWindow.cpp @@ -4,7 +4,7 @@ #include "LinearMath/btQuickprof.h" - +#ifndef BT_NO_PROFILE class MyProfileWindow : public Gwen::Controls::WindowControl @@ -42,8 +42,9 @@ protected: } public: - + CProfileIterator* profIter; + class MyMenuItems* m_menuItems; MyProfileWindow ( Gwen::Controls::Base* pParent) : Gwen::Controls::WindowControl( pParent ), @@ -304,3 +305,5 @@ void destroyProfileWindow(MyProfileWindow* window) CProfileManager::Release_Iterator(window->profIter); delete window; } + +#endif //BT_NO_PROFILE \ No newline at end of file diff --git a/src/LinearMath/btQuickprof.cpp b/src/LinearMath/btQuickprof.cpp index d88d965a4..cfbda3628 100644 --- a/src/LinearMath/btQuickprof.cpp +++ b/src/LinearMath/btQuickprof.cpp @@ -15,11 +15,8 @@ #include "btQuickprof.h" -#ifndef BT_NO_PROFILE -static btClock gProfileClock; - #ifdef __CELLOS_LV2__ #include @@ -250,6 +247,10 @@ btScalar btClock::getTimeSeconds() return btScalar(getTimeMicroseconds()) * microseconds_to_seconds; } +#ifndef BT_NO_PROFILE + + +static btClock gProfileClock; inline void Profile_Get_Ticks(unsigned long int * ticks) @@ -265,7 +266,6 @@ inline float Profile_Get_Tick_Rate(void) } - /*************************************************************************************************** ** ** CProfileNode diff --git a/src/LinearMath/btQuickprof.h b/src/LinearMath/btQuickprof.h index 362f62d6d..49545713b 100644 --- a/src/LinearMath/btQuickprof.h +++ b/src/LinearMath/btQuickprof.h @@ -15,18 +15,7 @@ #ifndef BT_QUICK_PROF_H #define BT_QUICK_PROF_H -//To disable built-in profiling, please comment out next line -//#define BT_NO_PROFILE 1 -#ifndef BT_NO_PROFILE -#include //@todo remove this, backwards compatibility #include "btScalar.h" -#include "btAlignedAllocator.h" -#include - - - - - #define USE_BT_CLOCK 1 #ifdef USE_BT_CLOCK @@ -64,6 +53,20 @@ private: #endif //USE_BT_CLOCK +//To disable built-in profiling, please comment out next line +#define BT_NO_PROFILE 1 +#ifndef BT_NO_PROFILE +#include //@todo remove this, backwards compatibility + +#include "btAlignedAllocator.h" +#include + + + + + + + ///A node in the Profile Hierarchy Tree