Fixed consistency of Trajectories with different time steps #436

Merged
direnbharwani merged 5 commits from SP3-2-Physics into main 2023-03-22 22:33:24 +08:00
1 changed files with 10 additions and 13 deletions
Showing only changes of commit 2737113a84 - Show all commits

View File

@ -269,9 +269,7 @@ namespace SHADE
double accumulatedTime = 0.0f;
bool terminate = true;
int iterationCounter = simInfo.maxSteps;
int iterationCounter = simInfo.maxSteps;
do
{
accumulatedTime += simInfo.timeStep;
@ -280,21 +278,22 @@ namespace SHADE
raycastInfo.ray.position = ghostBody.position;
raycastInfo.ray.direction = SHVec3::Normalise(ghostBody.linearVelocity);
terminate = !Raycast(raycastInfo).empty() || iterationCounter == 0;
if (terminate)
if (!Raycast(raycastInfo).empty())
return;
while (accumulatedTime > fixedDT)
{
simulateBody(ghostBody, simInfo);
accumulatedTime -= fixedDT;
}
if (!simInfo.continuousForce)
{
simInfo.force = SHVec3::Zero;
simInfo.torque = SHVec3::Zero;
if (!simInfo.continuousForce)
{
simInfo.force = SHVec3::Zero;
simInfo.torque = SHVec3::Zero;
}
if (--iterationCounter == 0)
return;
}
if (output.positions)
@ -303,8 +302,6 @@ namespace SHADE
if (output.orientations)
output.orientations->emplace_back(ghostBody.orientation);
--iterationCounter;
} while (true);
}