1
0

b2CircleShape.h 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /*
  2. * Copyright (c) 2006-2009 Erin Catto http://www.box2d.org
  3. *
  4. * This software is provided 'as-is', without any express or implied
  5. * warranty. In no event will the authors be held liable for any damages
  6. * arising from the use of this software.
  7. * Permission is granted to anyone to use this software for any purpose,
  8. * including commercial applications, and to alter it and redistribute it
  9. * freely, subject to the following restrictions:
  10. * 1. The origin of this software must not be misrepresented; you must not
  11. * claim that you wrote the original software. If you use this software
  12. * in a product, an acknowledgment in the product documentation would be
  13. * appreciated but is not required.
  14. * 2. Altered source versions must be plainly marked as such, and must not be
  15. * misrepresented as being the original software.
  16. * 3. This notice may not be removed or altered from any source distribution.
  17. */
  18. #ifndef B2_CIRCLE_SHAPE_H
  19. #define B2_CIRCLE_SHAPE_H
  20. #include <Box2D/Collision/Shapes/b2Shape.h>
  21. /// A circle shape.
  22. class b2CircleShape : public b2Shape
  23. {
  24. public:
  25. b2CircleShape();
  26. /// Implement b2Shape.
  27. b2Shape* Clone(b2BlockAllocator* allocator) const;
  28. /// @see b2Shape::GetChildCount
  29. int32 GetChildCount() const;
  30. /// Implement b2Shape.
  31. bool TestPoint(const b2Transform& transform, const b2Vec2& p) const;
  32. /// Implement b2Shape.
  33. bool RayCast(b2RayCastOutput* output, const b2RayCastInput& input,
  34. const b2Transform& transform, int32 childIndex) const;
  35. /// @see b2Shape::ComputeAABB
  36. void ComputeAABB(b2AABB* aabb, const b2Transform& transform, int32 childIndex) const;
  37. /// @see b2Shape::ComputeMass
  38. void ComputeMass(b2MassData* massData, float32 density) const;
  39. /// Get the supporting vertex index in the given direction.
  40. int32 GetSupport(const b2Vec2& d) const;
  41. /// Get the supporting vertex in the given direction.
  42. const b2Vec2& GetSupportVertex(const b2Vec2& d) const;
  43. /// Get the vertex count.
  44. int32 GetVertexCount() const { return 1; }
  45. /// Get a vertex by index. Used by b2Distance.
  46. const b2Vec2& GetVertex(int32 index) const;
  47. /// Position
  48. b2Vec2 m_p;
  49. };
  50. inline b2CircleShape::b2CircleShape()
  51. {
  52. m_type = e_circle;
  53. m_radius = 0.0f;
  54. m_p.SetZero();
  55. }
  56. inline int32 b2CircleShape::GetSupport(const b2Vec2 &d) const
  57. {
  58. B2_NOT_USED(d);
  59. return 0;
  60. }
  61. inline const b2Vec2& b2CircleShape::GetSupportVertex(const b2Vec2 &d) const
  62. {
  63. B2_NOT_USED(d);
  64. return m_p;
  65. }
  66. inline const b2Vec2& b2CircleShape::GetVertex(int32 index) const
  67. {
  68. B2_NOT_USED(index);
  69. b2Assert(index == 0);
  70. return m_p;
  71. }
  72. #endif