TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
ConvexPolyhedron.h
Go to the documentation of this file.
1 
13 #ifndef G3D_CONVEXPOLYHEDRON_H
14 #define G3D_CONVEXPOLYHEDRON_H
15 
16 #include "G3D/platform.h"
17 #include "G3D/Vector3.h"
18 #include "G3D/Vector2.h"
19 #include "G3D/CoordinateFrame.h"
20 #include "G3D/Plane.h"
21 #include "G3D/Line.h"
22 #include "G3D/Array.h"
23 
24 namespace G3D {
25 
26 class DirectedEdge {
27 public:
30 };
31 
33 private:
34 
35  friend class ConvexPolyhedron;
36 
38 
39 public:
40 
42  ConvexPolygon(const Vector3& v0, const Vector3& v1, const Vector3& v2);
43  ConvexPolygon(const Array<Vector3>& __vertex);
44  virtual ~ConvexPolygon() {}
45 
49  inline const Vector3& vertex(int i) const {
50  return _vertex[i];
51  }
52 
53  inline void setVertex(int i, const Vector3& v) {
54  _vertex[i] = v;
55  }
56 
60  inline int numVertices() const {
61  return _vertex.size();
62  }
63 
64  inline void setNumVertices(int n) {
65  _vertex.resize(n);
66  }
67 
71  bool isEmpty() const;
72 
82  void cut(const Plane& plane, ConvexPolygon &above, ConvexPolygon &below, DirectedEdge& newEdge);
83  void cut(const Plane& plane, ConvexPolygon &above, ConvexPolygon &below);
84 
94 
98  float getArea() const;
99 
100  inline Vector3 normal() const {
101  debugAssert(_vertex.length() >= 3);
102  return (_vertex[1] - _vertex[0]).cross(_vertex[2] - _vertex[0]).direction();
103  }
104 
108  ConvexPolygon inverse() const;
109 };
110 
111 
112 
114 public:
119 
122 
126  bool isEmpty() const;
127 
131  float getVolume() const;
132 
141  void cut(const Plane& plane, ConvexPolyhedron &above, ConvexPolyhedron &below);
142 };
143 
148 private:
149 
151 
152 public:
153 
155 
163  ConvexPolygon2D(const Array<Vector2>& pts, bool reverse = false);
164 
165  inline int numVertices() const {
166  return m_vertex.size();
167  }
168 
169  inline const Vector2& vertex(int index) const {
170  debugAssert((index >= 0) && (index <= m_vertex.size()));
171  return m_vertex[index];
172  }
173 
175  bool contains(const Vector2& p, bool reverseWinding = false) const;
176 };
177 
178 
179 } // namespace
180 #endif
Definition: Vector2.h:40
ConvexPolyhedron()
Definition: ConvexPolyhedron.h:120
Definition: Plane.h:25
void resize(size_t n, bool shrinkIfNecessary=true)
Definition: Array.h:490
void removeDuplicateVertices()
Definition: ConvexPolyhedron.cpp:202
Array< Vector3 > _vertex
Definition: ConvexPolyhedron.h:37
Vector3 start
Definition: ConvexPolyhedron.h:28
Array< Vector2 > m_vertex
Definition: ConvexPolyhedron.h:150
Definition: AABox.h:25
Dynamic 1D array tuned for performance.
Definition: Array.h:95
Array< ConvexPolygon > face
Definition: ConvexPolyhedron.h:118
Vector3 stop
Definition: ConvexPolyhedron.h:29
int length() const
Definition: Array.h:438
float getArea() const
Definition: ConvexPolyhedron.cpp:34
Definition: ConvexPolyhedron.h:147
Definition: Vector3.h:58
bool contains(const Vector2 &p, bool reverseWinding=false) const
Definition: ConvexPolyhedron.cpp:427
#define debugAssert(exp)
Definition: debugAssert.h:160
ConvexPolygon()
Definition: ConvexPolyhedron.h:41
ConvexPolygon inverse() const
Definition: ConvexPolyhedron.cpp:189
int numVertices() const
Definition: ConvexPolyhedron.h:165
int size() const
Definition: Array.h:430
float getVolume() const
Definition: ConvexPolyhedron.cpp:228
const Vector2 & vertex(int index) const
Definition: ConvexPolyhedron.h:169
ConvexPolygon2D()
Definition: ConvexPolyhedron.h:154
Definition: ConvexPolyhedron.h:32
Definition: ConvexPolyhedron.h:113
bool isEmpty() const
Definition: ConvexPolyhedron.cpp:29
void cut(const Plane &plane, ConvexPolyhedron &above, ConvexPolyhedron &below)
Definition: ConvexPolyhedron.cpp:258
void cut(const Plane &plane, ConvexPolygon &above, ConvexPolygon &below, DirectedEdge &newEdge)
Definition: ConvexPolyhedron.cpp:60
void setNumVertices(int n)
Definition: ConvexPolyhedron.h:64
bool isEmpty() const
Definition: ConvexPolyhedron.cpp:254
Definition: ConvexPolyhedron.h:26
virtual ~ConvexPolygon()
Definition: ConvexPolyhedron.h:44
const Vector3 & vertex(int i) const
Definition: ConvexPolyhedron.h:49
void setVertex(int i, const Vector3 &v)
Definition: ConvexPolyhedron.h:53
int numVertices() const
Definition: ConvexPolyhedron.h:60
Vector3 normal() const
Definition: ConvexPolyhedron.h:100