FIFE
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
camera.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2005-2013 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  }
302 
303  const Rect& Camera::getViewPort() const {
304  return m_viewport;
305  }
306 
308  if (!m_mapViewPortUpdated) {
313 
314  std::vector<ExactModelCoordinate> coords;
315  coords.push_back(toMapCoordinates(sp2, false));
316  coords.push_back(toMapCoordinates(sp3, false));
317  coords.push_back(toMapCoordinates(sp4, false));
318 
319  ExactModelCoordinate emc = toMapCoordinates(sp1, false);
320  ModelCoordinate min(static_cast<int32_t>(emc.x), static_cast<int32_t>(emc.y));
321  ModelCoordinate max(static_cast<int32_t>(emc.x+0.5), static_cast<int32_t>(emc.y+0.5));
322  std::vector<ExactModelCoordinate>::iterator it = coords.begin();
323  for (; it != coords.end(); ++it) {
324  min.x = std::min(min.x, static_cast<int32_t>((*it).x));
325  min.y = std::min(min.y, static_cast<int32_t>((*it).y));
326  max.x = std::max(max.x, static_cast<int32_t>((*it).x+0.5));
327  max.y = std::max(max.y, static_cast<int32_t>((*it).y+0.5));
328  }
329  // makes the viewport a bit larger
330  m_mapViewPort.x = min.x - 1;
331  m_mapViewPort.y = min.y - 1;
332  m_mapViewPort.w = ABS(max.x - min.x) + 2;
333  m_mapViewPort.h = ABS(max.y - min.y) + 2;
334  m_mapViewPortUpdated = true;
335  }
336 
337  return m_mapViewPort;
338  }
339 
341  Rect mapView = getMapViewPort();
342  Location loc(layer);
343  ExactModelCoordinate emc(mapView.x, mapView.y);
344  loc.setMapCoordinates(emc);
345  emc.x = mapView.x+mapView.w;
346  emc.y = mapView.y+mapView.h;
347  mapView.x = loc.getLayerCoordinates().x;
348  mapView.y = loc.getLayerCoordinates().y;
349  loc.setMapCoordinates(emc);
350  mapView.w = ABS(loc.getLayerCoordinates().x - mapView.x);
351  mapView.h = ABS(loc.getLayerCoordinates().y - mapView.y);
352 
353  return mapView;
354  }
355 
356  void Camera::setEnabled(bool enabled) {
357  m_enabled = enabled;
358  }
359 
361  return m_enabled;
362  }
363 
365  return m_cur_origo;
366  }
367 
371  if (m_location.getLayer()) {
373  if (cg) {
376  }
377  }
378  m_matrix.applyRotate(-m_rotation, 0.0, 0.0, 1.0);
379  m_matrix.applyRotate(-m_tilt, 1.0, 0.0, 0.0);
380  if (m_enabledZToY) {
381  m_matrix.m9 = -m_zToY; // z -> y height in pixels
382  }
383  double scale = m_zoom;
384  m_matrix.applyScale(scale, scale, scale);
387 
388  m_vs_matrix.applyRotate(-m_rotation, 0.0, 0.0, 1.0);
389  m_vs_matrix.applyRotate(-m_tilt, 1.0, 0.0, 0.0);
390  if (m_enabledZToY) {
391  m_vs_matrix.m9 = -m_zToY; // z -> y height in pixels
392  }
394 
395  // calculate the screen<->virtual screen transformation
396  // this explicitly ignores the z-value.
398  // NOTE: mult4by4 is an in-place modification.
400  // set the z transformation to unity
401  const int32_t N=4;
402  for(int32_t i=0; i!=N; ++i) {
403  m_vscreen_2_screen[2*N + i] = 0;
404  m_vscreen_2_screen[i*N + 2] = 0;
405  }
406  m_vscreen_2_screen[2*N + 2] = 1;
408 
409  m_mapViewPortUpdated = false;
410  // FL_WARN(_log, LMsg("matrix: ") << m_matrix << " 1: " << m_matrix.inverse().mult4by4(m_matrix));
411 // FL_WARN(_log, LMsg("vs2s matrix: ") << m_vscreen_2_screen << " s2vs matrix: " << m_screen_2_vscreen);
412  }
413 
414  void Camera::calculateZValue(ScreenPoint& screen_coords) {
415  int32_t dy = -(screen_coords.y - toScreenCoordinates(m_location.getMapCoordinates()).y);
416  screen_coords.z = static_cast<int32_t>(Mathd::Tan(m_tilt * (Mathd::pi() / 180.0)) * static_cast<double>(dy));
417  }
418 
419  ExactModelCoordinate Camera::toMapCoordinates(ScreenPoint screen_coords, bool z_calculated) {
420  if (!z_calculated) {
421  calculateZValue(screen_coords);
422  }
423  return m_inverse_matrix * intPt2doublePt(screen_coords);
424  }
425 
427  ScreenPoint pt = doublePt2intPt(m_matrix * elevation_coords);
428  return pt;
429  }
430 
432  DoublePoint3D pt = (m_vs_matrix * elevation_coords);
433  return pt;
434  }
435 
438  }
439 
442  }
443 
445  assert(layer);
446  CellGrid* cg = layer->getCellGrid();
447  assert(cg);
448 
449  ModelCoordinate cell(0,0);
450  std::vector<ExactModelCoordinate> vertices;
451  cg->getVertices(vertices, cell);
452 
453  DoubleMatrix mtx;
454  mtx.loadRotate(m_rotation, 0.0, 0.0, 1.0);
455  mtx.applyRotate(m_tilt, 1.0, 0.0, 0.0);
456 
457  double x1 = 0;
458  double x2 = 0;
459  double y1 = 0;
460  double y2 = 0;
461 
462  for (uint32_t i = 0; i < vertices.size(); i++) {
463  vertices[i] = cg->toMapCoordinates(vertices[i]);
464  vertices[i] = mtx * vertices[i];
465  if (i == 0) {
466  x1 = x2 = vertices[0].x;
467  y1 = y2 = vertices[0].y;
468  } else {
469  x1 = std::min(vertices[i].x, x1);
470  x2 = std::max(vertices[i].x, x2);
471  y1 = std::min(vertices[i].y, y1);
472  y2 = std::max(vertices[i].y, y2);
473  }
474  }
475  return DoublePoint( x2 - x1, y2 - y1 );
476  }
477 
479  assert(layer && layer->getCellGrid());
480 
481  Location loc(layer);
482  ModelCoordinate cell(0,0);
483  loc.setLayerCoordinates(cell);
484  ScreenPoint sp1 = toScreenCoordinates(loc.getMapCoordinates());
485  ++cell.y;
486  loc.setLayerCoordinates(cell);
487  ScreenPoint sp2 = toScreenCoordinates(loc.getMapCoordinates());
488 
489  Point p(ABS(sp2.x - sp1.x), ABS(sp2.y - sp1.y));
490  if (p.x == 0) {
491  p.x = 1;
492  }
493  if (p.y == 0) {
494  p.y = 1;
495  }
496  return p;
497  }
498 
500  assert(layer && layer->getCellGrid());
501 
502  Location loc(layer);
503  ModelCoordinate cell(0,0,0);
504  loc.setLayerCoordinates(cell);
505  ScreenPoint sp1 = toScreenCoordinates(loc.getMapCoordinates());
506  ++cell.z;
507  loc.setLayerCoordinates(cell);
508  ScreenPoint sp2 = toScreenCoordinates(loc.getMapCoordinates());
509 
510  return Point3D(sp2.x - sp1.x, sp2.y - sp1.y, sp2.z - sp1.z);
511  }
512 
515  m_referenceScaleX = static_cast<double>(m_screen_cell_width) / dim.x;
516  m_referenceScaleY = static_cast<double>(m_screen_cell_height) / dim.y;
517 
518  FL_DBG(_log, "Updating reference scale");
519  FL_DBG(_log, LMsg(" tilt=") << m_tilt << " rot=" << m_rotation);
520  FL_DBG(_log, LMsg(" m_screen_cell_width=") << m_screen_cell_width);
521  FL_DBG(_log, LMsg(" m_screen_cell_height=") << m_screen_cell_height);
522  FL_DBG(_log, LMsg(" m_referenceScaleX=") << m_referenceScaleX);
523  FL_DBG(_log, LMsg(" m_referenceScaleY=") << m_referenceScaleY);
524  }
525 
527  return m_layerToInstances[layer];
528  }
529 
530  void Camera::getMatchingInstances(ScreenPoint screen_coords, Layer& layer, std::list<Instance*>& instances, uint8_t alpha) {
531  instances.clear();
532  bool zoomed = !Mathd::Equal(m_zoom, 1.0);
533  bool special_alpha = alpha != 0;
534 
535  const RenderList& layer_instances = m_layerToInstances[&layer];
536  RenderList::const_iterator instance_it = layer_instances.end();
537  while (instance_it != layer_instances.begin()) {
538  --instance_it;
539  Instance* i = (*instance_it)->instance;
540  const RenderItem& vc = **instance_it;
541  if ((vc.dimensions.contains(Point(screen_coords.x, screen_coords.y)))) {
542  if(vc.image->isSharedImage()) {
543  vc.image->forceLoadInternal();
544  }
545  uint8_t r, g, b, a = 0;
546  int32_t x = screen_coords.x - vc.dimensions.x;
547  int32_t y = screen_coords.y - vc.dimensions.y;
548  if (zoomed) {
549  double fx = static_cast<double>(x);
550  double fy = static_cast<double>(y);
551  double fow = static_cast<double>(vc.image->getWidth());
552  double foh = static_cast<double>(vc.image->getHeight());
553  double fsw = static_cast<double>(vc.dimensions.w);
554  double fsh = static_cast<double>(vc.dimensions.h);
555  x = static_cast<int32_t>(round(fx / fsw * fow));
556  y = static_cast<int32_t>(round(fy / fsh * foh));
557  }
558  if (vc.getAnimationOverlay()) {
559  std::vector<ImagePtr>* ao = vc.getAnimationOverlay();
560  std::vector<ImagePtr>::iterator it = ao->begin();
561  for (; it != ao->end(); ++it) {
562  if ((*it)->isSharedImage()) {
563  (*it)->forceLoadInternal();
564  }
565  (*it)->getPixelRGBA(x, y, &r, &g, &b, &a);
566  // instance is hit with mouse if not totally transparent
567  if (a == 0 || (special_alpha && a < alpha)) {
568  continue;
569  }
570  instances.push_back(i);
571  break;
572  }
573  } else {
574  vc.image->getPixelRGBA(x, y, &r, &g, &b, &a);
575  // instance is hit with mouse if not totally transparent
576  if (a == 0 || (special_alpha && a < alpha)) {
577  continue;
578  }
579  instances.push_back(i);
580  }
581  }
582  }
583  }
584 
585  void Camera::getMatchingInstances(Rect screen_rect, Layer& layer, std::list<Instance*>& instances, uint8_t alpha) {
586  instances.clear();
587  bool zoomed = !Mathd::Equal(m_zoom, 1.0);
588  bool special_alpha = alpha != 0;
589 
590  const RenderList& layer_instances = m_layerToInstances[&layer];
591  RenderList::const_iterator instance_it = layer_instances.end();
592  while (instance_it != layer_instances.begin()) {
593  --instance_it;
594  Instance* i = (*instance_it)->instance;;
595  const RenderItem& vc = **instance_it;
596  if ((vc.dimensions.intersects(screen_rect))) {
597  if(vc.image->isSharedImage()) {
598  vc.image->forceLoadInternal();
599  }
600  uint8_t r, g, b, a = 0;
601  for(int32_t xx = screen_rect.x; xx < screen_rect.x + screen_rect.w; xx++) {
602  for(int32_t yy = screen_rect.y; yy < screen_rect.y + screen_rect.h; yy++) {
603  if ((vc.dimensions.contains(Point(xx, yy)))) {
604  int32_t x = xx - vc.dimensions.x;
605  int32_t y = yy - vc.dimensions.y;
606  if (zoomed) {
607  double fx = static_cast<double>(x);
608  double fy = static_cast<double>(y);
609  double fow = static_cast<double>(vc.image->getWidth());
610  double foh = static_cast<double>(vc.image->getHeight());
611  double fsw = static_cast<double>(vc.dimensions.w);
612  double fsh = static_cast<double>(vc.dimensions.h);
613  x = static_cast<int32_t>(round(fx / fsw * fow));
614  y = static_cast<int32_t>(round(fy / fsh * foh));
615  }
616  if (vc.getAnimationOverlay()) {
617  std::vector<ImagePtr>* ao = vc.getAnimationOverlay();
618  std::vector<ImagePtr>::iterator it = ao->begin();
619  for (; it != ao->end(); ++it) {
620  if ((*it)->isSharedImage()) {
621  (*it)->forceLoadInternal();
622  }
623  (*it)->getPixelRGBA(x, y, &r, &g, &b, &a);
624  // instance is hit with mouse if not totally transparent
625  if (a == 0 || (special_alpha && a < alpha)) {
626  continue;
627  }
628  instances.push_back(i);
629  goto found_non_transparent_pixel;
630  }
631  } else {
632  vc.image->getPixelRGBA(x, y, &r, &g, &b, &a);
633  // instance is hit with mouse if not totally transparent
634  if (a == 0 || (special_alpha && a < alpha)) {
635  continue;
636  }
637  instances.push_back(i);
638  goto found_non_transparent_pixel;
639  }
640  }
641  }
642  }
643  found_non_transparent_pixel:;
644  }
645  }
646  }
647 
648  void Camera::getMatchingInstances(Location& loc, std::list<Instance*>& instances, bool use_exactcoordinates) {
649  instances.clear();
650  Layer* layer = loc.getLayer();
651  if(!layer) {
652  return;
653  }
654 
655  const RenderList& layer_instances = m_layerToInstances[layer];
656  RenderList::const_iterator instance_it = layer_instances.end();
657  while (instance_it != layer_instances.begin()) {
658  --instance_it;
659  Instance* i = (*instance_it)->instance;
660  if (use_exactcoordinates) {
662  instances.push_back(i);
663  }
664  } else {
666  instances.push_back(i);
667  }
668  }
669  }
670  }
671 
672  void Camera::attach(Instance *instance) {
673  // fail if the layers aren't the same
674  if (m_location.getLayer()->getId() != instance->getLocation().getLayer()->getId()) {
675  FL_WARN(_log, "Tried to attach camera to instance on different layer.");
676  return ;
677  }
678  m_attachedto = instance;
679  }
680 
681  void Camera::detach() {
682  m_attachedto = NULL;
683  }
684 
685  void Camera::update() {
686  if (!m_attachedto) {
687  return;
688  }
691  if (Mathd::Equal(old_emc.x, new_emc.x) && Mathd::Equal(old_emc.y, new_emc.y)) {
692  return;
693  }
695  old_emc = new_emc;
696  updateMatrices();
697  }
698 
700  updateMatrices();
702  }
703 
705  if (m_transform == NoneTransform) {
706  m_updated = false;
707  } else {
708  m_updated = true;
709  }
711  }
712 
713  bool pipelineSort(const RendererBase* lhs, const RendererBase* rhs) {
714  return (lhs->getPipelinePosition() < rhs->getPipelinePosition());
715  }
716 
718  renderer->setRendererListener(this);
719  m_renderers[renderer->getName()] = renderer;
720  if (renderer->isEnabled()) {
721  m_pipeline.push_back(renderer);
722  }
723  m_pipeline.sort(pipelineSort);
724  }
725 
727  m_pipeline.sort(pipelineSort);
728  }
729 
731  assert(m_renderers[renderer->getName()]);
732  if (renderer->isEnabled()) {
733  FL_LOG(_log, LMsg("Enabling renderer ") << renderer->getName());
734  m_pipeline.push_back(renderer);
735  m_pipeline.sort(pipelineSort);
736  } else {
737  m_pipeline.remove(renderer);
738  }
739  }
740 
741  RendererBase* Camera::getRenderer(const std::string& name) {
742  return m_renderers[name];
743  }
744 
746  std::map<std::string, RendererBase*>::iterator r_it = m_renderers.begin();
747  for (; r_it != m_renderers.end(); ++r_it) {
748  r_it->second->reset();
749  }
750  }
751 
752  void Camera::addLayer(Layer* layer) {
753  m_cache[layer] = new LayerCache(this);
754  m_cache[layer]->setLayer(layer);
755  m_layerToInstances[layer] = RenderList();
756  refresh();
757  }
758 
759  void Camera::removeLayer(Layer* layer) {
760  delete m_cache[layer];
761  m_cache.erase(layer);
762  m_layerToInstances.erase(layer);
763  refresh();
764  }
765 
766  void Camera::setLightingColor(float red, float green, float blue) {
767  m_lighting = true;
768  m_light_colors.clear();
769  m_light_colors.push_back(red);
770  m_light_colors.push_back(green);
771  m_light_colors.push_back(blue);
772  }
773 
774  std::vector<float> Camera::getLightingColor() {
775  if(m_light_colors.empty()) {
776  for(int32_t colors = 0; colors != 3; ++colors) {
777  m_light_colors.push_back(1.0f);
778  }
779  }
780  return m_light_colors;
781  }
782 
784  m_lighting = false;
786  }
787 
788  void Camera::setOverlayColor(uint8_t red, uint8_t green, uint8_t blue, uint8_t alpha) {
789  m_col_overlay = true;
790  m_overlay_color.r = red;
791  m_overlay_color.g = green;
792  m_overlay_color.b = blue;
793  m_overlay_color.unused = alpha;
794  }
795 
796  std::vector<uint8_t> Camera::getOverlayColor() {
797  std::vector<uint8_t> colors;
798  if (m_col_overlay) {
799  colors.push_back(m_overlay_color.r);
800  colors.push_back(m_overlay_color.g);
801  colors.push_back(m_overlay_color.b);
802  colors.push_back(m_overlay_color.unused);
803  } else {
804  for(uint8_t cc = 0; cc != 4; ++cc) {
805  colors.push_back(255);
806  }
807  }
808  return colors;
809  }
810 
812  m_col_overlay = false;
813  }
814 
815  void Camera::setOverlayImage(int32_t id, bool fill) {
816  m_img_overlay = true;
817  m_img_id = id;
818  m_img_fill = fill;
819  }
820 
822  int32_t id = -1;
823  if (m_img_overlay) {
824  id = m_img_id;
825  }
826  return id;
827  }
828 
830  m_img_overlay = false;
831  m_img_id = -1;
832  }
833 
835  m_ani_overlay = true;
836  m_ani_ptr = anim;
837  m_ani_fill = fill;
838  m_start_time = 0;
839  }
840 
842  return m_ani_ptr;
843  }
844 
846  m_ani_overlay = false;
847  m_ani_ptr.reset();
848  }
849 
852  return;
853  }
854  uint16_t width = m_viewport.w;
855  uint16_t height = m_viewport.h;
856  Point pm = Point(m_viewport.x + width/2, m_viewport.y + height/2);
857  Rect r;
858 
859  // color overlay
860  if (m_col_overlay) {
863  }
864  // image overlay
865  if (m_img_overlay) {
867  Image* img = resptr.get();
868  if (img) {
869  if (m_img_fill) {
870  r.w = width;
871  r.h = height;
872  } else {
873  r.w = img->getWidth();
874  r.h = img->getHeight();
875  }
876  r.x = pm.x-r.w/2;
877  r.y = pm.y-r.h/2;
878  img->render(r);
879  }
880  }
881  // animation overlay
882  if (m_ani_overlay) {
883  assert(m_ani_ptr != 0);
884 
885  if (m_start_time == 0) {
887  }
888  uint32_t animtime = scaleTime(1.0, TimeManager::instance()->getTime() - m_start_time) % m_ani_ptr->getDuration();
889  ImagePtr img = m_ani_ptr->getFrameByTimestamp(animtime);
890  if (img) {
891  if (m_ani_fill) {
892  r.w = width;
893  r.h = height;
894  } else {
895  r.w = img->getWidth();
896  r.h = img->getHeight();
897  }
898  r.x = pm.x-r.w/2;
899  r.y = pm.y-r.h/2;
900  img->render(r);
901  }
902  }
903  }
904 
905  void Camera::renderStaticLayer(Layer* layer, bool update) {
906  // ToDo: Remove this function from the camera class to something like engine pre-render.
907  // ToDo: Check if partial rendering of only updated RenderItems to existing FBO is possible/faster in our case.
908  // ToDo: Add and fix support for SDL backend, for SDL it works only on the lowest layer(alpha/transparent bug).
909  LayerCache* cache = m_cache[layer];
910  ImagePtr cacheImage = cache->getCacheImage();
911  if (!cacheImage.get()) {
912  // the cacheImage name will be, camera id + _virtual_layer_image_ + layer id
913  cacheImage = ImageManager::instance()->loadBlank(m_id+"_virtual_layer_image_"+layer->getId(), m_viewport.w, m_viewport.h);
914  cache->setCacheImage(cacheImage);
915  update = true;
916  }
917  if (update) {
918  // for the case that the viewport size is not the same as the screen size,
919  // we have to change the values for OpenGL backend
921  if (m_renderbackend->getName() == "SDL") {
922  rec = m_viewport;
923  }
924  m_renderbackend->attachRenderTarget(cacheImage, true);
925  // here we use the new viewport size
926  m_renderbackend->pushClipArea(rec, false);
927  // render stuff to texture
928  RenderList& instancesToRender = m_layerToInstances[layer];
929  // split the RenderList into smaller parts
930  if (instancesToRender.size() > MAX_BATCH_SIZE) {
931  uint8_t batches = ceil(instancesToRender.size() / static_cast<float>(MAX_BATCH_SIZE));
932  uint32_t residual = instancesToRender.size() % MAX_BATCH_SIZE;
933  for (uint8_t i = 0; i < batches; ++i) {
934  uint32_t start = i*MAX_BATCH_SIZE;
935  uint32_t end = start + ((i+1 == batches) ? residual : MAX_BATCH_SIZE);
936  RenderList tempList(instancesToRender.begin() + start, instancesToRender.begin() + end);
937  std::list<RendererBase*>::iterator r_it = m_pipeline.begin();
938  for (; r_it != m_pipeline.end(); ++r_it) {
939  if ((*r_it)->isActivedLayer(layer)) {
940  (*r_it)->render(this, layer, tempList);
942  }
943  }
944  }
945  } else {
946  std::list<RendererBase*>::iterator r_it = m_pipeline.begin();
947  for (; r_it != m_pipeline.end(); ++r_it) {
948  if ((*r_it)->isActivedLayer(layer)) {
949  (*r_it)->render(this, layer, instancesToRender);
951  }
952  }
953  }
956  }
957  }
958 
960  Map* map = m_location.getMap();
961  if (!map) {
962  FL_ERR(_log, "No map for camera found");
963  return;
964  }
965 
966  const std::list<Layer*>& layers = map->getLayers();
967  std::list<Layer*>::const_iterator layer_it = layers.begin();
968  for (;layer_it != layers.end(); ++layer_it) {
969  LayerCache* cache = m_cache[*layer_it];
970  if(!cache) {
971  addLayer(*layer_it);
972  cache = m_cache[*layer_it];
973  FL_ERR(_log, LMsg("Layer Cache miss! (This shouldn't happen!)") << (*layer_it)->getId());
974  }
975  RenderList& instancesToRender = m_layerToInstances[*layer_it];
976  if ((*layer_it)->isStatic() && m_transform == NoneTransform) {
977  continue;
978  }
979  cache->update(m_transform, instancesToRender);
980  }
981  resetUpdates();
982  }
983 
984  void Camera::render() {
986  Map* map = m_location.getMap();
987  if (!map) {
988  return;
989  }
990 
992  if (lm != 0) {
994  if (m_lighting) {
996  }
997  }
998 
999  const std::list<Layer*>& layers = map->getLayers();
1000  std::list<Layer*>::const_iterator layer_it = layers.begin();
1001  for ( ; layer_it != layers.end(); ++layer_it) {
1002  // layer with static flag will rendered as one texture
1003  if ((*layer_it)->isStatic()) {
1004  renderStaticLayer(*layer_it, m_updated);
1005  continue;
1006  }
1007  }
1008 
1010 
1011  layer_it = layers.begin();
1012  for ( ; layer_it != layers.end(); ++layer_it) {
1013  // layer with static flag will rendered as one texture
1014  if ((*layer_it)->isStatic()) {
1015  m_cache[*layer_it]->getCacheImage()->render(m_viewport);
1017  continue;
1018  }
1019  RenderList& instancesToRender = m_layerToInstances[*layer_it];
1020  // split the RenderList into smaller parts
1021  if (instancesToRender.size() > MAX_BATCH_SIZE) {
1022  uint8_t batches = ceil(instancesToRender.size() / static_cast<float>(MAX_BATCH_SIZE));
1023  uint32_t residual = instancesToRender.size() % MAX_BATCH_SIZE;
1024  for (uint8_t i = 0; i < batches; ++i) {
1025  uint32_t start = i*MAX_BATCH_SIZE;
1026  uint32_t end = start + ((i+1 == batches) ? residual : MAX_BATCH_SIZE);
1027  RenderList tempList(instancesToRender.begin() + start, instancesToRender.begin() + end);
1028  std::list<RendererBase*>::iterator r_it = m_pipeline.begin();
1029  for (; r_it != m_pipeline.end(); ++r_it) {
1030  if ((*r_it)->isActivedLayer(*layer_it)) {
1031  (*r_it)->render(this, *layer_it, tempList);
1033  }
1034  }
1035  }
1036  } else {
1037  std::list<RendererBase*>::iterator r_it = m_pipeline.begin();
1038  for (; r_it != m_pipeline.end(); ++r_it) {
1039  if ((*r_it)->isActivedLayer(*layer_it)) {
1040  (*r_it)->render(this, *layer_it, instancesToRender);
1042  }
1043  }
1044  }
1045  }
1046 
1047  renderOverlay();
1049  if (m_lighting && lm != 0) {
1051  }
1053  }
1054 }
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:511
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:821
std::list< RendererBase * > m_pipeline
Definition: camera.h:485
DoublePoint getLogicalCellDimensions(Layer *layer)
Gets logical cell image dimensions for given layer.
Definition: camera.cpp:444
RenderBackend * m_renderbackend
Definition: camera.h:489
double m_tilt
Definition: camera.h:462
Matrix & applyRotate(T angle, T x, T y, T z)
Definition: matrix.h:306
DoubleMatrix m_vs_inverse_matrix
Definition: camera.h:458
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:815
void updateMap(Map *map)
Definition: camera.cpp:250
virtual ~MapObserver()
Definition: camera.cpp:66
Base Class for Images.
Definition: image.h:47
#define ABS(x)
Definition: fife_math.h:40
uint32_t m_screen_cell_height
Definition: camera.h:473
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:704
DoubleMatrix m_inverse_matrix
Definition: camera.h:455
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:788
Rect m_viewport
Definition: camera.h:469
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:481
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.
DoubleMatrix m_vs_matrix
Definition: camera.h:457
RenderList & getRenderListRef(Layer *layer)
Returns reference to RenderList.
Definition: camera.cpp:526
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:431
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:783
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:745
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:129
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:475
void resetOverlayAnimation()
Resets the animation overlay.
Definition: camera.cpp:845
bool isEnabled() const
Is renderer enabled.
Definition: rendererbase.h:136
virtual void detachRenderTarget()=0
Detaches current render surface.
bool m_enabledZToY
Definition: camera.h:466
void addChangeListener(MapChangeListener *listener)
Adds new change listener.
Definition: map.cpp:230
bool m_img_fill
Definition: camera.h:510
static Logger _log(LM_AUDIO)
PointType3D< int32_t > Point3D
Definition: point.h:325
void attach(Instance *instance)
Attaches the camera to an instance.
Definition: camera.cpp:672
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:499
DoubleMatrix m_screen_2_vscreen
Definition: camera.h:460
Camera * m_camera
Definition: camera.cpp:60
PointType2D< double > DoublePoint
Definition: point.h:195
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:796
void setRotation(double rotation)
Sets rotation for the camera.
Definition: camera.cpp:149
void resetOverlayColor()
Resets the color overlay.
Definition: camera.cpp:811
void onRendererEnabledChanged(RendererBase *renderer)
Renderer is enabled / disabled.
Definition: camera.cpp:730
t_layer_to_instances m_layerToInstances
Definition: camera.h:492
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:360
Camera describes properties of a view port shown in the main screen Main screen can have multiple cam...
Definition: camera.h:58
Layer * getLayer() const
Gets the layer where this location is pointing to.
Definition: location.cpp:83
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
uint32_t m_start_time
Definition: camera.h:512
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:468
RendererBase * getRenderer(const std::string &name)
Gets renderer with given name.
Definition: camera.cpp:741
const uint32_t MAX_BATCH_SIZE
Definition: camera.cpp:57
std::map< std::string, RendererBase * > m_renderers
Definition: camera.h:484
#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:454
uint32_t getHeight() const
Definition: image.cpp:160
bool m_enabled
Definition: camera.h:476
void addRenderer(RendererBase *renderer)
Adds new renderer on the view.
Definition: camera.cpp:717
double m_zToY
Definition: camera.h:465
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:494
bool m_ani_overlay
Definition: camera.h:506
PointType2D< int32_t > Point
Definition: point.h:194
uint32_t getTime() const
Get the time.
const Rect & getViewPort() const
Gets the viewport for camera in pixel coordinates.
Definition: camera.cpp:303
void onRendererPipelinePositionChanged(RendererBase *renderer)
Renderer's pipeline position has been changed.
Definition: camera.cpp:726
ImagePtr getFrameByTimestamp(uint32_t timestamp)
Gets the frame image that matches the given timestamp.
Definition: animation.cpp:99
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:286
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:487
ImagePtr getCacheImage()
Definition: layercache.cpp:806
void removeLayer(Layer *layer)
Definition: camera.cpp:759
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 instance gets deleted on layer.
Definition: camera.cpp:75
Point doublePt2intPt(DoublePoint pt)
Convert from 2D double point to 2D int32_t point.
Definition: point.h:330
Location getLocation() const
Gets current location of instance.
Definition: instance.cpp:311
void setLightingColor(float red, float green, float blue)
Sets lighting color.
Definition: camera.cpp:766
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:829
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:681
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:850
CellGrid * getCellGrid() const
Get the Cellgrid.
Definition: layer.cpp:93
const Rect & getMapViewPort()
Gets the viewport for camera in map coordinates.
Definition: camera.cpp:307
bool m_lighting
Definition: camera.h:499
void addLayer(Layer *layer)
Definition: camera.cpp:752
AnimationPtr getOverlayAnimation()
Returns an AnimationPtr to the overlay animation.
Definition: camera.cpp:841
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:281
bool pipelineSort(const RendererBase *lhs, const RendererBase *rhs)
Definition: camera.cpp:713
virtual ~Camera()
Destructor.
Definition: camera.cpp:123
void refresh()
Refreshes camera view in case e.g.
Definition: camera.cpp:699
#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:513
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:147
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:426
std::map< Layer *, Point > m_image_dimensions
Definition: camera.h:479
A 3D Point.
Definition: point.h:202
Instance * m_attachedto
Definition: camera.h:477
bool m_mapViewPortUpdated
Definition: camera.h:471
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:530
Location getLocation() const
Gets the location camera is rendering.
Definition: camera.cpp:291
void calculateZValue(ScreenPoint &screen_coords)
calculates z-value for given screenpoint
Definition: camera.cpp:414
DoublePoint intPt2doublePt(Point pt)
Convert from 2D int32_t point to 2D double point.
Definition: point.h:344
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:496
static num_type pi()
Definition: fife_math.h:133
ExactModelCoordinate toMapCoordinates(ScreenPoint screen_coords, bool z_calculated=true)
Transforms given point from screen coordinates to map coordinates.
Definition: camera.cpp:419
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:474
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:834
std::string m_id
Definition: camera.h:415
void renderStaticLayer(Layer *layer, bool update)
Renders the layer part that is on screen as one image.
Definition: camera.cpp:905
Rect m_mapViewPort
Definition: camera.h:470
DoubleMatrix m_vscreen_2_screen
Definition: camera.h:459
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:364
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:685
std::vector< float > m_light_colors
Definition: camera.h:501
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:464
MapObserver * m_map_observer
Definition: camera.h:495
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:440
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:467
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:356
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:507
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:984
An Instance is an "instantiation" of an Object at a Location.
Definition: instance.h:100
void updateRenderLists()
Updates camera RenderLists.
Definition: camera.cpp:959
ScreenPoint virtualScreenToScreen(const DoublePoint3D &p)
Transforms given point from virtual screen coordinates to screen coordinates.
Definition: camera.cpp:436
double m_rotation
Definition: camera.h:463
std::vector< float > getLightingColor()
Returns a vector that contain the light color.
Definition: camera.cpp:774
ExactModelCoordinate getMapCoordinates() const
Gets map coordinates set to this location.
Definition: location.cpp:117
bool m_img_overlay
Definition: camera.h:505
uint32_t m_screen_cell_width
Definition: camera.h:472
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:478
Rect getLayerViewPort(Layer *layer)
Gets the viewport for camera in layer coordinates.
Definition: camera.cpp:340
void setZoom(double zoom)
Sets zoom for the camera.
Definition: camera.cpp:161
Listener interface for changes happening on map.
Definition: map.h:56