Mercurial > fife-parpg
comparison engine/core/model/metamodel/grids/cellgrid.h @ 0:4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
author | mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222 |
---|---|
date | Sun, 29 Jun 2008 18:44:17 +0000 |
parents | |
children | 112fc4af772d |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:4a0efb7baf70 |
---|---|
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 modify * | |
7 * it under the terms of the GNU General Public License as published by * | |
8 * the Free Software Foundation; either version 2 of the License, or * | |
9 * (at your option) any later version. * | |
10 * * | |
11 * This program 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 * | |
14 * GNU General Public License for more details. * | |
15 * * | |
16 * You should have received a copy of the GNU General Public License * | |
17 * along with this program; if not, write to the * | |
18 * Free Software Foundation, Inc., * | |
19 * 51 Franklin St, 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: | |
41 /** Constructor | |
42 * @param allow_diagonals if true, cellgrid allows diagonal access | |
43 */ | |
44 CellGrid(bool allow_diagonals=false); | |
45 | |
46 /** Destructor | |
47 */ | |
48 virtual ~CellGrid(); | |
49 | |
50 /** Gets the coordinates that are accesible from given point | |
51 * only cells adjacent to given cell are considered in the evaluation | |
52 * @param curpos position (coordinates) to evaluate | |
53 * @param coordinate accessible coordinates | |
54 */ | |
55 void getAccessibleCoordinates(const ModelCoordinate& curpos, std::vector<ModelCoordinate>& coordinates); | |
56 | |
57 /** Type of cellgrid | |
58 */ | |
59 virtual const std::string& getType() const = 0; | |
60 | |
61 /** Name of the cellgrid (DEPRECATED? -jwt) | |
62 */ | |
63 virtual const std::string& getName() const = 0; | |
64 | |
65 /** Tells if given target point is accessible from curpos | |
66 * only cells adjacent to curpos are considered in the evaluation | |
67 * @param curpos position (coordinates) to evaluate | |
68 * @param target target coordinate to check | |
69 * @return true, if target is accessible from curpos, false otherwise | |
70 */ | |
71 virtual bool isAccessible(const ModelCoordinate& curpos, const ModelCoordinate& target) = 0; | |
72 | |
73 /** Returns *distance* const from curpos to target point | |
74 * only cells adjacent to curpos are considered in the evaluation | |
75 * @param curpos position (coordinates) to evaluate | |
76 * @param target target coordinate to check | |
77 * @return distance cost from curpos to target | |
78 */ | |
79 virtual float getAdjacentCost(const ModelCoordinate& curpos, const ModelCoordinate& target) = 0; | |
80 | |
81 /** Gets the count of sides for a single cell | |
82 * @return count of sides for a single cell | |
83 */ | |
84 virtual unsigned int getCellSideCount() const = 0; | |
85 | |
86 /** Transforms given point from layer coordinates to map coordinates | |
87 * @return point in map coordinates | |
88 */ | |
89 ExactModelCoordinate toMapCoordinates(const ModelCoordinate& layer_coords); | |
90 | |
91 /** Transforms given point from layer coordinates to map coordinates | |
92 * @return point in map coordinates | |
93 */ | |
94 virtual ExactModelCoordinate toMapCoordinates(const ExactModelCoordinate& layer_coords) = 0; | |
95 | |
96 /** Transforms given point from map coordinates to layer coordinates | |
97 * @return point in layer coordinates | |
98 */ | |
99 virtual ModelCoordinate toLayerCoordinates(const ExactModelCoordinate& map_coord) = 0; | |
100 | |
101 /** Transforms given point from map coordinates to layer coordinates | |
102 * @return point in layer coordinates | |
103 */ | |
104 virtual ExactModelCoordinate toExactLayerCoordinates(const ExactModelCoordinate& map_coord) = 0; | |
105 | |
106 /** Fills given point vector with vertices from selected cell | |
107 * @param vtx vertices for given cell | |
108 * @param cell cell to get vertices from | |
109 */ | |
110 virtual void getVertices(std::vector<ExactModelCoordinate>& vtx, const ModelCoordinate& cell) = 0; | |
111 | |
112 /** Set the cellgrid x shift | |
113 * @param shift The shift in map coords | |
114 */ | |
115 void setXShift(const double& xshift) { | |
116 m_xshift = xshift; | |
117 updateMatrices(); | |
118 } | |
119 | |
120 /** Get the cellgrid x shift | |
121 * @return The x shift | |
122 */ | |
123 const double getXShift() const { return m_xshift; } | |
124 | |
125 /** Set the cellgrid y shift | |
126 * @param shift The shift in map coords | |
127 */ | |
128 void setYShift(const double yshift) { | |
129 m_yshift = yshift; | |
130 updateMatrices(); | |
131 } | |
132 | |
133 /** Get the cellgrid x shift | |
134 * @return The x shift in map coords | |
135 */ | |
136 const double getYShift() const { return m_yshift; } | |
137 | |
138 /** Set the cellgrid x-scaling | |
139 * @param scale The x-scale of cellgrid | |
140 */ | |
141 void setXScale(const double scale) { | |
142 m_xscale = scale; | |
143 updateMatrices(); | |
144 } | |
145 | |
146 /** Set the cellgrid y-scaling | |
147 * @param scale The y-scale of cellgrid | |
148 */ | |
149 void setYScale(const double scale) { | |
150 m_yscale = scale; | |
151 updateMatrices(); | |
152 } | |
153 | |
154 /** Get the cellgrid x-scaling | |
155 * @return The x-scale of cellgrid | |
156 */ | |
157 const double getXScale() const { return m_xscale; } | |
158 | |
159 /** Get the cellgrid y-scaling | |
160 * @return The y-scale of cellgrid | |
161 */ | |
162 const double getYScale() const { return m_yscale; } | |
163 | |
164 /** Set the cellgrid rotation | |
165 * @param rotation The rotation of the cellgrid | |
166 */ | |
167 void setRotation(const double rotation) { | |
168 m_rotation = rotation; | |
169 updateMatrices(); | |
170 } | |
171 | |
172 /** Get the cellgrid rotation | |
173 * @return rotation The rotation of the cellgrid | |
174 */ | |
175 const double getRotation() const { return m_rotation; } | |
176 | |
177 protected: | |
178 void updateMatrices(); | |
179 bool ptInTriangle(const ExactModelCoordinate& pt, const ExactModelCoordinate& pt1, const ExactModelCoordinate& pt2, const ExactModelCoordinate& pt3); | |
180 | |
181 DoubleMatrix m_matrix; | |
182 DoubleMatrix m_inverse_matrix; | |
183 double m_xshift; | |
184 double m_yshift; | |
185 double m_xscale; | |
186 double m_yscale; | |
187 double m_rotation; | |
188 bool m_allow_diagonals; | |
189 | |
190 private: | |
191 int orientation(const ExactModelCoordinate& pt, const ExactModelCoordinate& pt1, const ExactModelCoordinate& pt2); | |
192 }; | |
193 } | |
194 | |
195 #endif |