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