Box2D  2.3.0
A 2D Physics Engine for Games
b2ChainShape.h
1 /*
2 * Copyright (c) 2006-2010 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_CHAIN_SHAPE_H
20 #define B2_CHAIN_SHAPE_H
21 
22 #include <Box2D/Collision/Shapes/b2Shape.h>
23 
24 class b2EdgeShape;
25 
32 class b2ChainShape : public b2Shape
33 {
34 public:
35  b2ChainShape();
36 
38  ~b2ChainShape();
39 
43  void CreateLoop(const b2Vec2* vertices, int32 count);
44 
48  void CreateChain(const b2Vec2* vertices, int32 count);
49 
52  void SetPrevVertex(const b2Vec2& prevVertex);
53 
56  void SetNextVertex(const b2Vec2& nextVertex);
57 
59  b2Shape* Clone(b2BlockAllocator* allocator) const;
60 
62  int32 GetChildCount() const;
63 
65  void GetChildEdge(b2EdgeShape* edge, int32 index) const;
66 
69  bool TestPoint(const b2Transform& transform, const b2Vec2& p) const;
70 
72  bool RayCast(b2RayCastOutput* output, const b2RayCastInput& input,
73  const b2Transform& transform, int32 childIndex) const;
74 
76  void ComputeAABB(b2AABB* aabb, const b2Transform& transform, int32 childIndex) const;
77 
80  void ComputeMass(b2MassData* massData, float32 density) const;
81 
84 
86  int32 m_count;
87 
88  b2Vec2 m_prevVertex, m_nextVertex;
89  bool m_hasPrevVertex, m_hasNextVertex;
90 };
91 
92 inline b2ChainShape::b2ChainShape()
93 {
94  m_type = e_chain;
95  m_radius = b2_polygonRadius;
96  m_vertices = NULL;
97  m_count = 0;
98  m_hasPrevVertex = false;
99  m_hasNextVertex = false;
100 }
101 
102 #endif