~ubuntu-branches/ubuntu/vivid/emscripten/vivid

« back to all changes in this revision

Viewing changes to tests/box2d/Box2D/Collision/Shapes/b2PolygonShape.h

  • Committer: Package Import Robot
  • Author(s): Sylvestre Ledru
  • Date: 2013-05-02 13:11:51 UTC
  • Revision ID: package-import@ubuntu.com-20130502131151-q8dvteqr1ef2x7xz
Tags: upstream-1.4.1~20130504~adb56cb
ImportĀ upstreamĀ versionĀ 1.4.1~20130504~adb56cb

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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_POLYGON_SHAPE_H
 
20
#define B2_POLYGON_SHAPE_H
 
21
 
 
22
#include <Box2D/Collision/Shapes/b2Shape.h>
 
23
 
 
24
/// A convex polygon. It is assumed that the interior of the polygon is to
 
25
/// the left of each edge.
 
26
/// Polygons have a maximum number of vertices equal to b2_maxPolygonVertices.
 
27
/// In most cases you should not need many vertices for a convex polygon.
 
28
class b2PolygonShape : public b2Shape
 
29
{
 
30
public:
 
31
        b2PolygonShape();
 
32
 
 
33
        /// Implement b2Shape.
 
34
        b2Shape* Clone(b2BlockAllocator* allocator) const;
 
35
 
 
36
        /// @see b2Shape::GetChildCount
 
37
        int32 GetChildCount() const;
 
38
 
 
39
        /// Copy vertices. This assumes the vertices define a convex polygon.
 
40
        /// It is assumed that the exterior is the the right of each edge.
 
41
        /// The count must be in the range [3, b2_maxPolygonVertices].
 
42
        void Set(const b2Vec2* vertices, int32 vertexCount);
 
43
 
 
44
        /// Build vertices to represent an axis-aligned box.
 
45
        /// @param hx the half-width.
 
46
        /// @param hy the half-height.
 
47
        void SetAsBox(float32 hx, float32 hy);
 
48
 
 
49
        /// Build vertices to represent an oriented box.
 
50
        /// @param hx the half-width.
 
51
        /// @param hy the half-height.
 
52
        /// @param center the center of the box in local coordinates.
 
53
        /// @param angle the rotation of the box in local coordinates.
 
54
        void SetAsBox(float32 hx, float32 hy, const b2Vec2& center, float32 angle);
 
55
 
 
56
        /// @see b2Shape::TestPoint
 
57
        bool TestPoint(const b2Transform& transform, const b2Vec2& p) const;
 
58
 
 
59
        /// Implement b2Shape.
 
60
        bool RayCast(b2RayCastOutput* output, const b2RayCastInput& input,
 
61
                                        const b2Transform& transform, int32 childIndex) const;
 
62
 
 
63
        /// @see b2Shape::ComputeAABB
 
64
        void ComputeAABB(b2AABB* aabb, const b2Transform& transform, int32 childIndex) const;
 
65
 
 
66
        /// @see b2Shape::ComputeMass
 
67
        void ComputeMass(b2MassData* massData, float32 density) const;
 
68
 
 
69
        /// Get the vertex count.
 
70
        int32 GetVertexCount() const { return m_vertexCount; }
 
71
 
 
72
        /// Get a vertex by index.
 
73
        const b2Vec2& GetVertex(int32 index) const;
 
74
 
 
75
        b2Vec2 m_centroid;
 
76
        b2Vec2 m_vertices[b2_maxPolygonVertices];
 
77
        b2Vec2 m_normals[b2_maxPolygonVertices];
 
78
        int32 m_vertexCount;
 
79
};
 
80
 
 
81
inline b2PolygonShape::b2PolygonShape()
 
82
{
 
83
        m_type = e_polygon;
 
84
        m_radius = b2_polygonRadius;
 
85
        m_vertexCount = 0;
 
86
        m_centroid.SetZero();
 
87
}
 
88
 
 
89
inline const b2Vec2& b2PolygonShape::GetVertex(int32 index) const
 
90
{
 
91
        b2Assert(0 <= index && index < m_vertexCount);
 
92
        return m_vertices[index];
 
93
}
 
94
 
 
95
#endif