FIFE
2008.0
|
00001 /*************************************************************************** 00002 * Copyright (C) 2005-2008 by the FIFE team * 00003 * http://www.fifengine.de * 00004 * This file is part of FIFE. * 00005 * * 00006 * FIFE is free software; you can redistribute it and/or * 00007 * modify it under the terms of the GNU Lesser General Public * 00008 * License as published by the Free Software Foundation; either * 00009 * version 2.1 of the License, or (at your option) any later version. * 00010 * * 00011 * This library is distributed in the hope that it will be useful, * 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * 00014 * Lesser General Public License for more details. * 00015 * * 00016 * You should have received a copy of the GNU Lesser General Public * 00017 * License along with this library; if not, write to the * 00018 * Free Software Foundation, Inc., * 00019 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * 00020 ***************************************************************************/ 00021 00022 #ifndef FIFE_MODEL_GRIDS_CELLGRID_H 00023 #define FIFE_MODEL_GRIDS_CELLGRID_H 00024 00025 // Standard C++ library includes 00026 #include <vector> 00027 00028 // 3rd party library includes 00029 00030 // FIFE includes 00031 // These includes are split up in two parts, separated by one empty line 00032 // First block: files included from the FIFE root src directory 00033 // Second block: files included from the same folder 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