[10262] | 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 _IcoSphere_H__ |
---|
| 18 | #define _IcoSphere_H__ |
---|
| 19 | |
---|
| 20 | #include "tools/ToolsPrereqs.h" |
---|
| 21 | |
---|
| 22 | #include <OgreSingleton.h> |
---|
| 23 | #include <map> |
---|
| 24 | |
---|
| 25 | namespace orxonox |
---|
| 26 | { |
---|
| 27 | typedef std::pair<Ogre::Vector3, Ogre::ColourValue> VertexPair; |
---|
| 28 | |
---|
| 29 | class _ToolsExport IcoSphere |
---|
| 30 | { |
---|
| 31 | public: |
---|
| 32 | struct TriangleIndices |
---|
| 33 | { |
---|
| 34 | int v1, v2, v3; |
---|
| 35 | |
---|
| 36 | TriangleIndices(int _v1, int _v2, int _v3) : |
---|
| 37 | v1(_v1), v2(_v2), v3(_v3) |
---|
| 38 | { |
---|
| 39 | } |
---|
| 40 | |
---|
| 41 | bool operator <(const TriangleIndices &o) const |
---|
| 42 | { |
---|
| 43 | return v1 < o.v1 && v2 < o.v2 && v3 < o.v3; |
---|
| 44 | } |
---|
| 45 | }; |
---|
| 46 | |
---|
| 47 | struct LineIndices |
---|
| 48 | { |
---|
| 49 | int v1, v2; |
---|
| 50 | |
---|
| 51 | LineIndices(int _v1, int _v2) : |
---|
| 52 | v1(_v1), v2(_v2) |
---|
| 53 | { |
---|
| 54 | } |
---|
| 55 | |
---|
| 56 | bool operator ==(const LineIndices &o) const |
---|
| 57 | { |
---|
| 58 | return (v1 == o.v1 && v2 == o.v2) || (v1 == o.v2 && v2 == o.v1); |
---|
| 59 | } |
---|
| 60 | }; |
---|
| 61 | |
---|
| 62 | IcoSphere(); |
---|
| 63 | ~IcoSphere(); |
---|
| 64 | |
---|
| 65 | void create(int recursionLevel); |
---|
| 66 | void addToLineIndices(int baseIndex, std::list<int>* target) const; |
---|
| 67 | int addToVertices(std::list<VertexPair>* target, const Ogre::Vector3& position, const Ogre::ColourValue& colour, float scale) const; |
---|
| 68 | void addToTriangleIndices(int baseIndex, std::list<int>* target) const; |
---|
| 69 | |
---|
| 70 | private: |
---|
| 71 | int addVertex(const Ogre::Vector3& vertex); |
---|
| 72 | void addLineIndices(int index0, int index1); |
---|
| 73 | void addTriangleLines(int index0, int index1, int index2); |
---|
| 74 | int getMiddlePoint(int index0, int index1); |
---|
| 75 | void addFace(int index0, int index1, int index2); |
---|
| 76 | |
---|
| 77 | void removeLineIndices(int index0, int index1); |
---|
| 78 | |
---|
| 79 | std::vector<Ogre::Vector3> vertices; |
---|
| 80 | std::list<LineIndices> lineIndices; |
---|
| 81 | std::list<int> triangleIndices; |
---|
| 82 | std::list<TriangleIndices> faces; |
---|
| 83 | std::map<int64_t, int> middlePointIndexCache; |
---|
| 84 | int index; |
---|
| 85 | }; |
---|
| 86 | } |
---|
| 87 | |
---|
| 88 | #endif /* _IcoSphere_H__ */ |
---|