forces are cleared after first iteration

This commit is contained in:
Diren D Bharwani 2023-03-22 22:25:11 +08:00
parent e02e3f5faf
commit 2737113a84
1 changed files with 10 additions and 13 deletions

View File

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