Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/libraries/tools/DebugDrawer.h @ 10190

Last change on this file since 10190 was 10190, checked in by landauf, 10 years ago

added utility to visualize collision shapes

File size: 4.8 KB
RevLine 
[10190]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
26namespace 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, float radius, int segmentsCount, const Ogre::ColourValue& colour, bool isFilled = false);
38            void drawCylinder(const Ogre::Vector3& centre, float radius, int segmentsCount, float height, const Ogre::ColourValue& colour, bool isFilled = false);
39            void drawQuad(const Ogre::Vector3* vertices, const Ogre::ColourValue& colour, bool isFilled = false);
40            void drawCuboid(const Ogre::Vector3* vertices, const Ogre::ColourValue& colour, bool isFilled = false);
41            void drawSphere(const Ogre::Vector3& centre, float radius, const Ogre::ColourValue& colour, bool isFilled = false);
42            void drawTetrahedron(const Ogre::Vector3& centre, float scale, const Ogre::ColourValue& colour, bool isFilled = false);
43
44            bool getEnabled()
45            {
46                return isEnabled;
47            }
48            void setEnabled(bool _isEnabled)
49            {
50                isEnabled = _isEnabled;
51            }
52            void switchEnabled()
53            {
54                isEnabled = !isEnabled;
55            }
56
57            void clear();
58
59        private:
60            const IcoSphere& getIcoSphere(float radius) const;
61
62            Ogre::SceneManager* sceneManager;
63            float fillAlpha;
64            Ogre::ManualObject* manualObject;
65            IcoSphere icoSphere0;
66            IcoSphere icoSphere1;
67            IcoSphere icoSphere2;
68            IcoSphere icoSphere3;
69            IcoSphere icoSphere4;
70
71            bool isEnabled;
72
73            std::list<VertexPair> lineVertices, triangleVertices;
74            std::list<int> lineIndices, triangleIndices;
75
76            int linesIndex, trianglesIndex;
77
78            void initialise();
79            void shutdown();
80
81            void buildLine(const Ogre::Vector3& start, const Ogre::Vector3& end, const Ogre::ColourValue& colour, float alpha = 1.0f);
82            void buildQuad(const Ogre::Vector3* vertices, const Ogre::ColourValue& colour, float alpha = 1.0f);
83            void buildFilledQuad(const Ogre::Vector3* vertices, const Ogre::ColourValue& colour, float alpha = 1.0f);
84            void buildFilledTriangle(const Ogre::Vector3* vertices, const Ogre::ColourValue& colour, float alpha = 1.0f);
85            void buildCuboid(const Ogre::Vector3* vertices, const Ogre::ColourValue& colour, float alpha = 1.0f);
86            void buildFilledCuboid(const Ogre::Vector3* vertices, const Ogre::ColourValue& colour, float alpha = 1.0f);
87
88            void buildCircle(const Ogre::Vector3& centre, float radius, int segmentsCount, const Ogre::ColourValue& colour, float alpha = 1.0f);
89            void buildFilledCircle(const Ogre::Vector3& centre, float radius, int segmentsCount, const Ogre::ColourValue& colour, float alpha = 1.0f);
90
91            void buildCylinder(const Ogre::Vector3& centre, float radius, int segmentsCount, float height, const Ogre::ColourValue& colour, float alpha = 1.0f);
92            void buildFilledCylinder(const Ogre::Vector3& centre, float radius, int segmentsCount, float height, const Ogre::ColourValue& colour, float alpha = 1.0f);
93
94            void buildTetrahedron(const Ogre::Vector3& centre, float scale, const Ogre::ColourValue& colour, float alpha = 1.0f);
95            void buildFilledTetrahedron(const Ogre::Vector3& centre, float scale, const Ogre::ColourValue& colour, float alpha = 1.0f);
96
97            int addLineVertex(const Ogre::Vector3& vertex, const Ogre::ColourValue& colour);
98            void addLineIndices(int index1, int index2);
99
100            int addTriangleVertex(const Ogre::Vector3& vertex, const Ogre::ColourValue& colour);
101            void addTriangleIndices(int index1, int index2, int index3);
102
103            void addQuadIndices(int index1, int index2, int index3, int index4);
104    };
105}
106
107#endif /* _DebugDrawer_H__ */
Note: See TracBrowser for help on using the repository browser.