comparison engine/core/view/camera.h @ 407:f27880d4c08c

Moved getAngleBetween() form Camera to angles.h and updated it to not use the camera angle in it's calculation. Added camera rotation to the angle calculation for selecting the correct image by angles. Added a call to setRotation() to make sure that instance rotation is valid.
author prock@33b003aa-7bff-0310-803a-e67f0ece8222
date Fri, 29 Jan 2010 21:03:51 +0000
parents 7e5717105212
children 9d94f4676d17
comparison
equal deleted inserted replaced
406:b50dd16543b2 407:f27880d4c08c
65 * @param emc coordinate, where camera is focused on given layer 65 * @param emc coordinate, where camera is focused on given layer
66 * @param renderbackend to use with rendering 66 * @param renderbackend to use with rendering
67 * @param ipool to use with rendering 67 * @param ipool to use with rendering
68 * @param apool to use with rendering 68 * @param apool to use with rendering
69 */ 69 */
70 Camera(const std::string& id, 70 Camera(const std::string& id,
71 Layer* layer, 71 Layer* layer,
72 Rect viewport, 72 Rect viewport,
73 ExactModelCoordinate emc, 73 ExactModelCoordinate emc,
74 RenderBackend* renderbackend, 74 RenderBackend* renderbackend,
75 ImagePool* ipool, 75 ImagePool* ipool,
76 AnimationPool* apool); 76 AnimationPool* apool);
77 77
78 /** Destructor 78 /** Destructor
124 * Cell image dimension is basically width and height of a bitmap, that covers 124 * Cell image dimension is basically width and height of a bitmap, that covers
125 * one cell in the layer where camera is bind 125 * one cell in the layer where camera is bind
126 * @return Point Point containing x=width and y=height 126 * @return Point Point containing x=width and y=height
127 */ 127 */
128 void setCellImageDimensions(unsigned int width, unsigned int height); 128 void setCellImageDimensions(unsigned int width, unsigned int height);
129 129
130 /** Gets screen cell image dimensions. 130 /** Gets screen cell image dimensions.
131 * @see setCellImageDimensions 131 * @see setCellImageDimensions
132 * @return Point containing x=width and y=height 132 * @return Point containing x=width and y=height
133 */ 133 */
134 Point getCellImageDimensions(); 134 Point getCellImageDimensions();
135 135
136 /** Gets screen cell image dimensions for given layer. 136 /** Gets screen cell image dimensions for given layer.
137 * @return Point Point containing x=width and y=height 137 * @return Point Point containing x=width and y=height
138 */ 138 */
139 Point getCellImageDimensions(Layer* layer); 139 Point getCellImageDimensions(Layer* layer);
140 140
141 /** Sets the location for camera 141 /** Sets the location for camera
142 * @param location location (center point) to render 142 * @param location location (center point) to render
143 */ 143 */
144 void setLocation(const Location& location); 144 void setLocation(const Location& location);
145 145
166 void detach(); 166 void detach();
167 167
168 /** Returns instance where camera is attached. NULL if not attached 168 /** Returns instance where camera is attached. NULL if not attached
169 */ 169 */
170 Instance* getAttached() const { return m_attachedto; } 170 Instance* getAttached() const { return m_attachedto; }
171 171
172 /** Sets the viewport for camera 172 /** Sets the viewport for camera
173 * viewport is rectangle inside the view where camera renders 173 * viewport is rectangle inside the view where camera renders
174 * @param viewport area for camera render 174 * @param viewport area for camera render
175 */ 175 */
176 void setViewPort(const Rect& viewport); 176 void setViewPort(const Rect& viewport);
197 void setEnabled(bool enabled); 197 void setEnabled(bool enabled);
198 198
199 /** Gets if camera is enabled / disabled 199 /** Gets if camera is enabled / disabled
200 */ 200 */
201 bool isEnabled(); 201 bool isEnabled();
202 202
203 /** Gets angle of vector defined by given locations and camera properties (e.g. rotation)
204 * @return angle in polar coordinates
205 */
206 inline int getAngleBetween(const Location& loc1, const Location& loc2) {
207 static const double VECTOR_MULTIP = 100000.0;
208 ExactModelCoordinate c1 = loc1.getMapCoordinates();
209 ExactModelCoordinate c2 = loc2.getMapCoordinates();
210 ExactModelCoordinate cd((c2.x - c1.x) * VECTOR_MULTIP, (c2.y - c1.y) * VECTOR_MULTIP, 0);
211 c2.x = c1.x + cd.x;
212 c2.y = c1.y + cd.y;
213 ScreenPoint pt1 = this->toScreenCoordinates(c1);
214 ScreenPoint pt2 = this->toScreenCoordinates(c2);
215 double dy = (pt2.y - pt1.y);
216 double dx = (pt2.x - pt1.x);
217 int angle = static_cast<int>(atan2(-dy,dx)*(180.0/M_PI));
218 return angle;
219 }
220
221 /** Returns instances that match given screen coordinate 203 /** Returns instances that match given screen coordinate
222 * @param screen_coords screen coordinates to be used for hit search 204 * @param screen_coords screen coordinates to be used for hit search
223 * @param layer layer to use for search 205 * @param layer layer to use for search
224 * @param instances list of instances that is filled based on hit test results 206 * @param instances list of instances that is filled based on hit test results
225 */ 207 */
226 void getMatchingInstances(ScreenPoint screen_coords, Layer& layer, std::list<Instance*>& instances); 208 void getMatchingInstances(ScreenPoint screen_coords, Layer& layer, std::list<Instance*>& instances);
227 209
228 /** Returns instances that match given screen coordinate 210 /** Returns instances that match given screen coordinate
229 * @param screen_point1 top left screen coordinates to be used for hit search 211 * @param screen_point1 top left screen coordinates to be used for hit search
230 * @param screen_point2 right bottom screen coordinates to be used for hit search 212 * @param screen_point2 right bottom screen coordinates to be used for hit search
231 * @param layer layer to use for search 213 * @param layer layer to use for search
232 * @param instances list of instances that is filled based on hit test results 214 * @param instances list of instances that is filled based on hit test results
238 * @param loc location where to fetch instances from 220 * @param loc location where to fetch instances from
239 * @param instances list of instances that is filled based on hit test results 221 * @param instances list of instances that is filled based on hit test results
240 * @param use_exactcoordinates if true, comparison is done using exact coordinates. if not, cell coordinates are used 222 * @param use_exactcoordinates if true, comparison is done using exact coordinates. if not, cell coordinates are used
241 */ 223 */
242 void getMatchingInstances(Location& loc, std::list<Instance*>& instances, bool use_exactcoordinates=false); 224 void getMatchingInstances(Location& loc, std::list<Instance*>& instances, bool use_exactcoordinates=false);
243 225
244 /** General update routine. 226 /** General update routine.
245 * In this function, the camera's position gets updated when its attached 227 * In this function, the camera's position gets updated when its attached
246 * to another instance. 228 * to another instance.
247 * @note call this only once in engine update cycle, so that tracking between 229 * @note call this only once in engine update cycle, so that tracking between
248 * current position and previous position keeps in sync. This information 230 * current position and previous position keeps in sync. This information
270 RendererBase* getRenderer(const std::string& name); 252 RendererBase* getRenderer(const std::string& name);
271 253
272 /** resets active layer information on all renderers. 254 /** resets active layer information on all renderers.
273 */ 255 */
274 void resetRenderers(); 256 void resetRenderers();
275 257
276 /** calculates z-value for given screenpoint 258 /** calculates z-value for given screenpoint
277 */ 259 */
278 void calculateZValue(ScreenPoint& screen_coords); 260 void calculateZValue(ScreenPoint& screen_coords);
279 261
280 void onRendererPipelinePositionChanged(RendererBase* renderer); 262 void onRendererPipelinePositionChanged(RendererBase* renderer);
281 void onRendererEnabledChanged(RendererBase* renderer); 263 void onRendererEnabledChanged(RendererBase* renderer);
282 264
283 /** Renders camera 265 /** Renders camera
284 */ 266 */
285 void render(); 267 void render();
286 268
287 private: 269 private:
288 std::string m_id; 270 std::string m_id;
289 271
290 /** Updates the camera transformation matrix T with requested values. 272 /** Updates the camera transformation matrix T with requested values.
291 * The requests are done using these functions : 273 * The requests are done using these functions :
292 * - setLocation 274 * - setLocation
293 * - setRotation 275 * - setRotation
294 * - setTilt 276 * - setTilt
295 */ 277 */
296 void updateMatrices(); 278 void updateMatrices();
297 279
298 /** Updates camera reference scale 280 /** Updates camera reference scale
299 * Reference scale is in a sense an internal zooming factor, 281 * Reference scale is in a sense an internal zooming factor,
300 * which adjusts cell dimensions in logical space to ones shown on 282 * which adjusts cell dimensions in logical space to ones shown on
301 * screen. Calculation is based on current camera properties (e.g. rotation) 283 * screen. Calculation is based on current camera properties (e.g. rotation)
302 * + given cell image dimensions for camera's layer 284 * + given cell image dimensions for camera's layer
304 void updateReferenceScale(); 286 void updateReferenceScale();
305 287
306 /** Gets logical cell image dimensions for given layer 288 /** Gets logical cell image dimensions for given layer
307 */ 289 */
308 DoublePoint getLogicalCellDimensions(Layer* layer); 290 DoublePoint getLogicalCellDimensions(Layer* layer);
309 291
310 DoubleMatrix m_matrix; 292 DoubleMatrix m_matrix;
311 DoubleMatrix m_inverse_matrix; 293 DoubleMatrix m_inverse_matrix;
312 double m_tilt; 294 double m_tilt;
313 double m_rotation; 295 double m_rotation;
314 double m_zoom; 296 double m_zoom;
323 bool m_enabled; 305 bool m_enabled;
324 Instance* m_attachedto; 306 Instance* m_attachedto;
325 // caches calculated image dimensions for already queried & calculated layers 307 // caches calculated image dimensions for already queried & calculated layers
326 std::map<Layer*, Point> m_image_dimensions; 308 std::map<Layer*, Point> m_image_dimensions;
327 bool m_iswarped; 309 bool m_iswarped;
328 310
329 // list of renderers managed by the view 311 // list of renderers managed by the view
330 std::map<std::string, RendererBase*> m_renderers; 312 std::map<std::string, RendererBase*> m_renderers;
331 std::list<RendererBase*> m_pipeline; 313 std::list<RendererBase*> m_pipeline;
332 bool m_updated; // false, if view has never been updated before 314 bool m_updated; // false, if view has never been updated before
333 315
334 RenderBackend* m_renderbackend; 316 RenderBackend* m_renderbackend;
335 ImagePool* m_ipool; 317 ImagePool* m_ipool;
336 AnimationPool* m_apool; 318 AnimationPool* m_apool;
337 319
338 // caches layer -> instances structure between renders e.g. to fast query of mouse picking order 320 // caches layer -> instances structure between renders e.g. to fast query of mouse picking order
339 t_layer_to_instances m_layer_to_instances; 321 t_layer_to_instances m_layer_to_instances;
340 }; 322 };
341 } 323 }
342 #endif 324 #endif