FIFE  2008.0
 All Classes Namespaces Functions Variables Enumerations Enumerator Pages
cellgrid.h
1 /***************************************************************************
2  * Copyright (C) 2005-2008 by the FIFE team *
3  * http://www.fifengine.de *
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:
45  CellGrid(bool allow_diagonals=false);
46 
49  virtual ~CellGrid();
50 
56  void getAccessibleCoordinates(const ModelCoordinate& curpos, std::vector<ModelCoordinate>& coordinates);
57 
60  virtual const std::string& getType() const = 0;
61 
64  virtual const std::string& getName() const = 0;
65 
72  virtual bool isAccessible(const ModelCoordinate& curpos, const ModelCoordinate& target) = 0;
73 
80  virtual double getAdjacentCost(const ModelCoordinate& curpos, const ModelCoordinate& target) = 0;
81 
85  virtual uint32_t getCellSideCount() const = 0;
86 
90  ExactModelCoordinate toMapCoordinates(const ModelCoordinate& layer_coords);
91 
95  virtual ExactModelCoordinate toMapCoordinates(const ExactModelCoordinate& layer_coords) = 0;
96 
100  virtual ModelCoordinate toLayerCoordinates(const ExactModelCoordinate& map_coord) = 0;
101 
105  virtual ExactModelCoordinate toExactLayerCoordinates(const ExactModelCoordinate& map_coord) = 0;
106 
111  virtual void getVertices(std::vector<ExactModelCoordinate>& vtx, const ModelCoordinate& cell) = 0;
112 
116  void setXShift(const double& xshift) {
117  m_xshift = xshift;
118  updateMatrices();
119  }
120 
124  const double getXShift() const { return m_xshift; }
125 
129  void setYShift(const double yshift) {
130  m_yshift = yshift;
131  updateMatrices();
132  }
133 
137  const double getYShift() const { return m_yshift; }
138 
142  void setZShift(const double zshift) {
143  m_zshift = zshift;
144  updateMatrices();
145  }
146 
150  const double getZShift() const { return m_zshift; }
151 
155  void setXScale(const double scale) {
156  m_xscale = scale;
157  updateMatrices();
158  }
159 
163  void setYScale(const double scale) {
164  m_yscale = scale;
165  updateMatrices();
166  }
167 
171  const double getXScale() const { return m_xscale; }
172 
176  const double getYScale() const { return m_yscale; }
177 
181  void setRotation(const double rotation) {
182  m_rotation = rotation;
183  updateMatrices();
184  }
185 
189  const double getRotation() const { return m_rotation; }
190 
193  virtual CellGrid* clone() = 0;
194 
195  protected:
196  void updateMatrices();
197  bool ptInTriangle(const ExactModelCoordinate& pt, const ExactModelCoordinate& pt1, const ExactModelCoordinate& pt2, const ExactModelCoordinate& pt3);
198 
199  DoubleMatrix m_matrix;
200  DoubleMatrix m_inverse_matrix;
201  double m_xshift;
202  double m_yshift;
203  double m_zshift;
204  double m_xscale;
205  double m_yscale;
206  double m_rotation;
207  bool m_allow_diagonals;
208 
209  private:
210  int32_t orientation(const ExactModelCoordinate& pt, const ExactModelCoordinate& pt1, const ExactModelCoordinate& pt2);
211  };
212 }
213 
214 #endif