93 m_mapViewPortUpdated(false),
94 m_screen_cell_width(1),
95 m_screen_cell_height(1),
100 m_transform(NoneTransform),
104 m_renderbackend(renderbackend),
105 m_layer_to_instances(),
108 m_col_overlay(false),
109 m_img_overlay(false),
110 m_ani_overlay(false) {
123 std::map<std::string, RendererBase*>::iterator r_it =
m_renderers.begin();
125 r_it->second->reset();
184 return matrix.
m9 * -1.0;
225 throw Exception(
"Location without layer given to Camera::setLocation");
228 throw Exception(
"Camera layer has no cellgrid specified");
253 for(std::list<Layer*>::const_iterator i = layers.begin(); i !=layers.end(); ++i) {
259 const std::list<Layer*>& layers = map->
getLayers();
260 for(std::list<Layer*>::const_iterator i = layers.begin(); i !=layers.end(); ++i) {
310 std::vector<ExactModelCoordinate> coords;
317 ModelCoordinate max(static_cast<int32_t>(emc.
x+0.5), static_cast<int32_t>(emc.
y+0.5));
318 std::vector<ExactModelCoordinate>::iterator it = coords.begin();
319 for (; it != coords.end(); ++it) {
320 min.
x = std::min(min.
x, static_cast<int32_t>((*it).x));
321 min.
y = std::min(min.
y, static_cast<int32_t>((*it).y));
322 max.
x = std::max(max.
x, static_cast<int32_t>((*it).x+0.5));
323 max.
y = std::max(max.
y, static_cast<int32_t>((*it).y+0.5));
341 emc.
x = mapView.
x+mapView.
w;
342 emc.
y = mapView.
y+mapView.
h;
399 for(int32_t i=0; i!=N; ++i) {
447 std::vector<ExactModelCoordinate> vertices;
459 for (
uint32_t i = 0; i < vertices.size(); i++) {
461 vertices[i] = mtx * vertices[i];
463 x1 = x2 = vertices[0].x;
464 y1 = y2 = vertices[0].y;
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);
480 loc.setLayerCoordinates(cell);
483 loc.setLayerCoordinates(cell);
501 loc.setLayerCoordinates(cell);
504 loc.setLayerCoordinates(cell);
526 bool special_alpha = alpha != 0;
529 RenderList::const_iterator instance_it = layer_instances.end();
530 while (instance_it != layer_instances.begin()) {
532 Instance* i = (*instance_it)->instance;
542 double fx =
static_cast<double>(x);
543 double fy =
static_cast<double>(y);
548 x =
static_cast<int32_t
>(round(fx / fsw * fow));
549 y =
static_cast<int32_t
>(round(fy / fsh * foh));
553 if (a == 0 || (special_alpha && a < alpha)) {
556 instances.push_back(i);
564 bool special_alpha = alpha != 0;
567 RenderList::const_iterator instance_it = layer_instances.end();
568 while (instance_it != layer_instances.begin()) {
570 Instance* i = (*instance_it)->instance;;
577 for(int32_t xx = screen_rect.
x; xx < screen_rect.
x + screen_rect.
w; xx++) {
578 for(int32_t yy = screen_rect.
y; yy < screen_rect.
y + screen_rect.
h; yy++) {
583 double fx =
static_cast<double>(x);
584 double fy =
static_cast<double>(y);
589 x =
static_cast<int32_t
>(round(fx / fsw * fow));
590 y =
static_cast<int32_t
>(round(fy / fsh * foh));
594 if (a == 0 || (special_alpha && a < alpha)) {
598 instances.push_back(i);
599 goto found_non_transparent_pixel;
603 found_non_transparent_pixel:;
616 RenderList::const_iterator instance_it = layer_instances.end();
617 while (instance_it != layer_instances.begin()) {
619 Instance* i = (*instance_it)->instance;
620 if (use_exactcoordinates) {
622 instances.push_back(i);
626 instances.push_back(i);
635 FL_WARN(
_log,
"Tried to attach camera to instance on different layer.");
706 std::map<std::string, RendererBase*>::iterator r_it =
m_renderers.begin();
708 r_it->second->reset();
714 m_cache[layer]->setLayer(layer);
734 for(int32_t colors = 0; colors != 3; ++colors) {
755 std::vector<uint8_t> colors;
762 for(
uint8_t cc = 0; cc != 4; ++cc) {
763 colors.push_back(255);
869 if (!cacheImage.
get()) {
887 std::list<RendererBase*>::iterator r_it =
m_pipeline.begin();
889 if ((*r_it)->isActivedLayer(layer)) {
890 (*r_it)->render(
this, layer, instances_to_render);
907 const std::list<Layer*>& layers = map->
getLayers();
908 std::list<Layer*>::const_iterator layer_it = layers.begin();
909 for (;layer_it != layers.end(); ++layer_it) {
914 FL_ERR(
_log,
LMsg(
"Layer Cache miss! (This shouldn't happen!)") << (*layer_it)->getId());
944 const std::list<Layer*>& layers = map->
getLayers();
945 std::list<Layer*>::const_iterator layer_it = layers.begin();
946 for ( ; layer_it != layers.end(); ++layer_it) {
948 if ((*layer_it)->isStatic()) {
953 std::list<RendererBase*>::iterator r_it =
m_pipeline.begin();
955 if ((*r_it)->isActivedLayer(*layer_it)) {
956 (*r_it)->render(
this, *layer_it, instances_to_render);
959 if (renderbackendOpenGLe) {
#define FL_WARN(logger, msg)
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.
virtual void setLighting(float red, float green, float blue)=0
Set colors for lighting.
T * get() const
allows direct access to underlying pointer
int32_t getOverlayImage()
Returns the pool id of the overlay image.
std::list< RendererBase * > m_pipeline
DoublePoint getLogicalCellDimensions(Layer *layer)
Gets logical cell image dimensions for given layer.
RenderBackend * m_renderbackend
Matrix & applyRotate(T angle, T x, T y, T z)
DoubleMatrix m_vs_inverse_matrix
Matrix inverse() const
Adjoint method inverse, constant time inversion implementation.
std::vector< RenderItem * > RenderList
void setOverlayImage(int32_t id, bool fill=false)
Sets a image as overlay, if fill is true the image gets the viewport size.
uint32_t m_screen_cell_height
T h
Height of the rectangle.
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.
void resetUpdates()
Resets temporary values from last update round, like warped flag.
DoubleMatrix m_inverse_matrix
virtual void onMapChanged(Map *map, std::vector< Layer * > &changedLayers)
Called when some layer is changed on map.
Helper class to create log strings out from separate parts Usage: LMsg("some text") << variable << "...
void removeChangeListener(MapChangeListener *listener)
Removes associated change listener.
MapObserver(Camera *camera)
void setOverlayColor(uint8_t red, uint8_t green, uint8_t blue, uint8_t alpha)
Sets a color as overlay.
void setLayer(Layer *layer)
Sets layer where this location is pointing to.
Matrix< T > & mult4by4(const Matrix< T > &mat)
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...
virtual const std::string & getName() const =0
The name of the renderbackend.
RenderList & getRenderListRef(Layer *layer)
Returns reference to RenderList.
bool isZToYEnabled() const
Gets if z to y manipulation is enabled / disabled.
uint32_t getHeight() const
DoublePoint3D toVirtualScreenCoordinates(const ExactModelCoordinate &map_coords)
Transforms given point from map coordinates to virtual screen coordinates.
bool contains(const PointType2D< T > &point) const
Checks whether a rectangle contains a Point.
void resetLightingColor()
Resets lighting color.
void setMapCoordinates(const ExactModelCoordinate &coordinates)
Sets map coordinates to this location.
void setZToYEnabled(bool enabled)
Sets z to y manipulation enabled / disabled.
void resetRenderers()
resets active layer information on all renderers.
void setTilt(double tilt)
Sets tilt for the camera.
uint32_t getDuration() const
Gets the total duration for the whole animation.
void getPixelRGBA(int32_t x, int32_t y, uint8_t *r, uint8_t *g, uint8_t *b, uint8_t *a)
void resetOverlayAnimation()
Resets the animation overlay.
bool isEnabled() const
Is renderer enabled.
virtual void detachRenderTarget()=0
Detaches current render surface.
void addChangeListener(MapChangeListener *listener)
Adds new change listener.
static Logger _log(LM_AUDIO)
PointType3D< int32_t > Point3D
void attach(Instance *instance)
Attaches the camera to an instance.
double getTilt() const
Gets camera tilt.
Point3D getZOffset(Layer *layer)
Gets a point that contain the visual z(z=1) difference, based on the given layer. ...
DoubleMatrix m_screen_2_vscreen
PointType2D< double > DoublePoint
Matrix & applyScale(T x, T y, T z)
Apply scale into this matrix.
std::vector< uint8_t > getOverlayColor()
Returns a vector that contain the overlay color.
void setRotation(double rotation)
Sets rotation for the camera.
void resetOverlayColor()
Resets the color overlay.
void onRendererEnabledChanged(RendererBase *renderer)
Renderer is enabled / disabled.
Camera(const std::string &id, Layer *layer, const Rect &viewport, RenderBackend *renderbackend)
Constructor Camera needs to be added to the view.
bool isEnabled()
Gets if camera is enabled / disabled.
Camera describes properties of a view port shown in the main screen Main screen can have multiple cam...
Layer * getLayer() const
Gets the layer where this location is pointing to.
static ImageManager * instance()
Location & getLocationRef()
Gets reference of current location of instance.
ModelCoordinate getLayerCoordinates() const
Gets cell precision layer coordinates set to this location.
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.
std::map< std::string, RendererBase * > m_renderers
#define FL_ERR(logger, msg)
virtual uint32_t getLightingModel() const =0
Gets the current light model.
uint32_t getHeight() const
void addRenderer(RendererBase *renderer)
Adds new renderer on the view.
Map * getMap() const
Gets the map where this location is pointing to.
double getOriginalZToY() const
Gets original zToY transformation value.
std::map< Layer *, LayerCache * > m_cache
PointType2D< int32_t > Point
uint32_t getTime() const
Get the time.
const Rect & getViewPort() const
Gets the viewport for camera in pixel coordinates.
void onRendererPipelinePositionChanged(RendererBase *renderer)
Renderer's pipeline position has been changed.
ImagePtr getFrameByTimestamp(uint32_t timestamp)
Gets the frame image that matches the given timestamp.
void setLocation(const Location &location)
Sets the location for camera.
static bool Equal(T _val1, T _val2)
Base class for all view renderers View renderer renders one aspect of the view shown on screen...
void pushClipArea(const Rect &cliparea, bool clear=true)
Pushes clip area to clip stack Clip areas define which area is drawn on screen.
t_layer_to_instances m_layer_to_instances
void removeLayer(Layer *layer)
double getZoom() const
Gets camera zoom.
virtual void onLayerDelete(Map *map, Layer *layer)
Called when some instance gets deleted on layer.
Point doublePt2intPt(DoublePoint pt)
Convert from 2D double point to 2D int32_t point.
Location getLocation() const
Gets current location of instance.
void setLightingColor(float red, float green, float blue)
Sets lighting color.
Location & getLocationRef()
Gets a reference to the camera location.
void setCacheImage(ImagePtr image)
void resetOverlayImage()
Resets the image overlay.
void popClipArea()
Pops clip area from clip stack.
ExactModelCoordinate & getExactLayerCoordinatesRef()
Gets reference to exact layer coordinates.
void detach()
Detaches the camera from an instance.
uint32_t getWidth() const
void renderOverlay()
Renders the overlay(color, image, animation) for the camera.
CellGrid * getCellGrid() const
Get the Cellgrid.
const Rect & getMapViewPort()
Gets the viewport for camera in map coordinates.
void addLayer(Layer *layer)
AnimationPtr getOverlayAnimation()
Returns an AnimationPtr to the overlay animation.
void setRendererListener(IRendererListener *listener)
Sets listener for renderer.
virtual std::string getName()=0
Name of the renderer.
bool pipelineSort(const RendererBase *lhs, const RendererBase *rhs)
virtual ~Camera()
Destructor.
void refresh()
Refreshes camera view in case e.g.
#define FL_LOG(logger, msg)
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.
Point getCellImageDimensions()
Gets screen cell image dimensions.
Matrix & loadRotate(T angle, T x, T y, T z)
Make this a rotation matrix.
Matrix & loadScale(T x, T y, T z=1)
Make this a scale matrix.
bool intersects(const RectType< T > &rect) const
Check whether two rectangles share some area.
bool isSharedImage() const
Returns true if this image shares data with another one.
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.
std::map< Layer *, Point > m_image_dimensions
bool m_mapViewPortUpdated
const std::string & getId() const
Get the id of this layer.
void getMatchingInstances(ScreenPoint screen_coords, Layer &layer, std::list< Instance * > &instances, uint8_t alpha=0)
Returns instances that match given screen coordinate.
Location getLocation() const
Gets the location camera is rendering.
void calculateZValue(ScreenPoint &screen_coords)
calculates z-value for given screenpoint
DoublePoint intPt2doublePt(Point pt)
Convert from 2D int32_t point to 2D double point.
void update(Camera::Transform transform, RenderList &renderlist)
const std::list< Layer * > & getLayers() const
Get the layers on this map.
ExactModelCoordinate toMapCoordinates(ScreenPoint screen_coords, bool z_calculated=true)
Transforms given point from screen coordinates to map coordinates.
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.
void setOverlayAnimation(AnimationPtr anim, bool fill=false)
Sets a animation as overlay, if fill is true the animation gets the viewport size.
void renderStaticLayer(Layer *layer, bool update)
Renders the layer part that is on screen as one image.
DoubleMatrix m_vscreen_2_screen
virtual void onLayerCreate(Map *map, Layer *layer)
Called when some layer gets created on the map.
Point3D getOrigin() const
Gets screen point for the camera location.
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.
std::vector< float > m_light_colors
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.
void setViewPort(const Rect &viewport)
Sets the viewport for camera viewport is rectangle inside the view where camera renders.
MapObserver * m_map_observer
DoublePoint3D screenToVirtualScreen(const ScreenPoint &p)
ExactModelCoordinate toMapCoordinates(const ModelCoordinate &layer_coords)
Transforms given point from layer coordinates to map coordinates.
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.
int32_t getPipelinePosition() const
Gets renderer position in the rendering pipeline.
Matrix & applyTranslate(T x, T y, T z)
Apply translation into this matrix.
ExactModelCoordinate getExactLayerCoordinates() const
Gets exact layer coordinates set to this location.
SDL_Color m_overlay_color
T w
Width of the rectangle.
#define FL_DBG(logger, msg)
double getZToY() const
Gets zToY value.
void render()
Renders camera.
An Instance is an "instantiation" of an Object at a Location.
void updateRenderLists()
Updates camera RenderLists.
ScreenPoint virtualScreenToScreen(const DoublePoint3D &p)
std::vector< float > getLightingColor()
Returns a vector that contain the light color.
ExactModelCoordinate getMapCoordinates() const
Gets map coordinates set to this location.
uint32_t m_screen_cell_width
double getRotation() const
Gets camera rotation.
Point getRealCellDimensions(Layer *layer)
Gets real cell image dimensions for given layer.
Rect getLayerViewPort(Layer *layer)
Gets the viewport for camera in layer coordinates.
void setZoom(double zoom)
Sets zoom for the camera.
Listener interface for changes happening on map.