Box2D: b2Shape.h Source File

| Box2D 2.3.0 A 2D Physics Engine for Games

b2Shape.h
1 /*
2 * Copyright (c) 2006-2009 Erin Catto http://www.box2d.org
3 *
4 * This software is provided 'as-is', without any express or implied
5 * warranty. In no event will the authors be held liable for any damages
6 * arising from the use of this software.
7 * Permission is granted to anyone to use this software for any purpose,
8 * including commercial applications, and to alter it and redistribute it
9 * freely, subject to the following restrictions:
10 * 1. The origin of this software must not be misrepresented; you must not
11 * claim that you wrote the original software. If you use this software
12 * in a product, an acknowledgment in the product documentation would be
13 * appreciated but is not required.
14 * 2. Altered source versions must be plainly marked as such, and must not be
15 * misrepresented as being the original software.
16 * 3. This notice may not be removed or altered from any source distribution.
17 */
18
19 #ifndef B2_SHAPE_H
20 #define B2_SHAPE_H
21
22 #include <Box2D/Common/b2BlockAllocator.h>
23 #include <Box2D/Common/b2Math.h>
24 #include <Box2D/Collision/b2Collision.h>
25
27 struct b2MassData
28 {
30 float32 mass;
31
33 b2Vec2 center;
34
36 float32 I;
37 };
38
42 class b2Shape
43 {
44 public:
45
46 enum Type
47 {
48 e_circle = 0,
49 e_edge = 1,
50 e_polygon = 2,
51 e_chain = 3,
52 e_typeCount = 4
53 };
54
55 virtual ~b2Shape() {}
56
58 virtual b2Shape* Clone(b2BlockAllocator* allocator) const = 0;
59
62 Type GetType() const;
63
65 virtual int32 GetChildCount() const = 0;
66
70 virtual bool TestPoint(const b2Transform& xf, const b2Vec2& p) const = 0;
71
77 virtual bool RayCast(b2RayCastOutput* output, const b2RayCastInput& input,
78 const b2Transform& transform, int32 childIndex) const = 0;
79
84 virtual void ComputeAABB(b2AABB* aabb, const b2Transform& xf, int32 childIndex) const = 0;
85
90 virtual void ComputeMass(b2MassData* massData, float32 density) const = 0;
91
92 Type m_type;
93 float32 m_radius;
94 };
95
96 inline b2Shape::Type b2Shape::GetType() const
97 {
98 return m_type;
99 }
100
101 #endif
b2Transform
Definition: b2Math.h:350
b2MassData::I
float32 I
The rotational inertia of the shape about the local origin.
Definition: b2Shape.h:36
b2BlockAllocator
Definition: b2BlockAllocator.h:35
b2Shape::GetChildCount
virtual int32 GetChildCount() const =0
Get the number of child primitives.
b2MassData
This holds the mass data computed for a shape.
Definition: b2Shape.h:27
b2Shape
Definition: b2Shape.h:42
b2Collision.h
b2RayCastOutput
Definition: b2Collision.h:155
b2Shape::ComputeAABB
virtual void ComputeAABB(b2AABB *aabb, const b2Transform &xf, int32 childIndex) const =0
b2AABB
An axis aligned bounding box.
Definition: b2Collision.h:162
b2MassData::mass
float32 mass
The mass of the shape, usually in kilograms.
Definition: b2Shape.h:30
b2MassData::center
b2Vec2 center
The position of the shape&#39;s centroid relative to the shape&#39;s origin.
Definition: b2Shape.h:33
b2RayCastInput
Ray-cast input data. The ray extends from p1 to p1 + maxFraction * (p2 - p1).
Definition: b2Collision.h:147
b2Shape::RayCast
virtual bool RayCast(b2RayCastOutput *output, const b2RayCastInput &input, const b2Transform &transform, int32 childIndex) const =0
b2Shape::Clone
virtual b2Shape * Clone(b2BlockAllocator *allocator) const =0
Clone the concrete shape using the provided allocator.
b2Shape::ComputeMass
virtual void ComputeMass(b2MassData *massData, float32 density) const =0
b2Vec2
A 2D column vector.
Definition: b2Math.h:53
b2Shape::GetType
Type GetType() const
Definition: b2Shape.h:96
b2Shape::TestPoint
virtual bool TestPoint(const b2Transform &xf, const b2Vec2 &p) const =0