Box2D  2.4.1
A 2D physics engine for games
b2_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 
23 #ifndef B2_SHAPE_H
24 #define B2_SHAPE_H
25 
26 #include "b2_api.h"
27 #include "b2_math.h"
28 #include "b2_collision.h"
29 
30 class b2BlockAllocator;
31 
33 struct B2_API b2MassData
34 {
36  float mass;
37 
40 
42  float I;
43 };
44 
48 class B2_API b2Shape
49 {
50 public:
51 
52  enum Type
53  {
54  e_circle = 0,
55  e_edge = 1,
56  e_polygon = 2,
57  e_chain = 3,
58  e_typeCount = 4
59  };
60 
61  virtual ~b2Shape() {}
62 
64  virtual b2Shape* Clone(b2BlockAllocator* allocator) const = 0;
65 
68  Type GetType() const;
69 
71  virtual int32 GetChildCount() const = 0;
72 
76  virtual bool TestPoint(const b2Transform& xf, const b2Vec2& p) const = 0;
77 
83  virtual bool RayCast(b2RayCastOutput* output, const b2RayCastInput& input,
84  const b2Transform& transform, int32 childIndex) const = 0;
85 
90  virtual void ComputeAABB(b2AABB* aabb, const b2Transform& xf, int32 childIndex) const = 0;
91 
96  virtual void ComputeMass(b2MassData* massData, float density) const = 0;
97 
98  Type m_type;
99 
102  float m_radius;
103 };
104 
105 inline b2Shape::Type b2Shape::GetType() const
106 {
107  return m_type;
108 }
109 
110 #endif
b2Vec2
A 2D column vector.
Definition: b2_math.h:41
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::m_radius
float m_radius
Definition: b2_shape.h:102
b2AABB
An axis aligned bounding box.
Definition: b2_collision.h:168
b2BlockAllocator
Definition: b2_block_allocator.h:37
b2_collision.h
b2Shape
Definition: b2_shape.h:48
b2MassData
This holds the mass data computed for a shape.
Definition: b2_shape.h:33
b2MassData::center
b2Vec2 center
The position of the shape's centroid relative to the shape's origin.
Definition: b2_shape.h:39
b2MassData::mass
float mass
The mass of the shape, usually in kilograms.
Definition: b2_shape.h:36
b2RayCastOutput
Definition: b2_collision.h:161
b2MassData::I
float I
The rotational inertia of the shape about the local origin.
Definition: b2_shape.h:42
b2Shape::GetType
Type GetType() const
Definition: b2_shape.h:105