[10262] | 1 | |
---|
| 2 | |
---|
| 3 | #ifndef _IcoSphere_H__ |
---|
| 4 | #define _IcoSphere_H__ |
---|
| 5 | |
---|
| 6 | #include "tools/ToolsPrereqs.h" |
---|
| 7 | |
---|
| 8 | #include <OgreSingleton.h> |
---|
| 9 | #include <map> |
---|
| 10 | |
---|
| 11 | namespace orxonox |
---|
| 12 | { |
---|
| 13 | typedef std::pair<Ogre::Vector3, Ogre::ColourValue> VertexPair; |
---|
| 14 | |
---|
[11099] | 15 | /** |
---|
| 16 | * Copy-pasted from |
---|
| 17 | * - https://bitbucket.org/hasyimi/ogre-debug-drawing-utility/src |
---|
| 18 | * - http://www.ogre3d.org/tikiwiki/tiki-index.php?page=Debug+Drawing+Utility+Class |
---|
| 19 | * |
---|
| 20 | * This source code is released into the Public Domain. |
---|
| 21 | * |
---|
| 22 | * Modified by Fabian 'x3n' Landau |
---|
| 23 | */ |
---|
[10262] | 24 | class _ToolsExport IcoSphere |
---|
| 25 | { |
---|
| 26 | public: |
---|
| 27 | struct TriangleIndices |
---|
| 28 | { |
---|
| 29 | int v1, v2, v3; |
---|
| 30 | |
---|
| 31 | TriangleIndices(int _v1, int _v2, int _v3) : |
---|
| 32 | v1(_v1), v2(_v2), v3(_v3) |
---|
| 33 | { |
---|
| 34 | } |
---|
| 35 | |
---|
| 36 | bool operator <(const TriangleIndices &o) const |
---|
| 37 | { |
---|
| 38 | return v1 < o.v1 && v2 < o.v2 && v3 < o.v3; |
---|
| 39 | } |
---|
| 40 | }; |
---|
| 41 | |
---|
| 42 | struct LineIndices |
---|
| 43 | { |
---|
| 44 | int v1, v2; |
---|
| 45 | |
---|
| 46 | LineIndices(int _v1, int _v2) : |
---|
| 47 | v1(_v1), v2(_v2) |
---|
| 48 | { |
---|
| 49 | } |
---|
| 50 | |
---|
| 51 | bool operator ==(const LineIndices &o) const |
---|
| 52 | { |
---|
| 53 | return (v1 == o.v1 && v2 == o.v2) || (v1 == o.v2 && v2 == o.v1); |
---|
| 54 | } |
---|
| 55 | }; |
---|
| 56 | |
---|
| 57 | IcoSphere(); |
---|
| 58 | ~IcoSphere(); |
---|
| 59 | |
---|
| 60 | void create(int recursionLevel); |
---|
| 61 | void addToLineIndices(int baseIndex, std::list<int>* target) const; |
---|
| 62 | int addToVertices(std::list<VertexPair>* target, const Ogre::Vector3& position, const Ogre::ColourValue& colour, float scale) const; |
---|
| 63 | void addToTriangleIndices(int baseIndex, std::list<int>* target) const; |
---|
| 64 | |
---|
| 65 | private: |
---|
| 66 | int addVertex(const Ogre::Vector3& vertex); |
---|
| 67 | void addLineIndices(int index0, int index1); |
---|
| 68 | void addTriangleLines(int index0, int index1, int index2); |
---|
| 69 | int getMiddlePoint(int index0, int index1); |
---|
| 70 | void addFace(int index0, int index1, int index2); |
---|
| 71 | |
---|
| 72 | void removeLineIndices(int index0, int index1); |
---|
| 73 | |
---|
| 74 | std::vector<Ogre::Vector3> vertices; |
---|
| 75 | std::list<LineIndices> lineIndices; |
---|
| 76 | std::list<int> triangleIndices; |
---|
| 77 | std::list<TriangleIndices> faces; |
---|
| 78 | std::map<int64_t, int> middlePointIndexCache; |
---|
| 79 | int index; |
---|
| 80 | }; |
---|
| 81 | } |
---|
| 82 | |
---|
| 83 | #endif /* _IcoSphere_H__ */ |
---|