FIFE  be64c707dea6b3250bd4355bf5c825d25920087d
cellgrid.h
Go to the documentation of this file.
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
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:
44  CellGrid();
45 
48  virtual ~CellGrid();
49 
55  void getAccessibleCoordinates(const ModelCoordinate& curpos, std::vector<ModelCoordinate>& coordinates);
56 
59  virtual const std::string& getType() const = 0;
60 
63  virtual const std::string& getName() const = 0;
64 
71  virtual bool isAccessible(const ModelCoordinate& curpos, const ModelCoordinate& target) = 0;
72 
79  virtual double getAdjacentCost(const ModelCoordinate& curpos, const ModelCoordinate& target) = 0;
80 
86  virtual double getHeuristicCost(const ModelCoordinate& curpos, const ModelCoordinate& target) = 0;
87 
91  virtual uint32_t getCellSideCount() const = 0;
92 
97 
101  virtual ExactModelCoordinate toMapCoordinates(const ExactModelCoordinate& layer_coords) = 0;
102 
106  virtual ModelCoordinate toLayerCoordinates(const ExactModelCoordinate& map_coord) = 0;
107 
112 
117 
122  virtual void getVertices(std::vector<ExactModelCoordinate>& vtx, const ModelCoordinate& cell) = 0;
123 
129  virtual std::vector<ModelCoordinate> toMultiCoordinates(const ModelCoordinate& position,
130  const std::vector<ModelCoordinate>& orig, bool reverse = false) = 0;
131 
137  virtual std::vector<ModelCoordinate> getCoordinatesInLine(const ModelCoordinate& start, const ModelCoordinate& end) = 0;
138 
142  void setXShift(const double& xshift) {
143  m_xshift = xshift;
144  updateMatrices();
145  }
146 
150  const double getXShift() const { return m_xshift; }
151 
155  void setYShift(const double yshift) {
156  m_yshift = yshift;
157  updateMatrices();
158  }
159 
163  const double getYShift() const { return m_yshift; }
164 
168  void setZShift(const double zshift) {
169  m_zshift = zshift;
170  updateMatrices();
171  }
172 
176  const double getZShift() const { return m_zshift; }
177 
181  void setXScale(const double scale) {
182  m_xscale = scale;
183  updateMatrices();
184  }
185 
189  void setYScale(const double scale) {
190  m_yscale = scale;
191  updateMatrices();
192  }
193 
197  void setZScale(const double scale) {
198  m_zscale = scale;
199  updateMatrices();
200  }
201 
205  const double getXScale() const { return m_xscale; }
206 
210  const double getYScale() const { return m_yscale; }
211 
215  const double getZScale() const { return m_zscale; }
216 
220  void setRotation(const double rotation) {
221  m_rotation = rotation;
222  updateMatrices();
223  }
224 
228  const double getRotation() const { return m_rotation; }
229 
233  void setAllowDiagonals(const bool allow_diagonals) {
234  m_allow_diagonals = allow_diagonals;
235  }
236 
240  const bool getAllowDiagonals() const { return m_allow_diagonals; }
241 
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 
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;
260 
261  private:
262  int32_t orientation(const ExactModelCoordinate& pt, const ExactModelCoordinate& pt1, const ExactModelCoordinate& pt2);
263  };
264 }
265 
266 #endif
void setZScale(const double scale)
Set the cellgrid z-scaling.
Definition: cellgrid.h:197
virtual double getAdjacentCost(const ModelCoordinate &curpos, const ModelCoordinate &target)=0
Returns distance const from curpos to target point only cells adjacent to curpos are considered in th...
double m_xscale
Definition: cellgrid.h:255
virtual std::vector< ModelCoordinate > toMultiCoordinates(const ModelCoordinate &position, const std::vector< ModelCoordinate > &orig, bool reverse=false)=0
Returns point vector with coordinates for a multi object.
const double getYShift() const
Get the cellgrid y shift.
Definition: cellgrid.h:163
double m_zscale
Definition: cellgrid.h:257
virtual ~CellGrid()
Destructor.
Definition: cellgrid.cpp:53
void setZShift(const double zshift)
Set the cellgrid z shift.
Definition: cellgrid.h:168
double m_yshift
Definition: cellgrid.h:253
Base class for all fife classes Used e.g.
Definition: fifeclass.h:42
virtual const std::string & getType() const =0
Type of cellgrid.
DoubleMatrix m_inverse_matrix
Definition: cellgrid.h:251
void setXShift(const double &xshift)
Set the cellgrid x shift.
Definition: cellgrid.h:142
void setYScale(const double scale)
Set the cellgrid y-scaling.
Definition: cellgrid.h:189
const double getZShift() const
Get the cellgrid z shift.
Definition: cellgrid.h:176
void setXScale(const double scale)
Set the cellgrid x-scaling.
Definition: cellgrid.h:181
virtual void getVertices(std::vector< ExactModelCoordinate > &vtx, const ModelCoordinate &cell)=0
Fills given point vector with vertices from selected cell.
const double getRotation() const
Get the cellgrid rotation.
Definition: cellgrid.h:228
virtual double getHeuristicCost(const ModelCoordinate &curpos, const ModelCoordinate &target)=0
Returns distance const from curpos to target point.
void setYShift(const double yshift)
Set the cellgrid y shift.
Definition: cellgrid.h:155
bool m_allow_diagonals
Definition: cellgrid.h:259
double m_rotation
Definition: cellgrid.h:258
const bool getAllowDiagonals() const
Get whether diagonal cell access is allowed.
Definition: cellgrid.h:240
DoubleMatrix m_matrix
Definition: cellgrid.h:250
const double getXShift() const
Get the cellgrid x shift.
Definition: cellgrid.h:150
void setAllowDiagonals(const bool allow_diagonals)
Set whether diagonal cell access is allowed.
Definition: cellgrid.h:233
void updateMatrices()
Definition: cellgrid.cpp:68
const double getXScale() const
Get the cellgrid x-scaling.
Definition: cellgrid.h:205
double m_zshift
Definition: cellgrid.h:254
const double getYScale() const
Get the cellgrid y-scaling.
Definition: cellgrid.h:210
A 3D Point.
Definition: point.h:205
virtual CellGrid * clone()=0
Returns clone of this cellgrid.
double m_yscale
Definition: cellgrid.h:256
int32_t orientation(const ExactModelCoordinate &pt, const ExactModelCoordinate &pt1, const ExactModelCoordinate &pt2)
Definition: cellgrid.cpp:79
virtual const std::string & getName() const =0
Name of the cellgrid (DEPRECATED? -jwt)
const double getZScale() const
Get the cellgrid z-scaling.
Definition: cellgrid.h:215
void setRotation(const double rotation)
Set the cellgrid rotation.
Definition: cellgrid.h:220
virtual uint32_t getCellSideCount() const =0
Gets the count of sides for a single cell.
CellGrid()
Constructor.
Definition: cellgrid.cpp:38
virtual std::vector< ModelCoordinate > getCoordinatesInLine(const ModelCoordinate &start, const ModelCoordinate &end)=0
Returns point vector with coordinates for a line from start to end.
double m_xshift
Definition: cellgrid.h:252
void getAccessibleCoordinates(const ModelCoordinate &curpos, std::vector< ModelCoordinate > &coordinates)
Gets the coordinates that are accesible from given point only cells adjacent to given cell are consid...
Definition: cellgrid.cpp:56
unsigned int uint32_t
Definition: core.h:40
ExactModelCoordinate toMapCoordinates(const ModelCoordinate &layer_coords)
Transforms given point from layer coordinates to map coordinates.
Definition: cellgrid.cpp:75
virtual ExactModelCoordinate toExactLayerCoordinates(const ExactModelCoordinate &map_coord)=0
Transforms given point from map coordinates to layer coordinates.
bool ptInTriangle(const ExactModelCoordinate &pt, const ExactModelCoordinate &pt1, const ExactModelCoordinate &pt2, const ExactModelCoordinate &pt3)
Definition: cellgrid.cpp:89
virtual bool isAccessible(const ModelCoordinate &curpos, const ModelCoordinate &target)=0
Tells if given target point is accessible from curpos only cells adjacent to curpos are considered in...
virtual ModelCoordinate toLayerCoordinatesFromExactLayerCoordinates(const ExactModelCoordinate &exact_layer_coords)=0
Transforms given point from exact layer coordinates to cell precision layer coordinates.
virtual ModelCoordinate toLayerCoordinates(const ExactModelCoordinate &map_coord)=0
Transforms given point from map coordinates to layer coordinates.