DebugDrawer.h

Go to the documentation of this file.
00001 /*
00002  * DebugDrawer.h
00003  *
00004  *  Created on: Mar 10, 2012
00005  *      Author: sushil
00006  */
00007 
00008 #ifndef DEBUGDRAWER_H_
00009 #define DEBUGDRAWER_H_
00010 #include <OgreSingleton.h>
00011 #include <map>
00012 
00013 namespace OgreGFX {
00014 
00015         typedef std::pair<Ogre::Vector3, Ogre::ColourValue> VertexPair;
00016         typedef long int __int64;
00017 
00018         #define DEFAULT_ICOSPHERE_RECURSION_LEVEL       1
00019 
00020         class IcoSphere
00021         {
00022         public:
00023                 struct TriangleIndices
00024                 {
00025                         int v1, v2, v3;
00026 
00027                         TriangleIndices(int _v1, int _v2, int _v3) : v1(_v1), v2(_v2), v3(_v3) {}
00028 
00029                         bool operator < (const TriangleIndices &o) const { return v1 < o.v1 && v2 < o.v2 && v3 < o.v3; }
00030                 };
00031 
00032                 struct LineIndices
00033                 {
00034                         int v1, v2;
00035 
00036                         LineIndices(int _v1, int _v2) : v1(_v1), v2(_v2) {}
00037 
00038                         bool operator == (const LineIndices &o) const
00039                         {
00040                                 return (v1 == o.v1 && v2 == o.v2) || (v1 == o.v2 && v2 == o.v1);
00041                         }
00042                 };
00043 
00044                 IcoSphere();
00045                 ~IcoSphere();
00046 
00047                 void create(int recursionLevel);
00048                 void addToLineIndices(int baseIndex, std::list<int> *target);
00049                 int addToVertices(std::list<VertexPair> *target, const Ogre::Vector3 &position, const Ogre::ColourValue &colour, float scale);
00050                 void addToTriangleIndices(int baseIndex, std::list<int> *target);
00051 
00052         private:
00053                 int addVertex(const Ogre::Vector3 &vertex);
00054                 void addLineIndices(int index0, int index1);
00055                 void addTriangleLines(int index0, int index1, int index2);
00056                 int getMiddlePoint(int index0, int index1);
00057                 void addFace(int index0, int index1, int index2);
00058 
00059                 void removeLineIndices(int index0, int index1);
00060 
00061                 std::vector<Ogre::Vector3> vertices;
00062                 std::list<LineIndices> lineIndices;
00063                 std::list<int> triangleIndices;
00064                 std::list<TriangleIndices> faces;
00065                 //std::map<__int64, int> middlePointIndexCache;
00066                 std::map<long int, int> middlePointIndexCache;
00067                 int index;
00068         };
00069 
00070         class DebugDrawer : public Ogre::Singleton<DebugDrawer>
00071         {
00072         public:
00073                 DebugDrawer(Ogre::SceneManager *_sceneManager, float _fillAlpha);
00074                 ~DebugDrawer();
00075 
00076                 static DebugDrawer& getSingleton(void);
00077                 static DebugDrawer* getSingletonPtr(void);
00078 
00079                 void build();
00080 
00081                 void setIcoSphereRecursionLevel(int recursionLevel);
00082 
00083                 void drawLine(const Ogre::Vector3 &start, const Ogre::Vector3 &end, const Ogre::ColourValue &colour);
00084                 void drawAngleLine(const Ogre::Vector3 &start, const Ogre::Radian &angle, float length, const Ogre::ColourValue &colour);
00085                 void drawCircle(const Ogre::Vector3 &centre, float radius, int segmentsCount, const Ogre::ColourValue& colour, bool isFilled = false);
00086                 void drawCylinder(const Ogre::Vector3 &centre, float radius, int segmentsCount, float height, const Ogre::ColourValue& colour, bool isFilled = false);
00087                 void drawQuad(const Ogre::Vector3 *vertices, const Ogre::ColourValue& colour, bool isFilled = false);
00088                 void drawCuboid(const Ogre::Vector3 *vertices, const Ogre::ColourValue& colour, bool isFilled = false);
00089                 void drawSphere(const Ogre::Vector3 &centre, float radius, const Ogre::ColourValue& colour, bool isFilled = false);
00090                 void drawTetrahedron(const Ogre::Vector3 &centre, float scale, const Ogre::ColourValue& colour, bool isFilled = false);
00091 
00092                 bool getEnabled() { return isEnabled; }
00093                 void setEnabled(bool _isEnabled) { isEnabled = _isEnabled; }
00094                 void switchEnabled() { isEnabled = !isEnabled; }
00095 
00096                 void clear();
00097 
00098         private:
00099                 bool isEnabled;
00100                 Ogre::SceneManager *sceneManager;
00101                 float fillAlpha;
00102 
00103                 Ogre::ManualObject *manualObject;
00104 
00105                 IcoSphere icoSphere;
00106 
00107 
00108 
00109                 std::list<VertexPair> lineVertices, triangleVertices;
00110                 std::list<int> lineIndices, triangleIndices;
00111 
00112                 int linesIndex, trianglesIndex;
00113 
00114                 void initialise();
00115                 void shutdown();
00116 
00117                 void buildLine(const Ogre::Vector3& start, const Ogre::Vector3& end, const Ogre::ColourValue& colour, float alpha = 1.0f);
00118                 void buildAngleLine(const Ogre::Vector3 &start, const Ogre::Radian &angle, float length, const Ogre::ColourValue &colour, float alpha = 1.0f);
00119                 void buildQuad(const Ogre::Vector3 *vertices, const Ogre::ColourValue& colour, float alpha = 1.0f);
00120                 void buildFilledQuad(const Ogre::Vector3 *vertices, const Ogre::ColourValue& colour, float alpha = 1.0f);
00121                 void buildFilledTriangle(const Ogre::Vector3 *vertices, const Ogre::ColourValue& colour, float alpha = 1.0f);
00122                 void buildCuboid(const Ogre::Vector3 *vertices, const Ogre::ColourValue& colour, float alpha = 1.0f);
00123                 void buildFilledCuboid(const Ogre::Vector3 *vertices, const Ogre::ColourValue& colour, float alpha = 1.0f);
00124 
00125                 void buildCircle(const Ogre::Vector3 &centre, float radius, int segmentsCount, const Ogre::ColourValue& colour, float alpha = 1.0f);
00126                 void buildFilledCircle(const Ogre::Vector3 &centre, float radius, int segmentsCount, const Ogre::ColourValue& colour, float alpha = 1.0f);
00127 
00128                 void buildCylinder(const Ogre::Vector3 &centre, float radius, int segmentsCount, float height, const Ogre::ColourValue& colour, float alpha = 1.0f);
00129                 void buildFilledCylinder(const Ogre::Vector3 &centre, float radius, int segmentsCount, float height, const Ogre::ColourValue& colour, float alpha = 1.0f);
00130 
00131                 void buildTetrahedron(const Ogre::Vector3 &centre, float scale, const Ogre::ColourValue &colour, float alpha = 1.0f);
00132                 void buildFilledTetrahedron(const Ogre::Vector3 &centre, float scale, const Ogre::ColourValue &colour, float alpha = 1.0f);
00133 
00134                 int addLineVertex(const Ogre::Vector3 &vertex, const Ogre::ColourValue &colour);
00135                 void addLineIndices(int index1, int index2);
00136 
00137                 int addTriangleVertex(const Ogre::Vector3 &vertex, const Ogre::ColourValue &colour);
00138                 void addTriangleIndices(int index1, int index2, int index3);
00139 
00140                 void addQuadIndices(int index1, int index2, int index3, int index4);
00141         };
00142 
00143 }
00144 #endif /* DEBUGDRAWER_H_ */

Generated on Fri Dec 13 14:54:16 2013 for FastECSLent by  doxygen 1.5.4