From d6464ce40d3ab0af85ef1d05855eaab2b851ada1 Mon Sep 17 00:00:00 2001 From: erwincoumans Date: Sun, 1 Nov 2015 12:48:15 -0800 Subject: [PATCH] add 'replay' command log feature: no mouse interaction during replay, and use a fixed number of sim steps in stepSimulation. workaround for reversed separating normal in gjk/epa when using very small shapes, detect case and revert normal. use smaller world size (10 units versus 100) for higher resolution shadow map use a hard-coded rolling friction of 0.2 for objects in physics server (will make this configurable) fix loading of command log files, when platform features are different (64bit/32bit) --- .../OpenGLWindow/GLInstancingRenderer.cpp | 2 +- examples/SharedMemory/PhysicsServer.cpp | 69 +++++++++++++++++-- .../SharedMemory/PhysicsServerExample.cpp | 28 ++++++-- .../btGjkPairDetector.cpp | 42 ++++++++++- 4 files changed, 127 insertions(+), 14 deletions(-) diff --git a/examples/OpenGLWindow/GLInstancingRenderer.cpp b/examples/OpenGLWindow/GLInstancingRenderer.cpp index 695f39e98..8d2bac643 100644 --- a/examples/OpenGLWindow/GLInstancingRenderer.cpp +++ b/examples/OpenGLWindow/GLInstancingRenderer.cpp @@ -19,7 +19,7 @@ subject to the following restrictions: bool useShadowMap=true;//false;//true; int shadowMapWidth=8192; int shadowMapHeight=8192; -float shadowMapWorldSize=100; +float shadowMapWorldSize=10; #define MAX_POINTS_IN_BATCH 1024 #define MAX_LINES_IN_BATCH 1024 diff --git a/examples/SharedMemory/PhysicsServer.cpp b/examples/SharedMemory/PhysicsServer.cpp index 7218f0ae3..aa43a7f52 100644 --- a/examples/SharedMemory/PhysicsServer.cpp +++ b/examples/SharedMemory/PhysicsServer.cpp @@ -119,6 +119,36 @@ public: int m_number; }; + +class bCommandChunkPtr4 +{ +public: + bCommandChunkPtr4(){} + int code; + int len; + union + { + int m_uniqueInt; + }; + int dna_nr; + int nr; +}; + +// ----------------------------------------------------- // +class bCommandChunkPtr8 +{ +public: + bCommandChunkPtr8(){} + int code, len; + union + { + int m_uniqueInts[2]; + }; + int dna_nr, nr; +}; + + + struct CommandLogger { FILE* m_file; @@ -194,8 +224,11 @@ struct CommandLogger struct CommandLogPlayback { - unsigned char* m_header[12]; + unsigned char m_header[12]; FILE* m_file; + bool m_bitsVary; + bool m_fileIs64bit; + CommandLogPlayback(const char* fileName) { @@ -204,6 +237,14 @@ struct CommandLogPlayback { fread(m_header,12,1,m_file); } + unsigned char c = m_header[7]; + m_fileIs64bit = (c=='-'); + + const bool VOID_IS_8 = ((sizeof(void*)==8)); + m_bitsVary = (VOID_IS_8 != m_fileIs64bit); + + + } virtual ~CommandLogPlayback() { @@ -215,14 +256,29 @@ struct CommandLogPlayback } bool processNextCommand(SharedMemoryCommand* cmd) { - btCommandChunk chunk; - size_t s = fread((void*)&chunk,sizeof(btCommandChunk),1,m_file); - if (s==1) + if (m_file) { - s = fread(cmd,sizeof(SharedMemoryCommand),1,m_file); - return (s==1); + size_t s = 0; + + + if (m_fileIs64bit) + { + bCommandChunkPtr8 chunk8; + s = fread((void*)&chunk8,sizeof(bCommandChunkPtr8),1,m_file); + } else + { + bCommandChunkPtr4 chunk4; + s = fread((void*)&chunk4,sizeof(bCommandChunkPtr4),1,m_file); + } + + if (s==1) + { + s = fread(cmd,sizeof(SharedMemoryCommand),1,m_file); + return (s==1); + } } return false; + } }; @@ -1627,6 +1683,7 @@ void PhysicsServerSharedMemory::processClientCommands() bool isDynamic = (mass>0); btRigidBody* rb = worldImporter->createRigidBody(isDynamic,mass,startTrans,shape,0); + rb->setRollingFriction(0.2); m_data->m_guiHelper->autogenerateGraphicsObjects(this->m_data->m_dynamicsWorld); SharedMemoryStatus& serverCmd =m_data->createServerStatus(CMD_RIGID_BODY_CREATION_COMPLETED,clientCmd.m_sequenceNumber,timeStamp); diff --git a/examples/SharedMemory/PhysicsServerExample.cpp b/examples/SharedMemory/PhysicsServerExample.cpp index 2d9fed993..7e21df1d9 100644 --- a/examples/SharedMemory/PhysicsServerExample.cpp +++ b/examples/SharedMemory/PhysicsServerExample.cpp @@ -18,6 +18,7 @@ class PhysicsServerExample : public SharedMemoryCommon bool m_isConnected; btClock m_clock; + bool m_replay; public: @@ -36,6 +37,7 @@ public: void replayFromLogFile() { + m_replay = true; m_physicsServer.replayFromLogFile("BulletPhysicsCommandLog.bin"); } @@ -61,6 +63,9 @@ public: virtual bool mouseMoveCallback(float x,float y) { + if (m_replay) + return false; + CommonRenderInterface* renderer = m_guiHelper->getRenderInterface(); if (!renderer) @@ -78,6 +83,9 @@ public: virtual bool mouseButtonCallback(int button, int state, float x, float y) { + if (m_replay) + return false; + CommonRenderInterface* renderer = m_guiHelper->getRenderInterface(); if (!renderer) @@ -128,7 +136,8 @@ public: PhysicsServerExample::PhysicsServerExample(GUIHelperInterface* helper) :SharedMemoryCommon(helper), m_wantsShutdown(false), -m_isConnected(false) +m_isConnected(false), +m_replay(false) { b3Printf("Started PhysicsServer\n"); } @@ -178,12 +187,19 @@ bool PhysicsServerExample::wantsTermination() void PhysicsServerExample::stepSimulation(float deltaTime) { - btClock rtc; - btScalar endTime = rtc.getTimeMilliseconds() + deltaTime*btScalar(800); - - while (rtc.getTimeMilliseconds()localGetSupportVertexWithoutMarginNonVirtual(seperatingAxisInA); + btVector3 qInB = m_minkowskiB->localGetSupportVertexWithoutMarginNonVirtual(seperatingAxisInB); + + btVector3 pWorld = localTransA(pInA); + btVector3 qWorld = localTransB(qInB); + btVector3 w = pWorld - qWorld; + d1 = (-normalInB).dot(w); + } + btScalar d0 = 0.f; + { + btVector3 seperatingAxisInA = (-normalInB)* input.m_transformA.getBasis(); + btVector3 seperatingAxisInB = normalInB* input.m_transformB.getBasis(); + + + btVector3 pInA = m_minkowskiA->localGetSupportVertexWithoutMarginNonVirtual(seperatingAxisInA); + btVector3 qInB = m_minkowskiB->localGetSupportVertexWithoutMarginNonVirtual(seperatingAxisInB); + + btVector3 pWorld = localTransA(pInA); + btVector3 qWorld = localTransB(qInB); + btVector3 w = pWorld - qWorld; + d0 = normalInB.dot(w); + } + if (d1>d0) + { + m_lastUsedMethod = 10; + normalInB*=-1; + } + + } isValid = true; - m_lastUsedMethod = 3; + } else { m_lastUsedMethod = 8;