From d0f20eafd161542ebf63c5f8061c5e266e3b8776 Mon Sep 17 00:00:00 2001 From: erwin coumans Date: Sat, 2 Jul 2016 18:53:19 -0700 Subject: [PATCH] Allow to build PhysicsServer in VR mode, to see the URDF/SDF robots in proper scale in VR. Add option to have Z as up-axis for VR examples. Add OpenVR LICENSE + README file Don't crash VR app when no HMD is detected, just exit. For now, don't request debug lines in client, it slows down physics server in VR mode too much. --- build_visual_studio.bat | 2 +- .../SharedMemory/PhysicsClientExample.cpp | 3 +- .../SharedMemory/PhysicsServerExample.cpp | 2 + examples/SharedMemory/premake4.lua | 62 ++++++++++++++++++- .../StandaloneMain/hellovr_opengl_main.cpp | 40 ++++++++---- examples/ThirdPartyLibs/openvr/LICENSE | 27 ++++++++ examples/ThirdPartyLibs/openvr/README | 9 +++ 7 files changed, 129 insertions(+), 16 deletions(-) create mode 100644 examples/ThirdPartyLibs/openvr/LICENSE create mode 100644 examples/ThirdPartyLibs/openvr/README diff --git a/build_visual_studio.bat b/build_visual_studio.bat index de3b886c9..56ee9f610 100644 --- a/build_visual_studio.bat +++ b/build_visual_studio.bat @@ -2,7 +2,7 @@ rem premake4 --with-pe vs2010 rem premake4 --bullet2demos vs2010 cd build3 -premake4 --targetdir="../bin" vs2010 +premake4 --enable_openvr --targetdir="../bin" vs2010 rem premake4 --targetdir="../server2bin" vs2010 rem cd vs2010 rem rename 0_Bullet3Solution.sln 0_server.sln diff --git a/examples/SharedMemory/PhysicsClientExample.cpp b/examples/SharedMemory/PhysicsClientExample.cpp index a4199071a..e8e181992 100644 --- a/examples/SharedMemory/PhysicsClientExample.cpp +++ b/examples/SharedMemory/PhysicsClientExample.cpp @@ -835,7 +835,7 @@ void PhysicsClientExample::stepSimulation(float deltaTime) enqueueCommand(CMD_STEP_FORWARD_SIMULATION); if (m_options != eCLIENTEXAMPLE_SERVER) { - enqueueCommand(CMD_REQUEST_DEBUG_LINES); + //enqueueCommand(CMD_REQUEST_DEBUG_LINES); } } } @@ -855,3 +855,4 @@ class CommonExampleInterface* PhysicsClientCreateFunc(struct CommonExampleOpt } return example; } + diff --git a/examples/SharedMemory/PhysicsServerExample.cpp b/examples/SharedMemory/PhysicsServerExample.cpp index 05c689e8a..7cb76e9c6 100644 --- a/examples/SharedMemory/PhysicsServerExample.cpp +++ b/examples/SharedMemory/PhysicsServerExample.cpp @@ -306,3 +306,5 @@ class CommonExampleInterface* PhysicsServerCreateFunc(struct CommonExampleOpt return example; } + +B3_STANDALONE_EXAMPLE(PhysicsServerCreateFunc) \ No newline at end of file diff --git a/examples/SharedMemory/premake4.lua b/examples/SharedMemory/premake4.lua index 34aea2de5..be3c7102c 100644 --- a/examples/SharedMemory/premake4.lua +++ b/examples/SharedMemory/premake4.lua @@ -15,7 +15,8 @@ links { language "C++" -files { +myfiles = +{ "PhysicsClient.cpp", "PhysicsClientSharedMemory.cpp", "PhysicsClientExample.cpp", @@ -24,7 +25,6 @@ files { "PhysicsServerSharedMemory.h", "PhysicsServer.cpp", "PhysicsServer.h", - "main.cpp", "PhysicsClientC_API.cpp", "SharedMemoryCommands.h", "SharedMemoryPublic.h", @@ -84,3 +84,61 @@ files { "../ThirdPartyLibs/stb_image/stb_image.cpp", } +files { + myfiles, + "main.cpp", +} + + + +project "App_SharedMemoryPhysics_VR" + +defines {"B3_USE_STANDALONE_EXAMPLE","BT_ENABLE_VR"} + +if _OPTIONS["ios"] then + kind "WindowedApp" +else + kind "ConsoleApp" +end + +includedirs { + ".","../../src", "../ThirdPartyLibs", + "../ThirdPartyLibs/openvr/headers", + "../ThirdPartyLibs/openvr/samples/shared" + } + +links { + "Bullet3Common", "BulletDynamics","BulletCollision", "LinearMath","OpenGL_Window","openvr_api" +} + +language "C++" + + + initOpenGL() + initGlew() + + +files +{ + myfiles, + "../StandaloneMain/hellovr_opengl_main.cpp", + "../ExampleBrowser/OpenGLGuiHelper.cpp", + "../ExampleBrowser/GL_ShapeDrawer.cpp", + "../ExampleBrowser/CollisionShape2TriangleMesh.cpp", + "../ThirdPartyLibs/openvr/samples/shared/lodepng.cpp", + "../ThirdPartyLibs/openvr/samples/shared/lodepng.h", + "../ThirdPartyLibs/openvr/samples/shared/Matrices.cpp", + "../ThirdPartyLibs/openvr/samples/shared/Matrices.h", + "../ThirdPartyLibs/openvr/samples/shared/pathtools.cpp", + "../ThirdPartyLibs/openvr/samples/shared/pathtools.h", + "../ThirdPartyLibs/openvr/samples/shared/Vectors.h", +} +if os.is("Windows") then + libdirs {"../ThirdPartyLibs/openvr/lib/win32"} +end + +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/StandaloneMain/hellovr_opengl_main.cpp b/examples/StandaloneMain/hellovr_opengl_main.cpp index 746f10835..547f813fd 100644 --- a/examples/StandaloneMain/hellovr_opengl_main.cpp +++ b/examples/StandaloneMain/hellovr_opengl_main.cpp @@ -11,6 +11,7 @@ #include "BulletCollision/CollisionShapes/btCollisionShape.h" #include "BulletDynamics/Dynamics/btDiscreteDynamicsWorld.h" +int gSharedMemoryKey = -1; //how can you try typing on a keyboard, without seeing it? //it is pretty funny, to see the desktop in VR! @@ -139,7 +140,7 @@ private: SimpleOpenGL3App* m_app; uint32_t m_nWindowWidth; uint32_t m_nWindowHeight; - + bool m_hasContext; private: // OpenGL bookkeeping int m_iTrackedControllerCount; @@ -234,6 +235,7 @@ private: // OpenGL bookkeeping //----------------------------------------------------------------------------- CMainApplication::CMainApplication( int argc, char *argv[] ) : m_app(NULL) + , m_hasContext(false) , m_nWindowWidth( 1280 ) , m_nWindowHeight( 720 ) , m_unSceneProgramID( 0 ) @@ -556,13 +558,16 @@ void CMainApplication::Shutdown() } m_vecRenderModels.clear(); - if( 1)//m_pContext ) + if( m_hasContext) { - glDebugMessageControl( GL_DONT_CARE, GL_DONT_CARE, GL_DONT_CARE, 0, nullptr, GL_FALSE ); - glDebugMessageCallback(nullptr, nullptr); - glDeleteBuffers(1, &m_glSceneVertBuffer); - glDeleteBuffers(1, &m_glIDVertBuffer); - glDeleteBuffers(1, &m_glIDIndexBuffer); + if (m_glSceneVertBuffer) + { + glDebugMessageControl( GL_DONT_CARE, GL_DONT_CARE, GL_DONT_CARE, 0, nullptr, GL_FALSE ); + glDebugMessageCallback(nullptr, nullptr); + glDeleteBuffers(1, &m_glSceneVertBuffer); + glDeleteBuffers(1, &m_glIDVertBuffer); + glDeleteBuffers(1, &m_glIDIndexBuffer); + } if ( m_unSceneProgramID ) { @@ -1067,6 +1072,7 @@ void CMainApplication::SetupScene() glDisableVertexAttribArray(0); glDisableVertexAttribArray(1); + m_hasContext = true; } @@ -1462,10 +1468,19 @@ void CMainApplication::RenderStereoTargets() m_app->m_instancingRenderer->init(); + Matrix4 rotYtoZ = rotYtoZ.identity(); + + //some Bullet apps (especially robotics related) require Z as up-axis) + if (m_app->getUpAxis()==2) + { + rotYtoZ.rotateX(-90); + } // Left Eye { - Matrix4 viewMatLeft = m_mat4eyePosLeft * m_mat4HMDPose; + + Matrix4 viewMatLeft = m_mat4eyePosLeft * m_mat4HMDPose * rotYtoZ; + m_app->m_instancingRenderer->getActiveCamera()->setVRCamera(viewMatLeft.get(),m_mat4ProjectionLeft.get()); m_app->m_instancingRenderer->updateCamera(); } @@ -1477,8 +1492,9 @@ void CMainApplication::RenderStereoTargets() m_app->m_window->startRendering(); RenderScene( vr::Eye_Left ); - - m_app->drawGrid(); + DrawGridData gridUp; + gridUp.upAxis = m_app->getUpAxis(); + m_app->drawGrid(gridUp); sExample->stepSimulation(1./60.); sExample->renderScene(); @@ -1507,7 +1523,7 @@ void CMainApplication::RenderStereoTargets() // Right Eye { - Matrix4 viewMatRight = m_mat4eyePosRight * m_mat4HMDPose; + Matrix4 viewMatRight = m_mat4eyePosRight * m_mat4HMDPose * rotYtoZ; m_app->m_instancingRenderer->getActiveCamera()->setVRCamera(viewMatRight.get(),m_mat4ProjectionRight.get()); m_app->m_instancingRenderer->updateCamera(); } @@ -1518,7 +1534,7 @@ void CMainApplication::RenderStereoTargets() m_app->m_window->startRendering(); RenderScene( vr::Eye_Right ); - m_app->drawGrid(); + m_app->drawGrid(gridUp); m_app->m_instancingRenderer->setRenderFrameBuffer((unsigned int)rightEyeDesc.m_nRenderFramebufferId); m_app->m_renderer->renderScene(); diff --git a/examples/ThirdPartyLibs/openvr/LICENSE b/examples/ThirdPartyLibs/openvr/LICENSE new file mode 100644 index 000000000..ee83337d7 --- /dev/null +++ b/examples/ThirdPartyLibs/openvr/LICENSE @@ -0,0 +1,27 @@ +Copyright (c) 2015, Valve Corporation +All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, +are permitted provided that the following conditions are met: + +1. Redistributions of source code must retain the above copyright notice, this +list of conditions and the following disclaimer. + +2. Redistributions in binary form must reproduce the above copyright notice, +this list of conditions and the following disclaimer in the documentation and/or +other materials provided with the distribution. + +3. Neither the name of the copyright holder nor the names of its contributors +may be used to endorse or promote products derived from this software without +specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR +ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON +ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/examples/ThirdPartyLibs/openvr/README b/examples/ThirdPartyLibs/openvr/README new file mode 100644 index 000000000..9a8923159 --- /dev/null +++ b/examples/ThirdPartyLibs/openvr/README @@ -0,0 +1,9 @@ +OpenVR is an API and runtime that allows access to VR hardware from multiple +vendors without requiring that applications have specific knowledge of the +hardware they are targeting. This repository is an SDK that contains the API +and samples. The runtime is under SteamVR in Tools on Steam. + +Documentation for the API is available in the wiki: https://github.com/ValveSoftware/openvr/wiki/API-Documentation + +More information on OpenVR and SteamVR can be found on http://steamvr.com +