b2EdgeShape.h 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /*
  2. * Copyright (c) 2006-2010 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_EDGE_SHAPE_H
  20. #define B2_EDGE_SHAPE_H
  21. #include <Box2D/Collision/Shapes/b2Shape.h>
  22. /// A line segment (edge) shape. These can be connected in chains or loops
  23. /// to other edge shapes. The connectivity information is used to ensure
  24. /// correct contact normals.
  25. class b2EdgeShape : public b2Shape
  26. {
  27. public:
  28. b2EdgeShape();
  29. /// Set this as an isolated edge.
  30. void Set(const b2Vec2& v1, const b2Vec2& v2);
  31. /// Implement b2Shape.
  32. b2Shape* Clone(b2BlockAllocator* allocator) const;
  33. /// @see b2Shape::GetChildCount
  34. int32 GetChildCount() const;
  35. /// @see b2Shape::TestPoint
  36. bool TestPoint(const b2Transform& transform, const b2Vec2& p) const;
  37. // @see b2Shape::ComputeDistance
  38. void ComputeDistance(const b2Transform& xf, const b2Vec2& p, float32* distance, b2Vec2* normal, int32 childIndex) const;
  39. /// Implement b2Shape.
  40. bool RayCast(b2RayCastOutput* output, const b2RayCastInput& input,
  41. const b2Transform& transform, int32 childIndex) const;
  42. /// @see b2Shape::ComputeAABB
  43. void ComputeAABB(b2AABB* aabb, const b2Transform& transform, int32 childIndex) const;
  44. /// @see b2Shape::ComputeMass
  45. void ComputeMass(b2MassData* massData, float32 density) const;
  46. #if LIQUIDFUN_EXTERNAL_LANGUAGE_API
  47. public:
  48. /// Set this as an isolated edge, with direct floats.
  49. void Set(float32 vx1, float32 vy1, float32 vx2, float32 vy2);
  50. #endif // LIQUIDFUN_EXTERNAL_LANGUAGE_API
  51. /// These are the edge vertices
  52. b2Vec2 m_vertex1, m_vertex2;
  53. /// Optional adjacent vertices. These are used for smooth collision.
  54. b2Vec2 m_vertex0, m_vertex3;
  55. bool m_hasVertex0, m_hasVertex3;
  56. };
  57. inline b2EdgeShape::b2EdgeShape()
  58. {
  59. m_type = e_edge;
  60. m_radius = b2_polygonRadius;
  61. m_vertex0.x = 0.0f;
  62. m_vertex0.y = 0.0f;
  63. m_vertex3.x = 0.0f;
  64. m_vertex3.y = 0.0f;
  65. m_hasVertex0 = false;
  66. m_hasVertex3 = false;
  67. }
  68. #if LIQUIDFUN_EXTERNAL_LANGUAGE_API
  69. inline void b2EdgeShape::Set(float32 vx1,
  70. float32 vy1,
  71. float32 vx2,
  72. float32 vy2) {
  73. Set(b2Vec2(vx1, vy1), b2Vec2(vx2, vy2));
  74. }
  75. #endif // LIQUIDFUN_EXTERNAL_LANGUAGE_API
  76. #endif