b2_circle_shape.h 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. // MIT License
  2. // Copyright (c) 2019 Erin Catto
  3. // Permission is hereby granted, free of charge, to any person obtaining a copy
  4. // of this software and associated documentation files (the "Software"), to deal
  5. // in the Software without restriction, including without limitation the rights
  6. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  7. // copies of the Software, and to permit persons to whom the Software is
  8. // furnished to do so, subject to the following conditions:
  9. // The above copyright notice and this permission notice shall be included in all
  10. // copies or substantial portions of the Software.
  11. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  12. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  13. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  14. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  15. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  16. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  17. // SOFTWARE.
  18. #ifndef B2_CIRCLE_SHAPE_H
  19. #define B2_CIRCLE_SHAPE_H
  20. #include "b2_api.h"
  21. #include "b2_shape.h"
  22. /// A solid circle shape
  23. class B2_API b2CircleShape : public b2Shape
  24. {
  25. public:
  26. b2CircleShape();
  27. /// Implement b2Shape.
  28. b2Shape* Clone(b2BlockAllocator* allocator) const override;
  29. /// @see b2Shape::GetChildCount
  30. int32 GetChildCount() const override;
  31. /// Implement b2Shape.
  32. bool TestPoint(const b2Transform& transform, const b2Vec2& p) const override;
  33. /// Implement b2Shape.
  34. /// @note because the circle is solid, rays that start inside do not hit because the normal is
  35. /// not defined.
  36. bool RayCast(b2RayCastOutput* output, const b2RayCastInput& input,
  37. const b2Transform& transform, int32 childIndex) const override;
  38. /// @see b2Shape::ComputeAABB
  39. void ComputeAABB(b2AABB* aabb, const b2Transform& transform, int32 childIndex) const override;
  40. /// @see b2Shape::ComputeMass
  41. void ComputeMass(b2MassData* massData, float density) const override;
  42. /// Position
  43. b2Vec2 m_p;
  44. };
  45. inline b2CircleShape::b2CircleShape()
  46. {
  47. m_type = e_circle;
  48. m_radius = 0.0f;
  49. m_p.SetZero();
  50. }
  51. #endif