debug_draw.cpp
Go to the documentation of this file.
00001 
00031 #include <LinearMath/btIDebugDraw.h>
00032 
00033 extern double bulletWorldScalingFactor;
00034 
00035 class CLBulletDebugDraw : public btIDebugDraw
00036 {
00037 public:
00038   struct Callbacks
00039   {
00040     void (*drawLine)(const double */*from*/, const double */*to*/, const double */*color*/, void *);
00041     void (*drawSphere)(const double */*p*/, double /*radius*/, const double */*color*/, void *);
00042     void (*drawTriangle)(const double */*v0*/, const double */*v1*/, const double */*v2*/,
00043                          const double */*color*/, double /*alpha*/, void *);
00044     void (*drawBox)(const double */*boxMin*/, const double */*boxMax*/,
00045                     const double */*color*/, void *);
00046     void (*drawAabb)(const double */*from*/, const double */*to*/, const double */*color*/, void *);
00047     void (*drawTransform)(const double */*transform*/, double /*orthoLen*/, void *);
00048     void (*drawArc)(const double */*center*/, const double */*normal*/,
00049                     const double */*axis*/, double /*radiusA*/, double /*radiusB*/,
00050                     double /*minAngle*/, double /*maxAngle*/, const double */*color*/,
00051                     bool /*drawSect*/, double /*stepDegrees*/, void *);
00052     void (*drawSpherePatch)(const double */*center*/, const double */*up*/, const double */*axis*/,
00053                             double /*radius*/, double /*minTh*/, double /*maxTh*/, double /*minPs*/,
00054                             double /*maxPs*/, const double */*color*/,
00055                             double /*stepDegrees*/, void *);
00056     void (*drawContactPoint)(const double */*PointOnB*/, const double */*normalOnB*/, double /*distance*/,
00057                              int /*lifeTime*/, const double */*color*/, void *);
00058     void (*reportErrorWarning)(const char */*warningString*/, void *);
00059     void (*draw3dText)(const double */*location*/, const char */*string*/, void *); 
00060 
00061     Callbacks()
00062       : drawLine(0), drawSphere(0), drawTriangle(0), drawBox(0),
00063         drawAabb(0), drawTransform(0), drawArc(0), drawSpherePatch(0),
00064         drawContactPoint(0), reportErrorWarning(0), draw3dText(0) {}
00065   };
00066 
00067 
00068   CLBulletDebugDraw(void *arg=0)
00069     : debug_mode_(DBG_NoDebug),
00070       arg_(arg) {}
00071 
00072   CLBulletDebugDraw(const Callbacks &callbacks, void *arg=0)
00073     : debug_mode_(DBG_NoDebug),
00074       callbacks_(callbacks),
00075       arg_(arg) {}
00076     
00077   virtual void drawLine(const btVector3& from,const btVector3& to,const btVector3& color)
00078   {
00079     double from_[3] = {from.x() / bulletWorldScalingFactor,
00080                        from.y() / bulletWorldScalingFactor,
00081                        from.z() / bulletWorldScalingFactor};
00082     double to_[3] = {to.x() / bulletWorldScalingFactor,
00083                      to.y() / bulletWorldScalingFactor,
00084                      to.z() / bulletWorldScalingFactor};
00085     double color_[3] = {color.x(), color.y(), color.z()};
00086     
00087     if(callbacks_.drawLine)
00088       (*callbacks_.drawLine)(from_, to_, color_, arg_);
00089   }
00090 
00091   virtual void drawSphere (const btVector3& p, btScalar radius, const btVector3& color)
00092   {
00093     double p_[3] = {p.x() / bulletWorldScalingFactor,
00094                     p.y() / bulletWorldScalingFactor,
00095                     p.z() / bulletWorldScalingFactor};
00096     double color_[3] = {color.x(), color.y(), color.z()};
00097 
00098     if(callbacks_.drawSphere)
00099       (*callbacks_.drawSphere)(p_, radius / bulletWorldScalingFactor, color_, arg_);
00100     else
00101       btIDebugDraw::drawSphere(p/bulletWorldScalingFactor, radius / bulletWorldScalingFactor, color);
00102   }
00103 
00104   virtual void drawTriangle(const btVector3& v0,const btVector3& v1,const btVector3& v2,const btVector3& color, btScalar alpha)
00105   {
00106     double v0_[3] = {v0.x() / bulletWorldScalingFactor,
00107                      v0.y() / bulletWorldScalingFactor,
00108                      v0.z() / bulletWorldScalingFactor};
00109     double v1_[3] = {v1.x() / bulletWorldScalingFactor,
00110                      v1.y() / bulletWorldScalingFactor,
00111                      v1.z() / bulletWorldScalingFactor};
00112     double v2_[3] = {v2.x() / bulletWorldScalingFactor,
00113                      v2.y() / bulletWorldScalingFactor,
00114                      v2.z() / bulletWorldScalingFactor};
00115     double color_[3] = {color.x(), color.y(), color.z()};
00116     
00117 
00118     if(callbacks_.drawTriangle)
00119       (callbacks_.drawTriangle)(v0_, v1_, v2_, color_, alpha, arg_);
00120     else
00121       btIDebugDraw::drawTriangle(v0 / bulletWorldScalingFactor,
00122         v1 / bulletWorldScalingFactor, v2 / bulletWorldScalingFactor,
00123         color, alpha);
00124   }
00125 
00126   virtual void drawBox (const btVector3& boxMin, const btVector3& boxMax, const btVector3& color)
00127   {
00128     double boxMin_[3] = {boxMin.x() / bulletWorldScalingFactor,
00129                          boxMin.y() / bulletWorldScalingFactor,
00130                          boxMin.z() / bulletWorldScalingFactor}; 
00131     double boxMax_[3] = {boxMax.x() / bulletWorldScalingFactor,
00132                          boxMax.y() / bulletWorldScalingFactor,
00133                          boxMax.z() / bulletWorldScalingFactor};
00134     double color_[3] = {color.x(), color.y(), color.z()};
00135     
00136     if(callbacks_.drawBox)
00137       (*callbacks_.drawBox)(boxMin_, boxMax_, color_, arg_);
00138     else
00139       btIDebugDraw::drawBox(boxMin / bulletWorldScalingFactor, boxMax / bulletWorldScalingFactor, color);
00140   }
00141 
00142   virtual void drawAabb(const btVector3& from,const btVector3& to,const btVector3& color)
00143   {
00144     double from_[3] = {from.x() / bulletWorldScalingFactor,
00145                        from.y() / bulletWorldScalingFactor,
00146                        from.z() / bulletWorldScalingFactor};
00147     double to_[3] = {to.x() / bulletWorldScalingFactor,
00148                      to.y() / bulletWorldScalingFactor,
00149                      to.z() / bulletWorldScalingFactor};
00150     double color_[3] = {color.x() / bulletWorldScalingFactor,
00151                         color.y() / bulletWorldScalingFactor,
00152                         color.z() / bulletWorldScalingFactor};
00153     
00154     if(callbacks_.drawAabb)
00155       (*callbacks_.drawAabb)(from_, to_, color_, arg_);
00156     else
00157       btIDebugDraw::drawAabb(from / bulletWorldScalingFactor, to / bulletWorldScalingFactor, color);
00158   }
00159 
00160   virtual void drawTransform(const btTransform& transform, btScalar orthoLen)
00161   {
00162     btVector3 origin = transform.getOrigin() / bulletWorldScalingFactor;
00163     btQuaternion rotation = transform.getRotation();
00164     double transform_[7] = {origin.x(), origin.y(), origin.z(),
00165                             rotation.x(), rotation.y(), rotation.z(),
00166                             rotation.w()};
00167     
00168     if(callbacks_.drawTransform)
00169       (*callbacks_.drawTransform)(transform_, orthoLen / bulletWorldScalingFactor, arg_);
00170     else
00171     {
00172       btTransform scaled(rotation, origin);
00173       btIDebugDraw::drawTransform(scaled, orthoLen / bulletWorldScalingFactor);
00174     }
00175   }
00176 
00177   virtual void drawArc(const btVector3& center, const btVector3& normal, const btVector3& axis, btScalar radiusA, btScalar radiusB, btScalar minAngle, btScalar maxAngle, 
00178                        const btVector3& color, bool drawSect, btScalar stepDegrees = btScalar(10.f))
00179   {
00180     double center_[3] = {center.x() / bulletWorldScalingFactor,
00181                          center.y() / bulletWorldScalingFactor,
00182                          center.z() / bulletWorldScalingFactor};
00183     double normal_[3] = {normal.x() / bulletWorldScalingFactor,
00184                          normal.y() / bulletWorldScalingFactor,
00185                          normal.z() / bulletWorldScalingFactor};
00186     double axis_[3] = {axis.x() / bulletWorldScalingFactor,
00187                        axis.y() / bulletWorldScalingFactor,
00188                        axis.z() / bulletWorldScalingFactor};
00189     double color_[3] = {color.x(), color.y(), color.z()};
00190 
00191     if(callbacks_.drawArc)
00192       (*callbacks_.drawArc)(center_, normal_, axis_,
00193         radiusA / bulletWorldScalingFactor, radiusB / bulletWorldScalingFactor,
00194         minAngle, maxAngle, color_, drawSect, stepDegrees, arg_);
00195     else
00196       btIDebugDraw::drawArc(center / bulletWorldScalingFactor, normal / bulletWorldScalingFactor,
00197         axis / bulletWorldScalingFactor, radiusA / bulletWorldScalingFactor, radiusB / bulletWorldScalingFactor,
00198         minAngle, maxAngle, color, drawSect, stepDegrees);
00199   }
00200 
00201   virtual void drawSpherePatch(const btVector3& center, const btVector3& up, const btVector3& axis, btScalar radius, 
00202                                btScalar minTh, btScalar maxTh, btScalar minPs, btScalar maxPs, const btVector3& color, btScalar stepDegrees = btScalar(10.f))
00203   {
00204     double center_[3] = {center.x() / bulletWorldScalingFactor,
00205                          center.y() / bulletWorldScalingFactor,
00206                          center.z() / bulletWorldScalingFactor};
00207     double up_[3] = {up.x() / bulletWorldScalingFactor,
00208                      up.y() / bulletWorldScalingFactor,
00209                      up.z() / bulletWorldScalingFactor};
00210     double axis_[3] = {axis.x() / bulletWorldScalingFactor,
00211                        axis.y() / bulletWorldScalingFactor,
00212                        axis.z() / bulletWorldScalingFactor};
00213     double color_[3] = {color.x(), color.y(), color.z()};
00214     
00215     if(callbacks_.drawSpherePatch)
00216       (*callbacks_.drawSpherePatch)(center_, up_, axis_, radius / bulletWorldScalingFactor,
00217         minTh, maxTh, minPs, maxPs, color_, stepDegrees, arg_);
00218     else
00219       btIDebugDraw::drawSpherePatch(center / bulletWorldScalingFactor, up / bulletWorldScalingFactor,
00220         axis / bulletWorldScalingFactor, radius / bulletWorldScalingFactor,
00221         minTh, maxTh, minPs, maxPs, color, stepDegrees);
00222   }
00223 
00224   virtual void drawContactPoint(const btVector3& PointOnB,const btVector3& normalOnB,btScalar distance,int lifeTime,const btVector3& color)
00225   {
00226     double PointOnB_[3] = {PointOnB.x() / bulletWorldScalingFactor,
00227                            PointOnB.y() / bulletWorldScalingFactor,
00228                            PointOnB.z() / bulletWorldScalingFactor};
00229     double normalOnB_[3] = {normalOnB.x() / bulletWorldScalingFactor,
00230                             normalOnB.y() / bulletWorldScalingFactor,
00231                             normalOnB.z() / bulletWorldScalingFactor};
00232     double color_[3] = {color.x(), color.y(), color.z()};
00233 
00234     if(callbacks_.drawContactPoint)
00235       (*callbacks_.drawContactPoint)(PointOnB_, normalOnB_, distance, lifeTime, color_, arg_);
00236   }
00237   
00238   virtual void reportErrorWarning(const char* warningString)
00239   {
00240     if(callbacks_.reportErrorWarning)
00241       (*callbacks_.reportErrorWarning)(warningString, arg_);
00242   }
00243 
00244   void draw3dText(const btVector3& location,const char* textString)
00245   {
00246     double location_[3] = {location.x() / bulletWorldScalingFactor,
00247                            location.y() / bulletWorldScalingFactor,
00248                            location.z() / bulletWorldScalingFactor};
00249 
00250     if(callbacks_.draw3dText)
00251       (*callbacks_.draw3dText)(location_, textString, arg_);
00252   }
00253 
00254   virtual void setDebugMode(int debugMode)
00255   {
00256     debug_mode_ = debugMode;
00257   }
00258 
00259   virtual int getDebugMode() const
00260   {
00261     return debug_mode_;
00262   }
00263 
00264   void setCallbacks(const Callbacks &callbacks)
00265   {
00266     callbacks_ = callbacks;
00267   }
00268 
00269   Callbacks &getCallbacks()
00270   {
00271     return callbacks_;
00272   }
00273 
00274 private:
00275   int debug_mode_;
00276   Callbacks callbacks_;
00277   void *arg_;
00278 };
00279 
00280 extern "C"
00281 {
00282   
00283   CLBulletDebugDraw *newCLBulletDebugDraw(CLBulletDebugDraw::Callbacks *callbacks, void *arg)
00284   {
00285     if(callbacks)
00286       return new CLBulletDebugDraw(*callbacks, arg);
00287     else
00288       return new CLBulletDebugDraw(arg);
00289   }
00290 
00291   void deleteCLBulletDebugDraw(CLBulletDebugDraw *ptr)
00292   {
00293     delete ptr;
00294   }
00295 
00296   void setDebugMode(CLBulletDebugDraw *draw, int debugMode)
00297   {
00298     draw->setDebugMode(debugMode);
00299   }
00300 
00301   int getDebugMode(CLBulletDebugDraw *draw)
00302   {
00303     return draw->getDebugMode();
00304   }
00305 
00306   void setCallbacks(CLBulletDebugDraw *draw, CLBulletDebugDraw::Callbacks *callbacks)
00307   {
00308     draw->setCallbacks(*callbacks);
00309   }
00310 
00311   CLBulletDebugDraw::Callbacks *getCallbacks(CLBulletDebugDraw *draw)
00312   {
00313     return &draw->getCallbacks();
00314   }
00315 
00316 }
 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