Properly separate sliders for each body

master
Martin Felis 2020-11-17 21:26:57 +01:00
parent d01417e8c9
commit 10b59578e1
1 changed files with 13 additions and 25 deletions

View File

@ -43,31 +43,17 @@ void simulator_init() {
sWorld.mStaticShapes.push_back(sGroundShape); sWorld.mStaticShapes.push_back(sGroundShape);
double restitution = 0.3; double restitution = 0.8;
int num_bodies = 10; int num_spheres = 7;
for (int i = 0; i < num_bodies; i++) { for (int i = 0; i < num_spheres; i++) {
SimBody body; SimBody sphere_body = CreateSphereBody(
1.,
bool create_sphere = i %2; 1.,
restitution,
if (!create_sphere) { Vector3d::Random() * 5.,
body = CreateBoxBody( Vector3d::Zero());
1., sWorld.mBodies.push_back(sphere_body);
Vector3d(2., 1., 1.),
restitution,
Vector3d::Random() * 5.,
Vector3d::Zero());
} else {
body = CreateSphereBody(
1.,
1.,
restitution,
Vector3d::Random() * 5.,
Vector3d::Zero());
}
sWorld.mBodies.push_back(body);
} }
for (int i = 0; i < sWorld.mBodies.size(); i++) { for (int i = 0; i < sWorld.mBodies.size(); i++) {
@ -164,6 +150,7 @@ void simulator_update(double dt) {
ImGui::Text("Bodies"); ImGui::Text("Bodies");
for (int i = 0; i < sWorld.mBodies.size(); i++) { for (int i = 0; i < sWorld.mBodies.size(); i++) {
ImGui::PushID(i);
SimBody& body = sWorld.mBodies[i]; SimBody& body = sWorld.mBodies[i];
Vector3f body_pos = body.q.block(0, 0, 3, 1); Vector3f body_pos = body.q.block(0, 0, 3, 1);
ImGui::DragFloat3("Pos", body_pos.data(), 0.01f, -5.0f, 5.0f); ImGui::DragFloat3("Pos", body_pos.data(), 0.01f, -5.0f, 5.0f);
@ -176,6 +163,7 @@ void simulator_update(double dt) {
Vector4f body_rot = body.mModel.GetQuaternion(2, body.q); Vector4f body_rot = body.mModel.GetQuaternion(2, body.q);
ImGui::DragFloat4("Rot", body_rot.data(), 0.01f, -20.0f, 20.0f); ImGui::DragFloat4("Rot", body_rot.data(), 0.01f, -20.0f, 20.0f);
ImGui::PopID();
body.updateCollisionShapes(); body.updateCollisionShapes();
} }
@ -272,4 +260,4 @@ void simulator_draw(srcmdbuf* cmdbuf) {
srcmdbuf_add(cmdbuf, &rcmd); srcmdbuf_add(cmdbuf, &rcmd);
} }
} }
} }