Number of solver steps now editable in debug gui
parent
384293a853
commit
b481b43264
|
@ -819,9 +819,6 @@ struct Storage {
|
||||||
|
|
||||||
inline size_t cols() const { return NumCols; }
|
inline size_t cols() const { return NumCols; }
|
||||||
|
|
||||||
#ifdef NDEBUG
|
|
||||||
void resize(int UNUSED(num_rows), int UNUSED(num_cols)) {}
|
|
||||||
#else
|
|
||||||
void resize(int num_rows, int num_cols) {
|
void resize(int num_rows, int num_cols) {
|
||||||
// Resizing of fixed size matrices not allowed
|
// Resizing of fixed size matrices not allowed
|
||||||
if (num_rows != NumRows || num_cols != NumCols) {
|
if (num_rows != NumRows || num_cols != NumCols) {
|
||||||
|
@ -831,7 +828,6 @@ struct Storage {
|
||||||
}
|
}
|
||||||
assert (num_rows == NumRows && num_cols == NumCols);
|
assert (num_rows == NumRows && num_cols == NumCols);
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
inline ScalarType& coeff(int row_index, int col_index) {
|
inline ScalarType& coeff(int row_index, int col_index) {
|
||||||
// assert (row_index >= 0 && row_index <= NumRows);
|
// assert (row_index >= 0 && row_index <= NumRows);
|
||||||
|
|
|
@ -86,7 +86,7 @@ struct World {
|
||||||
void calcUnconstrainedVelUpdate(double dt);
|
void calcUnconstrainedVelUpdate(double dt);
|
||||||
void updateCollisionShapes();
|
void updateCollisionShapes();
|
||||||
void detectCollisions();
|
void detectCollisions();
|
||||||
void resolveCollisions(double dt);
|
void resolveCollisions(double dt, int num_iter);
|
||||||
bool integrateWorld(double dt);
|
bool integrateWorld(double dt);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -26,7 +26,7 @@ void simplesim() {
|
||||||
do {
|
do {
|
||||||
world.updateCollisionShapes();
|
world.updateCollisionShapes();
|
||||||
world.detectCollisions();
|
world.detectCollisions();
|
||||||
world.resolveCollisions(dt);
|
world.resolveCollisions(dt, 20);
|
||||||
world.integrateWorld(dt);
|
world.integrateWorld(dt);
|
||||||
} while (world.mSimTime < 10.01);
|
} while (world.mSimTime < 10.01);
|
||||||
}
|
}
|
||||||
|
|
|
@ -796,14 +796,13 @@ void World::detectCollisions() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void World::resolveCollisions(double dt) {
|
void World::resolveCollisions(double dt, int num_iter) {
|
||||||
ZoneScoped;
|
ZoneScoped;
|
||||||
|
|
||||||
for (CollisionInfo& cinfo : mContactPoints) {
|
for (CollisionInfo& cinfo : mContactPoints) {
|
||||||
PrepareConstraintImpulse(dt, cinfo.mBodyA, cinfo.mBodyB, cinfo);
|
PrepareConstraintImpulse(dt, cinfo.mBodyA, cinfo.mBodyB, cinfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
int num_iter = 20;
|
|
||||||
for (int i = 0; i < num_iter; i++) {
|
for (int i = 0; i < num_iter; i++) {
|
||||||
for (CollisionInfo& cinfo : mContactPoints) {
|
for (CollisionInfo& cinfo : mContactPoints) {
|
||||||
CalcFrictionImpulse(cinfo.mBodyA, cinfo.mBodyB, cinfo);
|
CalcFrictionImpulse(cinfo.mBodyA, cinfo.mBodyB, cinfo);
|
||||||
|
|
|
@ -32,6 +32,7 @@ static double sSimTimeAccumulator = 0.;
|
||||||
static double sSimTimeStep = 1.0e-2;
|
static double sSimTimeStep = 1.0e-2;
|
||||||
static sthstry* sStateHistory = nullptr;
|
static sthstry* sStateHistory = nullptr;
|
||||||
static int sStateHistoryCurrent = 0;
|
static int sStateHistoryCurrent = 0;
|
||||||
|
static int sSolverNumIter = 20;
|
||||||
|
|
||||||
void simulator_init() {
|
void simulator_init() {
|
||||||
gLog("Initializing Simulator");
|
gLog("Initializing Simulator");
|
||||||
|
@ -153,6 +154,8 @@ void simulator_gui() {
|
||||||
sSimTime = sSimTimeStep * sStateHistoryCurrent;
|
sSimTime = sSimTimeStep * sStateHistoryCurrent;
|
||||||
ImGui::Text("Time: %f", sSimTime);
|
ImGui::Text("Time: %f", sSimTime);
|
||||||
|
|
||||||
|
ImGui::SliderInt("Solver Steps", &sSolverNumIter, 0, 100);
|
||||||
|
|
||||||
ImGui::Text("Ground Plane");
|
ImGui::Text("Ground Plane");
|
||||||
Vector3f ground_pos = sGroundShape.pos;
|
Vector3f ground_pos = sGroundShape.pos;
|
||||||
ImGui::DragFloat3("Position", ground_pos.data(), 0.1f, -5.0f, 5.0f);
|
ImGui::DragFloat3("Position", ground_pos.data(), 0.1f, -5.0f, 5.0f);
|
||||||
|
@ -205,7 +208,7 @@ void simulator_step(double dt) {
|
||||||
sWorld.updateCollisionShapes();
|
sWorld.updateCollisionShapes();
|
||||||
sWorld.detectCollisions();
|
sWorld.detectCollisions();
|
||||||
|
|
||||||
sWorld.resolveCollisions(dt);
|
sWorld.resolveCollisions(dt, sSolverNumIter);
|
||||||
sWorld.integrateWorld(dt);
|
sWorld.integrateWorld(dt);
|
||||||
|
|
||||||
{
|
{
|
||||||
|
|
|
@ -1009,8 +1009,8 @@ int main() {
|
||||||
ImGui::End();
|
ImGui::End();
|
||||||
}
|
}
|
||||||
|
|
||||||
gHullScene.draw(gRndrCmds);
|
//gHullScene.draw(gRndrCmds);
|
||||||
// SimulatorSceneRender(gRndrCmds);
|
SimulatorSceneRender(gRndrCmds);
|
||||||
srndr_render(gRndr, gView, gRndrCmds);
|
srndr_render(gRndr, gView, gRndrCmds);
|
||||||
ImSRenderWidget(gRndr, gView);
|
ImSRenderWidget(gRndr, gView);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue