The world object is a container for rigid bodies and joints. Objects in different worlds can not interact, for example rigid bodies from two different worlds can not collide.
All the objects in a world exist at the same point in time, thus one reason to use separate worlds is to simulate systems at different rates.
Most applications will only need one world.
Create a new, empty world and return its ID number.
void dWorldDestroy (dWorldID);
Destroy a world and everything in it. This includes all bodies, and all joints that are not part of a joint group. Joints that are part of a joint group will be deactivated, and can be destroyed by calling, for example, dJointGroupEmpty.
void dWorldSetGravity (dWorldID, dReal x, dReal y, dReal z); void dWorldGetGravity (dWorldID, dVector3 gravity);
Set and get the world's global gravity vector. In the SI units the Earth's gravity vector would be (0,0,-9.81), assuming that +z is up. The default is no gravity, i.e. (0,0,0).
void dWorldSetERP (dWorldID, dReal erp); dReal dWorldGetERP (dWorldID);
Set and get the global ERP value, that controls how much error correction is performed in each time step. Typical values are in the range 0.1-0.8. The default is 0.2.
void dWorldSetCFM (dWorldID, dReal cfm); dReal dWorldGetCFM (dWorldID);
Set and get the global CFM (constraint force mixing) value. Typical values are in the range 10-9 -- 1. The default is 10-5 if single precision is being used, or 10-10 if double precision is being used.
void dWorldSetAutoDisableFlag (dWorldID, int do_auto_disable); int dWorldGetAutoDisableFlag (dWorldID); void dWorldSetAutoDisableLinearThreshold (dWorldID, dReal linear_threshold); dReal dWorldGetAutoDisableLinearThreshold (dWorldID); void dWorldSetAutoDisableAngularThreshold (dWorldID, dReal angular_threshold); dReal dWorldGetAutoDisableAngularThreshold (dWorldID); void dWorldSetAutoDisableSteps (dWorldID, int steps); int dWorldGetAutoDisableSteps (dWorldID); void dWorldSetAutoDisableTime (dWorldID, dReal time); dReal dWorldGetAutoDisableTime (dWorldID);
Set and get the default auto-disable parameters for newly created bodies. See the Rigid Body documentation on auto-disabling for a description of this feature. The default parameters are:
- AutoDisableFlag = disabled
- AutoDisableLinearThreshold = 0.01
- AutoDisableAngularThreshold = 0.01
- AutoDisableSteps = 10
- AutoDisableTime = 0
void dWorldImpulseToForce (dWorldID, dReal stepsize, dReal ix, dReal iy, dReal iz, dVector3 force);
If you want to apply a linear or angular impulse to a rigid body, instead of a force or a torque, then you can use this function to convert the desired impulse into a force/torque vector before calling the
This function is given the desired impulse as (
iz) and puts the force vector in
force. The current algorithm simply scales the impulse by 1/
stepsize is the step size for the next step that will be taken.
This function is given a
dWorldID because, in the future, the force computation may depend on integrator parameters that are set as properties of the world.
void dWorldStep (dWorldID, dReal stepsize);
Step the world. This uses a "big matrix" method that takes time on the order of m3 and memory on the order of m2, where m is the total number of constraint rows.
For large systems this will use a lot of memory and can be very slow, but this is currently the most accurate method.
void dWorldQuickStep (dWorldID, dReal stepsize);
Step the world. This uses an iterative method that takes time on the order of m*N and memory on the order of m, where m is the total number of constraint rows and N is the number of iterations.
For large systems this is a lot faster than dWorldStep, but it is less accurate.
QuickStep is great for stacks of objects especially when the auto-disable feature is used as well. However, it has poor accuracy for near-singular systems. Near-singular systems can occur when using high-friction contacts, motors, or certain articulated structures. For example, a robot with multiple legs sitting on the ground may be near-singular.
There are ways to help overcome QuickStep's inaccuracy problems:
- Increase CFM.
- Reduce the number of contacts in your system (e.g. use the minimum number of contacts for the feet of a robot or creature).
- Don't use excessive friction in the contacts.
- Use contact slip if appropriate
- Avoid kinematic loops (however, kinematic loops are inevitable in legged creatures).
- Don't use excessive motor strength.
- Use force-based motors instead of velocity-based motors.
Increasing the number of QuickStep iterations may help a little bit, but it is not going to help much if your system is really near singular.
void dWorldSetQuickStepNumIterations (dWorldID, int num); int dWorldGetQuickStepNumIterations (dWorldID);
Set and get the number of iterations that the QuickStep method performs per step. More iterations will give a more accurate solution, but will take longer to compute. The default is 20 iterations.
void dWorldSetQuickStepW (WorldID, dReal over_relaxation); dReal dWorldGetQuickStepW (dWorldID);
Set and get the over-relaxation parameter for QuickStep's SOR algorithm. Default value is 1.3.
Variable Step Size: Don't!
Stepsize should be constant in your application. A variable stepsize is a one-way trip to a headache. For example, think of an object "resting" on the ground. It'll actually stabilize at a small depth into the ground. When step sizes vary, the ideal stable position will change at each step, and thus the object will jitter (and may very well gain energy!)
ODE was designed with fixed step-sizes in mind. It is possible to use variable step-sizes in ODE, but it isn't easy (and this editor can't help you).
See the Rigid Body damping documentation for more details.
dReal dWorldGetLinearDamping (dWorldID); dReal dWorldGetAngularDamping (dWorldID); void dWorldSetLinearDamping (dWorldID, dReal scale); void dWorldSetAngularDamping (dWorldID, dReal scale); void dWorldSetDamping (dWorldID, dReal linear_scale, dReal angular_scale); dReal dWorldGetLinearDampingThreshold (dWorldID); dReal dWorldGetAngularDampingThreshold (dWorldID); void dWorldSetLinearDampingThreshold (dWorldID, dReal threshold); void dWorldSetAngularDampingThreshold (dWorldID, dReal threshold);
Set/Get the world's default damping parameters (bodies will use the world's parameters by default). The default threshold is 0.01, and the default damping is zero (no damping).
dReal dWorldGetMaxAngularSpeed (dWorldID); void dWorldSetMaxAngularSpeed (dWorldID, dReal max_speed);
Set/Get the default maximum angular speed for new bodies.
void dWorldSetContactMaxCorrectingVel (dWorldID, dReal vel); dReal dWorldGetContactMaxCorrectingVel (dWorldID);
Set and get the maximum correcting velocity that contacts are allowed to generate. The default value is infinity (i.e. no limit). Reducing this value can help prevent "popping" of deeply embedded objects.
void dWorldSetContactSurfaceLayer (dWorldID, dReal depth); dReal dWorldGetContactSurfaceLayer (dWorldID);
Set and get the depth of the surface layer around all geometry objects. Contacts are allowed to sink into the surface layer up to the given depth before coming to rest. The default value is zero. Increasing this to some small value (e.g. 0.001) can help prevent jittering problems due to contacts being repeatedly made and broken.