b2CircleShape.h 3.0 KB

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