CCPUBaseCollider.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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_BASE_COLLIDER_H__
  22. #define __CC_PU_PARTICLE_3D_BASE_COLLIDER_H__
  23. #include "extensions/Particle3D/PU/CCPUAffector.h"
  24. #include "3d/CCAABB.h"
  25. NS_CC_BEGIN
  26. struct PUParticle3D;
  27. class CC_DLL PUBaseCollider : public PUAffector
  28. {
  29. public:
  30. /** Determines how a particle collision should be determined. IT_POINT means that the position of
  31. the particle will be validated against the Colliders' shape. IT_BOX means that the dimensions
  32. (width, height and depth) are used to determine whether the particle collides.
  33. */
  34. enum IntersectionType
  35. {
  36. IT_POINT,
  37. IT_BOX
  38. };
  39. /** Determines how a particle behaves after collision with this collider. The behaviour of the
  40. particle is solved in the collider and only behaviour that needs the colliders?data is taken
  41. into account. The fact that a particle expires for example, can be achieved by using an
  42. Observer in combination with an EventHandler (DoExpireEventHandler).
  43. CT_NONE means that the particle doesn't do anything. This value should be set if the behaviour
  44. of the particle is determined outside the collider (for example, expiring the particle).
  45. CT_BOUNCE means that the particle bounces off the collider.
  46. CT_FLOW means that the particle flows around the contours of the collider.
  47. */
  48. enum CollisionType
  49. {
  50. CT_NONE,
  51. CT_BOUNCE,
  52. CT_FLOW,
  53. };
  54. // Constants
  55. static const float DEFAULT_BOUNCYNESS;
  56. static const float DEFAULT_FRICTION;
  57. static const IntersectionType DEFAULT_INTERSECTION_TYPE;
  58. static const CollisionType DEFAULT_COLLISION_TYPE;
  59. virtual void preUpdateAffector(float deltaTime) override;
  60. /** Returns the type of intersection.
  61. */
  62. IntersectionType getIntersectionType() const;
  63. /** Sets the type of intersection.
  64. */
  65. void setIntersectionType(const IntersectionType& intersectionType);
  66. /** Returns the type of collision.
  67. */
  68. CollisionType getCollisionType() const;
  69. /** Sets the type of collision.
  70. */
  71. void setCollisionType(const CollisionType& collisionType);
  72. /** Returns the friction value.
  73. */
  74. float getFriction() const;
  75. /** Sets the friction value.
  76. */
  77. void setFriction(const float friction);
  78. /** Returns the bouncyness value.
  79. */
  80. float getBouncyness() const;
  81. /** Sets the bouncyness value.
  82. */
  83. void setBouncyness(const float bouncyness);
  84. /** Fill the AxisAlignedBox with data derived from the other arguments.
  85. */
  86. void populateAlignedBox(AABB& box,
  87. const Vec3& position,
  88. const float width,
  89. const float height,
  90. const float depth);
  91. /** Recalculates the rotation speed after collision.
  92. This function must be explicitly called in the updatePUAffector(float deltaTime) function of the class that inherits from
  93. BaseCollider.
  94. */
  95. void calculateRotationSpeedAfterCollision(PUParticle3D* particle);
  96. virtual void copyAttributesTo (PUAffector* affector) override;
  97. CC_CONSTRUCTOR_ACCESS:
  98. PUBaseCollider();
  99. virtual ~PUBaseCollider();
  100. protected:
  101. float _friction; // Physics characteristic that influences particle rotation speed.
  102. float _bouncyness; // Physics characteristic that influences particle velocity.
  103. IntersectionType _intersectionType;
  104. CollisionType _collisionType;
  105. float _velocityScale; // Value set in the particle system, but stored in the collider for convenience.
  106. };
  107. NS_CC_END
  108. #endif