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