1
0

CCFrustum.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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_FRUSTUM_H_
  21. #define __CC_FRUSTUM_H_
  22. #include "base/ccMacros.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. class Camera;
  29. /**
  30. * the frustum is a six-side geometry, usually use the frustum to do fast-culling:
  31. * check a entity whether is a potential visible entity
  32. * @js NA
  33. * @lua NA
  34. */
  35. class CC_DLL Frustum
  36. {
  37. friend class Camera;
  38. public:
  39. /**
  40. * Constructor & Destructor.
  41. */
  42. Frustum(): _clipZ(true), _initialized(false) {}
  43. ~Frustum(){}
  44. /**
  45. * init frustum from camera.
  46. */
  47. bool initFrustum(const Camera* camera);
  48. /**
  49. * is aabb out of frustum.
  50. */
  51. bool isOutOfFrustum(const AABB& aabb) const;
  52. /**
  53. * is obb out of frustum
  54. */
  55. bool isOutOfFrustum(const OBB& obb) const;
  56. /**
  57. * get & set z clip. if bclipZ == true use near and far plane
  58. */
  59. void setClipZ(bool clipZ) { _clipZ = clipZ; }
  60. bool isClipZ() { return _clipZ; }
  61. protected:
  62. /**
  63. * create clip plane
  64. */
  65. void createPlane(const Camera* camera);
  66. Plane _plane[6]; // clip plane, left, right, top, bottom, near, far
  67. bool _clipZ; // use near and far clip plane
  68. bool _initialized;
  69. };
  70. NS_CC_END
  71. #endif//__CC_FRUSTUM_H_