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 
38 namespace FIFE {
39  class CellGrid: public FifeClass {
40  public:
44  CellGrid(bool allow_diagonals=false);
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 float getAdjacentCost(const ModelCoordinate& curpos, const ModelCoordinate& target) = 0;
80 
84  virtual unsigned int getCellSideCount() const = 0;
85 
89  ExactModelCoordinate toMapCoordinates(const ModelCoordinate& layer_coords);
90 
94  virtual ExactModelCoordinate toMapCoordinates(const ExactModelCoordinate& layer_coords) = 0;
95 
99  virtual ModelCoordinate toLayerCoordinates(const ExactModelCoordinate& map_coord) = 0;
100 
104  virtual ExactModelCoordinate toExactLayerCoordinates(const ExactModelCoordinate& map_coord) = 0;
105 
110  virtual void getVertices(std::vector<ExactModelCoordinate>& vtx, const ModelCoordinate& cell) = 0;
111 
115  void setXShift(const double& xshift) {
116  m_xshift = xshift;
117  updateMatrices();
118  }
119 
123  const double getXShift() const { return m_xshift; }
124 
128  void setYShift(const double yshift) {
129  m_yshift = yshift;
130  updateMatrices();
131  }
132 
136  const double getYShift() const { return m_yshift; }
137 
141  void setXScale(const double scale) {
142  m_xscale = scale;
143  updateMatrices();
144  }
145 
149  void setYScale(const double scale) {
150  m_yscale = scale;
151  updateMatrices();
152  }
153 
157  const double getXScale() const { return m_xscale; }
158 
162  const double getYScale() const { return m_yscale; }
163 
167  void setRotation(const double rotation) {
168  m_rotation = rotation;
169  updateMatrices();
170  }
171 
175  const double getRotation() const { return m_rotation; }
176 
179  virtual CellGrid* clone() = 0;
180 
181  protected:
182  void updateMatrices();
183  bool ptInTriangle(const ExactModelCoordinate& pt, const ExactModelCoordinate& pt1, const ExactModelCoordinate& pt2, const ExactModelCoordinate& pt3);
184 
185  DoubleMatrix m_matrix;
186  DoubleMatrix m_inverse_matrix;
187  double m_xshift;
188  double m_yshift;
189  double m_xscale;
190  double m_yscale;
191  double m_rotation;
192  bool m_allow_diagonals;
193 
194  private:
195  int orientation(const ExactModelCoordinate& pt, const ExactModelCoordinate& pt1, const ExactModelCoordinate& pt2);
196  };
197 }
198 
199 #endif