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_EDGE_SHAPE_H
0020 #define B2_EDGE_SHAPE_H
0021 
0022 #include <Box2D/Collision/Shapes/b2Shape.h>
0023 
0024 /// A line segment (edge) shape. These can be connected in chains or loops
0025 /// to other edge shapes. The connectivity information is used to ensure
0026 /// correct contact normals.
0027 class b2EdgeShape : public b2Shape
0028 {
0029 public:
0030     b2EdgeShape();
0031 
0032     /// Set this as an isolated edge.
0033     void Set(const b2Vec2& v1, const b2Vec2& v2);
0034 
0035     /// Implement b2Shape.
0036     b2Shape* Clone(b2BlockAllocator* allocator) const override;
0037 
0038     /// @see b2Shape::GetChildCount
0039     int32 GetChildCount() const override;
0040 
0041     /// @see b2Shape::TestPoint
0042     bool TestPoint(const b2Transform& transform, const b2Vec2& p) const override;
0043 
0044     /// Implement b2Shape.
0045     bool RayCast(b2RayCastOutput* output, const b2RayCastInput& input,
0046                 const b2Transform& transform, int32 childIndex) const override;
0047 
0048     /// @see b2Shape::ComputeAABB
0049     void ComputeAABB(b2AABB* aabb, const b2Transform& transform, int32 childIndex) const override;
0050 
0051     /// @see b2Shape::ComputeMass
0052     void ComputeMass(b2MassData* massData, qreal density) const override;
0053     
0054     /// These are the edge vertices
0055     b2Vec2 m_vertex1, m_vertex2;
0056 
0057     /// Optional adjacent vertices. These are used for smooth collision.
0058     b2Vec2 m_vertex0, m_vertex3;
0059     bool m_hasVertex0, m_hasVertex3;
0060 };
0061 
0062 inline b2EdgeShape::b2EdgeShape()
0063 {
0064     m_type = e_edge;
0065     m_radius = b2_polygonRadius;
0066     m_hasVertex0 = false;
0067     m_hasVertex3 = false;
0068 }
0069 
0070 #endif