| 1 | /** | 
|---|
| 2 |  * @file DebugDrawer.h | 
|---|
| 3 |  * Copy-pasted from | 
|---|
| 4 |  *  - https://bitbucket.org/hasyimi/ogre-debug-drawing-utility/src | 
|---|
| 5 |  *  - http://www.ogre3d.org/tikiwiki/tiki-index.php?page=Debug+Drawing+Utility+Class | 
|---|
| 6 |  * | 
|---|
| 7 |  * This source code is released into the Public Domain. | 
|---|
| 8 |  * | 
|---|
| 9 |  * Modified by Fabian 'x3n' Landau | 
|---|
| 10 |  */ | 
|---|
| 11 |  | 
|---|
| 12 |  | 
|---|
| 13 |  | 
|---|
| 14 | #ifndef _DebugDrawer_H__ | 
|---|
| 15 | #define _DebugDrawer_H__ | 
|---|
| 16 |  | 
|---|
| 17 | #include "tools/ToolsPrereqs.h" | 
|---|
| 18 |  | 
|---|
| 19 | #include <map> | 
|---|
| 20 |  | 
|---|
| 21 | #include "IcoSphere.h" | 
|---|
| 22 |  | 
|---|
| 23 | namespace orxonox | 
|---|
| 24 | { | 
|---|
| 25 |     /** | 
|---|
| 26 |      * @brief DebugDrawer is a utility to draw debug shapes (lines, triangles, spheres) with Ogre. | 
|---|
| 27 |      * This utility is e.g. used by @ref orxonox::BulletDebugDrawer to visualize collision shapes and other physical entities. | 
|---|
| 28 |      */ | 
|---|
| 29 |     class _ToolsExport DebugDrawer | 
|---|
| 30 |     { | 
|---|
| 31 |         public: | 
|---|
| 32 |             DebugDrawer(Ogre::SceneManager *_sceneManager, float _fillAlpha); | 
|---|
| 33 |             ~DebugDrawer(); | 
|---|
| 34 |  | 
|---|
| 35 |             void build(); | 
|---|
| 36 |  | 
|---|
| 37 |             void drawLine(const Ogre::Vector3& start, const Ogre::Vector3& end, const Ogre::ColourValue& colour); | 
|---|
| 38 |             void drawCircle(const Ogre::Vector3& centre, const Ogre::Quaternion& rotation, float radius, const Ogre::ColourValue& colour, bool isFilled = false); | 
|---|
| 39 |             void drawCylinder(const Ogre::Vector3& centre, const Ogre::Quaternion& rotation, float radius, float height, const Ogre::ColourValue& colour, bool isFilled = false); | 
|---|
| 40 |             void drawCone(const Ogre::Vector3& centre, const Ogre::Quaternion& rotation, float radius, float height, const Ogre::ColourValue& colour, bool isFilled = false); | 
|---|
| 41 |  | 
|---|
| 42 |             void drawQuad(const Ogre::Vector3* vertices, const Ogre::ColourValue& colour, bool isFilled = false); | 
|---|
| 43 |             void drawCuboid(const Ogre::Vector3* vertices, const Ogre::ColourValue& colour, bool isFilled = false); | 
|---|
| 44 |             void drawSphere(const Ogre::Vector3& centre, const Ogre::Quaternion& rotation, float radius, const Ogre::ColourValue& colour, bool isFilled = false); | 
|---|
| 45 |             void drawTetrahedron(const Ogre::Vector3& centre, float scale, const Ogre::ColourValue& colour, bool isFilled = false); | 
|---|
| 46 |  | 
|---|
| 47 |             void setFillAlpha(float alpha) | 
|---|
| 48 |             { | 
|---|
| 49 |                 fillAlpha = alpha; | 
|---|
| 50 |             } | 
|---|
| 51 |  | 
|---|
| 52 |             bool getEnabled() | 
|---|
| 53 |             { | 
|---|
| 54 |                 return isEnabled; | 
|---|
| 55 |             } | 
|---|
| 56 |             void setEnabled(bool _isEnabled) | 
|---|
| 57 |             { | 
|---|
| 58 |                 isEnabled = _isEnabled; | 
|---|
| 59 |             } | 
|---|
| 60 |             void switchEnabled() | 
|---|
| 61 |             { | 
|---|
| 62 |                 isEnabled = !isEnabled; | 
|---|
| 63 |             } | 
|---|
| 64 |  | 
|---|
| 65 |             void clear(); | 
|---|
| 66 |  | 
|---|
| 67 |         private: | 
|---|
| 68 |             const IcoSphere& getIcoSphere(float radius) const; | 
|---|
| 69 |  | 
|---|
| 70 |             Ogre::SceneManager* sceneManager; | 
|---|
| 71 |             float fillAlpha; | 
|---|
| 72 |             Ogre::ManualObject* manualObject; | 
|---|
| 73 |             IcoSphere icoSphere0; | 
|---|
| 74 |             IcoSphere icoSphere1; | 
|---|
| 75 |             IcoSphere icoSphere2; | 
|---|
| 76 |             IcoSphere icoSphere3; | 
|---|
| 77 |             IcoSphere icoSphere4; | 
|---|
| 78 |  | 
|---|
| 79 |             bool isEnabled; | 
|---|
| 80 |  | 
|---|
| 81 |             std::list<VertexPair> lineVertices, triangleVertices; | 
|---|
| 82 |             std::list<int> lineIndices, triangleIndices; | 
|---|
| 83 |  | 
|---|
| 84 |             int linesIndex, trianglesIndex; | 
|---|
| 85 |  | 
|---|
| 86 |             void initialise(); | 
|---|
| 87 |             void shutdown(); | 
|---|
| 88 |  | 
|---|
| 89 |             void buildLine(const Ogre::Vector3& start, const Ogre::Vector3& end, const Ogre::ColourValue& colour, float alpha = 1.0f); | 
|---|
| 90 |             void buildQuad(const Ogre::Vector3* vertices, const Ogre::ColourValue& colour, float alpha = 1.0f); | 
|---|
| 91 |             void buildFilledQuad(const Ogre::Vector3* vertices, const Ogre::ColourValue& colour, float alpha = 1.0f); | 
|---|
| 92 |             void buildFilledTriangle(const Ogre::Vector3* vertices, const Ogre::ColourValue& colour, float alpha = 1.0f); | 
|---|
| 93 |             void buildCuboid(const Ogre::Vector3* vertices, const Ogre::ColourValue& colour, float alpha = 1.0f); | 
|---|
| 94 |             void buildFilledCuboid(const Ogre::Vector3* vertices, const Ogre::ColourValue& colour, float alpha = 1.0f); | 
|---|
| 95 |  | 
|---|
| 96 |             void buildCircle(const Ogre::Matrix4& transform, float radius, int segmentsCount, const Ogre::ColourValue& colour, float alpha = 1.0f); | 
|---|
| 97 |             void buildFilledCircle(const Ogre::Matrix4& transform, float radius, int segmentsCount, const Ogre::ColourValue& colour, bool up, float alpha = 1.0f); | 
|---|
| 98 |  | 
|---|
| 99 |             void buildCylinder(const Ogre::Vector3& centre, const Ogre::Quaternion& rotation, float radius, int segmentsCount, float height, const Ogre::ColourValue& colour, float alpha = 1.0f); | 
|---|
| 100 |             void buildFilledCylinder(const Ogre::Vector3& centre, const Ogre::Quaternion& rotation, float radius, int segmentsCount, float height, const Ogre::ColourValue& colour, float alpha = 1.0f); | 
|---|
| 101 |  | 
|---|
| 102 |             void buildCone(const Ogre::Vector3& centre, const Ogre::Quaternion& rotation, float radius, int segmentsCount, float height, const Ogre::ColourValue& colour, float alpha = 1.0f); | 
|---|
| 103 |             void buildFilledCone(const Ogre::Vector3& centre, const Ogre::Quaternion& rotation, float radius, int segmentsCount, float height, const Ogre::ColourValue& colour, float alpha = 1.0f); | 
|---|
| 104 |  | 
|---|
| 105 |             void buildTetrahedron(const Ogre::Vector3& centre, float scale, const Ogre::ColourValue& colour, float alpha = 1.0f); | 
|---|
| 106 |             void buildFilledTetrahedron(const Ogre::Vector3& centre, float scale, const Ogre::ColourValue& colour, float alpha = 1.0f); | 
|---|
| 107 |  | 
|---|
| 108 |             int addLineVertex(const Ogre::Vector3& vertex, const Ogre::ColourValue& colour); | 
|---|
| 109 |             void addLineIndices(int index1, int index2); | 
|---|
| 110 |  | 
|---|
| 111 |             int addTriangleVertex(const Ogre::Vector3& vertex, const Ogre::ColourValue& colour); | 
|---|
| 112 |             void addTriangleIndices(int index1, int index2, int index3); | 
|---|
| 113 |  | 
|---|
| 114 |             void addQuadIndices(int index1, int index2, int index3, int index4); | 
|---|
| 115 |     }; | 
|---|
| 116 | } | 
|---|
| 117 |  | 
|---|
| 118 | #endif /* _DebugDrawer_H__ */ | 
|---|