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;
|
bool useShadowMap=true;//false;//true;
|
||||||
int shadowMapWidth=8192;
|
int shadowMapWidth=8192;
|
||||||
int shadowMapHeight=8192;
|
int shadowMapHeight=8192;
|
||||||
float shadowMapWorldSize=100;
|
float shadowMapWorldSize=10;
|
||||||
|
|
||||||
#define MAX_POINTS_IN_BATCH 1024
|
#define MAX_POINTS_IN_BATCH 1024
|
||||||
#define MAX_LINES_IN_BATCH 1024
|
#define MAX_LINES_IN_BATCH 1024
|
||||||
|
|||||||
@@ -119,6 +119,36 @@ public:
|
|||||||
int m_number;
|
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
|
struct CommandLogger
|
||||||
{
|
{
|
||||||
FILE* m_file;
|
FILE* m_file;
|
||||||
@@ -194,8 +224,11 @@ struct CommandLogger
|
|||||||
|
|
||||||
struct CommandLogPlayback
|
struct CommandLogPlayback
|
||||||
{
|
{
|
||||||
unsigned char* m_header[12];
|
unsigned char m_header[12];
|
||||||
FILE* m_file;
|
FILE* m_file;
|
||||||
|
bool m_bitsVary;
|
||||||
|
bool m_fileIs64bit;
|
||||||
|
|
||||||
|
|
||||||
CommandLogPlayback(const char* fileName)
|
CommandLogPlayback(const char* fileName)
|
||||||
{
|
{
|
||||||
@@ -204,6 +237,14 @@ struct CommandLogPlayback
|
|||||||
{
|
{
|
||||||
fread(m_header,12,1,m_file);
|
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()
|
virtual ~CommandLogPlayback()
|
||||||
{
|
{
|
||||||
@@ -215,14 +256,29 @@ struct CommandLogPlayback
|
|||||||
}
|
}
|
||||||
bool processNextCommand(SharedMemoryCommand* cmd)
|
bool processNextCommand(SharedMemoryCommand* cmd)
|
||||||
{
|
{
|
||||||
btCommandChunk chunk;
|
if (m_file)
|
||||||
size_t s = fread((void*)&chunk,sizeof(btCommandChunk),1,m_file);
|
{
|
||||||
|
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)
|
if (s==1)
|
||||||
{
|
{
|
||||||
s = fread(cmd,sizeof(SharedMemoryCommand),1,m_file);
|
s = fread(cmd,sizeof(SharedMemoryCommand),1,m_file);
|
||||||
return (s==1);
|
return (s==1);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -1627,6 +1683,7 @@ void PhysicsServerSharedMemory::processClientCommands()
|
|||||||
|
|
||||||
bool isDynamic = (mass>0);
|
bool isDynamic = (mass>0);
|
||||||
btRigidBody* rb = worldImporter->createRigidBody(isDynamic,mass,startTrans,shape,0);
|
btRigidBody* rb = worldImporter->createRigidBody(isDynamic,mass,startTrans,shape,0);
|
||||||
|
rb->setRollingFriction(0.2);
|
||||||
m_data->m_guiHelper->autogenerateGraphicsObjects(this->m_data->m_dynamicsWorld);
|
m_data->m_guiHelper->autogenerateGraphicsObjects(this->m_data->m_dynamicsWorld);
|
||||||
|
|
||||||
SharedMemoryStatus& serverCmd =m_data->createServerStatus(CMD_RIGID_BODY_CREATION_COMPLETED,clientCmd.m_sequenceNumber,timeStamp);
|
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;
|
bool m_isConnected;
|
||||||
btClock m_clock;
|
btClock m_clock;
|
||||||
|
bool m_replay;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
@@ -36,6 +37,7 @@ public:
|
|||||||
|
|
||||||
void replayFromLogFile()
|
void replayFromLogFile()
|
||||||
{
|
{
|
||||||
|
m_replay = true;
|
||||||
m_physicsServer.replayFromLogFile("BulletPhysicsCommandLog.bin");
|
m_physicsServer.replayFromLogFile("BulletPhysicsCommandLog.bin");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -61,6 +63,9 @@ public:
|
|||||||
|
|
||||||
virtual bool mouseMoveCallback(float x,float y)
|
virtual bool mouseMoveCallback(float x,float y)
|
||||||
{
|
{
|
||||||
|
if (m_replay)
|
||||||
|
return false;
|
||||||
|
|
||||||
CommonRenderInterface* renderer = m_guiHelper->getRenderInterface();
|
CommonRenderInterface* renderer = m_guiHelper->getRenderInterface();
|
||||||
|
|
||||||
if (!renderer)
|
if (!renderer)
|
||||||
@@ -78,6 +83,9 @@ public:
|
|||||||
|
|
||||||
virtual bool mouseButtonCallback(int button, int state, float x, float y)
|
virtual bool mouseButtonCallback(int button, int state, float x, float y)
|
||||||
{
|
{
|
||||||
|
if (m_replay)
|
||||||
|
return false;
|
||||||
|
|
||||||
CommonRenderInterface* renderer = m_guiHelper->getRenderInterface();
|
CommonRenderInterface* renderer = m_guiHelper->getRenderInterface();
|
||||||
|
|
||||||
if (!renderer)
|
if (!renderer)
|
||||||
@@ -128,7 +136,8 @@ public:
|
|||||||
PhysicsServerExample::PhysicsServerExample(GUIHelperInterface* helper)
|
PhysicsServerExample::PhysicsServerExample(GUIHelperInterface* helper)
|
||||||
:SharedMemoryCommon(helper),
|
:SharedMemoryCommon(helper),
|
||||||
m_wantsShutdown(false),
|
m_wantsShutdown(false),
|
||||||
m_isConnected(false)
|
m_isConnected(false),
|
||||||
|
m_replay(false)
|
||||||
{
|
{
|
||||||
b3Printf("Started PhysicsServer\n");
|
b3Printf("Started PhysicsServer\n");
|
||||||
}
|
}
|
||||||
@@ -177,6 +186,12 @@ bool PhysicsServerExample::wantsTermination()
|
|||||||
|
|
||||||
|
|
||||||
void PhysicsServerExample::stepSimulation(float deltaTime)
|
void PhysicsServerExample::stepSimulation(float deltaTime)
|
||||||
|
{
|
||||||
|
if (m_replay)
|
||||||
|
{
|
||||||
|
for (int i=0;i<100;i++)
|
||||||
|
m_physicsServer.processClientCommands();
|
||||||
|
} else
|
||||||
{
|
{
|
||||||
btClock rtc;
|
btClock rtc;
|
||||||
btScalar endTime = rtc.getTimeMilliseconds() + deltaTime*btScalar(800);
|
btScalar endTime = rtc.getTimeMilliseconds() + deltaTime*btScalar(800);
|
||||||
@@ -186,6 +201,7 @@ void PhysicsServerExample::stepSimulation(float deltaTime)
|
|||||||
m_physicsServer.processClientCommands();
|
m_physicsServer.processClientCommands();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void PhysicsServerExample::renderScene()
|
void PhysicsServerExample::renderScene()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -339,6 +339,7 @@ void btGjkPairDetector::getClosestPointsNonVirtual(const ClosestPointInput& inpu
|
|||||||
{
|
{
|
||||||
tmpNormalInB /= btSqrt(lenSqr);
|
tmpNormalInB /= btSqrt(lenSqr);
|
||||||
btScalar distance2 = -(tmpPointOnA-tmpPointOnB).length();
|
btScalar distance2 = -(tmpPointOnA-tmpPointOnB).length();
|
||||||
|
m_lastUsedMethod = 3;
|
||||||
//only replace valid penetrations when the result is deeper (check)
|
//only replace valid penetrations when the result is deeper (check)
|
||||||
if (!isValid || (distance2 < distance))
|
if (!isValid || (distance2 < distance))
|
||||||
{
|
{
|
||||||
@@ -346,9 +347,48 @@ void btGjkPairDetector::getClosestPointsNonVirtual(const ClosestPointInput& inpu
|
|||||||
pointOnA = tmpPointOnA;
|
pointOnA = tmpPointOnA;
|
||||||
pointOnB = tmpPointOnB;
|
pointOnB = tmpPointOnB;
|
||||||
normalInB = tmpNormalInB;
|
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;
|
isValid = true;
|
||||||
m_lastUsedMethod = 3;
|
|
||||||
} else
|
} else
|
||||||
{
|
{
|
||||||
m_lastUsedMethod = 8;
|
m_lastUsedMethod = 8;
|
||||||
|
|||||||
Reference in New Issue
Block a user