CmPlane.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. /*
  2. -----------------------------------------------------------------------------
  3. This source file is part of OGRE
  4. (Object-oriented Graphics Rendering Engine)
  5. For the latest info, see http://www.ogre3d.org/
  6. Copyright (c) 2000-2011 Torus Knot Software Ltd
  7. Permission is hereby granted, free of charge, to any person obtaining a copy
  8. of this software and associated documentation files (the "Software"), to deal
  9. in the Software without restriction, including without limitation the rights
  10. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  11. copies of the Software, and to permit persons to whom the Software is
  12. furnished to do so, subject to the following conditions:
  13. The above copyright notice and this permission notice shall be included in
  14. all copies or substantial portions of the Software.
  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. */
  24. // This file is based on material originally from:
  25. // Geometric Tools, LLC
  26. // Copyright (c) 1998-2010
  27. // Distributed under the Boost Software License, Version 1.0.
  28. // http://www.boost.org/LICENSE_1_0.txt
  29. // http://www.geometrictools.com/License/Boost/LICENSE_1_0.txt
  30. #pragma once
  31. #include "CmPrerequisitesUtil.h"
  32. #include "CmVector3.h"
  33. namespace CamelotFramework
  34. {
  35. class CM_UTILITY_EXPORT Plane
  36. {
  37. public:
  38. /**
  39. * @brief The "positive side" of the plane is the half space to which the
  40. * plane normal points. The "negative side" is the other half
  41. * space. The flag "no side" indicates the plane itself.
  42. */
  43. enum Side
  44. {
  45. NO_SIDE,
  46. POSITIVE_SIDE,
  47. NEGATIVE_SIDE,
  48. BOTH_SIDE
  49. };
  50. public:
  51. Plane();
  52. Plane(const Plane& copy);
  53. Plane(const Vector3& normal, float d);
  54. Plane(float a, float b, float c, float d);
  55. Plane(const Vector3& normal, const Vector3& point);
  56. Plane(const Vector3& point0, const Vector3& point1, const Vector3& point2);
  57. /**
  58. * @brief Returns the side of the plane where the point is located on.
  59. *
  60. * @note NO_SIDE signifies the point is on the plane.
  61. */
  62. Side getSide(const Vector3& point) const;
  63. /**
  64. * @brief Returns the side where the alignedBox is. The flag BOTH_SIDE indicates an intersecting box.
  65. * One corner ON the plane is sufficient to consider the box and the plane intersecting.
  66. */
  67. Side getSide(const AABox& box) const;
  68. /**
  69. * @brief Returns a distance from point to plane.
  70. *
  71. * @note The sign of the return value is positive if the point is on the
  72. * positive side of the plane, negative if the point is on the negative
  73. * side, and zero if the point is on the plane.
  74. */
  75. float getDistance(const Vector3& point) const;
  76. /**
  77. * @brief Project a vector onto the plane.
  78. */
  79. Vector3 projectVector(const Vector3& v) const;
  80. /**
  81. * @brief Normalizes the plane's normal and the length scale of d
  82. * is as well.
  83. */
  84. float normalize();
  85. /**
  86. * @brief Box/plane intersection.
  87. */
  88. bool intersects(const AABox& box) const;
  89. /**
  90. * @brief Sphere/plane intersection.
  91. */
  92. bool intersects(const Sphere& sphere) const;
  93. /**
  94. * @brief Ray/plane intersection, returns boolean result and distance.
  95. */
  96. std::pair<bool, float> intersects(const Ray& ray) const;
  97. bool operator==(const Plane& rhs) const
  98. {
  99. return (rhs.d == d && rhs.normal == normal);
  100. }
  101. bool operator!=(const Plane& rhs) const
  102. {
  103. return (rhs.d != d || rhs.normal != normal);
  104. }
  105. public:
  106. Vector3 normal;
  107. float d;
  108. };
  109. typedef Vector<Plane>::type PlaneList;
  110. }