collision_shapes.cpp
Go to the documentation of this file.
00001 
00031 #include <stdio.h>
00032 
00033 #include <btBulletCollisionCommon.h>
00034 
00035 extern double bulletWorldScalingFactor;
00036 
00037 extern "C"
00038 {
00039 
00040   void deleteCollisionShape(btCollisionShape *ptr)
00041   {
00042     delete ptr;
00043   }
00044 
00045   int getShapeType(btCollisionShape *ptr)
00046   {
00047     return ptr->getShapeType();
00048   }
00049   
00050   btCollisionShape *newBoxShape(const double *half_extents)
00051   {
00052     return new btBoxShape(btVector3(half_extents[0] * bulletWorldScalingFactor,
00053         half_extents[1] * bulletWorldScalingFactor,
00054         half_extents[2] * bulletWorldScalingFactor));
00055   }
00056 
00057   bool isBoxShape(const btCollisionShape *ptr)
00058   {
00059     return dynamic_cast<const btBoxShape *>(ptr) != NULL;
00060   }
00061 
00062   void getBoxHalfExtents(const btBoxShape *box, double *half_extents)
00063   {
00064     btVector3 extents = box->getHalfExtentsWithMargin() / bulletWorldScalingFactor;
00065     half_extents[0] = extents.x();
00066     half_extents[1] = extents.y();
00067     half_extents[2] = extents.z();
00068   }
00069 
00070   btCollisionShape *newStaticPlaneShape(const double *normal, double constant)
00071   {
00072     return new btStaticPlaneShape(btVector3(normal[0], normal[1], normal[2]), constant);
00073   }
00074 
00075   bool isStaticPlaneShape(const btCollisionShape *ptr)
00076   {
00077     return dynamic_cast<const btStaticPlaneShape *>(ptr) != NULL;
00078   }
00079 
00080   void getPlaneNormal(const btStaticPlaneShape *plane, double *normal)
00081   {
00082     btVector3 normal_vec = plane->getPlaneNormal();
00083     normal[0] = normal_vec.x();
00084     normal[1] = normal_vec.y();
00085     normal[2] = normal_vec.z();
00086   }
00087 
00088   double getPlaneConstant(const btStaticPlaneShape *plane)
00089   {
00090     return plane->getPlaneConstant();
00091   }
00092   
00093   btCollisionShape *newSphereShape(double radius)
00094   {
00095     return new btSphereShape(radius * bulletWorldScalingFactor);
00096   }
00097 
00098   bool isSphereShape(const btCollisionShape *ptr)
00099   {
00100     return dynamic_cast<const btSphereShape *>(ptr) != NULL;
00101   }
00102 
00103   double getSphereRadius(const btSphereShape *sphere)
00104   {
00105     return sphere->getRadius() / bulletWorldScalingFactor;
00106   }
00107 
00108   btCollisionShape *newCylinderShape(const double *half_extents)
00109   {
00110     return new btCylinderShapeZ(
00111       btVector3(
00112         half_extents[0] * bulletWorldScalingFactor,
00113         half_extents[1] * bulletWorldScalingFactor,
00114         half_extents[2] * bulletWorldScalingFactor));
00115   }
00116 
00117   bool isCylinderShape(const btCollisionShape *ptr)
00118   {
00119     return dynamic_cast<const btCylinderShape *>(ptr) != NULL;
00120   }
00121 
00122   void getCylinderHalfExtents(const btCylinderShape *cylinder, double *half_extents)
00123   {
00124     btVector3 extents = cylinder->getHalfExtentsWithMargin() / bulletWorldScalingFactor;
00125     half_extents[0] = extents.x();
00126     half_extents[1] = extents.y();
00127     half_extents[2] = extents.z();
00128   }
00129   
00130   btCollisionShape *newConeShape(double radius, double height)
00131   {
00132     return new btConeShapeZ(
00133       radius * bulletWorldScalingFactor,
00134       height * bulletWorldScalingFactor);
00135   }
00136 
00137   bool isConeShape(const btCollisionShape *ptr)
00138   {
00139     return dynamic_cast<const btConeShape *>(ptr) != NULL;
00140   }
00141 
00142   double getConeRadius(const btConeShape *cone)
00143   {
00144     return cone->getRadius() / bulletWorldScalingFactor;
00145   }
00146 
00147   double getConeHeight(const btConeShape *cone)
00148   {
00149     return cone->getHeight() / bulletWorldScalingFactor;
00150   }
00151 
00152   btCollisionShape *newCompoundShape()
00153   {
00154     return new btCompoundShape();
00155   }
00156 
00157   bool isCompoundShape(const btCompoundShape *ptr)
00158   {
00159     return dynamic_cast<const btCompoundShape *>(ptr) != NULL;
00160   }
00161 
00162   void addChildShape(btCompoundShape *parent,
00163     const double *position, const double *orientation,
00164     btCollisionShape *shape)
00165   {
00166     parent->addChildShape(
00167       btTransform(
00168         btQuaternion(orientation[0],
00169           orientation[1],
00170           orientation[2],
00171           orientation[3]),
00172         btVector3(position[0] * bulletWorldScalingFactor,
00173           position[1] * bulletWorldScalingFactor,
00174           position[2] * bulletWorldScalingFactor)),
00175       shape);
00176   }
00177 
00178   int getNumChildShapes(btCompoundShape *shape)
00179   {
00180     return shape->getNumChildShapes();
00181   }
00182 
00183   const btCollisionShape *getChildShape(const btCompoundShape *shape, int index)
00184   {
00185     return shape->getChildShape(index);
00186   }
00187 
00188   void getChildTransform(const btCompoundShape *shape, int index, double *transform)
00189   {
00190     const btTransform &trans = shape->getChildTransform(index);
00191     const btVector3 &pos = trans.getOrigin() / bulletWorldScalingFactor;
00192     btQuaternion rot = trans.getRotation();
00193     transform[0] = pos.x();
00194     transform[1] = pos.y();
00195     transform[2] = pos.z();
00196     transform[3] = rot.x();
00197     transform[4] = rot.y();
00198     transform[5] = rot.z();
00199     transform[6] = rot.w();
00200   }
00201 
00202   btCollisionShape *newConvexHullShape(const double *points, int num_points)
00203   {
00204     double *scaled_points = new double[num_points*3];
00205     for(int i=0; i<num_points*3; i++)
00206       scaled_points[i] = points[i] * bulletWorldScalingFactor;
00207     return new btConvexHullShape(scaled_points, num_points, sizeof(double) * 3);
00208     delete scaled_points;
00209   }
00210 
00211   bool isConvexHullShape(const btCollisionShape *ptr)
00212   {
00213     return dynamic_cast<const btConvexHullShape *>(ptr) != NULL;
00214   }
00215 
00216   void addPoint(btConvexHullShape *shape, const double *point)
00217   {
00218     shape->addPoint(btVector3(point[0] * bulletWorldScalingFactor,
00219         point[1] * bulletWorldScalingFactor, point[2] * bulletWorldScalingFactor));
00220   }
00221 
00222   int convexHullGetNumPoints(const btConvexHullShape *shape)
00223   {
00224     return shape->getNumPoints();
00225   }
00226 
00227   void getPoint(const btConvexHullShape *shape, int index, double *point)
00228   {
00229     const btVector3 &pt = shape->getUnscaledPoints()[index] / bulletWorldScalingFactor;
00230     point[0] = pt.x();
00231     point[1] = pt.y();
00232     point[2] = pt.z();
00233   }
00234 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Properties Friends


cl_bullet
Author(s): Lorenz Moesenlechner
autogenerated on Thu May 23 2013 05:47:18