Gamedev Framework (gf)  0.3.0
A C++11 framework for 2D games
Direction.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 Main four directions
35  *
36  * gf::Direction represents one of the four main directions. A special value
37  * is added to represent the center, it indicates no direction.
38  *
39  * @sa gf::Orientation
40  */
41  enum class Direction : int {
42  Center = -1, ///< The center, indicates no direction
43  Up = 0, ///< The up direction
44  Right = 1, ///< The right direction
45  Down = 2, ///< The down direction
46  Left = 3, ///< The left direction
47  };
48 
49  /**
50  * @ingroup core
51  * @brief Get a unit vector from a direction
52  *
53  * @param direction The direction
54  * @returns A unit vector representing the direction
55  */
56  GF_API Vector2f unit(Direction direction);
57 
58  /**
59  * @ingroup core
60  * @brief Get a vector from a direction
61  *
62  * The vector has its coordinates at -1, 0 or 1 depending on the direction.
63  * It can be used to represent the displacement on a grid in the given
64  * direction.
65  *
66  * @param direction The direction
67  * @returns A vector representing the direction
68  */
69  GF_API Vector2i displacement(Direction direction);
70 
71  /**
72  * @ingroup core
73  * @brief Get an angle from a direction
74  *
75  * Up is at angle 0 and angle grows clockwise.
76  *
77  * @param direction The direction
78  * @returns an angle (in radians) representing the direction
79  */
80  GF_API float angle(Direction direction);
81 
82  /**
83  * @ingroup core
84  * @brief Get the opposite direction
85  *
86  * @param direction The direction
87  * @return The opposite direction
88  */
90 
91  /**
92  * @ingroup core
93  * @brief Get the orthogonal direction clockwise
94  *
95  * @param direction The direction
96  * @return The orthogonal direction clockwise
97  */
99 
100  /**
101  * @ingroup core
102  * @brief Get the orthogonal direction counter-clockwise
103  *
104  * @param direction The direction
105  * @return The orthogonal direction counter-clockwise
106  */
108 
109  /**
110  * @ingroup core
111  * @brief Get the next direction clockwise
112  *
113  * @param direction The direction
114  * @return The next direction clockwise
115  */
116  GF_API Direction nextCW(Direction direction);
117 
118  /**
119  * @ingroup core
120  * @brief Get the next direction counter-clockwise
121  *
122  * @param direction The direction
123  * @return The next direction counter-clockwise
124  */
125  GF_API Direction nextCCW(Direction direction);
126 
127 #ifndef DOXYGEN_SHOULD_SKIP_THIS
128 }
129 #endif
130 }
131 
132 #endif // GF_DIRECTION_H
Direction orthogonalCCW(Direction direction)
Get the orthogonal direction counter-clockwise.
Direction
Main four directions.
Definition: Direction.h:41
Vector2i displacement(Direction direction)
Get a vector from a direction.
The down direction.
Direction orthogonalCW(Direction direction)
Get the orthogonal direction clockwise.
Direction nextCCW(Direction direction)
Get the next direction counter-clockwise.
Direction opposite(Direction direction)
Get the opposite direction.
Direction nextCW(Direction direction)
Get the next direction clockwise.
The up direction.
The right direction.
Vector2f unit(Direction direction)
Get a unit vector from a direction.
Definition: Action.h:34
float angle(Direction direction)
Get an angle from a direction.
The left direction.
#define GF_API
Definition: Portability.h:35
The center, indicates no direction.