00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef FIFE_MODEL_GRIDS_CELLGRID_H
00023 #define FIFE_MODEL_GRIDS_CELLGRID_H
00024
00025
00026 #include <vector>
00027
00028
00029
00030
00031
00032
00033
00034 #include "model/metamodel/modelcoords.h"
00035 #include "util/math/matrix.h"
00036 #include "util/base/fifeclass.h"
00037
00038 namespace FIFE {
00039 class CellGrid: public FifeClass {
00040 public:
00044 CellGrid(bool allow_diagonals=false);
00045
00048 virtual ~CellGrid();
00049
00055 void getAccessibleCoordinates(const ModelCoordinate& curpos, std::vector<ModelCoordinate>& coordinates);
00056
00059 virtual const std::string& getType() const = 0;
00060
00063 virtual const std::string& getName() const = 0;
00064
00071 virtual bool isAccessible(const ModelCoordinate& curpos, const ModelCoordinate& target) = 0;
00072
00079 virtual float getAdjacentCost(const ModelCoordinate& curpos, const ModelCoordinate& target) = 0;
00080
00084 virtual unsigned int getCellSideCount() const = 0;
00085
00089 ExactModelCoordinate toMapCoordinates(const ModelCoordinate& layer_coords);
00090
00094 virtual ExactModelCoordinate toMapCoordinates(const ExactModelCoordinate& layer_coords) = 0;
00095
00099 virtual ModelCoordinate toLayerCoordinates(const ExactModelCoordinate& map_coord) = 0;
00100
00104 virtual ExactModelCoordinate toExactLayerCoordinates(const ExactModelCoordinate& map_coord) = 0;
00105
00110 virtual void getVertices(std::vector<ExactModelCoordinate>& vtx, const ModelCoordinate& cell) = 0;
00111
00115 void setXShift(const double& xshift) {
00116 m_xshift = xshift;
00117 updateMatrices();
00118 }
00119
00123 const double getXShift() const { return m_xshift; }
00124
00128 void setYShift(const double yshift) {
00129 m_yshift = yshift;
00130 updateMatrices();
00131 }
00132
00136 const double getYShift() const { return m_yshift; }
00137
00141 void setXScale(const double scale) {
00142 m_xscale = scale;
00143 updateMatrices();
00144 }
00145
00149 void setYScale(const double scale) {
00150 m_yscale = scale;
00151 updateMatrices();
00152 }
00153
00157 const double getXScale() const { return m_xscale; }
00158
00162 const double getYScale() const { return m_yscale; }
00163
00167 void setRotation(const double rotation) {
00168 m_rotation = rotation;
00169 updateMatrices();
00170 }
00171
00175 const double getRotation() const { return m_rotation; }
00176
00179 virtual CellGrid* clone() = 0;
00180
00181 protected:
00182 void updateMatrices();
00183 bool ptInTriangle(const ExactModelCoordinate& pt, const ExactModelCoordinate& pt1, const ExactModelCoordinate& pt2, const ExactModelCoordinate& pt3);
00184
00185 DoubleMatrix m_matrix;
00186 DoubleMatrix m_inverse_matrix;
00187 double m_xshift;
00188 double m_yshift;
00189 double m_xscale;
00190 double m_yscale;
00191 double m_rotation;
00192 bool m_allow_diagonals;
00193
00194 private:
00195 int orientation(const ExactModelCoordinate& pt, const ExactModelCoordinate& pt1, const ExactModelCoordinate& pt2);
00196 };
00197 }
00198
00199 #endif