Bouncing Spheres ExampleΒΆ

Author:Alex Dumitrache (

This is a slightly more advanced example of bouncing spheres, which lets you tweak a lot of settings.

For introduction, see the ODEDynamics: Bouncing Sphere tutorial.


Here is the code:


defaultContactProps = ODEContactProperties(bounce = 1, mu = 1, soft_erp=0.2, soft_cfm=1E-4)
odeSim = ODEDynamics( gravity=9.81,
                      defaultcontactproperties = defaultContactProps,
                      use_quick_step = False)

matRed = GLMaterial(name="Red", diffuse=(1,0,0))
matGreen = GLMaterial(name="Green", diffuse=(0,1,0))

p = Plane()
s1 = Sphere(radius = 0.1, pos = (0,0,1), mass = 1, material = matRed)
s2 = Sphere(radius = 0.1, pos = (0,0,1.5), mass = 1, material = matGreen)

odeSim.add(list(worldroot.iterChilds())) # Add all the cgkit objects to the simulation

Save the snippet as and run it using:

> python

What do all these parameters and settings do?

  • substeps: number of ODE steps per displayed frame.

    ODEDynamics will use a smaller timestep, which results in better accuracy, at the expense of some CPU time.

  • use_quick_step = False

    • This switches to a slower, but usually more accurate stepping method: dWorldStep.
    • The default is dWorldQuickStep.
    • Differences can be seen only in complex scenes (e.g. stacks of boxes, grasping simulation).
  • cfm and erp control the softness of constraints, and are explained in detail in the ODE manual.

    • Lower cfm means harder constraints, but can make simulation unstable. Good choices: 1e-4 ... 1e-10.
    • Higher erp is more aggressive. Good choices: 0.1 ... 0.5.

    These are advances simulation parameters. Check ODE World functions to see what they do, and use PyODE API to call them from Python.

    Damping and speed limits improve the stability of simulation and can prevent ODE crashes due to numerical errors.

  • matRed = GLMaterial(name=”Red”, diffuse=(1,0,0))

    This is the material used for rendering the objects. You may use materials for customizing contact properties, too.

Previous topic

How to use the spacedevice module

Next topic

Newton Cradle Example

This Page