i6engine  1.0
Debug.h
Go to the documentation of this file.
1 /*
2  * i6engine
3  * Copyright (2016) Daniel Bonrath, Michael Baer, All rights reserved.
4  *
5  * This file is part of i6engine; i6engine is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library 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 GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18  */
19 
25 #ifndef __I6ENGINE_MODULES_DEBUG_H__
26 #define __I6ENGINE_MODULES_DEBUG_H__
27 
28 #include <map>
29 
30 #include "OGRE/OgreSingleton.h"
31 
32 typedef std::pair<Ogre::Vector3, Ogre::ColourValue> VertexPair;
33 
34 #define DEFAULT_ICOSPHERE_RECURSION_LEVEL 1
35 
36 namespace i6e {
37 namespace modules {
38 
39  class IcoSphere {
40  public:
41  struct TriangleIndices {
42  int v1, v2, v3;
43 
44  TriangleIndices(int _v1, int _v2, int _v3) : v1(_v1), v2(_v2), v3(_v3) {}
45 
46  bool operator<(const TriangleIndices & o) const { return v1 < o.v1 && v2 < o.v2 && v3 < o.v3; }
47  };
48 
49  struct LineIndices {
50  int v1, v2;
51 
52  LineIndices(int _v1, int _v2) : v1(_v1), v2(_v2) {}
53 
54  bool operator==(const LineIndices & o) const {
55  return (v1 == o.v1 && v2 == o.v2) || (v1 == o.v2 && v2 == o.v1);
56  }
57  };
58 
59  IcoSphere();
60  ~IcoSphere();
61 
62  void create(int recursionLevel);
63  void addToLineIndices(int baseIndex, std::list<int> * target);
64  int addToVertices(std::list<VertexPair> *target, const Ogre::Vector3 & position, const Ogre::ColourValue & colour, float scale);
65  void addToTriangleIndices(int baseIndex, std::list<int> * target);
66 
67  private:
68  int addVertex(const Ogre::Vector3 & vertex);
69  void addLineIndices(int index0, int index1);
70  void addTriangleLines(int index0, int index1, int index2);
71  int getMiddlePoint(int index0, int index1);
72  void addFace(int index0, int index1, int index2);
73 
74  void removeLineIndices(int index0, int index1);
75 
76  std::vector<Ogre::Vector3> vertices;
77  std::list<LineIndices> lineIndices;
78  std::list<int> triangleIndices;
79  std::list<TriangleIndices> faces;
80  std::map<long, int> middlePointIndexCache;
81  int index;
82  };
83 
84  class Debug : public Ogre::Singleton<Debug> {
85  public:
86  Debug(Ogre::SceneManager * _sceneManager, float _fillAlpha);
87  ~Debug();
88 
89  static Debug & getSingleton(void);
90  static Debug * getSingletonPtr(void);
91 
92  void build();
93 
94  void drawLine(const Ogre::Vector3 &start, const Ogre::Vector3 &end, const Ogre::ColourValue &colour);
95  void drawCircle(const Ogre::Vector3 &centre, float radius, int segmentsCount, const Ogre::ColourValue& colour, bool isFilled = false);
96  void drawCylinder(const Ogre::Vector3 &centre, float radius, int segmentsCount, float height, const Ogre::ColourValue& colour, bool isFilled = false);
97  void drawQuad(const Ogre::Vector3 *vertices, const Ogre::ColourValue& colour, bool isFilled = false);
98  void drawCuboid(const Ogre::Vector3 *vertices, const Ogre::ColourValue& colour, bool isFilled = false);
99  void drawSphere(const Ogre::Vector3 &centre, float radius, const Ogre::ColourValue& colour, bool isFilled = false);
100 
101  bool getEnabled() { return isEnabled; }
102  void setEnabled(bool _isEnabled) { isEnabled = _isEnabled; }
103  void switchEnabled() { isEnabled = !isEnabled; }
104 
105  void clear();
106 
107  private:
111  Debug(const Debug &);
112 
116  const Debug & operator=(const Debug &);
117 
118 
119  Ogre::SceneManager * sceneManager;
120 
121  float fillAlpha;
122 
123  Ogre::ManualObject * manualObject;
124 
125  bool isEnabled;
126 
127  std::list<VertexPair> lineVertices, triangleVertices;
128  std::list<int> lineIndices, triangleIndices;
129 
130  int linesIndex, trianglesIndex;
131 
132  void initialise();
133  void shutdown();
134 
135  void buildLine(const Ogre::Vector3 & start, const Ogre::Vector3 & end, const Ogre::ColourValue & colour, float alpha = 1.0f);
136  void buildQuad(const Ogre::Vector3 * vertices, const Ogre::ColourValue & colour, float alpha = 1.0f);
137  void buildFilledQuad(const Ogre::Vector3 * vertices, const Ogre::ColourValue & colour, float alpha = 1.0f);
138  void buildFilledTriangle(const Ogre::Vector3 *vertices, const Ogre::ColourValue & colour, float alpha = 1.0f);
139  void buildCuboid(const Ogre::Vector3 * vertices, const Ogre::ColourValue & colour, float alpha = 1.0f);
140  void buildFilledCuboid(const Ogre::Vector3 * vertices, const Ogre::ColourValue & colour, float alpha = 1.0f);
141 
142  void buildCircle(const Ogre::Vector3 & centre, float radius, int segmentsCount, const Ogre::ColourValue & colour, float alpha = 1.0f);
143  void buildFilledCircle(const Ogre::Vector3 & centre, float radius, int segmentsCount, const Ogre::ColourValue & colour, float alpha = 1.0f);
144 
145  void buildCylinder(const Ogre::Vector3 & centre, float radius, int segmentsCount, float height, const Ogre::ColourValue & colour, float alpha = 1.0f);
146  void buildFilledCylinder(const Ogre::Vector3 & centre, float radius, int segmentsCount, float height, const Ogre::ColourValue & colour, float alpha = 1.0f);
147 
148  int addLineVertex(const Ogre::Vector3 & vertex, const Ogre::ColourValue & colour);
149  void addLineIndices(int index1, int index2);
150 
151  int addTriangleVertex(const Ogre::Vector3 & vertex, const Ogre::ColourValue & colour);
152  void addTriangleIndices(int index1, int index2, int index3);
153 
154  void addQuadIndices(int index1, int index2, int index3, int index4);
155  };
156 
157 } /* namespace modules */
158 } /* namespace i6e */
159 
160 #endif /* __I6ENGINE_MODULES_DEBUG_H__ */
161 
static Debug & getSingleton(void)
void addToLineIndices(int baseIndex, std::list< int > *target)
bool getEnabled()
Definition: Debug.h:101
void switchEnabled()
Definition: Debug.h:103
void setEnabled(bool _isEnabled)
Definition: Debug.h:102
std::pair< Ogre::Vector3, Ogre::ColourValue > VertexPair
Definition: Debug.h:32
static Debug * getSingletonPtr(void)
LineIndices(int _v1, int _v2)
Definition: Debug.h:52
void drawCuboid(const Ogre::Vector3 *vertices, const Ogre::ColourValue &colour, bool isFilled=false)
void create(int recursionLevel)
void drawCylinder(const Ogre::Vector3 &centre, float radius, int segmentsCount, float height, const Ogre::ColourValue &colour, bool isFilled=false)
int addToVertices(std::list< VertexPair > *target, const Ogre::Vector3 &position, const Ogre::ColourValue &colour, float scale)
Debug(Ogre::SceneManager *_sceneManager, float _fillAlpha)
void drawQuad(const Ogre::Vector3 *vertices, const Ogre::ColourValue &colour, bool isFilled=false)
void drawLine(const Ogre::Vector3 &start, const Ogre::Vector3 &end, const Ogre::ColourValue &colour)
TriangleIndices(int _v1, int _v2, int _v3)
Definition: Debug.h:44
void drawCircle(const Ogre::Vector3 &centre, float radius, int segmentsCount, const Ogre::ColourValue &colour, bool isFilled=false)
bool operator<(const TriangleIndices &o) const
Definition: Debug.h:46
void drawSphere(const Ogre::Vector3 &centre, float radius, const Ogre::ColourValue &colour, bool isFilled=false)
void addToTriangleIndices(int baseIndex, std::list< int > *target)
bool operator==(const LineIndices &o) const
Definition: Debug.h:54