FIFE
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
cellgrid.h
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2005-2013 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  virtual void getVertices(std::vector<ExactModelCoordinate>& vtx, const ModelCoordinate& cell) = 0;
118 
124  virtual std::vector<ModelCoordinate> toMultiCoordinates(const ModelCoordinate& position,
125  const std::vector<ModelCoordinate>& orig, bool reverse = false) = 0;
126 
132  virtual std::vector<ModelCoordinate> getCoordinatesInLine(const ModelCoordinate& start, const ModelCoordinate& end) = 0;
133 
137  void setXShift(const double& xshift) {
138  m_xshift = xshift;
139  updateMatrices();
140  }
141 
145  const double getXShift() const { return m_xshift; }
146 
150  void setYShift(const double yshift) {
151  m_yshift = yshift;
152  updateMatrices();
153  }
154 
158  const double getYShift() const { return m_yshift; }
159 
163  void setZShift(const double zshift) {
164  m_zshift = zshift;
165  updateMatrices();
166  }
167 
171  const double getZShift() const { return m_zshift; }
172 
176  void setXScale(const double scale) {
177  m_xscale = scale;
178  updateMatrices();
179  }
180 
184  void setYScale(const double scale) {
185  m_yscale = scale;
186  updateMatrices();
187  }
188 
192  void setZScale(const double scale) {
193  m_zscale = scale;
194  updateMatrices();
195  }
196 
200  const double getXScale() const { return m_xscale; }
201 
205  const double getYScale() const { return m_yscale; }
206 
210  const double getZScale() const { return m_zscale; }
211 
215  void setRotation(const double rotation) {
216  m_rotation = rotation;
217  updateMatrices();
218  }
219 
223  const double getRotation() const { return m_rotation; }
224 
228  void setAllowDiagonals(const bool allow_diagonals) {
229  m_allow_diagonals = allow_diagonals;
230  }
231 
235  const bool getAllowDiagonals() const { return m_allow_diagonals; }
236 
239  virtual CellGrid* clone() = 0;
240 
241  protected:
242  void updateMatrices();
243  bool ptInTriangle(const ExactModelCoordinate& pt, const ExactModelCoordinate& pt1, const ExactModelCoordinate& pt2, const ExactModelCoordinate& pt3);
244 
247  double m_xshift;
248  double m_yshift;
249  double m_zshift;
250  double m_xscale;
251  double m_yscale;
252  double m_zscale;
253  double m_rotation;
255 
256  private:
257  int32_t orientation(const ExactModelCoordinate& pt, const ExactModelCoordinate& pt1, const ExactModelCoordinate& pt2);
258  };
259 }
260 
261 #endif
void setZScale(const double scale)
Set the cellgrid z-scaling.
Definition: cellgrid.h:192
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:250
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.
double m_zscale
Definition: cellgrid.h:252
virtual ~CellGrid()
Destructor.
Definition: cellgrid.cpp:53
void setZShift(const double zshift)
Set the cellgrid z shift.
Definition: cellgrid.h:163
double m_yshift
Definition: cellgrid.h:248
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:246
void setXShift(const double &xshift)
Set the cellgrid x shift.
Definition: cellgrid.h:137
void setYScale(const double scale)
Set the cellgrid y-scaling.
Definition: cellgrid.h:184
void setXScale(const double scale)
Set the cellgrid x-scaling.
Definition: cellgrid.h:176
virtual void getVertices(std::vector< ExactModelCoordinate > &vtx, const ModelCoordinate &cell)=0
Fills given point vector with vertices from selected cell.
const double getZShift() const
Get the cellgrid z shift.
Definition: cellgrid.h:171
const double getYScale() const
Get the cellgrid y-scaling.
Definition: cellgrid.h:205
const bool getAllowDiagonals() const
Get whether diagonal cell access is allowed.
Definition: cellgrid.h:235
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:150
bool m_allow_diagonals
Definition: cellgrid.h:254
double m_rotation
Definition: cellgrid.h:253
DoubleMatrix m_matrix
Definition: cellgrid.h:245
const double getXScale() const
Get the cellgrid x-scaling.
Definition: cellgrid.h:200
const double getRotation() const
Get the cellgrid rotation.
Definition: cellgrid.h:223
const double getZScale() const
Get the cellgrid z-scaling.
Definition: cellgrid.h:210
const double getXShift() const
Get the cellgrid x shift.
Definition: cellgrid.h:145
void setAllowDiagonals(const bool allow_diagonals)
Set whether diagonal cell access is allowed.
Definition: cellgrid.h:228
void updateMatrices()
Definition: cellgrid.cpp:68
double m_zshift
Definition: cellgrid.h:249
A 3D Point.
Definition: point.h:202
virtual CellGrid * clone()=0
Returns clone of this cellgrid.
double m_yscale
Definition: cellgrid.h:251
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)
void setRotation(const double rotation)
Set the cellgrid rotation.
Definition: cellgrid.h:215
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:247
const double getYShift() const
Get the cellgrid y shift.
Definition: cellgrid.h:158
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 toLayerCoordinates(const ExactModelCoordinate &map_coord)=0
Transforms given point from map coordinates to layer coordinates.