File indexing completed on 2024-06-02 03:42:36

0001 /*
0002 * Copyright (c) 2006-2009 Erin Catto http://www.box2d.org
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_CIRCLE_SHAPE_H
0020 #define B2_CIRCLE_SHAPE_H
0021 
0022 #include <Box2D/Collision/Shapes/b2Shape.h>
0023 
0024 /// A circle shape.
0025 class b2CircleShape : public b2Shape
0026 {
0027 public:
0028     b2CircleShape();
0029 
0030     /// Implement b2Shape.
0031     b2Shape* Clone(b2BlockAllocator* allocator) const;
0032 
0033     /// @see b2Shape::GetChildCount
0034     int32 GetChildCount() const;
0035 
0036     /// Implement b2Shape.
0037     bool TestPoint(const b2Transform& transform, const b2Vec2& p) const;
0038 
0039     /// Implement b2Shape.
0040     bool RayCast(b2RayCastOutput* output, const b2RayCastInput& input,
0041                 const b2Transform& transform, int32 childIndex) const;
0042 
0043     /// @see b2Shape::ComputeAABB
0044     void ComputeAABB(b2AABB* aabb, const b2Transform& transform, int32 childIndex) const;
0045 
0046     /// @see b2Shape::ComputeMass
0047     void ComputeMass(b2MassData* massData, float32 density) const;
0048 
0049     /// Get the supporting vertex index in the given direction.
0050     int32 GetSupport(const b2Vec2& d) const;
0051 
0052     /// Get the supporting vertex in the given direction.
0053     const b2Vec2& GetSupportVertex(const b2Vec2& d) const;
0054 
0055     /// Get the vertex count.
0056     int32 GetVertexCount() const { return 1; }
0057 
0058     /// Get a vertex by index. Used by b2Distance.
0059     const b2Vec2& GetVertex(int32 index) const;
0060 
0061     /// Position
0062     b2Vec2 m_p;
0063 };
0064 
0065 inline b2CircleShape::b2CircleShape()
0066 {
0067     m_type = e_circle;
0068     m_radius = 0.0f;
0069     m_p.SetZero();
0070 }
0071 
0072 inline int32 b2CircleShape::GetSupport(const b2Vec2 &d) const
0073 {
0074     B2_NOT_USED(d);
0075     return 0;
0076 }
0077 
0078 inline const b2Vec2& b2CircleShape::GetSupportVertex(const b2Vec2 &d) const
0079 {
0080     B2_NOT_USED(d);
0081     return m_p;
0082 }
0083 
0084 inline const b2Vec2& b2CircleShape::GetVertex(int32 index) const
0085 {
0086     B2_NOT_USED(index);
0087     b2Assert(index == 0);
0088     return m_p;
0089 }
0090 
0091 #endif