allow to enable/disable VR picking and VR teleport. Disabling VR picking will also disable the rendering of the VR controller frames.

This commit is contained in:
Erwin Coumans
2017-05-15 11:39:39 -07:00
parent a554c250a7
commit 4dea68e43e
5 changed files with 79 additions and 19 deletions

View File

@@ -25,6 +25,8 @@
//@todo(erwincoumans) those globals are hacks for a VR demo, move this to Python/pybullet!
extern btVector3 gLastPickPos;
bool gEnablePicking=true;
bool gEnableTeleporting=true;
btVector3 gVRTeleportPosLocal(0,0,0);
btQuaternion gVRTeleportOrnLocal(0,0,0,1);
@@ -565,7 +567,11 @@ public:
m_childGuiHelper->setVisualizerFlag(flag,enable);
}
void setVisualizerFlagCallback(VisualizerFlagCallback callback)
{
m_childGuiHelper->setVisualizerFlagCallback(callback);
}
GUIHelperInterface* m_childGuiHelper;
int m_uidGenerator;
@@ -998,6 +1004,10 @@ public:
}
const char* m_mp4FileName;
virtual void dumpFramesToVideo(const char* mp4FileName)
{
@@ -2015,28 +2025,31 @@ void PhysicsServerExample::renderScene()
}
m_physicsServer.renderScene();
for (int i=0;i<MAX_VR_CONTROLLERS;i++)
if (gEnablePicking)
{
if (m_args[0].m_isVrControllerPicking[i] || m_args[0].m_isVrControllerDragging[i])
for (int i=0;i<MAX_VR_CONTROLLERS;i++)
{
btVector3 from = m_args[0].m_vrControllerPos[i];
btMatrix3x3 mat(m_args[0].m_vrControllerOrn[i]);
if (m_args[0].m_isVrControllerPicking[i] || m_args[0].m_isVrControllerDragging[i])
{
btVector3 from = m_args[0].m_vrControllerPos[i];
btMatrix3x3 mat(m_args[0].m_vrControllerOrn[i]);
btVector3 toX = from+mat.getColumn(0);
btVector3 toY = from+mat.getColumn(1);
btVector3 toZ = from+mat.getColumn(2);
btVector3 toX = from+mat.getColumn(0);
btVector3 toY = from+mat.getColumn(1);
btVector3 toZ = from+mat.getColumn(2);
int width = 2;
int width = 2;
btVector4 color;
color=btVector4(1,0,0,1);
m_guiHelper->getAppInterface()->m_renderer->drawLine(from,toX,color,width);
color=btVector4(0,1,0,1);
m_guiHelper->getAppInterface()->m_renderer->drawLine(from,toY,color,width);
color=btVector4(0,0,1,1);
m_guiHelper->getAppInterface()->m_renderer->drawLine(from,toZ,color,width);
btVector4 color;
color=btVector4(1,0,0,1);
m_guiHelper->getAppInterface()->m_renderer->drawLine(from,toX,color,width);
color=btVector4(0,1,0,1);
m_guiHelper->getAppInterface()->m_renderer->drawLine(from,toY,color,width);
color=btVector4(0,0,1,1);
m_guiHelper->getAppInterface()->m_renderer->drawLine(from,toZ,color,width);
}
}
}
@@ -2132,10 +2145,12 @@ btVector3 PhysicsServerExample::getRayTo(int x,int y)
extern int gSharedMemoryKey;
class CommonExampleInterface* PhysicsServerCreateFunc(struct CommonExampleOptions& options)
{
MultiThreadedOpenGLGuiHelper* guiHelperWrapper = new MultiThreadedOpenGLGuiHelper(options.m_guiHelper->getAppInterface(),options.m_guiHelper);
PhysicsServerExample* example = new PhysicsServerExample(guiHelperWrapper,
options.m_sharedMem,
@@ -2250,7 +2265,7 @@ void PhysicsServerExample::vrControllerButtonCallback(int controllerId, int butt
}
if (button==1)
if (button==1 && gEnableTeleporting)
{
m_args[0].m_isVrControllerTeleporting[controllerId] = true;
}
@@ -2262,7 +2277,7 @@ void PhysicsServerExample::vrControllerButtonCallback(int controllerId, int butt
else
{
if (button == 33)
if (button == 33 && gEnablePicking)
{
m_args[0].m_isVrControllerPicking[controllerId] = (state != 0);
m_args[0].m_isVrControllerReleasing[controllerId] = (state == 0);

View File

@@ -495,6 +495,8 @@ enum b3ConfigureDebugVisualizerEnum
COV_ENABLE_GUI=1,
COV_ENABLE_SHADOWS,
COV_ENABLE_WIREFRAME,
COV_ENABLE_VR_TELEPORTING,
COV_ENABLE_VR_PICKING,
};
enum eCONNECT_METHOD {

View File

@@ -516,7 +516,6 @@ void TinyRendererVisualShapeConverter::convertVisualShapes(
btAssert(linkPtr); // TODO: remove if (not doing it now, because diff will be 50+ lines)
if (linkPtr)
{
const btArray<UrdfVisual>* shapeArray;
bool useVisual;
int cnt = 0;
if (linkPtr->m_visualArray.size() > 0)

View File

@@ -367,6 +367,47 @@ void MyKeyboardCallback(int key, int state)
prevKeyboardCallback(key,state);
}
#include "../SharedMemory/SharedMemoryPublic.h"
extern bool useShadowMap;
extern int gDebugDrawFlags;
extern bool gEnablePicking;
extern bool gEnableTeleporting;
void VRPhysicsServerVisualizerFlagCallback(int flag, bool enable)
{
if (flag == COV_ENABLE_SHADOWS)
{
useShadowMap = enable;
}
if (flag == COV_ENABLE_GUI)
{
//there is no regular GUI here, but disable the
}
if (flag==COV_ENABLE_VR_TELEPORTING)
{
gEnableTeleporting = enable;
}
if (flag == COV_ENABLE_VR_PICKING)
{
gEnablePicking = enable;
}
if (flag == COV_ENABLE_WIREFRAME)
{
gDebugDrawFlags |= btIDebugDraw::DBG_DrawWireframe;
} else
{
gDebugDrawFlags &= ~btIDebugDraw::DBG_DrawWireframe;
}
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
@@ -418,6 +459,7 @@ bool CMainApplication::BInit()
sGuiPtr = new OpenGLGuiHelper(m_app,false);
sGuiPtr->setVisualizerFlagCallback(VRPhysicsServerVisualizerFlagCallback);
sGuiPtr->setVRMode(true);
//sGuiPtr = new DummyGUIHelper;

View File

@@ -6346,6 +6346,8 @@ initpybullet(void)
PyModule_AddIntConstant(m, "COV_ENABLE_GUI", COV_ENABLE_GUI);
PyModule_AddIntConstant(m, "COV_ENABLE_SHADOWS", COV_ENABLE_SHADOWS);
PyModule_AddIntConstant(m, "COV_ENABLE_WIREFRAME", COV_ENABLE_WIREFRAME);
PyModule_AddIntConstant(m, "COV_ENABLE_VR_PICKING", COV_ENABLE_VR_PICKING);
PyModule_AddIntConstant(m, "COV_ENABLE_VR_TELEPORTING", COV_ENABLE_VR_TELEPORTING);
PyModule_AddIntConstant(m, "ER_TINY_RENDERER", ER_TINY_RENDERER);
PyModule_AddIntConstant(m, "ER_BULLET_HARDWARE_OPENGL", ER_BULLET_HARDWARE_OPENGL);