LiquidFun
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
b2ChainShape.h
1 /*
2 * Copyright (c) 2006-2010 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_CHAIN_SHAPE_H
21 #define B2_CHAIN_SHAPE_H
22 
23 #include <Box2D/Collision/Shapes/b2Shape.h>
24 
25 class b2EdgeShape;
26 
33 class b2ChainShape : public b2Shape
34 {
35 public:
36  b2ChainShape();
37 
39  ~b2ChainShape();
40 
44  void CreateLoop(const b2Vec2* vertices, int32 count);
45 
49  void CreateChain(const b2Vec2* vertices, int32 count);
50 
53  void SetPrevVertex(const b2Vec2& prevVertex);
54 
57  void SetNextVertex(const b2Vec2& nextVertex);
58 
60  b2Shape* Clone(b2BlockAllocator* allocator) const;
61 
63  int32 GetChildCount() const;
64 
66  void GetChildEdge(b2EdgeShape* edge, int32 index) const;
67 
70  bool TestPoint(const b2Transform& transform, const b2Vec2& p) const;
71 
72  // @see b2Shape::ComputeDistance
73  void ComputeDistance(const b2Transform& xf, const b2Vec2& p, float32* distance, b2Vec2* normal, int32 childIndex) const;
74 
76  bool RayCast(b2RayCastOutput* output, const b2RayCastInput& input,
77  const b2Transform& transform, int32 childIndex) const;
78 
80  void ComputeAABB(b2AABB* aabb, const b2Transform& transform, int32 childIndex) const;
81 
84  void ComputeMass(b2MassData* massData, float32 density) const;
85 
88 
90  int32 m_count;
91 
92  b2Vec2 m_prevVertex, m_nextVertex;
93  bool m_hasPrevVertex, m_hasNextVertex;
94 };
95 
96 inline b2ChainShape::b2ChainShape()
97 {
98  m_type = e_chain;
99  m_radius = b2_polygonRadius;
100  m_vertices = NULL;
101  m_count = 0;
102  m_hasPrevVertex = false;
103  m_hasNextVertex = false;
104 }
105 
106 #endif
Definition: b2Math.h:411
Definition: b2ChainShape.h:33
void ComputeAABB(b2AABB *aabb, const b2Transform &transform, int32 childIndex) const
Definition: b2ChainShape.cpp:178
void CreateChain(const b2Vec2 *vertices, int32 count)
Definition: b2ChainShape.cpp:57
bool TestPoint(const b2Transform &transform, const b2Vec2 &p) const
Definition: b2ChainShape.cpp:151
Definition: b2BlockAllocator.h:36
This holds the mass data computed for a shape.
Definition: b2Shape.h:28
Definition: b2Shape.h:43
bool RayCast(b2RayCastOutput *output, const b2RayCastInput &input, const b2Transform &transform, int32 childIndex) const
Implement b2Shape.
Definition: b2ChainShape.cpp:158
Definition: b2Collision.h:155
int32 m_count
The vertex count.
Definition: b2ChainShape.h:90
#define b2_polygonRadius
Definition: b2Settings.h:120
An axis aligned bounding box.
Definition: b2Collision.h:162
void SetNextVertex(const b2Vec2 &nextVertex)
Definition: b2ChainShape.cpp:88
b2Shape * Clone(b2BlockAllocator *allocator) const
Implement b2Shape. Vertices are cloned using b2Alloc.
Definition: b2ChainShape.cpp:94
Ray-cast input data. The ray extends from p1 to p1 + maxFraction * (p2 - p1).
Definition: b2Collision.h:147
Definition: b2EdgeShape.h:28
int32 GetChildCount() const
Definition: b2ChainShape.cpp:106
void CreateLoop(const b2Vec2 *vertices, int32 count)
Definition: b2ChainShape.cpp:33
~b2ChainShape()
The destructor frees the vertices using b2Free.
Definition: b2ChainShape.cpp:26
b2Vec2 * m_vertices
The vertices. Owned by this class.
Definition: b2ChainShape.h:87
void ComputeDistance(const b2Transform &xf, const b2Vec2 &p, float32 *distance, b2Vec2 *normal, int32 childIndex) const
Definition: b2ChainShape.cpp:144
A 2D column vector.
Definition: b2Math.h:56
void SetPrevVertex(const b2Vec2 &prevVertex)
Definition: b2ChainShape.cpp:82
void GetChildEdge(b2EdgeShape *edge, int32 index) const
Get a child edge.
Definition: b2ChainShape.cpp:112
void ComputeMass(b2MassData *massData, float32 density) const
Definition: b2ChainShape.cpp:196