[ODE] simulating a bat hitting a ball in air

nordinzakaria at petronas.com.my nordinzakaria at petronas.com.my
Mon Jan 31 17:03:20 MST 2005


Hi everyone,

My physics is somewhat rusty, but I am trying to simulate a bat hitting a
ball in air using ODE.
In my current attempt, I am experimenting with the following setup: a ball
falls from a certain position under gravity. A bat hit the ball in a
vertical upward manner so that the ball is supposed to go straight up
again. My question is: how do I simulate the bat? I tried simply applying
an upward force using dBodyAddForce(ball_body, 0, up_force, 0) but even
with a very large upward force, the ball does not seem to switch direction
and accelerate upward fast enough (like when a real bat hits a real ball).

Here are fragments from my code:

      // init
      world = dWorldCreate();
      space = dHashSpaceCreate(0);
      contactgroup = dJointGroupCreate(0);
      dWorldSetGravity(world, 0, -9.81, 0);
      ground = dCreatePlane(space, 0, 1, 0, 0);

      // define the ball
      body0 = dBodyCreate(world);
      dBodySetPosition(body0, 0, 500, 0);
          dMass mass0;
      dMassSetSphere(&mass0, 1, 5);
      dBodySetMass(body0, &mass0);
      body0_sphere = dCreateSphere(0, 5);
      dGeomSetBody(body0_sphere, body0);
      dSpaceAdd(space, body0_sphere);

      ....

      // whenever the user press a key
      void KeyDown(unsigned char key, int x, int y)
      {
      if (key == 'a')
            dBodyAddForce(body0, 0, 200000, 0);
      glutPostRedisplay();
      }

Please help,


Thanks.
Nordin




More information about the ODE mailing list