Polyhedron.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. //
  2. // Urho3D Engine
  3. // Copyright (c) 2008-2011 Lasse Öörni
  4. //
  5. // Permission is hereby granted, free of charge, to any person obtaining a copy
  6. // of this software and associated documentation files (the "Software"), to deal
  7. // in the Software without restriction, including without limitation the rights
  8. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. // copies of the Software, and to permit persons to whom the Software is
  10. // furnished to do so, subject to the following conditions:
  11. //
  12. // The above copyright notice and this permission notice shall be included in
  13. // all copies or substantial portions of the Software.
  14. //
  15. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  18. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  20. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  21. // THE SOFTWARE.
  22. //
  23. #include "Vector3.h"
  24. class BoundingBox;
  25. class Frustum;
  26. class Matrix3x4;
  27. class Plane;
  28. /// A convex volume built from polygon faces.
  29. class Polyhedron
  30. {
  31. public:
  32. /// Construct empty.
  33. Polyhedron()
  34. {
  35. }
  36. /// Copy-construct from another polyhedron.
  37. Polyhedron(const Polyhedron& polyhedron) :
  38. faces_(polyhedron.faces_)
  39. {
  40. }
  41. /// Construct from a list of faces.
  42. Polyhedron(const Vector<Vector<Vector3> >& faces) :
  43. faces_(faces)
  44. {
  45. }
  46. /// Construct from a bounding box.
  47. Polyhedron(const BoundingBox& box)
  48. {
  49. Define(box);
  50. }
  51. /// Construct from a frustum.
  52. Polyhedron(const Frustum& frustum)
  53. {
  54. Define(frustum);
  55. }
  56. /// Destruct.
  57. ~Polyhedron();
  58. /// Define from a bounding box.
  59. void Define(const BoundingBox& box);
  60. /// Define from a frustum.
  61. void Define(const Frustum& frustum);
  62. /// Add a triangle face.
  63. void AddFace(const Vector3& v0, const Vector3& v1, const Vector3& v2);
  64. /// Add a quadrilateral face.
  65. void AddFace(const Vector3& v0, const Vector3& v1, const Vector3& v2, const Vector3& v3);
  66. /// Add an arbitrary face.
  67. void AddFace(const Vector<Vector3>& face);
  68. /// Clip with a plane.
  69. void Clip(const Plane& plane);
  70. /// Clip with a bounding box.
  71. void Clip(const BoundingBox& box);
  72. /// Clip with a frustum.
  73. void Clip(const Frustum& box);
  74. /// Clear all faces.
  75. void Clear();
  76. /// Transform by a 3x4 matrix.
  77. void Transform(const Matrix3x4& transform);
  78. /// Return transformed by a 3x4 matrix.
  79. Polyhedron Transformed(const Matrix3x4& transform) const;
  80. /// Return whether is empty.
  81. bool Empty() const { return faces_.Empty(); }
  82. /// Polygon faces.
  83. Vector<Vector<Vector3> > faces_;
  84. private:
  85. /// Internal vector for clipped vertices.
  86. Vector<Vector3> clippedVertices_;
  87. /// Internal vector for the new face being constructed.
  88. Vector<Vector3> outFace_;
  89. };