Panda3D Manual: Worlds, Bodies and MassesWorldsTo use the ODE physics system, you need to have an OdeWorld. A world is an essential component in the physics structure, it holds all your rigid bodies and joints, and controls global parameters, such as gravity, for the scene. #include "odeWorld.h" As you can see, the gravity is set to a downward vector with length 9.81. This value is the average gravity acceleration on Earth. If you want objects to fall faster or slower, (e.g. if your game plays on the Moon, where the gravity acceleration is 1.62 m/s²) you need to change this value, but in most cases you want to leave it around 9.81 m/s². Bodies and massesIn physics space, the objects that matter are called bodies. In order to have something affected by physics, you need to create an OdeBody, and set an OdeMass on it. An OdeMass does not just define how much an object weighs. You roughly have to specify a shape so ODE will know how the mass is divided over the body. Also, ODE will have to know either the density of the object or the mass. In the following example the geometry is assumed to be a box-shaped object made of lead, and the box has a width, length and height of 1 meter. #include "odeBody.h"
First, the position and quaternion are set of the body, this is directly copied from the NodePath's pos and quat; do note that when using get_pos and get_quat, you need to get them in global coordinate space, this is done here by specifying Then, a mass is set for the body. The first argument specified in the set_box call is the density of the object, the second is the dimensions (lx, ly, lz) of the box. Each material has it's own density, for example, water has a density of 1000 kg/m³, copper usually between 8920 and 8960 kg/m³. The value shown in the example above is the density for lead. There are of course cases where you don't know the density (although it is easy to calculate), or when the object is not easy to fit in a box shape. OdeMass provides the following methods:
More methods are listed in the API reference. For more complex shapes, you might want to decompose the object into several simple ones, and use the © Carnegie Mellon University 2010 |