I modelled 4 couples of 2 bodies linked between eachother with 4 customhinge joints.
I just changed the mass of the 2nd body of each couple.
0.01 1.01 2.01 and 3.01
When I hold the 1st body of each couple the hinge joint has always the same angle irrespective of the mass of the child body. The joint stiffness was set with SetAsSpringDamper(...) and same settings for all couples of bodies.
Here the code modified in the FlatlandGame.cpp file (2 methods modified only):
- Code: Select all
static void AttachLimbBody (DemoEntityManager* const scene, const dVector& dir, NewtonBody* const parent, float masse)
{
NewtonWorld* const world = scene->GetNewton();
dVector size(0.4f, 0.25f, 0.75f, 0.0f);
NewtonCollision* const collision = CreateConvexCollision(world, dGetIdentityMatrix(), size, _BOX_PRIMITIVE, 0);
DemoMesh* const geometry = new DemoMesh("box", scene->GetShaderCache(), collision, "smilli.tga", "logo_php.tga", "frowny.tga");
dMatrix location;
NewtonBodyGetMatrix(parent, &location[0][0]);
location.m_posit += dir.Scale(0.5f);
location.m_posit.m_y -= 0.5f;
// make a root body attached to the world
NewtonBody* const rootBody = CreateSimpleSolid(scene, geometry, masse, location, collision, 0);
// constrain these object to motion on the plane only
// location.m_posit -= dir.Scale (0.5f);
location.m_posit -= dir.Scale(0.5f);
dCustomHinge* const hinge = new dCustomHinge(location, rootBody, parent);
//hinge->EnableLimits(true);
hinge->SetLimits(-45.0f * dDegreeToRad, 45.0f * dDegreeToRad);
hinge->SetAsSpringDamper(true, 1.f, 500.f, 10.f);
geometry->Release();
NewtonDestroyCollision(collision);
}
static void AddRagdollBodies(DemoEntityManager* const scene, NewtonBody* const floor)
{
NewtonWorld* const world = scene->GetNewton();
dVector size(0.2f, 1.0f, 0.2f, 0.0f);
dMatrix location(dGetIdentityMatrix());
location.m_posit.m_y = 4.0f;
NewtonCollision* const collision = CreateConvexCollision(world, dGetIdentityMatrix(), size, _BOX_PRIMITIVE, 0);
DemoMesh* const geometry = new DemoMesh("box", scene->GetShaderCache(), collision, "smilli.tga", "logo_php.tga", "frowny.tga");
location.m_posit.m_z = 5.0f;
float rootmass = 10.f;
for (int i = 0; i < 4; i++) {
// make a root body attached to the world
//if (i == 3) { rootmass = 1000.f; }
NewtonBody* const rootBody = CreateSimpleSolid(scene, geometry, rootmass, location, collision, 0);
// constrain these object to motion on the plane only
dMatrix matrix;
NewtonBodyGetMatrix(rootBody, &matrix[0][0]);
// new dCustomPlane(matrix.m_posit, matrix.m_front, rootBody);
// now make some limb body and attach them to the root body
// AttachLimbBody (scene, matrix.m_right.Scale ( 1.0f), rootBody);
AttachLimbBody(scene, matrix.m_right.Scale(-1.0f), rootBody, 1.f * i +0.01f);
// AttachLimbBody(scene, matrix.m_right.Scale(-1.0f), rootBody, 0.01f);
location.m_posit.m_z += 2.5f;
}
geometry->Release();
NewtonDestroyCollision(collision);
}
here is the video illustrating:
here a video capture of the demo when the mass of the parent bodies is set to 0:
https://ibb.co/ckz2qNV