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)
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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()<endTime)
|
||||
if (m_replay)
|
||||
{
|
||||
m_physicsServer.processClientCommands();
|
||||
for (int i=0;i<100;i++)
|
||||
m_physicsServer.processClientCommands();
|
||||
} else
|
||||
{
|
||||
btClock rtc;
|
||||
btScalar endTime = rtc.getTimeMilliseconds() + deltaTime*btScalar(800);
|
||||
|
||||
while (rtc.getTimeMilliseconds()<endTime)
|
||||
{
|
||||
m_physicsServer.processClientCommands();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -339,6 +339,7 @@ void btGjkPairDetector::getClosestPointsNonVirtual(const ClosestPointInput& inpu
|
||||
{
|
||||
tmpNormalInB /= btSqrt(lenSqr);
|
||||
btScalar distance2 = -(tmpPointOnA-tmpPointOnB).length();
|
||||
m_lastUsedMethod = 3;
|
||||
//only replace valid penetrations when the result is deeper (check)
|
||||
if (!isValid || (distance2 < distance))
|
||||
{
|
||||
@@ -346,9 +347,48 @@ void btGjkPairDetector::getClosestPointsNonVirtual(const ClosestPointInput& inpu
|
||||
pointOnA = tmpPointOnA;
|
||||
pointOnB = tmpPointOnB;
|
||||
normalInB = tmpNormalInB;
|
||||
///todo: need to track down this EPA penetration solver degeneracy
|
||||
///the penetration solver reports penetration but the contact normal
|
||||
///connecting the contact points is pointing in the opposite direction
|
||||
///until then, detect the issue and revert the normal
|
||||
{
|
||||
btScalar d1=0;
|
||||
{
|
||||
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;
|
||||
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;
|
||||
|
||||
Reference in New Issue
Block a user