How to reduce oscillations

Hi everyone !

I'm actually working on a game where bodies are connected together by such rigid threads (they remains tended) which can rotate around the bodies they're linking. (note they are connected with Distance Joints)

The problem is, that actually when they're moving, it produces oscillations, but I want less oscillations and I don't know how to get such an effect.

I've tried augmenting the DistanceJoint dampingRatio to 1 and over (I even tried with 100) but it remains a lot of oscillations, they don't vanish as written in the manual.

So I ask you how to do that, thanks !
Up !

I want my bodies to sleep faster, can't anyone help me ?

Thanks in advance !
If you want specific feedback, please create a C++ testbed example that reproduces the problem.
Do you want me to post my code ? Or the part that uses box2D ?

Here is how I create the bodies I want to connect : http://pastie.org/932898

And here is how I link them : http://pastie.org/932899

I think it the simplest way I could do it. But I don't know what can I modificate to reduce oscillations…

For the testbed, I launched it but I don't get how to make my own test… Could you help me doing so ?

Thanks
You can just modify the code in an existing test. You might want to start with Web.h since it has distance joints.
Well okay, I built it but it's for mac OS X I think…

http://drp.ly/SL27L

As you can see, the body never stop moving…
No, post code like James did here: http://box2d.org/forum/viewtopic.php?f=4&t=4872
Ah ok, sorry I didn't understand.

So here it is :
Code:
#ifndef WEB_H
#define WEB_H

// This tests distance joints, body destruction, and joint destruction.
class Web : public Test
{
public:
   Web()
   {
      b2Body* ground = NULL;
      {
         b2BodyDef bd;
         ground = m_world->CreateBody(&bd);

         b2PolygonShape shape;
         shape.SetAsEdge(b2Vec2(-40.0f, 0.0f), b2Vec2(40.0f, 0.0f));
         ground->CreateFixture(&shape, 0.0f);
      }

      {
         b2CircleShape circle;
         circle.m_radius = 3.0f;

         b2FixtureDef fixtureDef2;
         fixtureDef2.shape = &circle;
         fixtureDef2.density = 1.0f;
         fixtureDef2.friction = 0.3f;
         
         b2BodyDef bodyDef;
         bodyDef.type = b2_dynamicBody;
         bodyDef.position.Set(5.0f, 10.0f);
         bodyDef.angularDamping = 1.5f;
         m_bodies[0] = m_world->CreateBody(&bodyDef);
         
         bodyDef.type = b2_staticBody;
         bodyDef.position.Set(10.0f, 10.0f);
         m_bodies[0] = m_world->CreateBody(&bodyDef);
         
         

         b2DistanceJointDef jointDef;
         jointDef.Initialize(m_bodies[0], m_bodies[1], m_bodies[0]->GetPosition(), m_bodies[1]->GetPosition());
         jointDef.collideConnected = true;
         jointDef.frequencyHz = 4.0f;
         jointDef.dampingRatio = 1.0f;
         
         m_joints[0] = m_world->CreateJoint(&jointDef);
      }
   }

   void Keyboard(unsigned char key)
   {
      switch (key)
      {
      case 'b':
         for (int32 i = 0; i < 4; ++i)
         {
            if (m_bodies[i])
            {
               m_world->DestroyBody(m_bodies[i]);
               m_bodies[i] = NULL;
               break;
            }
         }
         break;

      case 'j':
         for (int32 i = 0; i < 8; ++i)
         {
            if (m_joints[i])
            {
               m_world->DestroyJoint(m_joints[i]);
               m_joints[i] = NULL;
               break;
            }
         }
         break;
      }
   }

   void Step(Settings* settings)
   {
      Test::Step(settings);
      m_debugDraw.DrawString(5, m_textLine, "This demonstrates a soft distance joint.");
      m_textLine += 15;
      m_debugDraw.DrawString(5, m_textLine, "Press: (b) to delete a body, (j) to delete a joint");
      m_textLine += 15;
   }

   void JointDestroyed(b2Joint* joint)
   {
      for (int32 i = 0; i < 8; ++i)
      {
         if (m_joints[i] == joint)
         {
            m_joints[i] = NULL;
            break;
         }
      }
   }

   static Test* Create()
   {
      return new Web;
   }

   b2Body* m_bodies[4];
   b2Joint* m_joints[8];
};

#endif


I only changed the beginning to correspond better to my app, you can also change positions if it's not comfortable for you.
Your code was broken. You didn't initialize m_bodies[1] and you didn't create any fixtures.

The dynamic body is just oscillating like a pendulum and this is expected behavior. You can damp out the oscillations by increasing the angular damping on the dynamic body. It has nothing to do with the distance joint. You can also eliminate pendulum like behavior by setting gravity to zero.

Here is my modification:
Code:
{
   b2CircleShape circle;
   circle.m_radius = 3.0f;

   b2FixtureDef fixtureDef2;
   fixtureDef2.shape = &circle;
   fixtureDef2.density = 1.0f;
   fixtureDef2.friction = 0.3f;

   b2BodyDef bodyDef;
   bodyDef.type = b2_dynamicBody;
   bodyDef.position.Set(5.0f, 10.0f);
   bodyDef.angularDamping = 5.0f;
   m_bodies[0] = m_world->CreateBody(&bodyDef);
   m_bodies[0]->CreateFixture(&fixtureDef2);

   bodyDef.type = b2_staticBody;
   bodyDef.position.Set(10.0f, 10.0f);
   m_bodies[1] = m_world->CreateBody(&bodyDef);
   m_bodies[1]->CreateFixture(&fixtureDef2);

   b2DistanceJointDef jointDef;
   jointDef.Initialize(m_bodies[0], m_bodies[1], m_bodies[0]->GetPosition(), m_bodies[1]->GetPosition());
   jointDef.collideConnected = true;
   jointDef.frequencyHz = 2.0f;

   m_joints[0] = m_world->CreateJoint(&jointDef);
}
Up !

Is there anything wrong with my code ?

Original thread: https://box2d.org/forum/viewtopic.php?t=4772