b2CircleShape.h 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /*
  2. * Copyright (c) 2006-2007 Erin Catto http://www.gphysics.com
  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 "b2Shape.h"
  21. /// This structure is used to build circle shapes.
  22. struct b2CircleDef : public b2ShapeDef
  23. {
  24. b2CircleDef()
  25. {
  26. type = e_circleShape;
  27. localPosition.SetZero();
  28. radius = 1.0f;
  29. }
  30. b2Vec2 localPosition;
  31. float32 radius;
  32. };
  33. /// A circle shape.
  34. class b2CircleShape : public b2Shape
  35. {
  36. public:
  37. /// @see b2Shape::TestPoint
  38. bool TestPoint(const b2XForm& transform, const b2Vec2& p) const;
  39. /// @see b2Shape::TestSegment
  40. b2SegmentCollide TestSegment( const b2XForm& transform,
  41. float32* lambda,
  42. b2Vec2* normal,
  43. const b2Segment& segment,
  44. float32 maxLambda) const;
  45. /// @see b2Shape::ComputeAABB
  46. void ComputeAABB(b2AABB* aabb, const b2XForm& transform) const;
  47. /// @see b2Shape::ComputeSweptAABB
  48. void ComputeSweptAABB( b2AABB* aabb,
  49. const b2XForm& transform1,
  50. const b2XForm& transform2) const;
  51. /// @see b2Shape::ComputeMass
  52. void ComputeMass(b2MassData* massData) const;
  53. /// @see b2Shape::ComputeSubmergedArea
  54. float32 ComputeSubmergedArea( const b2Vec2& normal,
  55. float32 offset,
  56. const b2XForm& xf,
  57. b2Vec2* c) const;
  58. /// Get the local position of this circle in its parent body.
  59. const b2Vec2& GetLocalPosition() const;
  60. /// Get the radius of this circle.
  61. float32 GetRadius() const;
  62. private:
  63. friend class b2Shape;
  64. b2CircleShape(const b2ShapeDef* def);
  65. void UpdateSweepRadius(const b2Vec2& center);
  66. // Local position in parent body
  67. b2Vec2 m_localPosition;
  68. float32 m_radius;
  69. };
  70. inline const b2Vec2& b2CircleShape::GetLocalPosition() const
  71. {
  72. return m_localPosition;
  73. }
  74. inline float32 b2CircleShape::GetRadius() const
  75. {
  76. return m_radius;
  77. }
  78. #endif