Debian Codegraph @

engine/core/model/metamodel/grids/cellgrid.h

raw
1 /***************************************************************************
2 * Copyright (C) 2005-2019 by the FIFE team *
3 * http://www.fifengine.net *
4 * This file is part of FIFE. *
5 * *
6 * FIFE is free software; you can redistribute it and/or *
7 * modify it under the terms of the GNU Lesser General Public *
8 * License as published by the Free Software Foundation; either *
9 * version 2.1 of the License, or (at your option) any later version. *
10 * *
11 * This library is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
14 * Lesser General Public License for more details. *
15 * *
16 * You should have received a copy of the GNU Lesser General Public *
17 * License along with this library; if not, write to the *
18 * Free Software Foundation, Inc., *
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
20 ***************************************************************************/
21
22 #ifndef FIFE_MODEL_GRIDS_CELLGRID_H
23 #define FIFE_MODEL_GRIDS_CELLGRID_H
24
25 // Standard C++ library includes
26 #include <vector>
27
28 // 3rd party library includes
29
30 // FIFE includes
31 // These includes are split up in two parts, separated by one empty line
32 // First block: files included from the FIFE root src directory
33 // Second block: files included from the same folder
34 #include "model/metamodel/modelcoords.h"
35 #include "util/math/matrix.h"
36 #include "util/base/fifeclass.h"
37 #include "util/base/fife_stdint.h"
38
39 namespace FIFE {
40 class CellGrid: public FifeClass {
41 public:
42 /** Constructor
43 */
44 CellGrid();
45
46 /** Destructor
47 */
48 virtual ~CellGrid();
49
50 /** Gets the coordinates that are accesible from given point
51 * only cells adjacent to given cell are considered in the evaluation
52 * @param curpos position (coordinates) to evaluate
53 * @param coordinates accessible coordinates
54 */
55 void getAccessibleCoordinates(const ModelCoordinate& curpos, std::vector<ModelCoordinate>& coordinates);
56
57 /** Type of cellgrid
58 */
59 virtual const std::string& getType() const = 0;
60
61 /** Name of the cellgrid (DEPRECATED? -jwt)
62 */
63 virtual const std::string& getName() const = 0;
64
65 /** Tells if given target point is accessible from curpos
66 * only cells adjacent to curpos are considered in the evaluation
67 * @param curpos position (coordinates) to evaluate
68 * @param target target coordinate to check
69 * @return true, if target is accessible from curpos, false otherwise
70 */
71 virtual bool isAccessible(const ModelCoordinate& curpos, const ModelCoordinate& target) = 0;
72
73 /** Returns *distance* const from curpos to target point
74 * only cells adjacent to curpos are considered in the evaluation
75 * @param curpos position (coordinates) to evaluate
76 * @param target target coordinate to check
77 * @return distance cost from curpos to target
78 */
79 virtual double getAdjacentCost(const ModelCoordinate& curpos, const ModelCoordinate& target) = 0;
80
81 /** Returns *distance* const from curpos to target point
82 * @param curpos position (coordinates) to evaluate
83 * @param target target coordinate to check
84 * @return distance cost from curpos to target
85 */
86 virtual double getHeuristicCost(const ModelCoordinate& curpos, const ModelCoordinate& target) = 0;
87
88 /** Gets the count of sides for a single cell
89 * @return count of sides for a single cell
90 */
91 virtual uint32_t getCellSideCount() const = 0;
92
93 /** Transforms given point from layer coordinates to map coordinates
94 * @return point in map coordinates
95 */
96 ExactModelCoordinate toMapCoordinates(const ModelCoordinate& layer_coords);
97
98 /** Transforms given point from layer coordinates to map coordinates
99 * @return point in map coordinates
100 */
101 virtual ExactModelCoordinate toMapCoordinates(const ExactModelCoordinate& layer_coords) = 0;
102
103 /** Transforms given point from map coordinates to layer coordinates
104 * @return point in layer coordinates
105 */
106 virtual ModelCoordinate toLayerCoordinates(const ExactModelCoordinate& map_coord) = 0;
107
108 /** Transforms given point from map coordinates to layer coordinates
109 * @return point in layer coordinates
110 */
111 virtual ExactModelCoordinate toExactLayerCoordinates(const ExactModelCoordinate& map_coord) = 0;
112
113 /** Transforms given point from exact layer coordinates to cell precision layer coordinates
114 * @return point in layer coordinates
115 */
116 virtual ModelCoordinate toLayerCoordinatesFromExactLayerCoordinates(const ExactModelCoordinate& exact_layer_coords) = 0;
117
118 /** Fills given point vector with vertices from selected cell
119 * @param vtx vertices for given cell
120 * @param cell cell to get vertices from
121 */
122 virtual void getVertices(std::vector<ExactModelCoordinate>& vtx, const ModelCoordinate& cell) = 0;
123
124 /** Returns point vector with coordinates for a multi object
125 * @param position The center position
126 * @param orig The vector with the original coordinates from object
127 * @param reverse If true the orig coordinates are subtracted otherwise they are added
128 */
129 virtual std::vector<ModelCoordinate> toMultiCoordinates(const ModelCoordinate& position,
130 const std::vector<ModelCoordinate>& orig, bool reverse = false) = 0;
131
132 /** Returns point vector with coordinates for a line from start to end.
133 * @param start The start position
134 * @param end The end position
135 * @return vector with points
136 */
137 virtual std::vector<ModelCoordinate> getCoordinatesInLine(const ModelCoordinate& start, const ModelCoordinate& end) = 0;
138
139 /** Set the cellgrid x shift
140 * @param xshift The shift in map coords
141 */
142 void setXShift(const double& xshift) {
143 m_xshift = xshift;
144 updateMatrices();
145 }
146
147 /** Get the cellgrid x shift
148 * @return The x shift
149 */
150 const double getXShift() const { return m_xshift; }
151
152 /** Set the cellgrid y shift
153 * @param yshift The shift in map coords
154 */
155 void setYShift(const double yshift) {
156 m_yshift = yshift;
157 updateMatrices();
158 }
159
160 /** Get the cellgrid y shift
161 * @return The y shift in map coords
162 */
163 const double getYShift() const { return m_yshift; }
164
165 /** Set the cellgrid z shift
166 * @param zshift The shift in map coords
167 */
168 void setZShift(const double zshift) {
169 m_zshift = zshift;
170 updateMatrices();
171 }
172
173 /** Get the cellgrid z shift
174 * @return The z shift in map coords
175 */
176 const double getZShift() const { return m_zshift; }
177
178 /** Set the cellgrid x-scaling
179 * @param scale The x-scale of cellgrid
180 */
181 void setXScale(const double scale) {
182 m_xscale = scale;
183 updateMatrices();
184 }
185
186 /** Set the cellgrid y-scaling
187 * @param scale The y-scale of cellgrid
188 */
189 void setYScale(const double scale) {
190 m_yscale = scale;
191 updateMatrices();
192 }
193
194 /** Set the cellgrid z-scaling
195 * @param scale The z-scale of cellgrid
196 */
197 void setZScale(const double scale) {
198 m_zscale = scale;
199 updateMatrices();
200 }
201
202 /** Get the cellgrid x-scaling
203 * @return The x-scale of cellgrid
204 */
205 const double getXScale() const { return m_xscale; }
206
207 /** Get the cellgrid y-scaling
208 * @return The y-scale of cellgrid
209 */
210 const double getYScale() const { return m_yscale; }
211
212 /** Get the cellgrid z-scaling
213 * @return The z-scale of cellgrid
214 */
215 const double getZScale() const { return m_zscale; }
216
217 /** Set the cellgrid rotation
218 * @param rotation The rotation of the cellgrid
219 */
220 void setRotation(const double rotation) {
221 m_rotation = rotation;
222 updateMatrices();
223 }
224
225 /** Get the cellgrid rotation
226 * @return rotation The rotation of the cellgrid
227 */
228 const double getRotation() const { return m_rotation; }
229
230 /** Set whether diagonal cell access is allowed
231 * @param allow_diagonals True if diagonal access allowed, false if only cell edges allowed
232 */
233 void setAllowDiagonals(const bool allow_diagonals) {
234 m_allow_diagonals = allow_diagonals;
235 }
236
237 /** Get whether diagonal cell access is allowed
238 * @return True if diagonal access allowed, false if only cell edges allowed
239 */
240 const bool getAllowDiagonals() const { return m_allow_diagonals; }
241
242 /** Returns clone of this cellgrid
243 */
244 virtual CellGrid* clone() = 0;
245
246 protected:
247 void updateMatrices();
248 bool ptInTriangle(const ExactModelCoordinate& pt, const ExactModelCoordinate& pt1, const ExactModelCoordinate& pt2, const ExactModelCoordinate& pt3);
249
250 DoubleMatrix m_matrix;
251 DoubleMatrix m_inverse_matrix;
252 double m_xshift;
253 double m_yshift;
254 double m_zshift;
255 double m_xscale;
256 double m_yscale;
257 double m_zscale;
258 double m_rotation;
259 bool m_allow_diagonals;
260
261 private:
262 int32_t orientation(const ExactModelCoordinate& pt, const ExactModelCoordinate& pt1, const ExactModelCoordinate& pt2);
263 };
264 }
265
266 #endif