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 #include "util/base/fife_stdint.h"
00038
00039 namespace FIFE {
00040 class CellGrid: public FifeClass {
00041 public:
00045 CellGrid(bool allow_diagonals=false);
00046
00049 virtual ~CellGrid();
00050
00056 void getAccessibleCoordinates(const ModelCoordinate& curpos, std::vector<ModelCoordinate>& coordinates);
00057
00060 virtual const std::string& getType() const = 0;
00061
00064 virtual const std::string& getName() const = 0;
00065
00072 virtual bool isAccessible(const ModelCoordinate& curpos, const ModelCoordinate& target) = 0;
00073
00080 virtual double getAdjacentCost(const ModelCoordinate& curpos, const ModelCoordinate& target) = 0;
00081
00085 virtual uint32_t getCellSideCount() const = 0;
00086
00090 ExactModelCoordinate toMapCoordinates(const ModelCoordinate& layer_coords);
00091
00095 virtual ExactModelCoordinate toMapCoordinates(const ExactModelCoordinate& layer_coords) = 0;
00096
00100 virtual ModelCoordinate toLayerCoordinates(const ExactModelCoordinate& map_coord) = 0;
00101
00105 virtual ExactModelCoordinate toExactLayerCoordinates(const ExactModelCoordinate& map_coord) = 0;
00106
00111 virtual void getVertices(std::vector<ExactModelCoordinate>& vtx, const ModelCoordinate& cell) = 0;
00112
00116 void setXShift(const double& xshift) {
00117 m_xshift = xshift;
00118 updateMatrices();
00119 }
00120
00124 const double getXShift() const { return m_xshift; }
00125
00129 void setYShift(const double yshift) {
00130 m_yshift = yshift;
00131 updateMatrices();
00132 }
00133
00137 const double getYShift() const { return m_yshift; }
00138
00142 void setZShift(const double zshift) {
00143 m_zshift = zshift;
00144 updateMatrices();
00145 }
00146
00150 const double getZShift() const { return m_zshift; }
00151
00155 void setXScale(const double scale) {
00156 m_xscale = scale;
00157 updateMatrices();
00158 }
00159
00163 void setYScale(const double scale) {
00164 m_yscale = scale;
00165 updateMatrices();
00166 }
00167
00171 const double getXScale() const { return m_xscale; }
00172
00176 const double getYScale() const { return m_yscale; }
00177
00181 void setRotation(const double rotation) {
00182 m_rotation = rotation;
00183 updateMatrices();
00184 }
00185
00189 const double getRotation() const { return m_rotation; }
00190
00194 void setAllowDiagonals(const bool allow_diagonals) {
00195 m_allow_diagonals = allow_diagonals;
00196 }
00197
00201 const bool getAllowDiagonals() const { return m_allow_diagonals; }
00202
00205 virtual CellGrid* clone() = 0;
00206
00207 protected:
00208 void updateMatrices();
00209 bool ptInTriangle(const ExactModelCoordinate& pt, const ExactModelCoordinate& pt1, const ExactModelCoordinate& pt2, const ExactModelCoordinate& pt3);
00210
00211 DoubleMatrix m_matrix;
00212 DoubleMatrix m_inverse_matrix;
00213 double m_xshift;
00214 double m_yshift;
00215 double m_zshift;
00216 double m_xscale;
00217 double m_yscale;
00218 double m_rotation;
00219 bool m_allow_diagonals;
00220
00221 private:
00222 int32_t orientation(const ExactModelCoordinate& pt, const ExactModelCoordinate& pt1, const ExactModelCoordinate& pt2);
00223 };
00224 }
00225
00226 #endif