Gamedev Framework (gf)  0.3.0
A C++11 framework for 2D games
Orientation.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_DIRECTION_H
22 #define GF_DIRECTION_H
23 
24 #include "Portability.h"
25 #include "Vector.h"
26 
27 namespace gf {
28 #ifndef DOXYGEN_SHOULD_SKIP_THIS
29 inline namespace v1 {
30 #endif
31 
32  /**
33  * @ingroup core
34  * @brief Cardinal and ordinal orientation
35  *
36  * gf::Orientation represents one the four cardinal orientations and the
37  * four ordinal (or intercardinal) orientations. A special value is added to
38  * represent the center, it indicates no orientation.
39  *
40  * @sa gf::Direction
41  */
42  enum class Orientation : int {
43  Center = -1, ///< The center, indicates no orientation
44  North = 0, ///< The north orientation
45  NorthEast = 1, ///< The north-east orientation
46  East = 2, ///< The east orientation
47  SouthEast = 3, ///< The south-east orientation
48  South = 4, ///< The south orientation
49  SouthWest = 5, ///< The south-west orientation
50  West = 6, ///< The west orientation
51  NorthWest = 7, ///< The north-west orientation
52  };
53 
54 
55  /**
56  * @ingroup core
57  * @brief Get a unit vector from an orientation
58  *
59  * @param orientation The orientation
60  * @returns A unit vector representing the orientation
61  */
62  GF_API Vector2f unit(Orientation orientation);
63 
64  /**
65  * @ingroup core
66  * @brief Get a vector from an orientation
67  *
68  * The vector has its coordinates at -1, 0 or 1 depending on the orientation.
69  * It can be used to represent the displacement on a grid in the given
70  * orientation.
71  *
72  * @param orientation The orientation
73  * @returns A vector representing the orientation
74  */
75  GF_API Vector2i displacement(Orientation orientation);
76 
77  /**
78  * @ingroup core
79  * @brief Get an angle from a orientation
80  *
81  * North is at angle 0 and angle grows clockwise.
82  *
83  * @param orientation The orientation
84  * @returns an angle (in radians) representing the orientation
85  */
86  GF_API float angle(Orientation orientation);
87 
88  /**
89  * @ingroup core
90  * @brief Get the opposite orientation
91  *
92  * @param orientation The orientation
93  * @return The opposite orientation
94  */
96 
97  /**
98  * @ingroup core
99  * @brief Get the orthogonal orientation clockwise
100  *
101  * @param orientation The orientation
102  * @return The orthogonal orientation clockwise
103  */
105 
106  /**
107  * @ingroup core
108  * @brief Get the orthogonal orientation counter-clockwise
109  *
110  * @param orientation The orientation
111  * @return The orthogonal orientation counter-clockwise
112  */
114 
115  /**
116  * @ingroup core
117  * @brief Get the next orientation clockwise
118  *
119  * @param orientation The orientation
120  * @return The next orientation clockwise
121  */
122  GF_API Orientation nextCW(Orientation orientation);
123 
124  /**
125  * @ingroup core
126  * @brief Get the next orientation counter-clockwise
127  *
128  * @param orientation The orientation
129  * @return The next orientation counter-clockwise
130  */
131  GF_API Orientation nextCCW(Orientation orientation);
132 
133 #ifndef DOXYGEN_SHOULD_SKIP_THIS
134 }
135 #endif
136 }
137 
138 
139 #endif // GF_DIRECTION_H
Orientation nextCW(Orientation orientation)
Get the next orientation clockwise.
Orientation nextCCW(Orientation orientation)
Get the next orientation counter-clockwise.
Orientation opposite(Orientation orientation)
Get the opposite orientation.
The south orientation.
The center, indicates no orientation.
The south-west orientation.
The north-east orientation.
The south-east orientation.
Definition: Action.h:34
The east orientation.
The west orientation.
Orientation orthogonalCW(Orientation orientation)
Get the orthogonal orientation clockwise.
Orientation orthogonalCCW(Orientation orientation)
Get the orthogonal orientation counter-clockwise.
The north orientation.
Orientation
Cardinal and ordinal orientation.
Definition: Orientation.h:42
#define GF_API
Definition: Portability.h:35
float angle(Orientation orientation)
Get an angle from a orientation.
The north-west orientation.
Vector2i displacement(Orientation orientation)
Get a vector from an orientation.
Vector2f unit(Orientation orientation)
Get a unit vector from an orientation.