Mercurial > fife-parpg
comparison engine/core/view/camera.cpp @ 605:d242e6ce6f9f
Fixed a few compiler warning messages. Also removed a bunch of extra whitespace.
author | prock@33b003aa-7bff-0310-803a-e67f0ece8222 |
---|---|
date | Mon, 13 Sep 2010 19:00:12 +0000 |
parents | b2feacaed53c |
children | 356634098bd9 |
comparison
equal
deleted
inserted
replaced
604:da83338b6913 | 605:d242e6ce6f9f |
---|---|
56 static Logger _log(LM_CAMERA); | 56 static Logger _log(LM_CAMERA); |
57 | 57 |
58 class MapObserver : public MapChangeListener { | 58 class MapObserver : public MapChangeListener { |
59 Camera* m_camera; | 59 Camera* m_camera; |
60 | 60 |
61 public: | 61 public: |
62 MapObserver(Camera* camera) { | 62 MapObserver(Camera* camera) { |
63 m_camera = camera; | 63 m_camera = camera; |
64 } | 64 } |
65 virtual ~MapObserver() {} | 65 virtual ~MapObserver() {} |
66 | 66 |
67 virtual void onMapChanged(Map* map, std::vector<Layer*>& changedLayers) { | 67 virtual void onMapChanged(Map* map, std::vector<Layer*>& changedLayers) { |
68 } | 68 } |
69 | 69 |
70 virtual void onLayerCreate(Map* map, Layer* layer) { | 70 virtual void onLayerCreate(Map* map, Layer* layer) { |
71 m_camera->addLayer(layer); | 71 m_camera->addLayer(layer); |
72 } | 72 } |
73 | 73 |
74 virtual void onLayerDelete(Map* map, Layer* layer) { | 74 virtual void onLayerDelete(Map* map, Layer* layer) { |
75 m_camera->removeLayer(layer); | 75 m_camera->removeLayer(layer); |
76 } | 76 } |
77 }; | 77 }; |
78 | 78 |
79 Camera::Camera(const std::string& id, | 79 Camera::Camera(const std::string& id, |
80 Layer *layer, | 80 Layer *layer, |
81 const Rect& viewport, | 81 const Rect& viewport, |
205 // It is important that m_location is already set, | 205 // It is important that m_location is already set, |
206 // as the updates which are triggered here | 206 // as the updates which are triggered here |
207 // need to calculate screen-coordinates | 207 // need to calculate screen-coordinates |
208 // which depend on m_location. | 208 // which depend on m_location. |
209 updateMap(location.getMap()); | 209 updateMap(location.getMap()); |
210 | 210 |
211 m_cur_origo = toScreenCoordinates(ExactModelCoordinate(0,0,0)); | 211 m_cur_origo = toScreenCoordinates(ExactModelCoordinate(0,0,0)); |
212 } | 212 } |
213 | 213 |
214 void Camera::updateMap(Map* map) | 214 void Camera::updateMap(Map* map) |
215 { | 215 { |
276 } | 276 } |
277 | 277 |
278 bool Camera::isEnabled() { | 278 bool Camera::isEnabled() { |
279 return m_enabled; | 279 return m_enabled; |
280 } | 280 } |
281 | 281 |
282 Point3D Camera::getOrigin() const { | 282 Point3D Camera::getOrigin() const { |
283 return m_cur_origo; | 283 return m_cur_origo; |
284 } | 284 } |
285 | 285 |
286 void Camera::updateMatrices() { | 286 void Camera::updateMatrices() { |
287 double scale = m_reference_scale; | 287 double scale = m_reference_scale; |
288 m_matrix.loadScale(scale, scale, scale); | 288 m_matrix.loadScale(scale, scale, scale); |
289 m_vs_matrix.loadScale(scale,scale,scale); | 289 m_vs_matrix.loadScale(scale,scale,scale); |
290 if (m_location.getLayer()) { | 290 if (m_location.getLayer()) { |
318 m_vscreen_2_screen[2*N + i] = 0; | 318 m_vscreen_2_screen[2*N + i] = 0; |
319 m_vscreen_2_screen[i*N + 2] = 0; | 319 m_vscreen_2_screen[i*N + 2] = 0; |
320 } | 320 } |
321 m_vscreen_2_screen[2*N + 2] = 1; | 321 m_vscreen_2_screen[2*N + 2] = 1; |
322 m_screen_2_vscreen = m_vscreen_2_screen.inverse(); | 322 m_screen_2_vscreen = m_vscreen_2_screen.inverse(); |
323 | 323 |
324 // FL_WARN(_log, LMsg("matrix: ") << m_matrix << " 1: " << m_matrix.inverse().mult4by4(m_matrix)); | 324 // FL_WARN(_log, LMsg("matrix: ") << m_matrix << " 1: " << m_matrix.inverse().mult4by4(m_matrix)); |
325 // FL_WARN(_log, LMsg("vs2s matrix: ") << m_vscreen_2_screen << " s2vs matrix: " << m_screen_2_vscreen); | 325 // FL_WARN(_log, LMsg("vs2s matrix: ") << m_vscreen_2_screen << " s2vs matrix: " << m_screen_2_vscreen); |
326 } | 326 } |
327 | 327 |
328 void Camera::calculateZValue(ScreenPoint& screen_coords) { | 328 void Camera::calculateZValue(ScreenPoint& screen_coords) { |
346 DoublePoint3D Camera::toVirtualScreenCoordinates(ExactModelCoordinate elevation_coords) { | 346 DoublePoint3D Camera::toVirtualScreenCoordinates(ExactModelCoordinate elevation_coords) { |
347 ExactModelCoordinate p = elevation_coords; | 347 ExactModelCoordinate p = elevation_coords; |
348 DoublePoint3D pt = (m_vs_matrix * p); | 348 DoublePoint3D pt = (m_vs_matrix * p); |
349 return pt; | 349 return pt; |
350 } | 350 } |
351 | 351 |
352 ScreenPoint Camera::virtualScreenToScreen(const DoublePoint3D& p) { | 352 ScreenPoint Camera::virtualScreenToScreen(const DoublePoint3D& p) { |
353 return doublePt2intPt(m_vscreen_2_screen * p); | 353 return doublePt2intPt(m_vscreen_2_screen * p); |
354 } | 354 } |
355 | 355 |
356 DoublePoint3D Camera::screenToVirtualScreen(const ScreenPoint& p) { | 356 DoublePoint3D Camera::screenToVirtualScreen(const ScreenPoint& p) { |
369 cg->getVertices(vertices, cell); | 369 cg->getVertices(vertices, cell); |
370 | 370 |
371 DoubleMatrix mtx; | 371 DoubleMatrix mtx; |
372 mtx.loadRotate(m_rotation, 0.0, 0.0, 1.0); | 372 mtx.loadRotate(m_rotation, 0.0, 0.0, 1.0); |
373 mtx.applyRotate(m_tilt, 1.0, 0.0, 0.0); | 373 mtx.applyRotate(m_tilt, 1.0, 0.0, 0.0); |
374 double x1, x2, y1, y2; | 374 |
375 double x1 = 0; | |
376 double x2 = 0; | |
377 double y1 = 0; | |
378 double y2 = 0; | |
379 | |
375 for (unsigned int i = 0; i < vertices.size(); i++) { | 380 for (unsigned int i = 0; i < vertices.size(); i++) { |
376 vertices[i] = cg->toMapCoordinates(vertices[i]); | 381 vertices[i] = cg->toMapCoordinates(vertices[i]); |
377 vertices[i] = mtx * vertices[i]; | 382 vertices[i] = mtx * vertices[i]; |
378 if (i == 0) { | 383 if (i == 0) { |
379 x1 = x2 = vertices[0].x; | 384 x1 = x2 = vertices[0].x; |