These tutorials focus mainly on OpenGL, Win32 programming and the ODE physics engine. OpenGL has moved on to great heights and I don't cover the newest features but cover all of the basic concepts you will need with working example programs.
Working with the Win32 API is a great way to get to the heart of Windows and is just as relevant today as ever before. Whereas ODE has been marginalized as hardware accelerated physics becomes more common.
Games and graphics utilities can be made quickly and easily using game engines like Unity so this and Linux development in general will be the focus of my next tutorials.
ODE Bouncing Ball
By Alan Baylis 06/04/2006
Download Demo for Visual Studio 7.0
Those who have been following the ODE tutorial from the start will have experimented on their own and will probably find this little tutorial a bit boring. But for those new to the tutorials I thought I would cover how to create a spherical object that bounces. The InitODE routine is very similar to that of the first tutorial in that it only initializes a single object. I will only cover the second part of the InitODE routine here as the first part hasn't changed.
// Set the radius of our sphere object dReal radius = 0.5; dMass m; Object.Body = dBodyCreate(World); dMatrix3 R; dBodySetPosition(Object.Body, 0, 10, -5); VECTOR tempVect(0.0, 0.0, 0.0); dBodySetLinearVel(Object.Body, tempVect.x, tempVect.y, tempVect.z); dRFromAxisAndAngle(R, 1, 0, 0, -1.57); dBodySetRotation(Object.Body, R); // Here we use dMassSetSphere instead of dMassSetBox // and we pass the local radius variable as the third parameter dMassSetSphere(&m, DENSITY, radius); // To create the sphere object we use dCreateSphere and pass it the same local radius variable Object.Geom[0] = dCreateSphere(Space, radius); dGeomSetBody(Object.Geom[0], Object.Body); dBodySetMass(Object.Body, &m);
As you can see there isn't much difference between creating a sphere object and a rectangular object. In order to make the sphere bounce though we must change the contact parameters in the nearCallback routine.
contact[i].surface.bounce = 0.9; contact[i].surface.bounce_vel = 0.5;
I have set the bounciness of the contact to 0.9 to make the ball very bouncy, if you set this to a value greater than 1.0 then the ball will bounce higher than the position it was dropped from. Of course this looks very unnatural and you probably will want to use values less than 1.0 in your simulation. The second contact parameter sets the velocity at which the contacting objects will separate, which I have set to 0.5.
I noticed that in the earlier examples that the simulation would appear to lock up after a while, this was due to setting the dWorldSetAutoDisableFlag to true. If you don't want the objects in the simulation to be disabled when they come to rest then you can set this flag to false.
dWorldSetAutoDisableFlag(World, 0);
Another way to prevent objects that have been disabled from being passed over in the simulation is to use dBodyEnable on the objects before you change them as I have done when the space bar is pressed.
dBodyEnable(Object.Body); VECTOR tempVect(0.0, 3.0, 0.0); dBodySetLinearVel(Object.Body, tempVect.x, tempVect.y, tempVect.z);
In this example I have applied a force that pushes up beneath the sphere using dBodySetLinearVel and you can experiment with different vector directions to see the effect on the sphere. I hope that the information in this tutorial helps you to add spheres and bouncing objects to your own simulations. In the next tutorial I will cover the subject of adding constraints/stops to restrict the available movement of common joints.
See you there.
Alan Baylis