LiquidFun
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
b2PolygonShape.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_POLYGON_SHAPE_H
21 #define B2_POLYGON_SHAPE_H
22 
23 #include <Box2D/Collision/Shapes/b2Shape.h>
24 
29 class b2PolygonShape : public b2Shape
30 {
31 public:
33 
35  b2Shape* Clone(b2BlockAllocator* allocator) const;
36 
38  int32 GetChildCount() const;
39 
45  void Set(const b2Vec2* points, int32 count);
46 
50  void SetAsBox(float32 hx, float32 hy);
51 
57  void SetAsBox(float32 hx, float32 hy, const b2Vec2& center, float32 angle);
58 
60  bool TestPoint(const b2Transform& transform, const b2Vec2& p) const;
61 
62  // @see b2Shape::ComputeDistance
63  void ComputeDistance(const b2Transform& xf, const b2Vec2& p, float32* distance, b2Vec2* normal, int32 childIndex) const;
64 
66  bool RayCast(b2RayCastOutput* output, const b2RayCastInput& input,
67  const b2Transform& transform, int32 childIndex) const;
68 
70  void ComputeAABB(b2AABB* aabb, const b2Transform& transform, int32 childIndex) const;
71 
73  void ComputeMass(b2MassData* massData, float32 density) const;
74 
76  int32 GetVertexCount() const { return m_count; }
77 
79  const b2Vec2& GetVertex(int32 index) const;
80 
83  bool Validate() const;
84 
85 #if LIQUIDFUN_EXTERNAL_LANGUAGE_API
86 public:
88  void SetCentroid(float32 x, float32 y);
89 
92  void SetAsBox(float32 hx,
93  float32 hy,
94  float32 centerX,
95  float32 centerY,
96  float32 angle);
97 #endif // LIQUIDFUN_EXTERNAL_LANGUAGE_API
98 
99  b2Vec2 m_centroid;
100  b2Vec2 m_vertices[b2_maxPolygonVertices];
101  b2Vec2 m_normals[b2_maxPolygonVertices];
102  int32 m_count;
103 };
104 
105 inline b2PolygonShape::b2PolygonShape()
106 {
107  m_type = e_polygon;
108  m_radius = b2_polygonRadius;
109  m_count = 0;
110  m_centroid.SetZero();
111 }
112 
113 inline const b2Vec2& b2PolygonShape::GetVertex(int32 index) const
114 {
115  b2Assert(0 <= index && index < m_count);
116  return m_vertices[index];
117 }
118 
119 #if LIQUIDFUN_EXTERNAL_LANGUAGE_API
120 inline void b2PolygonShape::SetCentroid(float32 x, float32 y)
121 {
122  m_centroid.Set(x, y);
123 }
124 
125 inline void b2PolygonShape::SetAsBox(float32 hx,
126  float32 hy,
127  float32 centerX,
128  float32 centerY,
129  float32 angle) {
130  SetAsBox(hx, hy, b2Vec2(centerX, centerY), angle);
131 }
132 #endif // LIQUIDFUN_EXTERNAL_LANGUAGE_API
133 
134 #endif
Definition: b2Math.h:411
bool Validate() const
Definition: b2PolygonShape.cpp:478
void ComputeAABB(b2AABB *aabb, const b2Transform &transform, int32 childIndex) const
Definition: b2PolygonShape.cpp:376
bool TestPoint(const b2Transform &transform, const b2Vec2 &p) const
Definition: b2PolygonShape.cpp:244
int32 GetChildCount() const
Definition: b2PolygonShape.cpp:70
Definition: b2BlockAllocator.h:36
This holds the mass data computed for a shape.
Definition: b2Shape.h:28
Definition: b2Shape.h:43
void ComputeMass(b2MassData *massData, float32 density) const
Definition: b2PolygonShape.cpp:395
void SetAsBox(float32 hx, float32 hy)
Definition: b2PolygonShape.cpp:31
Definition: b2PolygonShape.h:29
void Set(float32 x_, float32 y_)
Set this vector to some specified coordinates.
Definition: b2Math.h:68
Definition: b2Collision.h:155
void SetZero()
Set this vector to all zeros.
Definition: b2Math.h:65
void ComputeDistance(const b2Transform &xf, const b2Vec2 &p, float32 *distance, b2Vec2 *normal, int32 childIndex) const
Definition: b2PolygonShape.cpp:260
bool RayCast(b2RayCastOutput *output, const b2RayCastInput &input, const b2Transform &transform, int32 childIndex) const
Implement b2Shape.
Definition: b2PolygonShape.cpp:304
#define b2_polygonRadius
Definition: b2Settings.h:120
An axis aligned bounding box.
Definition: b2Collision.h:162
b2Shape * Clone(b2BlockAllocator *allocator) const
Implement b2Shape.
Definition: b2PolygonShape.cpp:23
Ray-cast input data. The ray extends from p1 to p1 + maxFraction * (p2 - p1).
Definition: b2Collision.h:147
void Set(const b2Vec2 *points, int32 count)
Definition: b2PolygonShape.cpp:121
int32 GetVertexCount() const
Get the vertex count.
Definition: b2PolygonShape.h:76
A 2D column vector.
Definition: b2Math.h:56
const b2Vec2 & GetVertex(int32 index) const
Get a vertex by index.
Definition: b2PolygonShape.h:113
#define b2_maxPolygonVertices
Definition: b2Settings.h:97