Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 10191 was 10191, checked in by landauf, 9 years ago

added customized visualization for cylinders and cones to BulletDebugDrawer.
improved DebugDrawer by making circle, cylinder, and sphere rotatable. added rendering function for cones.

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