hx3d  1
2D/3D Simple Game Framework
polygon.hpp
1 /*
2  2D polygon collider.
3  Copyright (C) 2015 Denis BOURGE
4 
5  This library is free software; you can redistribute it and/or
6  modify it under the terms of the GNU Lesser General Public
7  License as published by the Free Software Foundation; either
8  version 2.1 of the License, or (at your option) any later version.
9 
10  This library is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU Lesser General Public
16  License along with this library; if not, write to the Free Software
17  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
18  USA
19 */
20 
21 #ifndef HX3D_PHYSICS_2D_COLLIDERS_POLYGON
22 #define HX3D_PHYSICS_2D_COLLIDERS_POLYGON
23 
24 #include "hx3d/physics/2d/collider.hpp"
25 
26 #include <vector>
27 
28 namespace hx3d {
29 namespace physics2d {
30 namespace colliders {
31 
35 struct Polygon: public Collider {
36 
42  Polygon(const Type colliderType = Type::Dynamic);
43 
49  void setPoints(const std::vector<glm::vec2>& points);
50 
57  void setAsBox(const float width, const float height);
58 
66  glm::vec2 getSupport(glm::vec2 dir);
67 
68  virtual void setOrientation(float angle) override;
69  virtual void computeMass(float density) override;
70 
72  unsigned int vertexCount;
74  std::vector<glm::vec2> vertices;
76  std::vector<glm::vec2> normals;
78  glm::mat2 u;
80  bool box;
81 };
82 
83 } /* colliders */
84 } /* physics2d */
85 } /* hx3d */
86 
87 #endif
void setAsBox(const float width, const float height)
Set the polygon points as a box.
Definition: polygon.cpp:97
std::vector< glm::vec2 > normals
Normals.
Definition: polygon.hpp:76
glm::vec2 getSupport(glm::vec2 dir)
Get the support vector following a direction.
Definition: polygon.cpp:80
void setPoints(const std::vector< glm::vec2 > &points)
Set the polygon points.
Definition: polygon.cpp:14
Type
Collider type.
Definition: collider.hpp:46
hx3d framework namespace
Definition: audio.hpp:26
virtual void computeMass(float density) override
Compute the collider mass.
Definition: polygon.cpp:125
Polygon(const Type colliderType=Type::Dynamic)
Create a polygon.
Definition: polygon.cpp:9
std::vector< glm::vec2 > vertices
Vertices.
Definition: polygon.hpp:74
Dynamic: forces and velocity.
bool box
Is the polygon a box ?
Definition: polygon.hpp:80
unsigned int vertexCount
Vertex count.
Definition: polygon.hpp:72
virtual void setOrientation(float angle) override
Set the collider orientation.
Definition: polygon.cpp:115
glm::mat2 u
Rotation matrix.
Definition: polygon.hpp:78
Physical collider.
Definition: collider.hpp:40
Polygon or box shaped collider.
Definition: polygon.hpp:35