FIFE  6e1afdbeda11afe9ac53e6023a4be96ef88f1dc6
camera.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2005-2017 by the FIFE team *
3  * http://www.fifengine.net *
4  * This file is part of FIFE. *
5  * *
6  * FIFE is free software; you can redistribute it and/or *
7  * modify it under the terms of the GNU Lesser General Public *
8  * License as published by the Free Software Foundation; either *
9  * version 2.1 of the License, or (at your option) any later version. *
10  * *
11  * This library 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 GNU *
14  * Lesser General Public License for more details. *
15  * *
16  * You should have received a copy of the GNU Lesser General Public *
17  * License along with this library; if not, write to the *
18  * Free Software Foundation, Inc., *
19  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
20  ***************************************************************************/
21 
22 // Standard C++ library includes
23 
24 // 3rd party library includes
25 
26 // FIFE includes
27 // These includes are split up in two parts, separated by one empty line
28 // First block: files included from the FIFE root src directory
29 // Second block: files included from the same folder
30 
32 #include "model/metamodel/action.h"
34 #include "model/structures/map.h"
35 #include "model/structures/layer.h"
39 #include "util/log/logger.h"
40 #include "util/math/fife_math.h"
41 #include "util/math/angles.h"
42 #include "util/time/timemanager.h"
43 #include "video/renderbackend.h"
44 #include "video/image.h"
45 #include "video/animation.h"
46 #include "video/imagemanager.h"
47 
48 #include "camera.h"
49 #include "layercache.h"
50 #include "visual.h"
51 
52 
53 namespace FIFE {
54  static Logger _log(LM_CAMERA);
55 
56  // to avoid std::bad_alloc errors, we determine the maximum size of batches
57  const uint32_t MAX_BATCH_SIZE = 100000;
58 
59  class MapObserver : public MapChangeListener {
61 
62  public:
63  MapObserver(Camera* camera) {
64  m_camera = camera;
65  }
66  virtual ~MapObserver() {}
67 
68  virtual void onMapChanged(Map* map, std::vector<Layer*>& changedLayers) {
69  }
70 
71  virtual void onLayerCreate(Map* map, Layer* layer) {
72  m_camera->addLayer(layer);
73  }
74 
75  virtual void onLayerDelete(Map* map, Layer* layer) {
76  m_camera->removeLayer(layer);
77  }
78  };
79 
80  Camera::Camera(const std::string& id,
81  Layer *layer,
82  const Rect& viewport,
83  RenderBackend* renderbackend):
84  m_id(id),
85  m_matrix(),
86  m_inverse_matrix(),
87  m_tilt(0),
88  m_rotation(0),
89  m_zoom(1),
90  m_zToY(0),
91  m_enabledZToY(false),
92  m_location(),
93  m_cur_origo(ScreenPoint(0,0,0)),
94  m_viewport(),
95  m_mapViewPort(),
96  m_mapViewPortUpdated(false),
97  m_screen_cell_width(1),
98  m_screen_cell_height(1),
99  m_referenceScaleX(1),
100  m_referenceScaleY(1),
101  m_enabled(true),
102  m_attachedto(NULL),
103  m_image_dimensions(),
104  m_transform(NoneTransform),
105  m_renderers(),
106  m_pipeline(),
107  m_updated(false),
108  m_renderbackend(renderbackend),
109  m_layerToInstances(),
110  m_lighting(false),
111  m_light_colors(),
112  m_col_overlay(false),
113  m_img_overlay(false),
114  m_ani_overlay(false) {
115  m_viewport = viewport;
116  m_map_observer = new MapObserver(this);
117  m_map = 0;
118  Location location;
119  location.setLayer(layer);
120  setLocation(location);
121  }
122 
124  // Trigger removal of LayerCaches and MapObserver
125  updateMap(NULL);
126 
127  std::map<std::string, RendererBase*>::iterator r_it = m_renderers.begin();
128  for(; r_it != m_renderers.end(); ++r_it) {
129  r_it->second->reset();
130  delete r_it->second;
131  }
132  m_renderers.clear();
133  delete m_map_observer;
134  }
135 
136  void Camera::setTilt(double tilt) {
137  if (!Mathd::Equal(m_tilt, tilt)) {
139  m_tilt = tilt;
141  updateMatrices();
142  }
143  }
144 
145  double Camera::getTilt() const {
146  return m_tilt;
147  }
148 
149  void Camera::setRotation(double rotation) {
150  if (!Mathd::Equal(m_rotation, rotation)) {
152  m_rotation = rotation;
153  updateMatrices();
154  }
155  }
156 
157  double Camera::getRotation() const {
158  return m_rotation;
159  }
160 
161  void Camera::setZoom(double zoom) {
162  if (!Mathd::Equal(m_zoom, zoom)) {
164  m_zoom = zoom;
165  if (m_zoom < 0.001) {
166  m_zoom = 0.001;
167  }
168  updateMatrices();
169  }
170  }
171 
172  double Camera::getZoom() const {
173  return m_zoom;
174  }
175 
176  double Camera::getOriginalZToY() const {
177  DoubleMatrix matrix;
179  if (m_location.getLayer()) {
181  if (cg) {
184  }
185  }
186  matrix.applyRotate(-m_rotation, 0.0, 0.0, 1.0);
187  matrix.applyRotate(-m_tilt, 1.0, 0.0, 0.0);
188  return matrix.m9 * -1.0;
189  }
190 
191  void Camera::setZToY(double zToY) {
192  m_enabledZToY = true;
193  if (!Mathd::Equal(m_zToY, zToY)) {
195  m_zToY = zToY;
196  updateMatrices();
197  }
198  }
199 
200  double Camera::getZToY() const {
201  return m_zToY;
202  }
203 
204  void Camera::setZToYEnabled(bool enabled) {
205  m_enabledZToY = enabled;
206  }
207 
208  bool Camera::isZToYEnabled() const {
209  return m_enabledZToY;
210  }
211 
213  m_screen_cell_width = width;
214  m_screen_cell_height = height;
216  updateMatrices();
218  }
219 
220  void Camera::setLocation(const Location& location) {
221  if (m_location == location ) {
222  return;
223  }
224 
225  CellGrid* cell_grid = NULL;
226  if (location.getLayer()) {
227  cell_grid = location.getLayer()->getCellGrid();
228  } else {
229  throw Exception("Location without layer given to Camera::setLocation");
230  }
231  if (!cell_grid) {
232  throw Exception("Camera layer has no cellgrid specified");
233  }
234 
236  m_location = location;
237  updateMatrices();
238 
241 
242  // WARNING
243  // It is important that m_location is already set,
244  // as the updates which are triggered here
245  // need to calculate screen-coordinates
246  // which depend on m_location.
248  }
249 
250  void Camera::updateMap(Map* map) {
251  if(m_map == map) {
252  return;
253  }
254  if(m_map) {
256  const std::list<Layer*>& layers = m_map->getLayers();
257  for(std::list<Layer*>::const_iterator i = layers.begin(); i !=layers.end(); ++i) {
258  removeLayer(*i);
259  }
260  }
261  if(map) {
263  const std::list<Layer*>& layers = map->getLayers();
264  for(std::list<Layer*>::const_iterator i = layers.begin(); i !=layers.end(); ++i) {
265  addLayer(*i);
266  }
267  }
268  m_map = map;
269  }
270 
273  }
274 
276  if (layer == m_location.getLayer()) {
278  }
279  std::map<Layer*, Point>::iterator it = m_image_dimensions.find(layer);
280  if (it != m_image_dimensions.end()) {
281  return it->second;
282  }
283  Point p;
284  DoublePoint dimensions = getLogicalCellDimensions(layer);
285  p.x = static_cast<int32_t>(round(m_referenceScaleX * dimensions.x));
286  p.y = static_cast<int32_t>(round(m_referenceScaleY * dimensions.y));
287  m_image_dimensions[layer] = p;
288  return p;
289  }
290 
292  return m_location;
293  }
294 
296  return m_location;
297  }
298 
299  void Camera::setViewPort(const Rect& viewport) {
300  m_viewport = viewport;
301  refresh();
302  }
303 
304  const Rect& Camera::getViewPort() const {
305  return m_viewport;
306  }
307 
309  if (!m_mapViewPortUpdated) {
314 
315  std::vector<ExactModelCoordinate> coords;
316  coords.push_back(toMapCoordinates(sp2, false));
317  coords.push_back(toMapCoordinates(sp3, false));
318  coords.push_back(toMapCoordinates(sp4, false));
319 
320  ExactModelCoordinate emc = toMapCoordinates(sp1, false);
321  ModelCoordinate min(static_cast<int32_t>(emc.x), static_cast<int32_t>(emc.y));
322  ModelCoordinate max(static_cast<int32_t>(emc.x+0.5), static_cast<int32_t>(emc.y+0.5));
323  std::vector<ExactModelCoordinate>::iterator it = coords.begin();
324  for (; it != coords.end(); ++it) {
325  min.x = std::min(min.x, static_cast<int32_t>((*it).x));
326  min.y = std::min(min.y, static_cast<int32_t>((*it).y));
327  max.x = std::max(max.x, static_cast<int32_t>((*it).x+0.5));
328  max.y = std::max(max.y, static_cast<int32_t>((*it).y+0.5));
329  }
330  // makes the viewport a bit larger
331  m_mapViewPort.x = min.x - 1;
332  m_mapViewPort.y = min.y - 1;
333  m_mapViewPort.w = ABS(max.x - min.x) + 2;
334  m_mapViewPort.h = ABS(max.y - min.y) + 2;
335  m_mapViewPortUpdated = true;
336  }
337 
338  return m_mapViewPort;
339  }
340 
342  Rect mapView = getMapViewPort();
343  Location loc(layer);
344  ExactModelCoordinate emc(mapView.x, mapView.y);
345  loc.setMapCoordinates(emc);
346  emc.x = mapView.x+mapView.w;
347  emc.y = mapView.y+mapView.h;
348  mapView.x = loc.getLayerCoordinates().x;
349  mapView.y = loc.getLayerCoordinates().y;
350  loc.setMapCoordinates(emc);
351  mapView.w = ABS(loc.getLayerCoordinates().x - mapView.x);
352  mapView.h = ABS(loc.getLayerCoordinates().y - mapView.y);
353 
354  return mapView;
355  }
356 
357  void Camera::setEnabled(bool enabled) {
358  m_enabled = enabled;
359  }
360 
362  return m_enabled;
363  }
364 
366  return m_cur_origo;
367  }
368 
372  if (m_location.getLayer()) {
374  if (cg) {
377  }
378  }
379  m_matrix.applyRotate(-m_rotation, 0.0, 0.0, 1.0);
380  m_matrix.applyRotate(-m_tilt, 1.0, 0.0, 0.0);
381  if (m_enabledZToY) {
382  m_matrix.m9 = -m_zToY; // z -> y height in pixels
383  }
384  double scale = m_zoom;
385  m_matrix.applyScale(scale, scale, scale);
388 
389  m_vs_matrix.applyRotate(-m_rotation, 0.0, 0.0, 1.0);
390  m_vs_matrix.applyRotate(-m_tilt, 1.0, 0.0, 0.0);
391  if (m_enabledZToY) {
392  m_vs_matrix.m9 = -m_zToY; // z -> y height in pixels
393  }
395 
396  // calculate the screen<->virtual screen transformation
397  // this explicitly ignores the z-value.
399  // NOTE: mult4by4 is an in-place modification.
401  // set the z transformation to unity
402  const int32_t N=4;
403  for(int32_t i=0; i!=N; ++i) {
404  m_vscreen_2_screen[2*N + i] = 0;
405  m_vscreen_2_screen[i*N + 2] = 0;
406  }
407  m_vscreen_2_screen[2*N + 2] = 1;
409 
410  m_mapViewPortUpdated = false;
411  // FL_WARN(_log, LMsg("matrix: ") << m_matrix << " 1: " << m_matrix.inverse().mult4by4(m_matrix));
412 // FL_WARN(_log, LMsg("vs2s matrix: ") << m_vscreen_2_screen << " s2vs matrix: " << m_screen_2_vscreen);
413  }
414 
415  void Camera::calculateZValue(DoublePoint3D& screen_coords) {
416  int32_t dy = -(screen_coords.y - toScreenCoordinates(m_location.getMapCoordinates()).y);
417  screen_coords.z = Mathd::Tan(m_tilt * (Mathd::pi() / 180.0)) * static_cast<double>(dy);
418  }
419 
420  ExactModelCoordinate Camera::toMapCoordinates(ScreenPoint screen_coords, bool z_calculated) {
421  DoublePoint3D double_screen_coords = intPt2doublePt(screen_coords);
422  if (!z_calculated) {
423  calculateZValue(double_screen_coords);
424  }
425  return m_inverse_matrix * double_screen_coords;
426  }
427 
429  ScreenPoint pt = doublePt2intPt(m_matrix * elevation_coords);
430  return pt;
431  }
432 
434  DoublePoint3D pt = (m_vs_matrix * elevation_coords);
435  return pt;
436  }
437 
440  }
441 
444  }
445 
447  assert(layer);
448  CellGrid* cg = layer->getCellGrid();
449  assert(cg);
450 
451  ModelCoordinate cell(0,0);
452  std::vector<ExactModelCoordinate> vertices;
453  cg->getVertices(vertices, cell);
454 
455  DoubleMatrix mtx;
456  mtx.loadRotate(m_rotation, 0.0, 0.0, 1.0);
457  mtx.applyRotate(m_tilt, 1.0, 0.0, 0.0);
458 
459  double x1 = 0;
460  double x2 = 0;
461  double y1 = 0;
462  double y2 = 0;
463 
464  for (uint32_t i = 0; i < vertices.size(); i++) {
465  vertices[i] = cg->toMapCoordinates(vertices[i]);
466  vertices[i] = mtx * vertices[i];
467  if (i == 0) {
468  x1 = x2 = vertices[0].x;
469  y1 = y2 = vertices[0].y;
470  } else {
471  x1 = std::min(vertices[i].x, x1);
472  x2 = std::max(vertices[i].x, x2);
473  y1 = std::min(vertices[i].y, y1);
474  y2 = std::max(vertices[i].y, y2);
475  }
476  }
477  return DoublePoint( x2 - x1, y2 - y1 );
478  }
479 
481  assert(layer && layer->getCellGrid());
482 
483  Location loc(layer);
484  ModelCoordinate cell(0,0);
485  loc.setLayerCoordinates(cell);
486  ScreenPoint sp1 = toScreenCoordinates(loc.getMapCoordinates());
487  ++cell.y;
488  loc.setLayerCoordinates(cell);
489  ScreenPoint sp2 = toScreenCoordinates(loc.getMapCoordinates());
490 
491  Point p(ABS(sp2.x - sp1.x), ABS(sp2.y - sp1.y));
492  if (p.x == 0) {
493  p.x = 1;
494  }
495  if (p.y == 0) {
496  p.y = 1;
497  }
498  return p;
499  }
500 
502  assert(layer && layer->getCellGrid());
503 
504  Location loc(layer);
505  ModelCoordinate cell(0,0,0);
506  loc.setLayerCoordinates(cell);
507  ScreenPoint sp1 = toScreenCoordinates(loc.getMapCoordinates());
508  ++cell.z;
509  loc.setLayerCoordinates(cell);
510  ScreenPoint sp2 = toScreenCoordinates(loc.getMapCoordinates());
511 
512  return Point3D(sp2.x - sp1.x, sp2.y - sp1.y, sp2.z - sp1.z);
513  }
514 
517  m_referenceScaleX = static_cast<double>(m_screen_cell_width) / dim.x;
518  m_referenceScaleY = static_cast<double>(m_screen_cell_height) / dim.y;
519 
520  FL_DBG(_log, "Updating reference scale");
521  FL_DBG(_log, LMsg(" tilt=") << m_tilt << " rot=" << m_rotation);
522  FL_DBG(_log, LMsg(" m_screen_cell_width=") << m_screen_cell_width);
523  FL_DBG(_log, LMsg(" m_screen_cell_height=") << m_screen_cell_height);
524  FL_DBG(_log, LMsg(" m_referenceScaleX=") << m_referenceScaleX);
525  FL_DBG(_log, LMsg(" m_referenceScaleY=") << m_referenceScaleY);
526  }
527 
529  return m_layerToInstances[layer];
530  }
531 
532  void Camera::getMatchingInstances(ScreenPoint screen_coords, Layer& layer, std::list<Instance*>& instances, uint8_t alpha) {
533  instances.clear();
534  bool zoomed = !Mathd::Equal(m_zoom, 1.0);
535  bool special_alpha = alpha != 0;
536 
537  const RenderList& layer_instances = m_layerToInstances[&layer];
538  RenderList::const_iterator instance_it = layer_instances.end();
539  while (instance_it != layer_instances.begin()) {
540  --instance_it;
541  Instance* i = (*instance_it)->instance;
542  const RenderItem& vc = **instance_it;
543  if ((vc.dimensions.contains(Point(screen_coords.x, screen_coords.y)))) {
544  if(vc.image->isSharedImage()) {
545  vc.image->forceLoadInternal();
546  }
547  uint8_t r, g, b, a = 0;
548  int32_t x = screen_coords.x - vc.dimensions.x;
549  int32_t y = screen_coords.y - vc.dimensions.y;
550  if (zoomed) {
551  double fx = static_cast<double>(x);
552  double fy = static_cast<double>(y);
553  double fow = static_cast<double>(vc.image->getWidth());
554  double foh = static_cast<double>(vc.image->getHeight());
555  double fsw = static_cast<double>(vc.dimensions.w);
556  double fsh = static_cast<double>(vc.dimensions.h);
557  x = static_cast<int32_t>(round(fx / fsw * fow));
558  y = static_cast<int32_t>(round(fy / fsh * foh));
559  }
560  if (vc.getAnimationOverlay()) {
561  std::vector<ImagePtr>* ao = vc.getAnimationOverlay();
562  std::vector<ImagePtr>::iterator it = ao->begin();
563  for (; it != ao->end(); ++it) {
564  if ((*it)->isSharedImage()) {
565  (*it)->forceLoadInternal();
566  }
567  (*it)->getPixelRGBA(x, y, &r, &g, &b, &a);
568  // instance is hit with mouse if not totally transparent
569  if (a == 0 || (special_alpha && a < alpha)) {
570  continue;
571  }
572  instances.push_back(i);
573  break;
574  }
575  } else {
576  vc.image->getPixelRGBA(x, y, &r, &g, &b, &a);
577  // instance is hit with mouse if not totally transparent
578  if (a == 0 || (special_alpha && a < alpha)) {
579  continue;
580  }
581  instances.push_back(i);
582  }
583  }
584  }
585  }
586 
587  void Camera::getMatchingInstances(Rect screen_rect, Layer& layer, std::list<Instance*>& instances, uint8_t alpha) {
588  instances.clear();
589  bool zoomed = !Mathd::Equal(m_zoom, 1.0);
590  bool special_alpha = alpha != 0;
591 
592  const RenderList& layer_instances = m_layerToInstances[&layer];
593  RenderList::const_iterator instance_it = layer_instances.end();
594  while (instance_it != layer_instances.begin()) {
595  --instance_it;
596  Instance* i = (*instance_it)->instance;;
597  const RenderItem& vc = **instance_it;
598  if ((vc.dimensions.intersects(screen_rect))) {
599  if(vc.image->isSharedImage()) {
600  vc.image->forceLoadInternal();
601  }
602  uint8_t r, g, b, a = 0;
603  for(int32_t xx = screen_rect.x; xx < screen_rect.x + screen_rect.w; xx++) {
604  for(int32_t yy = screen_rect.y; yy < screen_rect.y + screen_rect.h; yy++) {
605  if ((vc.dimensions.contains(Point(xx, yy)))) {
606  int32_t x = xx - vc.dimensions.x;
607  int32_t y = yy - vc.dimensions.y;
608  if (zoomed) {
609  double fx = static_cast<double>(x);
610  double fy = static_cast<double>(y);
611  double fow = static_cast<double>(vc.image->getWidth());
612  double foh = static_cast<double>(vc.image->getHeight());
613  double fsw = static_cast<double>(vc.dimensions.w);
614  double fsh = static_cast<double>(vc.dimensions.h);
615  x = static_cast<int32_t>(round(fx / fsw * fow));
616  y = static_cast<int32_t>(round(fy / fsh * foh));
617  }
618  if (vc.getAnimationOverlay()) {
619  std::vector<ImagePtr>* ao = vc.getAnimationOverlay();
620  std::vector<ImagePtr>::iterator it = ao->begin();
621  for (; it != ao->end(); ++it) {
622  if ((*it)->isSharedImage()) {
623  (*it)->forceLoadInternal();
624  }
625  (*it)->getPixelRGBA(x, y, &r, &g, &b, &a);
626  // instance is hit with mouse if not totally transparent
627  if (a == 0 || (special_alpha && a < alpha)) {
628  continue;
629  }
630  instances.push_back(i);
631  goto found_non_transparent_pixel;
632  }
633  } else {
634  vc.image->getPixelRGBA(x, y, &r, &g, &b, &a);
635  // instance is hit with mouse if not totally transparent
636  if (a == 0 || (special_alpha && a < alpha)) {
637  continue;
638  }
639  instances.push_back(i);
640  goto found_non_transparent_pixel;
641  }
642  }
643  }
644  }
645  found_non_transparent_pixel:;
646  }
647  }
648  }
649 
650  void Camera::getMatchingInstances(Location& loc, std::list<Instance*>& instances, bool use_exactcoordinates) {
651  instances.clear();
652  Layer* layer = loc.getLayer();
653  if(!layer) {
654  return;
655  }
656 
657  const RenderList& layer_instances = m_layerToInstances[layer];
658  RenderList::const_iterator instance_it = layer_instances.end();
659  while (instance_it != layer_instances.begin()) {
660  --instance_it;
661  Instance* i = (*instance_it)->instance;
662  if (use_exactcoordinates) {
664  instances.push_back(i);
665  }
666  } else {
668  instances.push_back(i);
669  }
670  }
671  }
672  }
673 
674  void Camera::attach(Instance *instance) {
675  // fail if the layers aren't the same
676  if (m_location.getLayer()->getId() != instance->getLocation().getLayer()->getId()) {
677  FL_WARN(_log, "Tried to attach camera to instance on different layer.");
678  return ;
679  }
680  m_attachedto = instance;
681  }
682 
683  void Camera::detach() {
684  m_attachedto = NULL;
685  }
686 
687  void Camera::update() {
688  if (!m_attachedto) {
689  return;
690  }
693  if (Mathd::Equal(old_emc.x, new_emc.x) && Mathd::Equal(old_emc.y, new_emc.y)) {
694  return;
695  }
697  old_emc = new_emc;
698  updateMatrices();
699  }
700 
702  updateMatrices();
705  }
706 
708  if (m_transform == NoneTransform) {
709  m_updated = false;
710  } else {
711  m_updated = true;
712  }
714  }
715 
716  bool pipelineSort(const RendererBase* lhs, const RendererBase* rhs) {
717  return (lhs->getPipelinePosition() < rhs->getPipelinePosition());
718  }
719 
721  renderer->setRendererListener(this);
722  m_renderers[renderer->getName()] = renderer;
723  if (renderer->isEnabled()) {
724  m_pipeline.push_back(renderer);
725  }
726  m_pipeline.sort(pipelineSort);
727  }
728 
730  m_pipeline.sort(pipelineSort);
731  }
732 
734  assert(m_renderers[renderer->getName()]);
735  if (renderer->isEnabled()) {
736  FL_LOG(_log, LMsg("Enabling renderer ") << renderer->getName());
737  m_pipeline.push_back(renderer);
738  m_pipeline.sort(pipelineSort);
739  } else {
740  m_pipeline.remove(renderer);
741  }
742  }
743 
744  RendererBase* Camera::getRenderer(const std::string& name) {
745  return m_renderers[name];
746  }
747 
749  std::map<std::string, RendererBase*>::iterator r_it = m_renderers.begin();
750  for (; r_it != m_renderers.end(); ++r_it) {
751  r_it->second->reset();
752  }
753  }
754 
755  void Camera::addLayer(Layer* layer) {
756  m_cache[layer] = new LayerCache(this);
757  m_cache[layer]->setLayer(layer);
758  m_layerToInstances[layer] = RenderList();
759  refresh();
760  }
761 
762  void Camera::removeLayer(Layer* layer) {
763  delete m_cache[layer];
764  m_cache.erase(layer);
765  m_layerToInstances.erase(layer);
766  refresh();
767  }
768 
769  void Camera::setLightingColor(float red, float green, float blue) {
770  m_lighting = true;
771  m_light_colors.clear();
772  m_light_colors.push_back(red);
773  m_light_colors.push_back(green);
774  m_light_colors.push_back(blue);
775  }
776 
777  std::vector<float> Camera::getLightingColor() {
778  if(m_light_colors.empty()) {
779  for(int32_t colors = 0; colors != 3; ++colors) {
780  m_light_colors.push_back(1.0f);
781  }
782  }
783  return m_light_colors;
784  }
785 
787  m_lighting = false;
789  }
790 
791  void Camera::setOverlayColor(uint8_t red, uint8_t green, uint8_t blue, uint8_t alpha) {
792  m_col_overlay = true;
793  m_overlay_color.r = red;
794  m_overlay_color.g = green;
795  m_overlay_color.b = blue;
796  m_overlay_color.a = alpha;
797  }
798 
799  std::vector<uint8_t> Camera::getOverlayColor() {
800  std::vector<uint8_t> colors;
801  if (m_col_overlay) {
802  colors.push_back(m_overlay_color.r);
803  colors.push_back(m_overlay_color.g);
804  colors.push_back(m_overlay_color.b);
805  colors.push_back(m_overlay_color.a);
806  } else {
807  for(uint8_t cc = 0; cc != 4; ++cc) {
808  colors.push_back(255);
809  }
810  }
811  return colors;
812  }
813 
815  m_col_overlay = false;
816  }
817 
818  void Camera::setOverlayImage(int32_t id, bool fill) {
819  m_img_overlay = true;
820  m_img_id = id;
821  m_img_fill = fill;
822  }
823 
825  int32_t id = -1;
826  if (m_img_overlay) {
827  id = m_img_id;
828  }
829  return id;
830  }
831 
833  m_img_overlay = false;
834  m_img_id = -1;
835  }
836 
838  m_ani_overlay = true;
839  m_ani_ptr = anim;
840  m_ani_fill = fill;
841  m_start_time = 0;
842  }
843 
845  return m_ani_ptr;
846  }
847 
849  m_ani_overlay = false;
850  m_ani_ptr.reset();
851  }
852 
855  return;
856  }
857  uint16_t width = m_viewport.w;
858  uint16_t height = m_viewport.h;
859  Point pm = Point(m_viewport.x + width/2, m_viewport.y + height/2);
860  Rect r;
861 
862  // color overlay
863  if (m_col_overlay) {
866  }
867  // image overlay
868  if (m_img_overlay) {
870  Image* img = resptr.get();
871  if (img) {
872  if (m_img_fill) {
873  r.w = width;
874  r.h = height;
875  } else {
876  r.w = img->getWidth();
877  r.h = img->getHeight();
878  }
879  r.x = pm.x-r.w/2;
880  r.y = pm.y-r.h/2;
881  img->render(r);
882  }
883  }
884  // animation overlay
885  if (m_ani_overlay) {
886  assert(m_ani_ptr != 0);
887 
888  if (m_start_time == 0) {
890  }
891  uint32_t animtime = scaleTime(1.0, TimeManager::instance()->getTime() - m_start_time) % m_ani_ptr->getDuration();
892  ImagePtr img = m_ani_ptr->getFrameByTimestamp(animtime);
893  if (img) {
894  if (m_ani_fill) {
895  r.w = width;
896  r.h = height;
897  } else {
898  r.w = img->getWidth();
899  r.h = img->getHeight();
900  }
901  r.x = pm.x-r.w/2;
902  r.y = pm.y-r.h/2;
903  img->render(r);
904  }
905  }
906  }
907 
909  // ToDo: Remove this function from the camera class to something like engine pre-render.
910  // ToDo: Check if partial rendering of only updated RenderItems to existing FBO is possible/faster in our case.
911  // ToDo: Add and fix support for SDL backend, for SDL it works only on the lowest layer(alpha/transparent bug).
912  LayerCache* cache = m_cache[layer];
913  ImagePtr cacheImage = cache->getCacheImage();
914  if (!cacheImage.get()) {
915  // the cacheImage name will be, camera id + _virtual_layer_image_ + layer id
916  cacheImage = ImageManager::instance()->loadBlank(m_id+"_virtual_layer_image_"+layer->getId(), m_viewport.w, m_viewport.h);
917  cache->setCacheImage(cacheImage);
918  update = true;
919  }
920  if (update) {
921  // for the case that the viewport size is not the same as the screen size,
922  // we have to change the values for OpenGL backend
924  if (m_renderbackend->getName() == "SDL") {
925  rec = m_viewport;
926  }
927  m_renderbackend->attachRenderTarget(cacheImage, true);
928  // here we use the new viewport size
929  m_renderbackend->pushClipArea(rec, false);
930  // render stuff to texture
931  RenderList& instancesToRender = m_layerToInstances[layer];
932  // split the RenderList into smaller parts
933  if (instancesToRender.size() > MAX_BATCH_SIZE) {
934  uint8_t batches = ceil(instancesToRender.size() / static_cast<float>(MAX_BATCH_SIZE));
935  uint32_t residual = instancesToRender.size() % MAX_BATCH_SIZE;
936  for (uint8_t i = 0; i < batches; ++i) {
937  uint32_t start = i*MAX_BATCH_SIZE;
938  uint32_t end = start + ((i+1 == batches) ? residual : MAX_BATCH_SIZE);
939  RenderList tempList(instancesToRender.begin() + start, instancesToRender.begin() + end);
940  std::list<RendererBase*>::iterator r_it = m_pipeline.begin();
941  for (; r_it != m_pipeline.end(); ++r_it) {
942  if ((*r_it)->isActivedLayer(layer)) {
943  (*r_it)->render(this, layer, tempList);
945  }
946  }
947  }
948  } else {
949  std::list<RendererBase*>::iterator r_it = m_pipeline.begin();
950  for (; r_it != m_pipeline.end(); ++r_it) {
951  if ((*r_it)->isActivedLayer(layer)) {
952  (*r_it)->render(this, layer, instancesToRender);
954  }
955  }
956  }
959  }
960  }
961 
963  Map* map = m_location.getMap();
964  if (!map) {
965  FL_ERR(_log, "No map for camera found");
966  return;
967  }
968 
969  const std::list<Layer*>& layers = map->getLayers();
970  std::list<Layer*>::const_iterator layer_it = layers.begin();
971  for (;layer_it != layers.end(); ++layer_it) {
972  LayerCache* cache = m_cache[*layer_it];
973  if(!cache) {
974  addLayer(*layer_it);
975  cache = m_cache[*layer_it];
976  FL_ERR(_log, LMsg("Layer Cache miss! (This shouldn't happen!)") << (*layer_it)->getId());
977  }
978  RenderList& instancesToRender = m_layerToInstances[*layer_it];
979  if ((*layer_it)->isStatic() && m_transform == NoneTransform) {
980  continue;
981  }
982  cache->update(m_transform, instancesToRender);
983  }
984  resetUpdates();
985  }
986 
987  void Camera::render() {
989  Map* map = m_location.getMap();
990  if (!map) {
991  return;
992  }
993 
995  if (lm != 0) {
997  if (m_lighting) {
999  }
1000  }
1001 
1002  const std::list<Layer*>& layers = map->getLayers();
1003  std::list<Layer*>::const_iterator layer_it = layers.begin();
1004  for ( ; layer_it != layers.end(); ++layer_it) {
1005  // layer with static flag will rendered as one texture
1006  if ((*layer_it)->isStatic()) {
1007  renderStaticLayer(*layer_it, m_updated);
1008  continue;
1009  }
1010  }
1011 
1013 
1014  layer_it = layers.begin();
1015  for ( ; layer_it != layers.end(); ++layer_it) {
1016  // layer with static flag will rendered as one texture
1017  if ((*layer_it)->isStatic()) {
1018  m_cache[*layer_it]->getCacheImage()->render(m_viewport);
1020  continue;
1021  }
1022  RenderList& instancesToRender = m_layerToInstances[*layer_it];
1023  // split the RenderList into smaller parts
1024  if (instancesToRender.size() > MAX_BATCH_SIZE) {
1025  uint8_t batches = ceil(instancesToRender.size() / static_cast<float>(MAX_BATCH_SIZE));
1026  uint32_t residual = instancesToRender.size() % MAX_BATCH_SIZE;
1027  for (uint8_t i = 0; i < batches; ++i) {
1028  uint32_t start = i*MAX_BATCH_SIZE;
1029  uint32_t end = start + ((i+1 == batches) ? residual : MAX_BATCH_SIZE);
1030  RenderList tempList(instancesToRender.begin() + start, instancesToRender.begin() + end);
1031  std::list<RendererBase*>::iterator r_it = m_pipeline.begin();
1032  for (; r_it != m_pipeline.end(); ++r_it) {
1033  if ((*r_it)->isActivedLayer(*layer_it)) {
1034  (*r_it)->render(this, *layer_it, tempList);
1036  }
1037  }
1038  }
1039  } else {
1040  std::list<RendererBase*>::iterator r_it = m_pipeline.begin();
1041  for (; r_it != m_pipeline.end(); ++r_it) {
1042  if ((*r_it)->isActivedLayer(*layer_it)) {
1043  (*r_it)->render(this, *layer_it, instancesToRender);
1045  }
1046  }
1047  }
1048  }
1049 
1050  renderOverlay();
1052  if (m_lighting && lm != 0) {
1054  }
1056  }
1057 }
std::vector< ImagePtr > * getAnimationOverlay() const
Returns pointer to AnimationOverlay vector.
Definition: renderitem.cpp:101
#define FL_WARN(logger, msg)
Definition: logger.h:72
bool m_ani_fill
Definition: camera.h:512
Abstract interface for all the renderbackends.
virtual ImagePtr loadBlank(uint32_t width, uint32_t height)
Loads a blank resource.
void setZToY(double zToY)
Sets zToY value for the camera and enables their use.
Definition: camera.cpp:191
virtual void setLighting(float red, float green, float blue)=0
Set colors for lighting.
T * get() const
allows direct access to underlying pointer
Definition: sharedptr.h:155
int32_t getOverlayImage()
Returns the pool id of the overlay image.
Definition: camera.cpp:824
std::list< RendererBase * > m_pipeline
Definition: camera.h:486
DoublePoint getLogicalCellDimensions(Layer *layer)
Gets logical cell image dimensions for given layer.
Definition: camera.cpp:446
RenderBackend * m_renderbackend
Definition: camera.h:490
double m_tilt
Definition: camera.h:463
Matrix & applyRotate(T angle, T x, T y, T z)
Definition: matrix.h:306
DoubleMatrix m_vs_inverse_matrix
Definition: camera.h:459
Matrix inverse() const
Adjoint method inverse, constant time inversion implementation.
Definition: matrix.h:63
std::vector< RenderItem * > RenderList
Definition: renderitem.h:130
void setOverlayImage(int32_t id, bool fill=false)
Sets a image as overlay, if fill is true the image gets the viewport size.
Definition: camera.cpp:818
void updateMap(Map *map)
Definition: camera.cpp:250
void calculateZValue(DoublePoint3D &screen_coords)
calculates z-value for given screenpoint
Definition: camera.cpp:415
virtual ~MapObserver()
Definition: camera.cpp:66
Base Class for Images.
Definition: image.h:48
#define ABS(x)
Definition: fife_math.h:41
uint32_t m_screen_cell_height
Definition: camera.h:474
T h
Height of the rectangle.
Definition: rect.h:93
virtual ImagePtr get(const std::string &name)
Gets a shared pointer to the Image.
void updateMatrices()
Updates the camera transformation matrix T with requested values.
Definition: camera.cpp:369
void resetUpdates()
Resets temporary values from last update round, like warped flag.
Definition: camera.cpp:707
DoubleMatrix m_inverse_matrix
Definition: camera.h:456
virtual void onMapChanged(Map *map, std::vector< Layer * > &changedLayers)
Called when some layer is changed on map.
Definition: camera.cpp:68
Helper class to create log strings out from separate parts Usage: LMsg("some text") << variable << "...
Definition: logger.h:82
void removeChangeListener(MapChangeListener *listener)
Removes associated change listener.
Definition: map.cpp:234
MapObserver(Camera *camera)
Definition: camera.cpp:63
void setOverlayColor(uint8_t red, uint8_t green, uint8_t blue, uint8_t alpha)
Sets a color as overlay.
Definition: camera.cpp:791
Rect m_viewport
Definition: camera.h:470
void setLayer(Layer *layer)
Sets layer where this location is pointing to.
Definition: location.cpp:79
Matrix< T > & mult4by4(const Matrix< T > &mat)
Definition: matrix.h:281
T x
The X Coordinate.
Definition: rect.h:84
Transform m_transform
Definition: camera.h:482
int32_t m_img_id
Definition: camera.h:509
void reset(T *ptr=0)
reset this pointer to a null shared pointer this can be used to lower the reference count of the shar...
Definition: sharedptr.h:164
virtual const std::string & getName() const =0
The name of the renderbackend.
DoubleMatrix m_vs_matrix
Definition: camera.h:458
RenderList & getRenderListRef(Layer *layer)
Returns reference to RenderList.
Definition: camera.cpp:528
bool isZToYEnabled() const
Gets if z to y manipulation is enabled / disabled.
Definition: camera.cpp:208
uint32_t getHeight() const
DoublePoint3D toVirtualScreenCoordinates(const ExactModelCoordinate &map_coords)
Transforms given point from map coordinates to virtual screen coordinates.
Definition: camera.cpp:433
bool contains(const PointType2D< T > &point) const
Checks whether a rectangle contains a Point.
Definition: rect.h:184
void resetLightingColor()
Resets lighting color.
Definition: camera.cpp:786
void setMapCoordinates(const ExactModelCoordinate &coordinates)
Sets map coordinates to this location.
Definition: location.cpp:98
void setZToYEnabled(bool enabled)
Sets z to y manipulation enabled / disabled.
Definition: camera.cpp:204
void resetRenderers()
resets active layer information on all renderers.
Definition: camera.cpp:748
void setTilt(double tilt)
Sets tilt for the camera.
Definition: camera.cpp:136
uint32_t getDuration() const
Gets the total duration for the whole animation.
Definition: animation.h:138
void getPixelRGBA(int32_t x, int32_t y, uint8_t *r, uint8_t *g, uint8_t *b, uint8_t *a)
Definition: image.cpp:181
double m_referenceScaleY
Definition: camera.h:476
void resetOverlayAnimation()
Resets the animation overlay.
Definition: camera.cpp:848
bool isEnabled() const
Is renderer enabled.
Definition: rendererbase.h:136
virtual void detachRenderTarget()=0
Detaches current render surface.
bool m_enabledZToY
Definition: camera.h:467
void addChangeListener(MapChangeListener *listener)
Adds new change listener.
Definition: map.cpp:230
bool m_img_fill
Definition: camera.h:511
static Logger _log(LM_AUDIO)
PointType3D< int32_t > Point3D
Definition: point.h:328
void attach(Instance *instance)
Attaches the camera to an instance.
Definition: camera.cpp:674
double getTilt() const
Gets camera tilt.
Definition: camera.cpp:145
Point3D getZOffset(Layer *layer)
Gets a point that contain the visual z(z=1) difference, based on the given layer. ...
Definition: camera.cpp:501
DoubleMatrix m_screen_2_vscreen
Definition: camera.h:461
Camera * m_camera
Definition: camera.cpp:60
PointType2D< double > DoublePoint
Definition: point.h:196
Exception base class.
Definition: exception.h:43
Matrix & applyScale(T x, T y, T z)
Apply scale into this matrix.
Definition: matrix.h:148
std::vector< uint8_t > getOverlayColor()
Returns a vector that contain the overlay color.
Definition: camera.cpp:799
void setRotation(double rotation)
Sets rotation for the camera.
Definition: camera.cpp:149
void resetOverlayColor()
Resets the color overlay.
Definition: camera.cpp:814
void onRendererEnabledChanged(RendererBase *renderer)
Renderer is enabled / disabled.
Definition: camera.cpp:733
t_layer_to_instances m_layerToInstances
Definition: camera.h:493
Camera(const std::string &id, Layer *layer, const Rect &viewport, RenderBackend *renderbackend)
Constructor Camera needs to be added to the view.
Definition: camera.cpp:80
bool isEnabled()
Gets if camera is enabled / disabled.
Definition: camera.cpp:361
Camera describes properties of a view port shown in the main screen Main screen can have multiple cam...
Definition: camera.h:59
Layer * getLayer() const
Gets the layer where this location is pointing to.
Definition: location.cpp:83
bool m_col_overlay
Definition: camera.h:505
static ImageManager * instance()
Definition: singleton.h:84
Location & getLocationRef()
Gets reference of current location of instance.
Definition: instance.cpp:318
uint32_t m_start_time
Definition: camera.h:513
ModelCoordinate getLayerCoordinates() const
Gets cell precision layer coordinates set to this location.
Definition: location.cpp:113
virtual void getVertices(std::vector< ExactModelCoordinate > &vtx, const ModelCoordinate &cell)=0
Fills given point vector with vertices from selected cell.
ScreenPoint m_cur_origo
Definition: camera.h:469
RendererBase * getRenderer(const std::string &name)
Gets renderer with given name.
Definition: camera.cpp:744
const uint32_t MAX_BATCH_SIZE
Definition: camera.cpp:57
std::map< std::string, RendererBase * > m_renderers
Definition: camera.h:485
#define FL_ERR(logger, msg)
Definition: logger.h:73
virtual uint32_t getLightingModel() const =0
Gets the current light model.
DoubleMatrix m_matrix
Definition: camera.h:455
uint32_t getHeight() const
Definition: image.cpp:160
bool m_enabled
Definition: camera.h:477
void addRenderer(RendererBase *renderer)
Adds new renderer on the view.
Definition: camera.cpp:720
double m_zToY
Definition: camera.h:466
unsigned char uint8_t
Definition: core.h:38
Map * getMap() const
Gets the map where this location is pointing to.
Definition: location.cpp:72
double getOriginalZToY() const
Gets original zToY transformation value.
Definition: camera.cpp:176
std::map< Layer *, LayerCache * > m_cache
Definition: camera.h:495
bool m_ani_overlay
Definition: camera.h:507
PointType2D< int32_t > Point
Definition: point.h:195
uint32_t getTime() const
Get the time.
const Rect & getViewPort() const
Gets the viewport for camera in pixel coordinates.
Definition: camera.cpp:304
void onRendererPipelinePositionChanged(RendererBase *renderer)
Renderer&#39;s pipeline position has been changed.
Definition: camera.cpp:729
ImagePtr getFrameByTimestamp(uint32_t timestamp)
Gets the frame image that matches the given timestamp.
Definition: animation.cpp:150
void setLocation(const Location &location)
Sets the location for camera.
Definition: camera.cpp:220
static bool Equal(T _val1, T _val2)
Definition: fife_math.h:287
friend class MapObserver
Definition: camera.h:412
Base class for all view renderers View renderer renders one aspect of the view shown on screen...
Definition: rendererbase.h:78
void pushClipArea(const Rect &cliparea, bool clear=true)
Pushes clip area to clip stack Clip areas define which area is drawn on screen.
bool m_updated
Definition: camera.h:488
ImagePtr getCacheImage()
Definition: layercache.cpp:806
void removeLayer(Layer *layer)
Definition: camera.cpp:762
A basic layer on a map.
Definition: layer.h:99
double getZoom() const
Gets camera zoom.
Definition: camera.cpp:172
virtual void onLayerDelete(Map *map, Layer *layer)
Called when some layer gets deleted on map.
Definition: camera.cpp:75
Point doublePt2intPt(DoublePoint pt)
Convert from 2D double point to 2D int32_t point.
Definition: point.h:335
Location getLocation() const
Gets current location of instance.
Definition: instance.cpp:314
void setLightingColor(float red, float green, float blue)
Sets lighting color.
Definition: camera.cpp:769
Location & getLocationRef()
Gets a reference to the camera location.
Definition: camera.cpp:295
void setCacheImage(ImagePtr image)
Definition: layercache.cpp:810
void resetOverlayImage()
Resets the image overlay.
Definition: camera.cpp:832
void popClipArea()
Pops clip area from clip stack.
ExactModelCoordinate & getExactLayerCoordinatesRef()
Gets reference to exact layer coordinates.
Definition: location.cpp:105
void detach()
Detaches the camera from an instance.
Definition: camera.cpp:683
uint32_t getWidth() const
Definition: image.cpp:151
unsigned short uint16_t
Definition: core.h:39
T y
The Y Coordinate.
Definition: rect.h:87
void renderOverlay()
Renders the overlay(color, image, animation) for the camera.
Definition: camera.cpp:853
CellGrid * getCellGrid() const
Get the Cellgrid.
Definition: layer.cpp:93
const Rect & getMapViewPort()
Gets the viewport for camera in map coordinates.
Definition: camera.cpp:308
bool m_lighting
Definition: camera.h:500
void addLayer(Layer *layer)
Definition: camera.cpp:755
AnimationPtr getOverlayAnimation()
Returns an AnimationPtr to the overlay animation.
Definition: camera.cpp:844
void setRendererListener(IRendererListener *listener)
Sets listener for renderer.
Definition: rendererbase.h:140
virtual std::string getName()=0
Name of the renderer.
static T Tan(T _val)
Definition: fife_math.h:282
bool pipelineSort(const RendererBase *lhs, const RendererBase *rhs)
Definition: camera.cpp:716
virtual ~Camera()
Destructor.
Definition: camera.cpp:123
void refresh()
Refreshes camera view in case e.g.
Definition: camera.cpp:701
#define FL_LOG(logger, msg)
Definition: logger.h:71
AnimationPtr m_ani_ptr
Definition: camera.h:510
void updateReferenceScale()
Updates camera reference scale Reference scale is in a sense an internal zooming factor, which adjusts cell dimensions in logical space to ones shown on screen.
Definition: camera.cpp:515
Point getCellImageDimensions()
Gets screen cell image dimensions.
Definition: camera.cpp:271
Matrix & loadRotate(T angle, T x, T y, T z)
Make this a rotation matrix.
Definition: matrix.h:113
Matrix & loadScale(T x, T y, T z=1)
Make this a scale matrix.
Definition: matrix.h:157
bool intersects(const RectType< T > &rect) const
Check whether two rectangles share some area.
Definition: rect.h:227
bool isSharedImage() const
Returns true if this image shares data with another one.
Definition: image.h:148
ImagePtr image
Definition: renderitem.h:112
virtual void render(const Rect &rect, uint8_t alpha=255, uint8_t const *rgb=0)=0
Renders itself to the current render target (main screen or attached destination image) at the rectan...
ScreenPoint toScreenCoordinates(const ExactModelCoordinate &map_coords)
Transforms given point from map coordinates to screen coordinates.
Definition: camera.cpp:428
std::map< Layer *, Point > m_image_dimensions
Definition: camera.h:480
A 3D Point.
Definition: point.h:205
Instance * m_attachedto
Definition: camera.h:478
bool m_mapViewPortUpdated
Definition: camera.h:472
const std::string & getId() const
Get the id of this layer.
Definition: layer.cpp:81
void getMatchingInstances(ScreenPoint screen_coords, Layer &layer, std::list< Instance * > &instances, uint8_t alpha=0)
Returns instances that match given screen coordinate.
Definition: camera.cpp:532
Location getLocation() const
Gets the location camera is rendering.
Definition: camera.cpp:291
DoublePoint intPt2doublePt(Point pt)
Convert from 2D int32_t point to 2D double point.
Definition: point.h:349
void update(Camera::Transform transform, RenderList &renderlist)
Definition: layercache.cpp:369
const std::list< Layer * > & getLayers() const
Get the layers on this map.
Definition: map.h:120
Map * m_map
Definition: camera.h:497
static num_type pi()
Definition: fife_math.h:134
ExactModelCoordinate toMapCoordinates(ScreenPoint screen_coords, bool z_calculated=true)
Transforms given point from screen coordinates to map coordinates.
Definition: camera.cpp:420
virtual void forceLoadInternal()=0
Forces to load the image into internal memory of GPU.
virtual void attachRenderTarget(ImagePtr &img, bool discard)=0
Attaches given image as a new render surface.
double m_referenceScaleX
Definition: camera.h:475
void setOverlayAnimation(AnimationPtr anim, bool fill=false)
Sets a animation as overlay, if fill is true the animation gets the viewport size.
Definition: camera.cpp:837
std::string m_id
Definition: camera.h:416
void renderStaticLayer(Layer *layer, bool update)
Renders the layer part that is on screen as one image.
Definition: camera.cpp:908
Rect m_mapViewPort
Definition: camera.h:471
DoubleMatrix m_vscreen_2_screen
Definition: camera.h:460
virtual void onLayerCreate(Map *map, Layer *layer)
Called when some layer gets created on the map.
Definition: camera.cpp:71
Point3D getOrigin() const
Gets screen point for the camera location.
Definition: camera.cpp:365
virtual void renderVertexArrays()=0
Render the Vertex Arrays, only for primitives (points, lines,...)
virtual void fillRectangle(const Point &p, uint16_t w, uint16_t h, uint8_t r, uint8_t g, uint8_t b, uint8_t a=255)=0
Draws a filled axis parallel rectangle.
void update()
General update routine.
Definition: camera.cpp:687
std::vector< float > m_light_colors
Definition: camera.h:502
uint32_t scaleTime(float multiplier, uint32_t ticks)
Utility function to calculate time scaling.
void setCellImageDimensions(uint32_t width, uint32_t height)
Sets screen cell image dimensions.
Definition: camera.cpp:212
void setViewPort(const Rect &viewport)
Sets the viewport for camera viewport is rectangle inside the view where camera renders.
Definition: camera.cpp:299
A container of Layer(s).
Definition: map.h:88
double m_zoom
Definition: camera.h:465
MapObserver * m_map_observer
Definition: camera.h:496
unsigned int uint32_t
Definition: core.h:40
DoublePoint3D screenToVirtualScreen(const ScreenPoint &p)
Transforms given point from screen coordinates to virtual screen coordinates.
Definition: camera.cpp:442
ExactModelCoordinate toMapCoordinates(const ModelCoordinate &layer_coords)
Transforms given point from layer coordinates to map coordinates.
Definition: cellgrid.cpp:75
Location m_location
Definition: camera.h:468
virtual void resetLighting()=0
Reset lighting with default values.
virtual void resetStencilBuffer(uint8_t buffer)=0
Reset stencil buffer with given value.
void setEnabled(bool enabled)
Sets camera enabled / disabled.
Definition: camera.cpp:357
int32_t getPipelinePosition() const
Gets renderer position in the rendering pipeline.
Definition: rendererbase.h:117
Matrix & applyTranslate(T x, T y, T z)
Apply translation into this matrix.
Definition: matrix.h:180
ExactModelCoordinate getExactLayerCoordinates() const
Gets exact layer coordinates set to this location.
Definition: location.cpp:109
SDL_Color m_overlay_color
Definition: camera.h:508
T w
Width of the rectangle.
Definition: rect.h:90
#define FL_DBG(logger, msg)
Definition: logger.h:70
double getZToY() const
Gets zToY value.
Definition: camera.cpp:200
void render()
Renders camera.
Definition: camera.cpp:987
An Instance is an "instantiation" of an Object at a Location.
Definition: instance.h:101
void updateRenderLists()
Updates camera RenderLists.
Definition: camera.cpp:962
ScreenPoint virtualScreenToScreen(const DoublePoint3D &p)
Transforms given point from virtual screen coordinates to screen coordinates.
Definition: camera.cpp:438
double m_rotation
Definition: camera.h:464
std::vector< float > getLightingColor()
Returns a vector that contain the light color.
Definition: camera.cpp:777
ExactModelCoordinate getMapCoordinates() const
Gets map coordinates set to this location.
Definition: location.cpp:117
bool m_img_overlay
Definition: camera.h:506
uint32_t m_screen_cell_width
Definition: camera.h:473
double getRotation() const
Gets camera rotation.
Definition: camera.cpp:157
Point getRealCellDimensions(Layer *layer)
Gets real cell image dimensions for given layer.
Definition: camera.cpp:480
Rect getLayerViewPort(Layer *layer)
Gets the viewport for camera in layer coordinates.
Definition: camera.cpp:341
void setZoom(double zoom)
Sets zoom for the camera.
Definition: camera.cpp:161
Listener interface for changes happening on map.
Definition: map.h:56