Gamedev Framework (gf)  0.3.0
A C++11 framework for 2D games
Collision.h
1 /*
2  * Gamedev Framework (gf)
3  * Copyright (C) 2016 Julien Bernard
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  *
9  * Permission is granted to anyone to use this software for any purpose,
10  * including commercial applications, and to alter it and redistribute it
11  * freely, subject to the following restrictions:
12  *
13  * 1. The origin of this software must not be misrepresented; you must not
14  * claim that you wrote the original software. If you use this software
15  * in a product, an acknowledgment in the product documentation would be
16  * appreciated but is not required.
17  * 2. Altered source versions must be plainly marked as such, and must not be
18  * misrepresented as being the original software.
19  * 3. This notice may not be removed or altered from any source distribution.
20  */
21 #ifndef GF_COLLISION_H
22 #define GF_COLLISION_H
23 
24 #include "Circ.h"
25 #include "Polygon.h"
26 #include "Portability.h"
27 #include "Rect.h"
28 #include "Vector.h"
29 
30 namespace gf {
31 #ifndef DOXYGEN_SHOULD_SKIP_THIS
32 inline namespace v1 {
33 #endif
34 
35  /**
36  * @ingroup game
37  * @brief Data about the collision between two objects
38  *
39  * @sa [How to Create a Custom Physics Engine](http://gamedevelopment.tutsplus.com/series/how-to-create-a-custom-physics-engine--gamedev-12715)
40  */
41  struct Penetration {
42  Vector2f normal; ///< Collision normal
43  float depth; ///< Penetration depth
44  };
45 
46  /**
47  * @relates Penetration
48  * @brief Check if two circles collides
49  *
50  * @param lhs First circle
51  * @param rhs Second circle
52  * @param p Data to fill if there is a collision
53  * @return True if there is a collision
54  */
55  GF_API bool collides(const CircF& lhs, const CircF& rhs, Penetration& p);
56 
57  /**
58  * @relates Penetration
59  * @brief Check if a rectangle collides with a circle
60  *
61  * @param lhs The rectangle
62  * @param rhs The circle
63  * @param p Data to fill if there is a collision
64  * @return True if there is a collision
65  */
66  GF_API bool collides(const RectF& lhs, const CircF& rhs, Penetration& p);
67 
68  /**
69  * @relates Penetration
70  * @brief Check if a circle collides with a rectangle
71  *
72  * @param lhs The circle
73  * @param rhs The rectangle
74  * @param p Data to fill if there is a collision
75  * @return True if there is a collision
76  */
77  GF_API bool collides(const CircF& lhs, const RectF& rhs, Penetration& p);
78 
79  /**
80  * @relates Penetration
81  * @brief Check if two rectangles collides
82  *
83  * @param lhs First rectangle
84  * @param rhs Second rectangle
85  * @param p Data to fill if there is a collision
86  * @return True if there is a collision
87  */
88  GF_API bool collides(const RectF& lhs, const RectF& rhs, Penetration& p);
89 
90  /**
91  * @relates Penetration
92  * @brief Check if two polygons collides
93  *
94  * @param lhs First polygon
95  * @param rhs Second polygon
96  * @param p Data to fill if there is a collision
97  * @return True if there is a collision
98  */
99  GF_API bool collides(const Polygon& lhs, const Polygon& rhs, Penetration& p);
100 
101 #ifndef DOXYGEN_SHOULD_SKIP_THIS
102 }
103 #endif
104 }
105 
106 #endif // GF_COLLISION_H
bool collides(const Polygon &lhs, const Polygon &rhs, Penetration &p)
Check if two polygons collides.
bool collides(const CircF &lhs, const RectF &rhs, Penetration &p)
Check if a circle collides with a rectangle.
Vector2f normal
Collision normal.
Definition: Collision.h:42
bool collides(const CircF &lhs, const CircF &rhs, Penetration &p)
Check if two circles collides.
Definition: Action.h:34
float depth
Penetration depth.
Definition: Collision.h:43
A convex polygon.
Definition: Polygon.h:40
Data about the collision between two objects.
Definition: Collision.h:41
bool collides(const RectF &lhs, const CircF &rhs, Penetration &p)
Check if a rectangle collides with a circle.
#define GF_API
Definition: Portability.h:35
bool collides(const RectF &lhs, const RectF &rhs, Penetration &p)
Check if two rectangles collides.