1 //
2 //  SuperTuxKart - a fun racing game with go-kart
3 //  Copyright (C) 2006-2015 Joerg Henrichs
4 //
5 //  This program is free software; you can redistribute it and/or
6 //  modify it under the terms of the GNU General Public License
7 //  as published by the Free Software Foundation; either version 3
8 //  of the License, or (at your option) any later version.
9 //
10 //  This program is distributed in the hope that it will be useful,
11 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
12 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 //  GNU General Public License for more details.
14 //
15 //  You should have received a copy of the GNU General Public License
16 //  along with this program; if not, write to the Free Software
17 //  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
18 
19 #ifndef HEADER_IRR_DEBUG_DRAWER_HPP
20 #define HEADER_IRR_DEBUG_DRAWER_HPP
21 
22 #include "btBulletDynamicsCommon.h"
23 
24 #include <SColor.h>
25 #include "utils/vec3.hpp"
26 #include <map>
27 #include <vector>
28 
29 /**
30   * \ingroup physics
31   */
32 class IrrDebugDrawer : public btIDebugDraw
33 {
34 public:
35     /** The drawing mode to use:
36      *  If bit 0 is set, draw the bullet collision shape of karts
37      *  If bit 1 is set, don't draw the kart graphics
38      */
39     enum            DebugModeType { DM_NONE              = 0x00,
40                                     DM_KARTS_PHYSICS     = 0x01,
41                                     DM_NO_KARTS_GRAPHICS = 0x02
42                                   };
43     DebugModeType   m_debug_mode;
44 
45     std::map<video::SColor, std::vector<float> > m_lines;
46 
47     Vec3 m_camera_pos;
48 
49 protected:
setDebugMode(int debug_mode)50     virtual void    setDebugMode(int debug_mode) {}
51     /** Callback for bullet: if debug drawing should be done or not.
52      *  Note that getDebugMode is even called when debug_drawing is disabled
53      *  (i.e. not via Physics::draw()), but internally from bullet. So
54      *  we have to make sure to return nodebug if debugging is disabled. */
getDebugMode() const55     virtual int     getDebugMode() const
56                     { return m_debug_mode==DM_NONE ? DBG_NoDebug
57                                                    : DBG_DrawWireframe;}
58 public:
59                     IrrDebugDrawer();
60     void            render(float dt);
61     /** Draws a line. */
62     virtual void    drawLine(const btVector3& from, const btVector3& to,
63                              const btVector3& color);
64     ///optional debug methods
drawContactPoint(const btVector3 & Point_on_b,const btVector3 & normal_on_b,btScalar distance,int life_time,const btVector3 & color)65     virtual void    drawContactPoint(const btVector3& Point_on_b,
66                                      const btVector3& normal_on_b,
67                                      btScalar distance,int life_time,
68                                      const btVector3& color)      {}
reportErrorWarning(const char * warningString)69     virtual void    reportErrorWarning(const char* warningString) {}
draw3dText(const btVector3 & location,const char * textString)70     virtual void    draw3dText(const btVector3& location,
71                                const char* textString)            {}
72     /** Returns true if debug mode is enabled. */
debugEnabled() const73     bool            debugEnabled() const         {return m_debug_mode!=0;}
74     void            nextDebugMode();
75     void            setDebugMode(DebugModeType mode);
76 
77     void            beginNextFrame();
getLines() const78     const std::map<video::SColor, std::vector<float> >& getLines() const { return m_lines; }
79 };   // IrrDebugDrawer
80 
81 #endif
82 /* EOF */
83 
84