From 02582e3a785431f98359ab0645c8d6f49ae40ebb Mon Sep 17 00:00:00 2001 From: erwin coumans Date: Sat, 9 Jul 2016 15:09:09 -0700 Subject: [PATCH] shrink down cube size of BasicDemo 10 times (it looked ginormous in VR) from 2x2x2 meter to 0.2 add test for VR HUD/sub-titles fix issue in previous commit, partial string use %.8s not %8.s use long long int in b3Clock fix warning/error in pointer alignment in serialization Fix pybullet Windows compilation. (thanks to bkeys/https://github.com/bulletphysics/bullet3/pull/687) --- Extras/Serialize/BulletFileLoader/bDNA.cpp | 27 ++----- Extras/Serialize/BulletFileLoader/bFile.cpp | 21 +----- examples/BasicDemo/BasicExample.cpp | 12 ++-- examples/BasicDemo/CMakeLists.txt | 1 + examples/BasicDemo/premake4.lua | 12 +++- .../CommonInterfaces/CommonCameraInterface.h | 4 +- .../CommonGUIHelperInterface.h | 4 +- .../CommonInterfaces/CommonRenderInterface.h | 4 +- .../InProcessExampleBrowser.cpp | 4 +- examples/ExampleBrowser/OpenGLGuiHelper.h | 2 +- examples/ExtendedTutorials/premake4.lua | 8 ++- .../MultiThreading/MultiThreadingExample.cpp | 2 +- .../MultiThreading/b3Win32ThreadSupport.cpp | 35 +++++++-- .../MultiThreading/b3Win32ThreadSupport.h | 4 +- .../OpenGLWindow/GLInstancingRenderer.cpp | 46 ++++++++---- examples/OpenGLWindow/GLInstancingRenderer.h | 5 +- examples/OpenGLWindow/SimpleCamera.cpp | 10 +++ examples/OpenGLWindow/SimpleCamera.h | 2 + .../OpenGLWindow/SimpleOpenGL2Renderer.cpp | 8 +++ examples/OpenGLWindow/SimpleOpenGL2Renderer.h | 2 + .../SharedMemory/PhysicsServerExample.cpp | 71 +++++++++++-------- .../StandaloneMain/hellovr_opengl_main.cpp | 27 +++++++ .../main_opengl_single_example.cpp | 17 +++-- examples/Utils/b3Clock.cpp | 15 ++-- examples/Utils/b3Clock.h | 7 +- examples/pybullet/pybullet.c | 19 ++--- .../Bullet2FileLoader/b3DNA.cpp | 22 +----- .../Bullet2FileLoader/b3File.cpp | 22 +----- 28 files changed, 243 insertions(+), 170 deletions(-) diff --git a/Extras/Serialize/BulletFileLoader/bDNA.cpp b/Extras/Serialize/BulletFileLoader/bDNA.cpp index f30f7fec6..86d15cfdd 100644 --- a/Extras/Serialize/BulletFileLoader/bDNA.cpp +++ b/Extras/Serialize/BulletFileLoader/bDNA.cpp @@ -389,18 +389,10 @@ void bDNA::init(char *data, int len, bool swap) cp++; } + + + cp = btAlignPointer(cp,4); - { - nr= (long)cp; - //long mask=3; - nr= ((nr+3)&~3)-nr; - while (nr--) - { - cp++; - } - } - - /* TYPE (4 bytes) amount of types (int) @@ -426,17 +418,8 @@ void bDNA::init(char *data, int len, bool swap) cp++; } -{ - nr= (long)cp; - // long mask=3; - nr= ((nr+3)&~3)-nr; - while (nr--) - { - cp++; - } - } - - + cp = btAlignPointer(cp,4); + /* TLEN (4 bytes) (short) the lengths of types diff --git a/Extras/Serialize/BulletFileLoader/bFile.cpp b/Extras/Serialize/BulletFileLoader/bFile.cpp index 35135ba7a..cb8010dc2 100644 --- a/Extras/Serialize/BulletFileLoader/bFile.cpp +++ b/Extras/Serialize/BulletFileLoader/bFile.cpp @@ -460,15 +460,7 @@ void bFile::swapDNA(char* ptr) } - { - nr= (long)cp; - //long mask=3; - nr= ((nr+3)&~3)-nr; - while (nr--) - { - cp++; - } - } + cp = btAlignPointer(cp,4); /* @@ -497,16 +489,7 @@ void bFile::swapDNA(char* ptr) cp++; } -{ - nr= (long)cp; - // long mask=3; - nr= ((nr+3)&~3)-nr; - while (nr--) - { - cp++; - } - } - + cp = btAlignPointer(cp,4); /* TLEN (4 bytes) diff --git a/examples/BasicDemo/BasicExample.cpp b/examples/BasicDemo/BasicExample.cpp index b6365df36..b687c35b1 100644 --- a/examples/BasicDemo/BasicExample.cpp +++ b/examples/BasicDemo/BasicExample.cpp @@ -39,7 +39,7 @@ struct BasicExample : public CommonRigidBodyBase virtual void renderScene(); void resetCamera() { - float dist = 41; + float dist = 4; float pitch = 52; float yaw = 35; float targetPos[3]={0,0,0}; @@ -81,7 +81,7 @@ void BasicExample::initPhysics() //create a few dynamic rigidbodies // Re-using the same collision is better for memory usage and performance - btBoxShape* colShape = createBoxShape(btVector3(1,1,1)); + btBoxShape* colShape = createBoxShape(btVector3(.1,.1,.1)); //btCollisionShape* colShape = new btSphereShape(btScalar(1.)); @@ -108,9 +108,9 @@ void BasicExample::initPhysics() for(int j = 0;jautogenerateGraphicsObjects(m_dynamicsWorld); + } diff --git a/examples/BasicDemo/CMakeLists.txt b/examples/BasicDemo/CMakeLists.txt index 2ad8f8ccf..f01a03a51 100644 --- a/examples/BasicDemo/CMakeLists.txt +++ b/examples/BasicDemo/CMakeLists.txt @@ -53,6 +53,7 @@ SET(AppBasicExampleGui_SRCS ../ExampleBrowser/OpenGLGuiHelper.cpp ../ExampleBrowser/GL_ShapeDrawer.cpp ../ExampleBrowser/CollisionShape2TriangleMesh.cpp + ../Utils/b3Clock.cpp ) #this define maps StandaloneExampleCreateFunc to the right 'CreateFunc' diff --git a/examples/BasicDemo/premake4.lua b/examples/BasicDemo/premake4.lua index dd88389e1..dd924249e 100644 --- a/examples/BasicDemo/premake4.lua +++ b/examples/BasicDemo/premake4.lua @@ -49,6 +49,8 @@ files { "../ExampleBrowser/OpenGLGuiHelper.cpp", "../ExampleBrowser/GL_ShapeDrawer.cpp", "../ExampleBrowser/CollisionShape2TriangleMesh.cpp", + "../Utils/b3Clock.cpp", + "../Utils/b3Clock.h", } if os.is("Linux") then initX11() end @@ -93,7 +95,9 @@ files { "../TinyRenderer/tgaimage.cpp", "../TinyRenderer/our_gl.cpp", "../TinyRenderer/TinyRenderer.cpp", - "../Utils/b3ResourcePath.cpp" + "../Utils/b3ResourcePath.cpp", + "../Utils/b3Clock.cpp", + "../Utils/b3Clock.h", } if os.is("Linux") then initX11() end @@ -132,7 +136,9 @@ files { "../TinyRenderer/tgaimage.cpp", "../TinyRenderer/our_gl.cpp", "../TinyRenderer/TinyRenderer.cpp", - "../Utils/b3ResourcePath.cpp" + "../Utils/b3ResourcePath.cpp", + "../Utils/b3Clock.cpp", + "../Utils/b3Clock.h", } @@ -179,6 +185,8 @@ files { "../ThirdPartyLibs/openvr/samples/shared/pathtools.cpp", "../ThirdPartyLibs/openvr/samples/shared/pathtools.h", "../ThirdPartyLibs/openvr/samples/shared/Vectors.h", + "../Utils/b3Clock.cpp", + "../Utils/b3Clock.h", } diff --git a/examples/CommonInterfaces/CommonCameraInterface.h b/examples/CommonInterfaces/CommonCameraInterface.h index 73147d760..9c1740788 100644 --- a/examples/CommonInterfaces/CommonCameraInterface.h +++ b/examples/CommonInterfaces/CommonCameraInterface.h @@ -6,7 +6,9 @@ struct CommonCameraInterface virtual void getCameraProjectionMatrix(float m[16])const = 0; virtual void getCameraViewMatrix(float m[16]) const = 0; - virtual void setVRCamera(const float viewMat[16], const float projectionMatrix[16])=0; + virtual void setVRCamera(const float viewMat[16], const float projectionMatrix[16])=0; + virtual void disableVRCamera()=0; + virtual bool isVRCamera() const =0; virtual void getCameraTargetPosition(float pos[3]) const = 0; virtual void getCameraPosition(float pos[3]) const = 0; diff --git a/examples/CommonInterfaces/CommonGUIHelperInterface.h b/examples/CommonInterfaces/CommonGUIHelperInterface.h index f76414126..a8ff41d4f 100644 --- a/examples/CommonInterfaces/CommonGUIHelperInterface.h +++ b/examples/CommonInterfaces/CommonGUIHelperInterface.h @@ -33,7 +33,7 @@ struct GUIHelperInterface virtual int registerGraphicsShape(const float* vertices, int numvertices, const int* indices, int numIndices,int primitiveType, int textureId) = 0; virtual int registerGraphicsInstance(int shapeIndex, const float* position, const float* quaternion, const float* color, const float* scaling) =0; virtual void removeAllGraphicsInstances()=0; - + virtual Common2dCanvasInterface* get2dCanvasInterface()=0; virtual CommonParameterInterface* getParameterInterface()=0; @@ -78,7 +78,7 @@ struct DummyGUIHelper : public GUIHelperInterface virtual int registerGraphicsShape(const float* vertices, int numvertices, const int* indices, int numIndices,int primitiveType, int textureId){return -1;} virtual int registerGraphicsInstance(int shapeIndex, const float* position, const float* quaternion, const float* color, const float* scaling) {return -1;} virtual void removeAllGraphicsInstances(){} - + virtual Common2dCanvasInterface* get2dCanvasInterface() { return 0; diff --git a/examples/CommonInterfaces/CommonRenderInterface.h b/examples/CommonInterfaces/CommonRenderInterface.h index 0242a2bbe..0ac09975f 100644 --- a/examples/CommonInterfaces/CommonRenderInterface.h +++ b/examples/CommonInterfaces/CommonRenderInterface.h @@ -22,7 +22,7 @@ struct CommonRenderInterface virtual void init()=0; virtual void updateCamera(int upAxis)=0; virtual void removeAllInstances() = 0; - + virtual const CommonCameraInterface* getActiveCamera() const =0; virtual CommonCameraInterface* getActiveCamera()=0; virtual void setActiveCamera(CommonCameraInterface* cam)=0; @@ -52,6 +52,8 @@ struct CommonRenderInterface virtual void writeSingleInstanceTransformToCPU(const double* position, const double* orientation, int srcIndex)=0; virtual void writeSingleInstanceColorToCPU(float* color, int srcIndex)=0; virtual void writeSingleInstanceColorToCPU(double* color, int srcIndex)=0; + virtual void writeSingleInstanceScaleToCPU(float* scale, int srcIndex)=0; + virtual void writeSingleInstanceScaleToCPU(double* scale, int srcIndex)=0; virtual int getTotalNumInstances() const = 0; diff --git a/examples/ExampleBrowser/InProcessExampleBrowser.cpp b/examples/ExampleBrowser/InProcessExampleBrowser.cpp index b7254db71..e562b5d52 100644 --- a/examples/ExampleBrowser/InProcessExampleBrowser.cpp +++ b/examples/ExampleBrowser/InProcessExampleBrowser.cpp @@ -226,7 +226,7 @@ enum TestExampleBrowserCommunicationEnums void ExampleBrowserThreadFunc(void* userPtr,void* lsMemory) { - printf("thread started\n"); + printf("ExampleBrowserThreadFunc started\n"); ExampleBrowserThreadLocalStorage* localStorage = (ExampleBrowserThreadLocalStorage*) lsMemory; @@ -369,7 +369,7 @@ void btShutDownExampleBrowser(btInProcessExampleBrowserInternalData* data) } }; - printf("stopping threads\n"); + printf("btShutDownExampleBrowser stopping threads\n"); delete data->m_threadSupport; delete data->m_sharedMem; delete data; diff --git a/examples/ExampleBrowser/OpenGLGuiHelper.h b/examples/ExampleBrowser/OpenGLGuiHelper.h index 72d784a0c..707b325ae 100644 --- a/examples/ExampleBrowser/OpenGLGuiHelper.h +++ b/examples/ExampleBrowser/OpenGLGuiHelper.h @@ -24,7 +24,7 @@ struct OpenGLGuiHelper : public GUIHelperInterface virtual int registerGraphicsShape(const float* vertices, int numvertices, const int* indices, int numIndices,int primitiveType, int textureId); virtual int registerGraphicsInstance(int shapeIndex, const float* position, const float* quaternion, const float* color, const float* scaling); virtual void removeAllGraphicsInstances(); - + virtual void createCollisionShapeGraphicsObject(btCollisionShape* collisionShape); virtual void syncPhysicsToGraphics(const btDiscreteDynamicsWorld* rbWorld); diff --git a/examples/ExtendedTutorials/premake4.lua b/examples/ExtendedTutorials/premake4.lua index 92ac12d45..41126e0af 100644 --- a/examples/ExtendedTutorials/premake4.lua +++ b/examples/ExtendedTutorials/premake4.lua @@ -39,7 +39,7 @@ files { "../Importers/ImportURDFDemo/UrdfParser.cpp", "../Importers/ImportURDFDemo/urdfStringSplit.cpp", "../Importers/ImportMeshUtility/b3ImportMeshUtility.cpp", - "../ThirdPartyLibs/stb_image/stb_image.cpp", + "../ThirdPartyLibs/stb_image/stb_image.cpp", } @@ -91,7 +91,9 @@ files { "../Importers/ImportURDFDemo/UrdfParser.cpp", "../Importers/ImportURDFDemo/urdfStringSplit.cpp", "../Importers/ImportMeshUtility/b3ImportMeshUtility.cpp", - "../ThirdPartyLibs/stb_image/stb_image.cpp", + "../ThirdPartyLibs/stb_image/stb_image.cpp", + "../Utils/b3Clock.cpp", + "../Utils/b3Clock.h", } if os.is("Linux") then initX11() end @@ -156,7 +158,7 @@ files { "../Importers/ImportURDFDemo/UrdfParser.cpp", "../Importers/ImportURDFDemo/urdfStringSplit.cpp", "../Importers/ImportMeshUtility/b3ImportMeshUtility.cpp", - "../ThirdPartyLibs/stb_image/stb_image.cpp", + "../ThirdPartyLibs/stb_image/stb_image.cpp", } if os.is("Linux") then initX11() end diff --git a/examples/MultiThreading/MultiThreadingExample.cpp b/examples/MultiThreading/MultiThreadingExample.cpp index 2e9f9ee15..1969912b9 100644 --- a/examples/MultiThreading/MultiThreadingExample.cpp +++ b/examples/MultiThreading/MultiThreadingExample.cpp @@ -119,7 +119,7 @@ struct SampleThreadLocalStorage void SampleThreadFunc(void* userPtr,void* lsMemory) { - printf("thread started\n"); + printf("SampleThreadFunc thread started\n"); SampleThreadLocalStorage* localStorage = (SampleThreadLocalStorage*) lsMemory; diff --git a/examples/MultiThreading/b3Win32ThreadSupport.cpp b/examples/MultiThreading/b3Win32ThreadSupport.cpp index db1d5915a..199533b1b 100644 --- a/examples/MultiThreading/b3Win32ThreadSupport.cpp +++ b/examples/MultiThreading/b3Win32ThreadSupport.cpp @@ -223,7 +223,8 @@ bool b3Win32ThreadSupport::isTaskCompleted(int *puiArgument0, int *puiArgument1, void b3Win32ThreadSupport::startThreads(const Win32ThreadConstructionInfo& threadConstructionInfo) { - + static int uniqueId = 0; + uniqueId++; m_activeThreadStatus.resize(threadConstructionInfo.m_numThreads); m_completeHandles.resize(threadConstructionInfo.m_numThreads); @@ -244,18 +245,40 @@ void b3Win32ThreadSupport::startThreads(const Win32ThreadConstructionInfo& threa threadStatus.m_userPtr=0; - sprintf(threadStatus.m_eventStartHandleName,"eventStart%8.s%d",threadConstructionInfo.m_uniqueName,i); + sprintf(threadStatus.m_eventStartHandleName,"es%.8s%d%d",threadConstructionInfo.m_uniqueName,uniqueId,i); threadStatus.m_eventStartHandle = CreateEventA (0,false,false,threadStatus.m_eventStartHandleName); - sprintf(threadStatus.m_eventCompletetHandleName,"eventComplete%8.s%d",threadConstructionInfo.m_uniqueName,i); + sprintf(threadStatus.m_eventCompletetHandleName,"ec%.8s%d%d",threadConstructionInfo.m_uniqueName,uniqueId,i); threadStatus.m_eventCompletetHandle = CreateEventA (0,false,false,threadStatus.m_eventCompletetHandleName); m_completeHandles[i] = threadStatus.m_eventCompletetHandle; HANDLE handle = CreateThread(lpThreadAttributes,dwStackSize,lpStartAddress,lpParameter, dwCreationFlags,lpThreadId); - //SetThreadPriority(handle,THREAD_PRIORITY_HIGHEST); - SetThreadPriority(handle,THREAD_PRIORITY_TIME_CRITICAL); + switch(threadConstructionInfo.m_priority) + { + case 0: + { + SetThreadPriority(handle,THREAD_PRIORITY_HIGHEST); + break; + } + case 1: + { + SetThreadPriority(handle,THREAD_PRIORITY_TIME_CRITICAL); + break; + } + case 2: + { + SetThreadPriority(handle,THREAD_PRIORITY_BELOW_NORMAL); + break; + } + + default: + { + + } + } + SetThreadAffinityMask(handle, 1<m_totalNumInstances = 0; + for (int i=0;im_index_vbo) @@ -276,6 +278,7 @@ void GLInstancingRenderer::removeAllInstances() m_graphicsInstances.clear(); } + GLInstancingRenderer::~GLInstancingRenderer() { delete m_data->m_shadowMap; @@ -323,6 +326,7 @@ void GLInstancingRenderer::writeSingleInstanceTransformToCPU(const float* positi */ } + void GLInstancingRenderer::writeSingleInstanceColorToCPU(double* color, int srcIndex) { m_data->m_instance_colors_ptr[srcIndex*4+0]=float(color[0]); @@ -340,7 +344,19 @@ void GLInstancingRenderer::writeSingleInstanceColorToCPU(float* color, int srcIn m_data->m_instance_colors_ptr[srcIndex*4+3]=color[3]; } +void GLInstancingRenderer::writeSingleInstanceScaleToCPU(float* scale, int srcIndex) +{ + m_data->m_instance_scale_ptr[srcIndex*3+0]=scale[0]; + m_data->m_instance_scale_ptr[srcIndex*3+1]=scale[1]; + m_data->m_instance_scale_ptr[srcIndex*3+2]=scale[2]; +} +void GLInstancingRenderer::writeSingleInstanceScaleToCPU(double* scale, int srcIndex) +{ + m_data->m_instance_scale_ptr[srcIndex*3+0]=scale[0]; + m_data->m_instance_scale_ptr[srcIndex*3+1]=scale[1]; + m_data->m_instance_scale_ptr[srcIndex*3+2]=scale[2]; +} void GLInstancingRenderer::writeSingleInstanceTransformToGPU(float* position, float* orientation, int objectIndex) { @@ -389,27 +405,33 @@ void GLInstancingRenderer::writeTransforms() //glFlush(); b3Assert(glGetError() ==GL_NO_ERROR); - int totalNumInstances= 0; + - for (int k=0;km_numGraphicsInstances; + int totalNumInstances= 0; + for (int k=0;km_numGraphicsInstances; + } + b3Assert(m_data->m_totalNumInstances == totalNumInstances); } +#endif//B3_DEBUG - int POSITION_BUFFER_SIZE = (totalNumInstances*sizeof(float)*4); - int ORIENTATION_BUFFER_SIZE = (totalNumInstances*sizeof(float)*4); - int COLOR_BUFFER_SIZE = (totalNumInstances*sizeof(float)*4); + int POSITION_BUFFER_SIZE = (m_data->m_totalNumInstances*sizeof(float)*4); + int ORIENTATION_BUFFER_SIZE = (m_data->m_totalNumInstances*sizeof(float)*4); + int COLOR_BUFFER_SIZE = (m_data->m_totalNumInstances*sizeof(float)*4); // int SCALE_BUFFER_SIZE = (totalNumInstances*sizeof(float)*3); #if 1 - glBufferSubData( GL_ARRAY_BUFFER,m_data->m_maxShapeCapacityInBytes,totalNumInstances*sizeof(float)*4, + glBufferSubData( GL_ARRAY_BUFFER,m_data->m_maxShapeCapacityInBytes,m_data->m_totalNumInstances*sizeof(float)*4, &m_data->m_instance_positions_ptr[0]); - glBufferSubData( GL_ARRAY_BUFFER,m_data->m_maxShapeCapacityInBytes+POSITION_BUFFER_SIZE,totalNumInstances*sizeof(float)*4, + glBufferSubData( GL_ARRAY_BUFFER,m_data->m_maxShapeCapacityInBytes+POSITION_BUFFER_SIZE,m_data->m_totalNumInstances*sizeof(float)*4, &m_data->m_instance_quaternion_ptr[0]); - glBufferSubData( GL_ARRAY_BUFFER,m_data->m_maxShapeCapacityInBytes+ POSITION_BUFFER_SIZE+ORIENTATION_BUFFER_SIZE, totalNumInstances*sizeof(float)*4, + glBufferSubData( GL_ARRAY_BUFFER,m_data->m_maxShapeCapacityInBytes+ POSITION_BUFFER_SIZE+ORIENTATION_BUFFER_SIZE, m_data->m_totalNumInstances*sizeof(float)*4, &m_data->m_instance_colors_ptr[0]); - glBufferSubData( GL_ARRAY_BUFFER, m_data->m_maxShapeCapacityInBytes+POSITION_BUFFER_SIZE+ORIENTATION_BUFFER_SIZE+COLOR_BUFFER_SIZE,totalNumInstances*sizeof(float)*3, + glBufferSubData( GL_ARRAY_BUFFER, m_data->m_maxShapeCapacityInBytes+POSITION_BUFFER_SIZE+ORIENTATION_BUFFER_SIZE+COLOR_BUFFER_SIZE,m_data->m_totalNumInstances*sizeof(float)*3, &m_data->m_instance_scale_ptr[0]); #else @@ -419,7 +441,7 @@ void GLInstancingRenderer::writeTransforms() - m_data->m_totalNumInstances = totalNumInstances; + for (int k=0;km_enableVR = false; +} + +bool SimpleCamera::isVRCamera() const +{ + return m_data->m_enableVR ; +} + static void b3CreateFrustum( float left, diff --git a/examples/OpenGLWindow/SimpleCamera.h b/examples/OpenGLWindow/SimpleCamera.h index 51f802f9b..5a057baf0 100644 --- a/examples/OpenGLWindow/SimpleCamera.h +++ b/examples/OpenGLWindow/SimpleCamera.h @@ -15,6 +15,8 @@ struct SimpleCamera : public CommonCameraInterface virtual void getCameraViewMatrix(float m[16]) const; virtual void setVRCamera(const float viewMat[16], const float projectionMatrix[16]); + virtual void disableVRCamera(); + virtual bool isVRCamera() const; virtual void getCameraTargetPosition(float pos[3]) const; virtual void getCameraPosition(float pos[3]) const; diff --git a/examples/OpenGLWindow/SimpleOpenGL2Renderer.cpp b/examples/OpenGLWindow/SimpleOpenGL2Renderer.cpp index dbc90d729..050ec447e 100644 --- a/examples/OpenGLWindow/SimpleOpenGL2Renderer.cpp +++ b/examples/OpenGLWindow/SimpleOpenGL2Renderer.cpp @@ -65,6 +65,14 @@ void SimpleOpenGL2Renderer::writeSingleInstanceColorToCPU(double* color, int src } +void SimpleOpenGL2Renderer::writeSingleInstanceScaleToCPU(float* scale, int srcIndex) +{ +} +void SimpleOpenGL2Renderer::writeSingleInstanceScaleToCPU(double* scale, int srcIndex) +{ +} + + int SimpleOpenGL2Renderer::getTotalNumInstances() const { return 0; diff --git a/examples/OpenGLWindow/SimpleOpenGL2Renderer.h b/examples/OpenGLWindow/SimpleOpenGL2Renderer.h index 0e343a4a6..393cc7375 100644 --- a/examples/OpenGLWindow/SimpleOpenGL2Renderer.h +++ b/examples/OpenGLWindow/SimpleOpenGL2Renderer.h @@ -32,6 +32,8 @@ struct SimpleOpenGL2Renderer : public CommonRenderInterface virtual void writeSingleInstanceColorToCPU(float* color, int srcIndex); virtual void writeSingleInstanceColorToCPU(double* color, int srcIndex); + virtual void writeSingleInstanceScaleToCPU(float* scale, int srcIndex); + virtual void writeSingleInstanceScaleToCPU(double* scale, int srcIndex); virtual void getCameraViewMatrix(float viewMat[16]) const; virtual void getCameraProjectionMatrix(float projMat[16]) const; diff --git a/examples/SharedMemory/PhysicsServerExample.cpp b/examples/SharedMemory/PhysicsServerExample.cpp index 003064e94..85d896a72 100644 --- a/examples/SharedMemory/PhysicsServerExample.cpp +++ b/examples/SharedMemory/PhysicsServerExample.cpp @@ -97,11 +97,9 @@ struct MotionThreadLocalStorage int skip = 0; - void MotionThreadFunc(void* userPtr,void* lsMemory) { - printf("thread started\n"); - + printf("MotionThreadFunc thread started\n"); MotionThreadLocalStorage* localStorage = (MotionThreadLocalStorage*) lsMemory; MotionArgs* args = (MotionArgs*) userPtr; @@ -116,41 +114,23 @@ void MotionThreadFunc(void* userPtr,void* lsMemory) args->m_cs->setSharedParam(0,eMotionIsInitialized); args->m_cs->unlock(); - double m_x=0; - double m_y=0; - double m_z=0; - do { - double deltaTimeInSeconds = double(clock.getTimeMicroseconds())/1000000.; - //if (deltaTimeInSeconds<.3) - //if (deltaTimeInSeconds<(1./15.)) if (deltaTimeInSeconds<(1./260.)) { skip++; - //if (deltaTimeInSeconds<.001) - continue; + if (deltaTimeInSeconds<.001) + continue; } - m_x+=deltaTimeInSeconds; - m_y+=deltaTimeInSeconds; - m_z+=deltaTimeInSeconds; - clock.reset(); - - int index = 0; - index++; - if (!blockme) { - args->m_physicsServerPtr->processClientCommands(); + args->m_physicsServerPtr->processClientCommands(); } - - - } while (args->m_cs->getSharedParam(0)!=eRequestTerminateMotion); } else { @@ -160,9 +140,6 @@ void MotionThreadFunc(void* userPtr,void* lsMemory) } - args->m_cs->lock(); - args->m_cs->setSharedParam(0,eMotionHasTerminated); - args->m_cs->unlock(); printf("finished, #skip = %d\n",skip); skip=0; //do nothing @@ -358,7 +335,7 @@ public: virtual CommonGraphicsApp* getAppInterface() { - return 0; + return m_childGuiHelper->getAppInterface(); } @@ -615,7 +592,7 @@ void PhysicsServerExample::exitPhysics() delete m_threadSupport; m_threadSupport = 0; - m_physicsServer.resetDynamicsWorld(); + //m_physicsServer.resetDynamicsWorld(); } @@ -698,6 +675,9 @@ void PhysicsServerExample::stepSimulation(float deltaTime) case eGUIHelperRemoveAllGraphicsInstances: { m_multiThreadedHelper->m_childGuiHelper->removeAllGraphicsInstances(); + int numRenderInstances = m_multiThreadedHelper->m_childGuiHelper->getRenderInterface()->getTotalNumInstances(); + b3Assert(numRenderInstances==0); + m_multiThreadedHelper->getCriticalSection()->lock(); m_multiThreadedHelper->getCriticalSection()->setSharedParam(1,eGUIHelperIdle); m_multiThreadedHelper->getCriticalSection()->unlock(); @@ -739,12 +719,45 @@ void PhysicsServerExample::stepSimulation(float deltaTime) } } + void PhysicsServerExample::renderScene() { ///debug rendering //m_args[0].m_cs->lock(); m_physicsServer.renderScene(); + + if (m_guiHelper->getAppInterface()->m_renderer->getActiveCamera()->isVRCamera()) + { + //some little experiment to add text/HUD to a VR camera (HTC Vive/Oculus Rift) + + static int frameCount=0; + frameCount++; + char bla[1024]; + sprintf(bla,"VR sub-title text test, frame %d", frameCount/2); + float pos[4]; + m_guiHelper->getAppInterface()->m_renderer->getActiveCamera()->getCameraTargetPosition(pos); + btTransform viewTr; + btScalar m[16]; + float mf[16]; + m_guiHelper->getAppInterface()->m_renderer->getActiveCamera()->getCameraViewMatrix(mf); + for (int i=0;i<16;i++) + { + m[i] = mf[i]; + } + viewTr.setFromOpenGLMatrix(m); + btTransform viewTrInv = viewTr.inverse(); + float upMag = -.6; + btVector3 side = viewTrInv.getBasis().getColumn(0); + btVector3 up = viewTrInv.getBasis().getColumn(1); + up+=0.35*side; + m_guiHelper->getAppInterface()->drawText3D(bla,pos[0]+upMag*up[0],pos[1]+upMag*up[1],pos[2]+upMag*up[2],1); + //btVector3 fwd = viewTrInv.getBasis().getColumn(2); + sprintf(bla,"VR line 2 sub-title text test, frame %d", frameCount/2); + upMag = -0.7; + m_guiHelper->getAppInterface()->drawText3D(bla,pos[0]+upMag*up[0],pos[1]+upMag*up[1],pos[2]+upMag*up[2],1); + } + //m_args[0].m_cs->unlock(); } diff --git a/examples/StandaloneMain/hellovr_opengl_main.cpp b/examples/StandaloneMain/hellovr_opengl_main.cpp index 6fe0aca97..dcb7aa22f 100644 --- a/examples/StandaloneMain/hellovr_opengl_main.cpp +++ b/examples/StandaloneMain/hellovr_opengl_main.cpp @@ -1486,7 +1486,34 @@ void CMainApplication::RenderStereoTargets() { Matrix4 viewMatLeft = m_mat4eyePosLeft * m_mat4HMDPose * rotYtoZ; + Matrix4 viewMatCenter = m_mat4HMDPose * rotYtoZ; + //0,1,2,3 + //4,5,6,7, + //8,9,10,11 + //12,13,14,15 + //m_mat4eyePosLeft.get()[10] + //m_app->m_instancingRenderer->getActiveCamera()->setCameraTargetPosition( + // m_mat4eyePosLeft.get()[3], + // m_mat4eyePosLeft.get()[7], + // m_mat4eyePosLeft.get()[11]); + Matrix4 m; + m = viewMatCenter; + const float* mat = m.invertAffine().get(); + + /*printf("camera:\n,%f,%f,%f,%f\n%f,%f,%f,%f\n%f,%f,%f,%f\n%f,%f,%f,%f", + mat[0],mat[1],mat[2],mat[3], + mat[4],mat[5],mat[6],mat[7], + mat[8],mat[9],mat[10],mat[11], + mat[12],mat[13],mat[14],mat[15]); + */ + float dist=1; + m_app->m_instancingRenderer->getActiveCamera()->setCameraTargetPosition( + mat[12]-dist*mat[8], + mat[13]-dist*mat[9], + mat[14]-dist*mat[10] + ); + m_app->m_instancingRenderer->getActiveCamera()->setCameraUpVector(mat[0],mat[1],mat[2]); m_app->m_instancingRenderer->getActiveCamera()->setVRCamera(viewMatLeft.get(),m_mat4ProjectionLeft.get()); m_app->m_instancingRenderer->updateCamera(m_app->getUpAxis()); } diff --git a/examples/StandaloneMain/main_opengl_single_example.cpp b/examples/StandaloneMain/main_opengl_single_example.cpp index d331e7607..8bf97619d 100644 --- a/examples/StandaloneMain/main_opengl_single_example.cpp +++ b/examples/StandaloneMain/main_opengl_single_example.cpp @@ -17,14 +17,9 @@ subject to the following restrictions: #include "../CommonInterfaces/CommonExampleInterface.h" #include "../CommonInterfaces/CommonGUIHelperInterface.h" -#include "BulletCollision/CollisionDispatch/btCollisionObject.h" -#include "BulletCollision/CollisionShapes/btCollisionShape.h" -#include "BulletDynamics/Dynamics/btDiscreteDynamicsWorld.h" +#include "../Utils/b3Clock.h" -#include "LinearMath/btTransform.h" -#include "LinearMath/btHashMap.h" - #include "../OpenGLWindow/SimpleOpenGL3App.h" @@ -74,7 +69,7 @@ public: }; int main(int argc, char* argv[]) { - + SimpleOpenGL3App* app = new SimpleOpenGL3App("Bullet Standalone Example",1024,768,true); prevMouseButtonCallback = app->m_window->getMouseButtonCallback(); @@ -93,13 +88,17 @@ int main(int argc, char* argv[]) example->initPhysics(); example->resetCamera(); + b3Clock clock; + do { app->m_instancingRenderer->init(); app->m_instancingRenderer->updateCamera(app->getUpAxis()); - example->stepSimulation(1./60.); - + btScalar dtSec = btScalar(clock.getTimeInSeconds()); + example->stepSimulation(dtSec); + clock.reset(); + example->renderScene(); DrawGridData dg; diff --git a/examples/Utils/b3Clock.cpp b/examples/Utils/b3Clock.cpp index a504ba856..6802726d9 100644 --- a/examples/Utils/b3Clock.cpp +++ b/examples/Utils/b3Clock.cpp @@ -166,7 +166,7 @@ unsigned long int b3Clock::getTimeMilliseconds() /// Returns the time in us since the last call to reset or since /// the Clock was created. -unsigned long int b3Clock::getTimeMicroseconds() +unsigned long long int b3Clock::getTimeMicroseconds() { #ifdef B3_USE_WINDOWS_TIMERS LARGE_INTEGER currentTime; @@ -175,14 +175,14 @@ unsigned long int b3Clock::getTimeMicroseconds() m_data->mStartTime.QuadPart; // Compute the number of millisecond ticks elapsed. - unsigned long msecTicks = (unsigned long)(1000 * elapsedTime / + unsigned long long msecTicks = (unsigned long long)(1000 * elapsedTime / m_data->mClockFrequency.QuadPart); // Check for unexpected leaps in the Win32 performance counter. // (This is caused by unexpected data across the PCI to ISA // bridge, aka south bridge. See Microsoft KB274323.) - unsigned long elapsedTicks = GetTickCount() - m_data->mStartTick; - signed long msecOff = (signed long)(msecTicks - elapsedTicks); + unsigned long long elapsedTicks = GetTickCount() - m_data->mStartTick; + signed long long msecOff = (signed long)(msecTicks - elapsedTicks); if (msecOff < -100 || msecOff > 100) { // Adjust the starting time forwards. @@ -197,7 +197,7 @@ unsigned long int b3Clock::getTimeMicroseconds() m_data->mPrevElapsedTime = elapsedTime; // Convert to microseconds. - unsigned long usecTicks = (unsigned long)(1000000 * elapsedTime / + unsigned long long usecTicks = (unsigned long)(1000000 * elapsedTime / m_data->mClockFrequency.QuadPart); return usecTicks; @@ -222,3 +222,8 @@ unsigned long int b3Clock::getTimeMicroseconds() #endif } +double b3Clock::getTimeInSeconds() +{ + return double(getTimeMicroseconds()/1.e6); +} + diff --git a/examples/Utils/b3Clock.h b/examples/Utils/b3Clock.h index d30c615a3..cb1c0c29d 100644 --- a/examples/Utils/b3Clock.h +++ b/examples/Utils/b3Clock.h @@ -22,7 +22,12 @@ public: /// Returns the time in us since the last call to reset or since /// the Clock was created. - unsigned long int getTimeMicroseconds(); + unsigned long long int getTimeMicroseconds(); + + /// Returns the time in seconds since the last call to reset or since + /// the Clock was created. + double getTimeInSeconds(); + private: struct b3ClockData* m_data; }; diff --git a/examples/pybullet/pybullet.c b/examples/pybullet/pybullet.c index 4212ed996..58e4df4c2 100644 --- a/examples/pybullet/pybullet.c +++ b/examples/pybullet/pybullet.c @@ -374,8 +374,8 @@ static PyObject* pybullet_setJointMotorControl(PyObject* self, PyObject* args) { case CONTROL_MODE_VELOCITY: { + double kd = gains; b3JointControlSetDesiredVelocity(commandHandle, info.m_uIndex, targetValue); - double kd = gains; b3JointControlSetKd(commandHandle,info.m_uIndex,kd); b3JointControlSetMaximumForce(commandHandle,info.m_uIndex,maxForce); break; @@ -389,8 +389,8 @@ static PyObject* pybullet_setJointMotorControl(PyObject* self, PyObject* args) case CONTROL_MODE_POSITION_VELOCITY_PD: { + double kp = gains; b3JointControlSetDesiredPosition( commandHandle, info.m_qIndex, targetValue); - double kp = gains; b3JointControlSetKp(commandHandle,info.m_uIndex,kp); b3JointControlSetMaximumForce(commandHandle,info.m_uIndex,maxForce); break; @@ -1270,10 +1270,12 @@ static PyObject* pybullet_applyExternalTorque(PyObject* self, PyObject* args) PyErr_SetString(SpamError, "flag has to be either WORLD_FRAME or LINK_FRAME"); return NULL; } - b3SharedMemoryStatusHandle statusHandle; - b3SharedMemoryCommandHandle command = b3ApplyExternalForceCommandInit(sm); - b3ApplyExternalTorque(command,objectUniqueId,-1,torque, flags); - statusHandle = b3SubmitClientCommandAndWaitStatus(sm, command); + { + b3SharedMemoryStatusHandle statusHandle; + b3SharedMemoryCommandHandle command = b3ApplyExternalForceCommandInit(sm); + b3ApplyExternalTorque(command,objectUniqueId,-1,torque, flags); + statusHandle = b3SubmitClientCommandAndWaitStatus(sm, command); + } } } @@ -1389,12 +1391,13 @@ static PyObject* pybullet_getEulerFromQuaternion(PyObject* self, PyObject* args) { double rpy[3]; - sqx = quat[0] * quat[0]; + double sarg; + sqx = quat[0] * quat[0]; sqy = quat[1] * quat[1]; sqz = quat[2] * quat[2]; squ = quat[3] * quat[3]; rpy[0] = atan2(2 * (quat[1]*quat[2] + quat[3]*quat[0]), squ - sqx - sqy + sqz); - double sarg = -2 * (quat[0]*quat[2] - quat[3] * quat[1]); + sarg = -2 * (quat[0]*quat[2] - quat[3] * quat[1]); rpy[1] = sarg <= -1.0 ? -0.5*3.141592538 : (sarg >= 1.0 ? 0.5*3.141592538 : asin(sarg)); rpy[2] = atan2(2 * (quat[0]*quat[1] + quat[3]*quat[2]), squ + sqx - sqy - sqz); { diff --git a/src/Bullet3Serialize/Bullet2FileLoader/b3DNA.cpp b/src/Bullet3Serialize/Bullet2FileLoader/b3DNA.cpp index 6b332f50c..b78f76331 100644 --- a/src/Bullet3Serialize/Bullet2FileLoader/b3DNA.cpp +++ b/src/Bullet3Serialize/Bullet2FileLoader/b3DNA.cpp @@ -389,16 +389,8 @@ void bDNA::init(char *data, int len, bool swap) } - { - nr= (long)cp; - //long mask=3; - nr= ((nr+3)&~3)-nr; - while (nr--) - { - cp++; - } - } - + cp = b3AlignPointer(cp,4); + /* TYPE (4 bytes) @@ -425,16 +417,8 @@ void bDNA::init(char *data, int len, bool swap) cp++; } -{ - nr= (long)cp; - // long mask=3; - nr= ((nr+3)&~3)-nr; - while (nr--) - { - cp++; - } - } + cp = b3AlignPointer(cp,4); /* TLEN (4 bytes) diff --git a/src/Bullet3Serialize/Bullet2FileLoader/b3File.cpp b/src/Bullet3Serialize/Bullet2FileLoader/b3File.cpp index 01d3a696c..71d3b9e30 100644 --- a/src/Bullet3Serialize/Bullet2FileLoader/b3File.cpp +++ b/src/Bullet3Serialize/Bullet2FileLoader/b3File.cpp @@ -428,16 +428,7 @@ void bFile::swapDNA(char* ptr) } - { - nr= (long)cp; - //long mask=3; - nr= ((nr+3)&~3)-nr; - while (nr--) - { - cp++; - } - } - + cp = b3AlignPointer(cp,4); /* TYPE (4 bytes) @@ -465,16 +456,7 @@ void bFile::swapDNA(char* ptr) cp++; } -{ - nr= (long)cp; - // long mask=3; - nr= ((nr+3)&~3)-nr; - while (nr--) - { - cp++; - } - } - + cp = b3AlignPointer(cp,4); /* TLEN (4 bytes)