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,16 +278,13 @@ 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) if (!simInfo.continuousForce)
{ {
@ -297,14 +292,16 @@ namespace SHADE
simInfo.torque = SHVec3::Zero; simInfo.torque = SHVec3::Zero;
} }
if (--iterationCounter == 0)
return;
}
if (output.positions) if (output.positions)
output.positions->emplace_back(ghostBody.position); output.positions->emplace_back(ghostBody.position);
if (output.orientations) if (output.orientations)
output.orientations->emplace_back(ghostBody.orientation); output.orientations->emplace_back(ghostBody.orientation);
--iterationCounter;
} while (true); } while (true);
} }