The JUCE cross-platform C++ framework, with DISTRHO/KXStudio specific changes
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

96 lines
3.3KB

  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_POLYGON_SHAPE_H
  19. #define B2_POLYGON_SHAPE_H
  20. #include "../Shapes/b2Shape.h"
  21. /// A convex polygon. It is assumed that the interior of the polygon is to
  22. /// the left of each edge.
  23. /// Polygons have a maximum number of vertices equal to b2_maxPolygonVertices.
  24. /// In most cases you should not need many vertices for a convex polygon.
  25. class b2PolygonShape : public b2Shape
  26. {
  27. public:
  28. b2PolygonShape();
  29. /// Implement b2Shape.
  30. b2Shape* Clone(b2BlockAllocator* allocator) const;
  31. /// @see b2Shape::GetChildCount
  32. juce::int32 GetChildCount() const;
  33. /// Copy vertices. This assumes the vertices define a convex polygon.
  34. /// It is assumed that the exterior is the the right of each edge.
  35. /// The count must be in the range [3, b2_maxPolygonVertices].
  36. void Set(const b2Vec2* vertices, juce::int32 vertexCount);
  37. /// Build vertices to represent an axis-aligned box.
  38. /// @param hx the half-width.
  39. /// @param hy the half-height.
  40. void SetAsBox(float32 hx, float32 hy);
  41. /// Build vertices to represent an oriented box.
  42. /// @param hx the half-width.
  43. /// @param hy the half-height.
  44. /// @param center the center of the box in local coordinates.
  45. /// @param angle the rotation of the box in local coordinates.
  46. void SetAsBox(float32 hx, float32 hy, const b2Vec2& center, float32 angle);
  47. /// @see b2Shape::TestPoint
  48. bool TestPoint(const b2Transform& transform, const b2Vec2& p) const;
  49. /// Implement b2Shape.
  50. bool RayCast(b2RayCastOutput* output, const b2RayCastInput& input,
  51. const b2Transform& transform, juce::int32 childIndex) const;
  52. /// @see b2Shape::ComputeAABB
  53. void ComputeAABB(b2AABB* aabb, const b2Transform& transform, juce::int32 childIndex) const;
  54. /// @see b2Shape::ComputeMass
  55. void ComputeMass(b2MassData* massData, float32 density) const;
  56. /// Get the vertex count.
  57. juce::int32 GetVertexCount() const { return m_vertexCount; }
  58. /// Get a vertex by index.
  59. const b2Vec2& GetVertex(juce::int32 index) const;
  60. b2Vec2 m_centroid;
  61. b2Vec2 m_vertices[b2_maxPolygonVertices];
  62. b2Vec2 m_normals[b2_maxPolygonVertices];
  63. juce::int32 m_vertexCount;
  64. };
  65. inline b2PolygonShape::b2PolygonShape()
  66. {
  67. m_type = e_polygon;
  68. m_radius = b2_polygonRadius;
  69. m_vertexCount = 0;
  70. m_centroid.SetZero();
  71. }
  72. inline const b2Vec2& b2PolygonShape::GetVertex(juce::int32 index) const
  73. {
  74. b2Assert(0 <= index && index < m_vertexCount);
  75. return m_vertices[index];
  76. }
  77. #endif