1
0

CCPlane.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /****************************************************************************
  2. Copyright (c) 2014-2017 Chukong Technologies Inc.
  3. http://www.cocos2d-x.org
  4. Permission is hereby granted, free of charge, to any person obtaining a copy
  5. of this software and associated documentation files (the "Software"), to deal
  6. in the Software without restriction, including without limitation the rights
  7. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. copies of the Software, and to permit persons to whom the Software is
  9. furnished to do so, subject to the following conditions:
  10. The above copyright notice and this permission notice shall be included in
  11. all copies or substantial portions of the Software.
  12. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  13. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  14. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  15. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  16. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  17. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  18. THE SOFTWARE.
  19. ****************************************************************************/
  20. #ifndef __CC_PLANE_H_
  21. #define __CC_PLANE_H_
  22. #include "base/ccMacros.h"
  23. #include "math/CCMath.h"
  24. NS_CC_BEGIN
  25. enum class PointSide
  26. {
  27. IN_PLANE,
  28. FRONT_PLANE,
  29. BEHIND_PLANE,
  30. };
  31. /**
  32. * Defines plane
  33. * @js NA
  34. * @lua NA
  35. **/
  36. class CC_DLL Plane
  37. {
  38. public:
  39. /**
  40. * create plane from tree point.
  41. */
  42. Plane(const Vec3& p1, const Vec3& p2, const Vec3& p3);
  43. /**
  44. * create plane from normal and dist.
  45. */
  46. Plane(const Vec3& normal, float dist);
  47. /**
  48. * create plane from normal and a point on plane.
  49. */
  50. Plane(const Vec3& normal, const Vec3& point);
  51. /**
  52. * create a default plan whose normal is (0, 0, 1), and _dist is 0, xoy plan in fact.
  53. */
  54. Plane();
  55. /**
  56. * init plane from tree point.
  57. */
  58. void initPlane(const Vec3& p1, const Vec3& p2, const Vec3& p3);
  59. /**
  60. * init plane from normal and dist.
  61. */
  62. void initPlane(const Vec3& normal, float dist);
  63. /**
  64. * init plane from normal and a point on plane.
  65. */
  66. void initPlane(const Vec3& normal, const Vec3& point);
  67. /**
  68. * dist to plane, > 0 normal direction
  69. */
  70. float dist2Plane(const Vec3& p) const;
  71. /**
  72. * Gets the plane's normal.
  73. */
  74. const Vec3& getNormal() const { return _normal; }
  75. /**
  76. * Gets the plane's distance to the origin along its normal.
  77. */
  78. float getDist() const { return _dist; }
  79. /**
  80. * Return the side where the point is.
  81. */
  82. PointSide getSide(const Vec3& point) const;
  83. protected:
  84. Vec3 _normal; // the normal line of the plane
  85. float _dist; // original displacement of the normal
  86. };
  87. NS_CC_END
  88. #endif