FIFE  be64c707dea6b3250bd4355bf5c825d25920087d
camera.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2005-2019 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, Map* map, const Rect& viewport, RenderBackend* renderbackend) :
81  m_id(id),
82  m_map(map),
83  m_viewport(viewport),
84  m_renderbackend(renderbackend),
85  m_position(ExactModelCoordinate(0, 0, 0)),
86  m_matrix(),
87  m_inverse_matrix(),
88  m_tilt(0),
89  m_rotation(0),
90  m_zoom(1),
91  m_zToY(0),
92  m_enabledZToY(false),
93  m_location(),
94  m_curOrigin(ScreenPoint(0, 0, 0)),
95  m_mapViewPort(),
96  m_mapViewPortUpdated(false),
97  m_screenCellWidth(1),
98  m_screenCellHeight(1),
99  m_referenceScaleX(1),
100  m_referenceScaleY(1),
101  m_enabled(true),
102  m_attachedTo(NULL),
103  m_transform(NoneTransform),
104  m_renderers(),
105  m_pipeline(),
106  m_updated(false),
107  m_layerToInstances(),
108  m_lighting(false),
109  m_light_colors(),
110  m_col_overlay(false),
111  m_img_overlay(false),
112  m_ani_overlay(false) {
113 
114  m_map_observer = new MapObserver(this);
115  init();
116  }
117 
119  // Trigger removal of LayerCaches and MapObserver
120  if (m_map) {
122  const std::list<Layer*>& layers = m_map->getLayers();
123  for (std::list<Layer*>::const_iterator i = layers.begin(); i != layers.end(); ++i) {
124  removeLayer(*i);
125  }
126  }
127 
128  std::map<std::string, RendererBase*>::iterator r_it = m_renderers.begin();
129  for(; r_it != m_renderers.end(); ++r_it) {
130  r_it->second->reset();
131  delete r_it->second;
132  }
133  m_renderers.clear();
134  delete m_map_observer;
135  }
136 
137  void Camera::init() {
139  updateMatrices();
140 
142 
143  // Trigger addition of LayerCaches and MapObserver
145  const std::list<Layer*>& layers = m_map->getLayers();
146  for (std::list<Layer*>::const_iterator i = layers.begin(); i != layers.end(); ++i) {
147  addLayer(*i);
148  }
149  }
150 
151  void Camera::setTilt(double tilt) {
152  if (!Mathd::Equal(m_tilt, tilt)) {
154  m_tilt = tilt;
156  updateMatrices();
157  }
158  }
159 
160  double Camera::getTilt() const {
161  return m_tilt;
162  }
163 
164  void Camera::setRotation(double rotation) {
165  if (!Mathd::Equal(m_rotation, rotation)) {
167  m_rotation = rotation;
169  updateMatrices();
170  }
171  }
172 
173  double Camera::getRotation() const {
174  return m_rotation;
175  }
176 
177  void Camera::setZoom(double zoom) {
178  if (!Mathd::Equal(m_zoom, zoom)) {
180  m_zoom = zoom;
181  if (m_zoom < 0.001) {
182  m_zoom = 0.001;
183  }
184  updateMatrices();
185  }
186  }
187 
188  double Camera::getZoom() const {
189  return m_zoom;
190  }
191 
192  double Camera::getOriginalZToY() const {
193  DoubleMatrix matrix;
195  if (m_location.getLayer()) {
197  if (cg) {
200  }
201  }
202  matrix.applyRotate(-m_rotation, 0.0, 0.0, 1.0);
203  matrix.applyRotate(-m_tilt, 1.0, 0.0, 0.0);
204  return matrix.m9 * -1.0;
205  }
206 
207  void Camera::setZToY(double zToY) {
208  m_enabledZToY = true;
209  if (!Mathd::Equal(m_zToY, zToY)) {
211  m_zToY = zToY;
212  updateMatrices();
213  }
214  }
215 
216  double Camera::getZToY() const {
217  return m_zToY;
218  }
219 
220  void Camera::setZToYEnabled(bool enabled) {
221  m_enabledZToY = enabled;
222  }
223 
224  bool Camera::isZToYEnabled() const {
225  return m_enabledZToY;
226  }
227 
229  m_screenCellWidth = width;
230  m_screenCellHeight = height;
232  updateMatrices();
234  }
235 
236  void Camera::setLocation(const Location& location) {
237  if (m_location == location) {
238  return;
239  }
240 
241  CellGrid* cell_grid = NULL;
242  if (location.getLayer()) {
243  cell_grid = location.getLayer()->getCellGrid();
244  if (!cell_grid) {
245  throw Exception("Location layer without cellgrid given to Camera::setLocation");
246  }
247  }
248  else {
249  throw Exception("Location without layer given to Camera::setLocation");
250  }
251 
253  m_location = location;
255  updateMatrices();
257  }
258 
261  }
262 
264  Point p;
265  DoublePoint dimensions = getLogicalCellDimensions(layer);
266  p.x = static_cast<int32_t>(round(m_referenceScaleX * dimensions.x));
267  p.y = static_cast<int32_t>(round(m_referenceScaleY * dimensions.y));
268  return p;
269  }
270 
272  if (m_location.getLayer()) {
274  return m_location;
275  }
276  Location loc = Location();
277  if (m_map && m_map->getLayerCount() > 0) {
278  loc.setLayer(m_map->getLayers().back());
280  }
281  return loc;
282  }
283 
284  void Camera::setViewPort(const Rect& viewport) {
285  m_viewport = viewport;
286  refresh();
287  }
288 
289  const Rect& Camera::getViewPort() const {
290  return m_viewport;
291  }
292 
294  if (!m_mapViewPortUpdated) {
299 
300  std::vector<ExactModelCoordinate> coords;
301  coords.push_back(toMapCoordinates(sp2, false));
302  coords.push_back(toMapCoordinates(sp3, false));
303  coords.push_back(toMapCoordinates(sp4, false));
304 
305  ExactModelCoordinate emc = toMapCoordinates(sp1, false);
306  ModelCoordinate min(static_cast<int32_t>(emc.x), static_cast<int32_t>(emc.y));
307  ModelCoordinate max(static_cast<int32_t>(emc.x+0.5), static_cast<int32_t>(emc.y+0.5));
308  std::vector<ExactModelCoordinate>::iterator it = coords.begin();
309  for (; it != coords.end(); ++it) {
310  min.x = std::min(min.x, static_cast<int32_t>((*it).x));
311  min.y = std::min(min.y, static_cast<int32_t>((*it).y));
312  max.x = std::max(max.x, static_cast<int32_t>((*it).x+0.5));
313  max.y = std::max(max.y, static_cast<int32_t>((*it).y+0.5));
314  }
315  // makes the viewport a bit larger
316  m_mapViewPort.x = min.x - 1;
317  m_mapViewPort.y = min.y - 1;
318  m_mapViewPort.w = ABS(max.x - min.x) + 2;
319  m_mapViewPort.h = ABS(max.y - min.y) + 2;
320  m_mapViewPortUpdated = true;
321  }
322 
323  return m_mapViewPort;
324  }
325 
327  Rect mapView = getMapViewPort();
328  Location loc(layer);
329  ExactModelCoordinate emc(mapView.x, mapView.y);
330  loc.setMapCoordinates(emc);
331  emc.x = mapView.x+mapView.w;
332  emc.y = mapView.y+mapView.h;
333  mapView.x = loc.getLayerCoordinates().x;
334  mapView.y = loc.getLayerCoordinates().y;
335  loc.setMapCoordinates(emc);
336  mapView.w = ABS(loc.getLayerCoordinates().x - mapView.x);
337  mapView.h = ABS(loc.getLayerCoordinates().y - mapView.y);
338 
339  return mapView;
340  }
341 
342  void Camera::setEnabled(bool enabled) {
343  m_enabled = enabled;
344  }
345 
347  return m_enabled;
348  }
349 
351  if (Mathd::Equal(m_position.x, position.x) && Mathd::Equal(m_position.y, position.y)) {
352  return;
353  }
355  m_position = position;
356  updateMatrices();
358  }
359 
361  return m_position;
362  }
363 
365  return m_curOrigin;
366  }
367 
371 
373 
374  m_matrix.applyRotate(-m_rotation, 0.0, 0.0, 1.0);
375  m_matrix.applyRotate(-m_tilt, 1.0, 0.0, 0.0);
376  if (m_enabledZToY) {
377  m_matrix.m9 = -m_zToY; // z -> y height in pixels
378  }
379  double scale = m_zoom;
380  m_matrix.applyScale(scale, scale, scale);
383 
384  m_vs_matrix.applyRotate(-m_rotation, 0.0, 0.0, 1.0);
385  m_vs_matrix.applyRotate(-m_tilt, 1.0, 0.0, 0.0);
386  if (m_enabledZToY) {
387  m_vs_matrix.m9 = -m_zToY; // z -> y height in pixels
388  }
390 
391  // calculate the screen<->virtual screen transformation
392  // this explicitly ignores the z-value.
394  // NOTE: mult4by4 is an in-place modification.
396  // set the z transformation to unity
397  const int32_t N=4;
398  for(int32_t i=0; i!=N; ++i) {
399  m_vscreen_2_screen[2*N + i] = 0;
400  m_vscreen_2_screen[i*N + 2] = 0;
401  }
402  m_vscreen_2_screen[2*N + 2] = 1;
404 
405  m_mapViewPortUpdated = false;
406  // FL_WARN(_log, LMsg("matrix: ") << m_matrix << " 1: " << m_matrix.inverse().mult4by4(m_matrix));
407 // FL_WARN(_log, LMsg("vs2s matrix: ") << m_vscreen_2_screen << " s2vs matrix: " << m_screen_2_vscreen);
408  }
409 
410  void Camera::calculateZValue(DoublePoint3D& screen_coords) {
411  int32_t dy = -(screen_coords.y - toScreenCoordinates(m_position).y);
412  screen_coords.z = Mathd::Tan(m_tilt * (Mathd::pi() / 180.0)) * static_cast<double>(dy);
413  }
414 
415  ExactModelCoordinate Camera::toMapCoordinates(ScreenPoint screen_coords, bool z_calculated) {
416  DoublePoint3D double_screen_coords = intPt2doublePt(screen_coords);
417  if (!z_calculated) {
418  calculateZValue(double_screen_coords);
419  }
420  return m_inverse_matrix * double_screen_coords;
421  }
422 
424  ScreenPoint pt = doublePt2intPt(m_matrix * elevation_coords);
425  return pt;
426  }
427 
429  DoublePoint3D pt = (m_vs_matrix * elevation_coords);
430  return pt;
431  }
432 
435  }
436 
439  }
440 
442  assert(layer);
443  CellGrid* cg = layer->getCellGrid();
444  assert(cg);
445 
446  ModelCoordinate cell(0,0);
447  std::vector<ExactModelCoordinate> vertices;
448  cg->getVertices(vertices, cell);
449 
450  DoubleMatrix mtx;
451  mtx.loadRotate(m_rotation, 0.0, 0.0, 1.0);
452  mtx.applyRotate(m_tilt, 1.0, 0.0, 0.0);
453 
454  double x1 = 0;
455  double x2 = 0;
456  double y1 = 0;
457  double y2 = 0;
458 
459  for (uint32_t i = 0; i < vertices.size(); i++) {
460  vertices[i] = cg->toMapCoordinates(vertices[i]);
461  vertices[i] = mtx * vertices[i];
462  if (i == 0) {
463  x1 = x2 = vertices[0].x;
464  y1 = y2 = vertices[0].y;
465  } else {
466  x1 = std::min(vertices[i].x, x1);
467  x2 = std::max(vertices[i].x, x2);
468  y1 = std::min(vertices[i].y, y1);
469  y2 = std::max(vertices[i].y, y2);
470  }
471  }
472  return DoublePoint( x2 - x1, y2 - y1 );
473  }
474 
476  std::vector<ExactModelCoordinate> vertices;
477  vertices.push_back(ExactModelCoordinate(-0.5, -0.5));
478  vertices.push_back(ExactModelCoordinate(0.5, -0.5));
479  vertices.push_back(ExactModelCoordinate(0.5, 0.5));
480  vertices.push_back(ExactModelCoordinate(-0.5, 0.5));
481 
482  DoubleMatrix mtx;
483  mtx.loadRotate(m_rotation, 0.0, 0.0, 1.0);
484  mtx.applyRotate(m_tilt, 1.0, 0.0, 0.0);
485 
486  double x1 = 0;
487  double x2 = 0;
488  double y1 = 0;
489  double y2 = 0;
490 
491  for (uint32_t i = 0; i < vertices.size(); i++) {
492  vertices[i] = mtx * vertices[i];
493  if (i == 0) {
494  x1 = x2 = vertices[0].x;
495  y1 = y2 = vertices[0].y;
496  }
497  else {
498  x1 = std::min(vertices[i].x, x1);
499  x2 = std::max(vertices[i].x, x2);
500  y1 = std::min(vertices[i].y, y1);
501  y2 = std::max(vertices[i].y, y2);
502  }
503  }
504  return DoublePoint(x2 - x1, y2 - y1);
505  }
506 
509  m_referenceScaleX = static_cast<double>(m_screenCellWidth) / dim.x;
510  m_referenceScaleY = static_cast<double>(m_screenCellHeight) / dim.y;
511 
512  FL_DBG(_log, "Updating reference scale");
513  FL_DBG(_log, LMsg(" tilt=") << m_tilt << " rot=" << m_rotation);
514  FL_DBG(_log, LMsg(" m_screenCellWidth=") << m_screenCellWidth);
515  FL_DBG(_log, LMsg(" m_screenCellHeight=") << m_screenCellHeight);
516  FL_DBG(_log, LMsg(" m_referenceScaleX=") << m_referenceScaleX);
517  FL_DBG(_log, LMsg(" m_referenceScaleY=") << m_referenceScaleY);
518  }
519 
521  return m_layerToInstances[layer];
522  }
523 
524  void Camera::getMatchingInstances(ScreenPoint screen_coords, Layer& layer, std::list<Instance*>& instances, uint8_t alpha) {
525  instances.clear();
526  bool zoomed = !Mathd::Equal(m_zoom, 1.0);
527  bool special_alpha = alpha != 0;
528 
529  const RenderList& layer_instances = m_layerToInstances[&layer];
530  RenderList::const_iterator instance_it = layer_instances.end();
531  while (instance_it != layer_instances.begin()) {
532  --instance_it;
533  Instance* i = (*instance_it)->instance;
534  const RenderItem& vc = **instance_it;
535  if ((vc.dimensions.contains(Point(screen_coords.x, screen_coords.y)))) {
536  if(vc.image->isSharedImage()) {
537  vc.image->forceLoadInternal();
538  }
539  uint8_t r, g, b, a = 0;
540  int32_t x = screen_coords.x - vc.dimensions.x;
541  int32_t y = screen_coords.y - vc.dimensions.y;
542  if (zoomed) {
543  double fx = static_cast<double>(x);
544  double fy = static_cast<double>(y);
545  double fow = static_cast<double>(vc.image->getWidth());
546  double foh = static_cast<double>(vc.image->getHeight());
547  double fsw = static_cast<double>(vc.dimensions.w);
548  double fsh = static_cast<double>(vc.dimensions.h);
549  x = static_cast<int32_t>(round(fx / fsw * fow));
550  y = static_cast<int32_t>(round(fy / fsh * foh));
551  }
552  if (vc.getAnimationOverlay()) {
553  std::vector<ImagePtr>* ao = vc.getAnimationOverlay();
554  std::vector<ImagePtr>::iterator it = ao->begin();
555  for (; it != ao->end(); ++it) {
556  if ((*it)->isSharedImage()) {
557  (*it)->forceLoadInternal();
558  }
559  (*it)->getPixelRGBA(x, y, &r, &g, &b, &a);
560  // instance is hit with mouse if not totally transparent
561  if (a == 0 || (special_alpha && a < alpha)) {
562  continue;
563  }
564  instances.push_back(i);
565  break;
566  }
567  } else {
568  vc.image->getPixelRGBA(x, y, &r, &g, &b, &a);
569  // instance is hit with mouse if not totally transparent
570  if (a == 0 || (special_alpha && a < alpha)) {
571  continue;
572  }
573  instances.push_back(i);
574  }
575  }
576  }
577  }
578 
579  void Camera::getMatchingInstances(Rect screen_rect, Layer& layer, std::list<Instance*>& instances, uint8_t alpha) {
580  instances.clear();
581  bool zoomed = !Mathd::Equal(m_zoom, 1.0);
582  bool special_alpha = alpha != 0;
583 
584  const RenderList& layer_instances = m_layerToInstances[&layer];
585  RenderList::const_iterator instance_it = layer_instances.end();
586  while (instance_it != layer_instances.begin()) {
587  --instance_it;
588  Instance* i = (*instance_it)->instance;;
589  const RenderItem& vc = **instance_it;
590  if ((vc.dimensions.intersects(screen_rect))) {
591  if(vc.image->isSharedImage()) {
592  vc.image->forceLoadInternal();
593  }
594  uint8_t r, g, b, a = 0;
595  int32_t intersection_left = std::max(screen_rect.x, vc.dimensions.x);
596  int32_t intersection_right = std::min(screen_rect.right(), vc.dimensions.right());
597  int32_t intersection_top = std::max(screen_rect.y, vc.dimensions.y);
598  int32_t intersection_bottom = std::min(screen_rect.bottom(), vc.dimensions.bottom());
599 
600  for(int32_t xx = intersection_left; xx < intersection_right; xx++) {
601  for(int32_t yy = intersection_top; yy < intersection_bottom; yy++) {
602  int32_t x = xx - vc.dimensions.x;
603  int32_t y = yy - vc.dimensions.y;
604  if (zoomed) {
605  double fx = static_cast<double>(x);
606  double fy = static_cast<double>(y);
607  double fow = static_cast<double>(vc.image->getWidth());
608  double foh = static_cast<double>(vc.image->getHeight());
609  double fsw = static_cast<double>(vc.dimensions.w);
610  double fsh = static_cast<double>(vc.dimensions.h);
611  x = static_cast<int32_t>(round(fx / fsw * fow));
612  y = static_cast<int32_t>(round(fy / fsh * foh));
613  }
614  if (vc.getAnimationOverlay()) {
615  std::vector<ImagePtr>* ao = vc.getAnimationOverlay();
616  std::vector<ImagePtr>::iterator it = ao->begin();
617  for (; it != ao->end(); ++it) {
618  if ((*it)->isSharedImage()) {
619  (*it)->forceLoadInternal();
620  }
621  (*it)->getPixelRGBA(x, y, &r, &g, &b, &a);
622  // instance is hit with mouse if not totally transparent
623  if (a == 0 || (special_alpha && a < alpha)) {
624  continue;
625  }
626  instances.push_back(i);
627  goto found_non_transparent_pixel;
628  }
629  } else {
630  vc.image->getPixelRGBA(x, y, &r, &g, &b, &a);
631  // instance is hit with mouse if not totally transparent
632  if (a == 0 || (special_alpha && a < alpha)) {
633  continue;
634  }
635  instances.push_back(i);
636  goto found_non_transparent_pixel;
637  }
638  }
639  }
640  found_non_transparent_pixel:;
641  }
642  }
643  }
644 
645  void Camera::getMatchingInstances(Location& loc, std::list<Instance*>& instances, bool use_exactcoordinates) {
646  instances.clear();
647  Layer* layer = loc.getLayer();
648  if(!layer) {
649  return;
650  }
651 
652  const RenderList& layer_instances = m_layerToInstances[layer];
653  RenderList::const_iterator instance_it = layer_instances.end();
654  while (instance_it != layer_instances.begin()) {
655  --instance_it;
656  Instance* i = (*instance_it)->instance;
657  if (use_exactcoordinates) {
659  instances.push_back(i);
660  }
661  } else {
663  instances.push_back(i);
664  }
665  }
666  }
667  }
668 
669  void Camera::attach(Instance *instance) {
670  if (instance && instance != m_attachedTo) {
671  m_attachedTo = instance;
672  }
673  }
674 
675  void Camera::detach() {
676  m_attachedTo = NULL;
677  }
678 
679  void Camera::update() {
680  if (!m_attachedTo) {
681  return;
682  }
684  if (Mathd::Equal(m_position.x, pos.x) && Mathd::Equal(m_position.y, pos.y)) {
685  return;
686  }
688  m_position = pos;
689  updateMatrices();
691  }
692 
694  updateMatrices();
697  }
698 
700  if (m_transform == NoneTransform) {
701  m_updated = false;
702  } else {
703  m_updated = true;
704  }
706  }
707 
708  bool pipelineSort(const RendererBase* lhs, const RendererBase* rhs) {
709  return (lhs->getPipelinePosition() < rhs->getPipelinePosition());
710  }
711 
713  renderer->setRendererListener(this);
714  m_renderers[renderer->getName()] = renderer;
715  if (renderer->isEnabled()) {
716  m_pipeline.push_back(renderer);
717  }
718  m_pipeline.sort(pipelineSort);
719  }
720 
722  m_pipeline.sort(pipelineSort);
723  }
724 
726  assert(m_renderers[renderer->getName()]);
727  if (renderer->isEnabled()) {
728  FL_LOG(_log, LMsg("Enabling renderer ") << renderer->getName());
729  m_pipeline.push_back(renderer);
730  m_pipeline.sort(pipelineSort);
731  } else {
732  m_pipeline.remove(renderer);
733  }
734  }
735 
736  RendererBase* Camera::getRenderer(const std::string& name) {
737  return m_renderers[name];
738  }
739 
741  std::map<std::string, RendererBase*>::iterator r_it = m_renderers.begin();
742  for (; r_it != m_renderers.end(); ++r_it) {
743  r_it->second->reset();
744  }
745  }
746 
747  void Camera::addLayer(Layer* layer) {
748  m_cache[layer] = new LayerCache(this);
749  m_cache[layer]->setLayer(layer);
750  m_layerToInstances[layer] = RenderList();
751  refresh();
752  }
753 
754  void Camera::removeLayer(Layer* layer) {
755  delete m_cache[layer];
756  m_cache.erase(layer);
757  m_layerToInstances.erase(layer);
758  if (m_location.getLayer() == layer) {
759  m_location.reset();
760  }
761  refresh();
762  }
763 
764  void Camera::setLightingColor(float red, float green, float blue) {
765  m_lighting = true;
766  m_light_colors.clear();
767  m_light_colors.push_back(red);
768  m_light_colors.push_back(green);
769  m_light_colors.push_back(blue);
770  }
771 
772  std::vector<float> Camera::getLightingColor() {
773  if(m_light_colors.empty()) {
774  for(int32_t colors = 0; colors != 3; ++colors) {
775  m_light_colors.push_back(1.0f);
776  }
777  }
778  return m_light_colors;
779  }
780 
782  m_lighting = false;
784  }
785 
786  void Camera::setOverlayColor(uint8_t red, uint8_t green, uint8_t blue, uint8_t alpha) {
787  m_col_overlay = true;
788  m_overlay_color.r = red;
789  m_overlay_color.g = green;
790  m_overlay_color.b = blue;
791  m_overlay_color.a = alpha;
792  }
793 
794  std::vector<uint8_t> Camera::getOverlayColor() {
795  std::vector<uint8_t> colors;
796  if (m_col_overlay) {
797  colors.push_back(m_overlay_color.r);
798  colors.push_back(m_overlay_color.g);
799  colors.push_back(m_overlay_color.b);
800  colors.push_back(m_overlay_color.a);
801  } else {
802  for(uint8_t cc = 0; cc != 4; ++cc) {
803  colors.push_back(255);
804  }
805  }
806  return colors;
807  }
808 
810  m_col_overlay = false;
811  }
812 
813  void Camera::setOverlayImage(int32_t id, bool fill) {
814  m_img_overlay = true;
815  m_img_id = id;
816  m_img_fill = fill;
817  }
818 
820  int32_t id = -1;
821  if (m_img_overlay) {
822  id = m_img_id;
823  }
824  return id;
825  }
826 
828  m_img_overlay = false;
829  m_img_id = -1;
830  }
831 
833  m_ani_overlay = true;
834  m_ani_ptr = anim;
835  m_ani_fill = fill;
836  m_start_time = 0;
837  }
838 
840  return m_ani_ptr;
841  }
842 
844  m_ani_overlay = false;
845  m_ani_ptr.reset();
846  }
847 
850  return;
851  }
852  uint16_t width = m_viewport.w;
853  uint16_t height = m_viewport.h;
854  Point pm = Point(m_viewport.x + width/2, m_viewport.y + height/2);
855  Rect r;
856 
857  // color overlay
858  if (m_col_overlay) {
861  }
862  // image overlay
863  if (m_img_overlay) {
865  Image* img = resptr.get();
866  if (img) {
867  if (m_img_fill) {
868  r.w = width;
869  r.h = height;
870  } else {
871  r.w = img->getWidth();
872  r.h = img->getHeight();
873  }
874  r.x = pm.x-r.w/2;
875  r.y = pm.y-r.h/2;
876  img->render(r);
877  }
878  }
879  // animation overlay
880  if (m_ani_overlay) {
881  assert(m_ani_ptr != 0);
882 
883  if (m_start_time == 0) {
885  }
886  uint32_t animtime = scaleTime(1.0, TimeManager::instance()->getTime() - m_start_time) % m_ani_ptr->getDuration();
887  ImagePtr img = m_ani_ptr->getFrameByTimestamp(animtime);
888  if (img) {
889  if (m_ani_fill) {
890  r.w = width;
891  r.h = height;
892  } else {
893  r.w = img->getWidth();
894  r.h = img->getHeight();
895  }
896  r.x = pm.x-r.w/2;
897  r.y = pm.y-r.h/2;
898  img->render(r);
899  }
900  }
901  }
902 
904  // ToDo: Remove this function from the camera class to something like engine pre-render.
905  // ToDo: Check if partial rendering of only updated RenderItems to existing FBO is possible/faster in our case.
906  // ToDo: Add and fix support for SDL backend, for SDL it works only on the lowest layer(alpha/transparent bug).
907  LayerCache* cache = m_cache[layer];
908  ImagePtr cacheImage = cache->getCacheImage();
909  if (!cacheImage.get()) {
910  // the cacheImage name will be, camera id + _virtual_layer_image_ + layer id
911  cacheImage = ImageManager::instance()->loadBlank(m_id+"_virtual_layer_image_"+layer->getId(), m_viewport.w, m_viewport.h);
912  cache->setCacheImage(cacheImage);
913  update = true;
914  }
915  if (update) {
916  // for the case that the viewport size is not the same as the screen size,
917  // we have to change the values for OpenGL backend
919  if (m_renderbackend->getName() == "SDL") {
920  rec = m_viewport;
921  }
922  m_renderbackend->attachRenderTarget(cacheImage, true);
923  // here we use the new viewport size
924  m_renderbackend->pushClipArea(rec, false);
925  // render stuff to texture
926  RenderList& instancesToRender = m_layerToInstances[layer];
927  // split the RenderList into smaller parts
928  if (instancesToRender.size() > MAX_BATCH_SIZE) {
929  uint8_t batches = ceil(instancesToRender.size() / static_cast<float>(MAX_BATCH_SIZE));
930  uint32_t residual = instancesToRender.size() % MAX_BATCH_SIZE;
931  for (uint8_t i = 0; i < batches; ++i) {
932  uint32_t start = i*MAX_BATCH_SIZE;
933  uint32_t end = start + ((i+1 == batches) ? residual : MAX_BATCH_SIZE);
934  RenderList tempList(instancesToRender.begin() + start, instancesToRender.begin() + end);
935  std::list<RendererBase*>::iterator r_it = m_pipeline.begin();
936  for (; r_it != m_pipeline.end(); ++r_it) {
937  if ((*r_it)->isActivedLayer(layer)) {
938  (*r_it)->render(this, layer, tempList);
940  }
941  }
942  }
943  } else {
944  std::list<RendererBase*>::iterator r_it = m_pipeline.begin();
945  for (; r_it != m_pipeline.end(); ++r_it) {
946  if ((*r_it)->isActivedLayer(layer)) {
947  (*r_it)->render(this, layer, instancesToRender);
949  }
950  }
951  }
954  }
955  }
956 
958  if (!m_map) {
959  FL_ERR(_log, "No map for camera found");
960  return;
961  }
962 
963  const std::list<Layer*>& layers = m_map->getLayers();
964  std::list<Layer*>::const_iterator layer_it = layers.begin();
965  for (;layer_it != layers.end(); ++layer_it) {
966  LayerCache* cache = m_cache[*layer_it];
967  if(!cache) {
968  addLayer(*layer_it);
969  cache = m_cache[*layer_it];
970  FL_ERR(_log, LMsg("Layer Cache miss! (This shouldn't happen!)") << (*layer_it)->getId());
971  }
972  RenderList& instancesToRender = m_layerToInstances[*layer_it];
973  if ((*layer_it)->isStatic() && m_transform == NoneTransform) {
974  continue;
975  }
976  cache->update(m_transform, instancesToRender);
977  }
978  resetUpdates();
979  }
980 
981  void Camera::render() {
983 
984  if (!m_map) {
985  return;
986  }
987 
989  if (lm != 0) {
991  if (m_lighting) {
993  }
994  }
995 
996  const std::list<Layer*>& layers = m_map->getLayers();
997  std::list<Layer*>::const_iterator layer_it = layers.begin();
998  for ( ; layer_it != layers.end(); ++layer_it) {
999  // layer with static flag will rendered as one texture
1000  if ((*layer_it)->isStatic()) {
1001  renderStaticLayer(*layer_it, m_updated);
1002  continue;
1003  }
1004  }
1005 
1007 
1008  layer_it = layers.begin();
1009  for ( ; layer_it != layers.end(); ++layer_it) {
1010  // layer with static flag will rendered as one texture
1011  if ((*layer_it)->isStatic()) {
1012  m_cache[*layer_it]->getCacheImage()->render(m_viewport);
1014  continue;
1015  }
1016  RenderList& instancesToRender = m_layerToInstances[*layer_it];
1017  // split the RenderList into smaller parts
1018  if (instancesToRender.size() > MAX_BATCH_SIZE) {
1019  uint8_t batches = ceil(instancesToRender.size() / static_cast<float>(MAX_BATCH_SIZE));
1020  uint32_t residual = instancesToRender.size() % MAX_BATCH_SIZE;
1021  for (uint8_t i = 0; i < batches; ++i) {
1022  uint32_t start = i*MAX_BATCH_SIZE;
1023  uint32_t end = start + ((i+1 == batches) ? residual : MAX_BATCH_SIZE);
1024  RenderList tempList(instancesToRender.begin() + start, instancesToRender.begin() + end);
1025  std::list<RendererBase*>::iterator r_it = m_pipeline.begin();
1026  for (; r_it != m_pipeline.end(); ++r_it) {
1027  if ((*r_it)->isActivedLayer(*layer_it)) {
1028  (*r_it)->render(this, *layer_it, tempList);
1030  }
1031  }
1032  }
1033  } else {
1034  std::list<RendererBase*>::iterator r_it = m_pipeline.begin();
1035  for (; r_it != m_pipeline.end(); ++r_it) {
1036  if ((*r_it)->isActivedLayer(*layer_it)) {
1037  (*r_it)->render(this, *layer_it, instancesToRender);
1039  }
1040  }
1041  }
1042  }
1043 
1044  renderOverlay();
1046  if (m_lighting && lm != 0) {
1048  }
1050  }
1051 }
bool m_ani_fill
Definition: camera.h:511
void setPosition(const ExactModelCoordinate &position)
Sets map point for the camera.
Definition: camera.cpp:350
int32_t getPipelinePosition() const
Gets renderer position in the rendering pipeline.
Definition: rendererbase.h:117
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:207
virtual void setLighting(float red, float green, float blue)=0
Set colors for lighting.
int32_t getOverlayImage()
Returns the pool id of the overlay image.
Definition: camera.cpp:819
std::list< RendererBase * > m_pipeline
Definition: camera.h:488
uint32_t getHeight() const
RenderBackend * m_renderbackend
Definition: camera.h:419
double m_tilt
Definition: camera.h:466
Matrix & applyRotate(T angle, T x, T y, T z)
Definition: matrix.h:306
DoubleMatrix m_vs_inverse_matrix
Definition: camera.h:462
std::vector< RenderItem * > RenderList
Definition: renderitem.h:130
uint32_t getTime() const
Get the time.
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:813
void calculateZValue(DoublePoint3D &screen_coords)
calculates z-value for given screenpoint
Definition: camera.cpp:410
virtual ~MapObserver()
Definition: camera.cpp:66
Base Class for Images.
Definition: image.h:48
#define ABS(x)
Definition: fife_math.h:41
void init()
Definition: camera.cpp:137
Layer * getLayer() const
Gets the layer where this location is pointing to.
Definition: location.cpp:83
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:368
void resetUpdates()
Resets temporary values from last update round, like warped flag.
Definition: camera.cpp:699
DoubleMatrix m_inverse_matrix
Definition: camera.h:459
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:786
Instance * m_attachedTo
Definition: camera.h:481
Rect m_viewport
Definition: camera.h:418
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:484
int32_t m_img_id
Definition: camera.h:508
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.
uint32_t m_screenCellHeight
Definition: camera.h:477
DoubleMatrix m_vs_matrix
Definition: camera.h:461
RenderList & getRenderListRef(Layer *layer)
Returns reference to RenderList.
Definition: camera.cpp:520
DoublePoint3D toVirtualScreenCoordinates(const ExactModelCoordinate &map_coords)
Transforms given point from map coordinates to virtual screen coordinates.
Definition: camera.cpp:428
double getZToY() const
Gets zToY value.
Definition: camera.cpp:216
void resetLightingColor()
Resets lighting color.
Definition: camera.cpp:781
void setMapCoordinates(const ExactModelCoordinate &coordinates)
Sets map coordinates to this location.
Definition: location.cpp:98
const std::string & getId() const
Get the id of this layer.
Definition: layer.cpp:81
void setZToYEnabled(bool enabled)
Sets z to y manipulation enabled / disabled.
Definition: camera.cpp:220
void resetRenderers()
resets active layer information on all renderers.
Definition: camera.cpp:740
void setTilt(double tilt)
Sets tilt for the camera.
Definition: camera.cpp:151
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:479
void resetOverlayAnimation()
Resets the animation overlay.
Definition: camera.cpp:843
Camera(const std::string &id, Map *map, const Rect &viewport, RenderBackend *renderbackend)
Constructor Camera needs to be added to the view.
Definition: camera.cpp:80
virtual void detachRenderTarget()=0
Detaches current render surface.
bool m_enabledZToY
Definition: camera.h:470
void addChangeListener(MapChangeListener *listener)
Adds new change listener.
Definition: map.cpp:230
const std::list< Layer * > & getLayers() const
Get the layers on this map.
Definition: map.h:120
bool m_img_fill
Definition: camera.h:510
static Logger _log(LM_AUDIO)
void reset()
Resets location (so that layer and coordinate information becomes invalid)
Definition: location.cpp:57
bool contains(const PointType2D< T > &point) const
Checks whether a rectangle contains a Point.
Definition: rect.h:184
void attach(Instance *instance)
Attaches the camera to an instance.
Definition: camera.cpp:669
DoubleMatrix m_screen_2_vscreen
Definition: camera.h:464
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:794
void setRotation(double rotation)
Sets rotation for the camera.
Definition: camera.cpp:164
void resetOverlayColor()
Resets the color overlay.
Definition: camera.cpp:809
void onRendererEnabledChanged(RendererBase *renderer)
Renderer is enabled / disabled.
Definition: camera.cpp:725
t_layer_to_instances m_layerToInstances
Definition: camera.h:493
bool isEnabled()
Gets if camera is enabled / disabled.
Definition: camera.cpp:346
Camera describes properties of a view port shown in the main screen Main screen can have multiple cam...
Definition: camera.h:59
bool m_col_overlay
Definition: camera.h:504
static ImageManager * instance()
Definition: singleton.h:84
Location & getLocationRef()
Gets reference of current location of instance.
Definition: instance.cpp:315
ScreenPoint m_curOrigin
Definition: camera.h:472
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:524
uint32_t m_start_time
Definition: camera.h:512
virtual void getVertices(std::vector< ExactModelCoordinate > &vtx, const ModelCoordinate &cell)=0
Fills given point vector with vertices from selected cell.
RendererBase * getRenderer(const std::string &name)
Gets renderer with given name.
Definition: camera.cpp:736
uint32_t m_screenCellWidth
Definition: camera.h:476
virtual void onMapChanged(Map *map, std::vector< Layer *> &changedLayers)
Called when some layer is changed on map.
Definition: camera.cpp:68
const uint32_t MAX_BATCH_SIZE
Definition: camera.cpp:57
std::map< std::string, RendererBase * > m_renderers
Definition: camera.h:487
#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:458
bool intersects(const RectType< T > &rect) const
Check whether two rectangles share some area.
Definition: rect.h:227
bool m_enabled
Definition: camera.h:480
void addRenderer(RendererBase *renderer)
Adds new renderer on the view.
Definition: camera.cpp:712
double m_zToY
Definition: camera.h:469
unsigned char uint8_t
Definition: core.h:38
std::map< Layer *, LayerCache * > m_cache
Definition: camera.h:495
bool m_ani_overlay
Definition: camera.h:506
PointType2D< int32_t > Point
Definition: point.h:195
void onRendererPipelinePositionChanged(RendererBase *renderer)
Renderer&#39;s pipeline position has been changed.
Definition: camera.cpp:721
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:236
uint32_t getHeight() const
Definition: image.cpp:160
static bool Equal(T _val1, T _val2)
Definition: fife_math.h:287
friend class MapObserver
Definition: camera.h:411
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:490
ImagePtr getCacheImage()
Definition: layercache.cpp:806
void removeLayer(Layer *layer)
Definition: camera.cpp:754
A basic layer on a map.
Definition: layer.h:99
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
double getRotation() const
Gets camera rotation.
Definition: camera.cpp:173
void setLightingColor(float red, float green, float blue)
Sets lighting color.
Definition: camera.cpp:764
void setCacheImage(ImagePtr image)
Definition: layercache.cpp:810
void resetOverlayImage()
Resets the image overlay.
Definition: camera.cpp:827
double getOriginalZToY() const
Gets original zToY transformation value.
Definition: camera.cpp:192
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:675
unsigned short uint16_t
Definition: core.h:39
T y
The Y Coordinate.
Definition: rect.h:87
T right() const
The X coordinate of the right edge.
Definition: rect.h:168
Matrix inverse() const
Adjoint method inverse, constant time inversion implementation.
Definition: matrix.h:63
void renderOverlay()
Renders the overlay(color, image, animation) for the camera.
Definition: camera.cpp:848
double getZoom() const
Gets camera zoom.
Definition: camera.cpp:188
const Rect & getMapViewPort()
Gets the viewport for camera in map coordinates.
Definition: camera.cpp:293
bool m_lighting
Definition: camera.h:499
void addLayer(Layer *layer)
Definition: camera.cpp:747
AnimationPtr getOverlayAnimation()
Returns an AnimationPtr to the overlay animation.
Definition: camera.cpp:839
void setRendererListener(IRendererListener *listener)
Sets listener for renderer.
Definition: rendererbase.h:140
const Rect & getViewPort() const
Gets the viewport for camera in pixel coordinates.
Definition: camera.cpp:289
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:708
virtual ~Camera()
Destructor.
Definition: camera.cpp:118
void refresh()
Refreshes camera view in case e.g.
Definition: camera.cpp:693
#define FL_LOG(logger, msg)
Definition: logger.h:71
AnimationPtr m_ani_ptr
Definition: camera.h:509
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:507
Point getCellImageDimensions()
Gets screen cell image dimensions.
Definition: camera.cpp:259
Matrix & loadRotate(T angle, T x, T y, T z)
Make this a rotation matrix.
Definition: matrix.h:113
DoublePoint3D ExactModelCoordinate
Definition: modelcoords.h:37
CellGrid * getCellGrid() const
Get the Cellgrid.
Definition: layer.cpp:93
Matrix & loadScale(T x, T y, T z=1)
Make this a scale matrix.
Definition: matrix.h:157
bool isSharedImage() const
Returns true if this image shares data with another one.
Definition: image.h:148
ImagePtr image
Definition: renderitem.h:112
std::vector< ImagePtr > * getAnimationOverlay() const
Returns pointer to AnimationOverlay vector.
Definition: renderitem.cpp:101
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:423
double getTilt() const
Gets camera tilt.
Definition: camera.cpp:160
bool m_mapViewPortUpdated
Definition: camera.h:475
ExactModelCoordinate m_position
Definition: camera.h:421
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
Map * m_map
Definition: camera.h:417
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:415
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:478
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:832
Location getLocation()
Gets the location camera is rendering.
Definition: camera.cpp:271
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:903
ExactModelCoordinate getMapCoordinates() const
Gets map coordinates set to this location.
Definition: location.cpp:117
ModelCoordinate getLayerCoordinates() const
Gets cell precision layer coordinates set to this location.
Definition: location.cpp:113
Rect m_mapViewPort
Definition: camera.h:474
DoubleMatrix m_vscreen_2_screen
Definition: camera.h:463
Point3D getOrigin() const
Gets screen point of the camera.
Definition: camera.cpp:364
virtual void onLayerCreate(Map *map, Layer *layer)
Called when some layer gets created on the map.
Definition: camera.cpp:71
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:679
T * get() const
allows direct access to underlying pointer
Definition: sharedptr.h:155
std::vector< float > m_light_colors
Definition: camera.h:501
uint32_t scaleTime(float multiplier, uint32_t ticks)
Utility function to calculate time scaling.
DoublePoint getLogicalCellDimensions()
Gets logical cell image dimensions and ignores the layer and cellgrid.
Definition: camera.cpp:475
void setCellImageDimensions(uint32_t width, uint32_t height)
Sets screen cell image dimensions.
Definition: camera.cpp:228
void setViewPort(const Rect &viewport)
Sets the viewport for camera viewport is rectangle inside the view where camera renders.
Definition: camera.cpp:284
A container of Layer(s).
Definition: map.h:88
double m_zoom
Definition: camera.h:468
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:437
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:471
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:342
Matrix & applyTranslate(T x, T y, T z)
Apply translation into this matrix.
Definition: matrix.h:180
uint32_t getDuration() const
Gets the total duration for the whole animation.
Definition: animation.h:138
uint32_t getLayerCount() const
Get the overall number of layers.
Definition: map.cpp:82
SDL_Color m_overlay_color
Definition: camera.h:507
T w
Width of the rectangle.
Definition: rect.h:90
#define FL_DBG(logger, msg)
Definition: logger.h:70
bool isEnabled() const
Is renderer enabled.
Definition: rendererbase.h:136
ExactModelCoordinate getPosition() const
Gets map point of the camera.
Definition: camera.cpp:360
void render()
Renders camera.
Definition: camera.cpp:981
An Instance is an "instantiation" of an Object at a Location.
Definition: instance.h:94
void updateRenderLists()
Updates camera RenderLists.
Definition: camera.cpp:957
ScreenPoint virtualScreenToScreen(const DoublePoint3D &p)
Transforms given point from virtual screen coordinates to screen coordinates.
Definition: camera.cpp:433
double m_rotation
Definition: camera.h:467
std::vector< float > getLightingColor()
Returns a vector that contain the light color.
Definition: camera.cpp:772
T bottom() const
The Y coordinate of the bottom edge.
Definition: rect.h:173
bool m_img_overlay
Definition: camera.h:505
uint32_t getWidth() const
Definition: image.cpp:151
bool isZToYEnabled() const
Gets if z to y manipulation is enabled / disabled.
Definition: camera.cpp:224
Rect getLayerViewPort(Layer *layer)
Gets the viewport for camera in layer coordinates.
Definition: camera.cpp:326
void setZoom(double zoom)
Sets zoom for the camera.
Definition: camera.cpp:177
Listener interface for changes happening on map.
Definition: map.h:56