CCRay.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /****************************************************************************
  2. Copyright (c) 2014-2016 Chukong Technologies Inc.
  3. Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
  4. http://www.cocos2d-x.org
  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. The above copyright notice and this permission notice shall be included in
  12. all copies or substantial portions of the Software.
  13. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  14. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  15. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  16. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  17. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  18. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  19. THE SOFTWARE.
  20. ****************************************************************************/
  21. #ifndef __CC_RAY_H_
  22. #define __CC_RAY_H_
  23. #include "math/CCMath.h"
  24. #include "3d/CCAABB.h"
  25. #include "3d/CCOBB.h"
  26. #include "3d/CCPlane.h"
  27. NS_CC_BEGIN
  28. /**
  29. * @addtogroup _3d
  30. * @{
  31. */
  32. /**
  33. * @brief Ray is a line with one end. usually use it to check intersects with some object,such as Plane, OBB, AABB
  34. * @js NA
  35. **/
  36. class CC_DLL Ray
  37. {
  38. public:
  39. /**
  40. * Constructor.
  41. *
  42. * @lua new
  43. */
  44. Ray();
  45. /**
  46. * Constructor.
  47. * @lua NA
  48. */
  49. Ray(const Ray& ray);
  50. /**
  51. * Constructs a new ray initialized to the specified values.
  52. *
  53. * @param origin The ray's origin.
  54. * @param direction The ray's direction.
  55. * @lua new
  56. */
  57. Ray(const Vec3& origin, const Vec3& direction);
  58. /**
  59. * Destructor.
  60. * @lua NA
  61. */
  62. ~Ray();
  63. /**
  64. * Check whether this ray intersects with the specified AABB.
  65. */
  66. bool intersects(const AABB& aabb, float* distance = nullptr) const;
  67. /**
  68. * Check whether this ray intersects with the specified OBB.
  69. */
  70. bool intersects(const OBB& obb, float* distance = nullptr) const;
  71. float dist(const Plane& plane) const;
  72. Vec3 intersects(const Plane& plane) const;
  73. /**
  74. * Sets this ray to the specified values.
  75. *
  76. * @param origin The ray's origin.
  77. * @param direction The ray's direction.
  78. */
  79. void set(const Vec3& origin, const Vec3& direction);
  80. /**
  81. * Transforms this ray by the given transformation matrix.
  82. *
  83. * @param matrix The transformation matrix to transform by.
  84. */
  85. void transform(const Mat4& matrix);
  86. Vec3 _origin; // The ray origin position.
  87. Vec3 _direction; // The ray direction vector.
  88. };
  89. // end of 3d group
  90. /// @}
  91. NS_CC_END
  92. #endif