File indexing completed on 2025-08-03 03:49:54
0001 /* 0002 * Copyright (c) 2006-2010 Erin Catto http://www.gphysics.com 0003 * 0004 * This software is provided 'as-is', without any express or implied 0005 * warranty. In no event will the authors be held liable for any damages 0006 * arising from the use of this software. 0007 * Permission is granted to anyone to use this software for any purpose, 0008 * including commercial applications, and to alter it and redistribute it 0009 * freely, subject to the following restrictions: 0010 * 1. The origin of this software must not be misrepresented; you must not 0011 * claim that you wrote the original software. If you use this software 0012 * in a product, an acknowledgment in the product documentation would be 0013 * appreciated but is not required. 0014 * 2. Altered source versions must be plainly marked as such, and must not be 0015 * misrepresented as being the original software. 0016 * 3. This notice may not be removed or altered from any source distribution. 0017 */ 0018 0019 #ifndef B2_LOOP_SHAPE_H 0020 #define B2_LOOP_SHAPE_H 0021 0022 #include <Box2D/Collision/Shapes/b2Shape.h> 0023 0024 class b2EdgeShape; 0025 0026 /// A loop shape is a free form sequence of line segments that form a circular list. 0027 /// The loop may cross upon itself, but this is not recommended for smooth collision. 0028 /// The loop has double sided collision, so you can use inside and outside collision. 0029 /// Therefore, you may use any winding order. 0030 /// Since there may be many vertices, they are allocated using b2Alloc. 0031 class b2LoopShape : public b2Shape 0032 { 0033 public: 0034 b2LoopShape(); 0035 0036 /// The destructor frees the vertices using b2Free. 0037 ~b2LoopShape() override; 0038 0039 /// Create the loop shape, copy all vertices. 0040 void Create(const b2Vec2* vertices, int32 count); 0041 0042 /// Implement b2Shape. Vertices are cloned using b2Alloc. 0043 b2Shape* Clone(b2BlockAllocator* allocator) const override; 0044 0045 /// @see b2Shape::GetChildCount 0046 int32 GetChildCount() const override; 0047 0048 /// Get a child edge. 0049 void GetChildEdge(b2EdgeShape* edge, int32 index) const; 0050 0051 /// This always return false. 0052 /// @see b2Shape::TestPoint 0053 bool TestPoint(const b2Transform& transform, const b2Vec2& p) const override; 0054 0055 /// Implement b2Shape. 0056 bool RayCast(b2RayCastOutput* output, const b2RayCastInput& input, 0057 const b2Transform& transform, int32 childIndex) const override; 0058 0059 /// @see b2Shape::ComputeAABB 0060 void ComputeAABB(b2AABB* aabb, const b2Transform& transform, int32 childIndex) const override; 0061 0062 /// Chains have zero mass. 0063 /// @see b2Shape::ComputeMass 0064 void ComputeMass(b2MassData* massData, qreal density) const override; 0065 0066 /// Get the number of vertices. 0067 int32 GetCount() const { return m_count; } 0068 0069 /// Get the vertices (read-only). 0070 const b2Vec2& GetVertex(int32 index) const 0071 { 0072 b2Assert(0 <= index && index < m_count); 0073 return m_vertices[index]; 0074 } 0075 0076 /// Get the vertices (read-only). 0077 const b2Vec2* GetVertices() const { return m_vertices; } 0078 0079 protected: 0080 0081 /// The vertices. Owned by this class. 0082 b2Vec2* m_vertices; 0083 0084 /// The vertex count. 0085 int32 m_count; 0086 }; 0087 0088 inline b2LoopShape::b2LoopShape() 0089 { 0090 m_type = e_loop; 0091 m_radius = b2_polygonRadius; 0092 m_vertices = NULL; 0093 m_count = 0; 0094 } 0095 0096 #endif