Panda3D Manual: Bullet Collision ShapesOn the previous page we have been introduced to Bullet basics. Two simple collision shapes - a box and a plane - have been used in this simple script. This page will now introduce more collison shapes provided by Bullet, starting with primitive shapes and then moving on to more complex ones. Primitive shapes:
Complex shapes:
Sphere ShapeThe most basic collision shape, a sphere with radius radius. The sphere is centered around it's origin.
#include "panda3d/bulletSphereShape.h"
Plane ShapeAnother primitive collision shape, an infinite plane. To create a plane you have to pass both the plane's normal vector (Vec3(nx, ny, nz)) and the plane constant (d, which is the distance of the plane's origin. Planes can only be used for static objects.
#include "panda3d/bulletPlaneShape.h"
Box ShapeA box-shaped primitive collision shape. To create a box you have to pass a vector with the half-extents (Vec3(dx, dx, dx)). The full extents of the box will be twice the half extents, e. g. from -dx to +dx on the local x-axis.
#include "panda3d/bulletBoxShape.h"
Cylinder ShapeA primitive collision shape which is represents a cylinder. We can create a cylinder shape by either passing it's radius, height and cylinder axis, or by passing a vector with half extents and the cylinder axis. The following example creates two cylinder shapes, both with radius 0.5 and height 1.4.
#include "panda3d/bulletCylinderShape.h"
Capsule ShapeA primitive collision shape which is a "capped" cylinder. "Capped" means that there are half-spheres at both ends, unlike the real cylinder which has flat ends. Capsule shapes are a good choice for character controllers, since they are fast, symmetrical, and allow smooth movement over steps. To create a capsule shape we have to pass the capsule's radius, the height of the cylindrical part, and the up-axis. The total height of the capsule will be the height of the cylindrical part, plus twice the radius.
#include "panda3d/bulletCapsuleShape.h"
Cone ShapeAgain a primitive collision shape, which represents a cone. We have to pass the radius of the circular base of the cone, and it's height.
#include "panda3d/bulletConeShape.h"
Compound ShapeCompound shapes are assemblies made up from two or more individual shapes. For example you could create a collision shape for a table from five box shapes. One "flat" box for the table plate, and four "thin" ones for the table legs. The Panda3D Bullet module has no specialized class for compound shapes. It automatically creates a compound shape if more than one shape is added to a body node. The following code snippet will create such a compound shape, resembling the before mentioned table.
BulletBoxShape *shape1 = new BulletBoxShape(LVecBase3f(0.1,0.1,0.5));
Convex Hull ShapeThe first of the non-primitive collision shapes. A good analogy for a convex hull is an elastic membrane or balloon under pressure which is placed around a given set of vertices. When released the membrane will assume the shape of the convex hull. Convex hull shapes should be used for dynamic objects, if it is not possible to find a good approximation of the objects shape using collision primitives. Convex hull shapes can be created is several ways:
#include "panda3d/bulletConvexHullShape.h"
Triangle Mesh ShapeAnother non-primitive collision shape. A triangle mesh shape is similar to the convex hull shape, except that it is not restricted to convex geometry - it can contain concave parts. A typical use case for triangle mesh shapes is the static geometry of a game level. However, it is possible to use triangle mesh shapes for dynamic object too. We have to explicitly tell Bullet if we want to static or dynamic triangle mesh shape at the time where the shape is created. To create a triangle mesh shape we first have to create a triangle mesh object. The following example will create a simple quad made up from two triangles.
#include "panda3d/bulletTriangleMesh.h" we can use a convenience method to add all triangles from a Geom object with one method call. The geom will be decomposed first, so it must not contain only triangles; it can contain for example triangle trips too.
#include "panda3d/bulletTriangleMesh.h"
Heightfield ShapeA special non-primitive collision shape. Give a heightfield image we can construct a terrain mesh with only a few lines of code.
#include "panda3d/pnmImage.h"
The heightfield shape will be oriented the same way as a GeoMipTerrain created from the same image, but GeoMipTerrain and BulletHeightfieldShape have different origins. The BulletHeightfieldShape is centered around the origin, while the GeoMipTerrain uses the lower left corner as its origin. However, this can be easily corrected by positioning the GeoMipTerrain with an offset relative to the static rigid body node.
GeoMipTerrain *terrain = get_geomip_terrain();
Soft Body ShapeThis special collision shape is used in connection with soft bodies. It can not be created directly. Soft bodies will be discussed later within this manual. © Carnegie Mellon University 2010 |