Box2D  2.4.1
A 2D physics engine for games
b2_polygon_shape.h
1 // MIT License
2 
3 // Copyright (c) 2019 Erin Catto
4 
5 // Permission is hereby granted, free of charge, to any person obtaining a copy
6 // of this software and associated documentation files (the "Software"), to deal
7 // in the Software without restriction, including without limitation the rights
8 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 // copies of the Software, and to permit persons to whom the Software is
10 // furnished to do so, subject to the following conditions:
11 
12 // The above copyright notice and this permission notice shall be included in all
13 // copies or substantial portions of the Software.
14 
15 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 // SOFTWARE.
22 #ifndef B2_POLYGON_SHAPE_H
23 #define B2_POLYGON_SHAPE_H
24 
25 #include "b2_api.h"
26 #include "b2_shape.h"
27 
32 class B2_API b2PolygonShape : public b2Shape
33 {
34 public:
36 
38  b2Shape* Clone(b2BlockAllocator* allocator) const override;
39 
41  int32 GetChildCount() const override;
42 
48  void Set(const b2Vec2* points, int32 count);
49 
53  void SetAsBox(float hx, float hy);
54 
60  void SetAsBox(float hx, float hy, const b2Vec2& center, float angle);
61 
63  bool TestPoint(const b2Transform& transform, const b2Vec2& p) const override;
64 
68  bool RayCast(b2RayCastOutput* output, const b2RayCastInput& input,
69  const b2Transform& transform, int32 childIndex) const override;
70 
72  void ComputeAABB(b2AABB* aabb, const b2Transform& transform, int32 childIndex) const override;
73 
75  void ComputeMass(b2MassData* massData, float density) const override;
76 
79  bool Validate() const;
80 
81  b2Vec2 m_centroid;
82  b2Vec2 m_vertices[b2_maxPolygonVertices];
83  b2Vec2 m_normals[b2_maxPolygonVertices];
84  int32 m_count;
85 };
86 
87 inline b2PolygonShape::b2PolygonShape()
88 {
89  m_type = e_polygon;
91  m_count = 0;
92  m_centroid.SetZero();
93 }
94 
95 #endif
b2Vec2
A 2D column vector.
Definition: b2_math.h:41
b2Shape::RayCast
virtual bool RayCast(b2RayCastOutput *output, const b2RayCastInput &input, const b2Transform &transform, int32 childIndex) const =0
b2Shape::GetChildCount
virtual int32 GetChildCount() const =0
Get the number of child primitives.
b2RayCastInput
Ray-cast input data. The ray extends from p1 to p1 + maxFraction * (p2 - p1).
Definition: b2_collision.h:153
b2Transform
Definition: b2_math.h:338
b2Shape::ComputeAABB
virtual void ComputeAABB(b2AABB *aabb, const b2Transform &xf, int32 childIndex) const =0
b2Shape::m_radius
float m_radius
Definition: b2_shape.h:102
b2Shape::ComputeMass
virtual void ComputeMass(b2MassData *massData, float density) const =0
b2AABB
An axis aligned bounding box.
Definition: b2_collision.h:168
b2BlockAllocator
Definition: b2_block_allocator.h:37
b2PolygonShape
Definition: b2_polygon_shape.h:32
b2_polygonRadius
#define b2_polygonRadius
Definition: b2_common.h:74
b2Shape
Definition: b2_shape.h:48
b2MassData
This holds the mass data computed for a shape.
Definition: b2_shape.h:33
b2Vec2::SetZero
void SetZero()
Set this vector to all zeros.
Definition: b2_math.h:50
b2Shape::Clone
virtual b2Shape * Clone(b2BlockAllocator *allocator) const =0
Clone the concrete shape using the provided allocator.
b2RayCastOutput
Definition: b2_collision.h:161
b2Shape::TestPoint
virtual bool TestPoint(const b2Transform &xf, const b2Vec2 &p) const =0
b2_maxPolygonVertices
#define b2_maxPolygonVertices
Definition: b2_settings.h:53