CCPUBoxCollider.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. /****************************************************************************
  2. Copyright (C) 2013 Henry van Merode. All rights reserved.
  3. Copyright (c) 2015-2017 Chukong Technologies Inc.
  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_PU_PARTICLE_3D_BOX_COLLIDER_H__
  22. #define __CC_PU_PARTICLE_3D_BOX_COLLIDER_H__
  23. #include "CCPUBaseCollider.h"
  24. NS_CC_BEGIN
  25. class CC_DLL PUBoxCollider : public PUBaseCollider
  26. {
  27. public:
  28. static const float DEFAULT_WIDTH;
  29. static const float DEFAULT_HEIGHT;
  30. static const float DEFAULT_DEPTH;
  31. static PUBoxCollider* create();
  32. virtual void preUpdateAffector(float deltaTime) override;
  33. virtual void updatePUAffector(PUParticle3D *particle, float deltaTime) override;
  34. /** Returns the width of the box
  35. */
  36. float getWidth() const;
  37. /** Sets the width of the box
  38. */
  39. void setWidth(const float width);
  40. /** Returns the height of the box
  41. */
  42. float getHeight() const;
  43. /** Sets the height of the box
  44. */
  45. void setHeight(const float height);
  46. /** Returns the depth of the box
  47. */
  48. float getDepth() const;
  49. /** Sets the depth of the box
  50. */
  51. void setDepth(const float depth);
  52. /** Returns indication whether the collision is inside or outside of the box
  53. @remarks
  54. If value is true, the collision is inside of the box.
  55. */
  56. bool isInnerCollision() const;
  57. /** Set indication whether the collision is inside or outside of the box
  58. @remarks
  59. If value is set to true, the collision is inside of the box.
  60. */
  61. void setInnerCollision(bool innerCollision);
  62. /**
  63. */
  64. void calculateDirectionAfterCollision(PUParticle3D* particle);
  65. virtual void copyAttributesTo (PUAffector* affector) override;
  66. CC_CONSTRUCTOR_ACCESS:
  67. PUBoxCollider();
  68. virtual ~PUBoxCollider();
  69. protected:
  70. /**
  71. */
  72. void calculateBounds ();
  73. /**
  74. */
  75. bool isSmallestValue(float value, const Vec3& particlePosition);
  76. protected:
  77. float _width;
  78. float _height;
  79. float _depth;
  80. float _xmin;
  81. float _xmax;
  82. float _ymin;
  83. float _ymax;
  84. float _zmin;
  85. float _zmax;
  86. AABB _box;
  87. Vec3 _predictedPosition;
  88. bool _innerCollision;
  89. };
  90. NS_CC_END
  91. #endif