84 m_renderbackend(renderbackend),
96 m_mapViewPortUpdated(false),
98 m_screenCellHeight(1),
100 m_referenceScaleY(1),
103 m_transform(NoneTransform),
107 m_layerToInstances(),
110 m_col_overlay(false),
111 m_img_overlay(false),
112 m_ani_overlay(false) {
123 for (std::list<Layer*>::const_iterator i = layers.begin(); i != layers.end(); ++i) {
128 std::map<std::string, RendererBase*>::iterator r_it =
m_renderers.begin();
130 r_it->second->reset();
146 for (std::list<Layer*>::const_iterator i = layers.begin(); i != layers.end(); ++i) {
204 return matrix.
m9 * -1.0;
245 throw Exception(
"Location layer without cellgrid given to Camera::setLocation");
249 throw Exception(
"Location without layer given to Camera::setLocation");
300 std::vector<ExactModelCoordinate> coords;
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));
331 emc.
x = mapView.
x+mapView.
w;
332 emc.
y = mapView.
y+mapView.
h;
398 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);
476 std::vector<ExactModelCoordinate> vertices;
491 for (
uint32_t i = 0; i < vertices.size(); i++) {
492 vertices[i] = mtx * vertices[i];
494 x1 = x2 = vertices[0].x;
495 y1 = y2 = vertices[0].y;
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);
527 bool special_alpha = alpha != 0;
530 RenderList::const_iterator instance_it = layer_instances.end();
531 while (instance_it != layer_instances.begin()) {
533 Instance* i = (*instance_it)->instance;
543 double fx =
static_cast<double>(x);
544 double fy =
static_cast<double>(y);
549 x =
static_cast<int32_t
>(round(fx / fsw * fow));
550 y =
static_cast<int32_t
>(round(fy / fsh * foh));
554 std::vector<ImagePtr>::iterator it = ao->begin();
555 for (; it != ao->end(); ++it) {
556 if ((*it)->isSharedImage()) {
557 (*it)->forceLoadInternal();
559 (*it)->getPixelRGBA(x, y, &r, &g, &b, &a);
561 if (a == 0 || (special_alpha && a < alpha)) {
564 instances.push_back(i);
570 if (a == 0 || (special_alpha && a < alpha)) {
573 instances.push_back(i);
582 bool special_alpha = alpha != 0;
585 RenderList::const_iterator instance_it = layer_instances.end();
586 while (instance_it != layer_instances.begin()) {
588 Instance* i = (*instance_it)->instance;;
595 int32_t intersection_left = std::max(screen_rect.
x, vc.
dimensions.
x);
597 int32_t intersection_top = std::max(screen_rect.
y, vc.
dimensions.
y);
600 for(int32_t xx = intersection_left; xx < intersection_right; xx++) {
601 for(int32_t yy = intersection_top; yy < intersection_bottom; yy++) {
605 double fx =
static_cast<double>(x);
606 double fy =
static_cast<double>(y);
611 x =
static_cast<int32_t
>(round(fx / fsw * fow));
612 y =
static_cast<int32_t
>(round(fy / fsh * foh));
616 std::vector<ImagePtr>::iterator it = ao->begin();
617 for (; it != ao->end(); ++it) {
618 if ((*it)->isSharedImage()) {
619 (*it)->forceLoadInternal();
621 (*it)->getPixelRGBA(x, y, &r, &g, &b, &a);
623 if (a == 0 || (special_alpha && a < alpha)) {
626 instances.push_back(i);
627 goto found_non_transparent_pixel;
632 if (a == 0 || (special_alpha && a < alpha)) {
635 instances.push_back(i);
636 goto found_non_transparent_pixel;
640 found_non_transparent_pixel:;
653 RenderList::const_iterator instance_it = layer_instances.end();
654 while (instance_it != layer_instances.begin()) {
656 Instance* i = (*instance_it)->instance;
657 if (use_exactcoordinates) {
659 instances.push_back(i);
663 instances.push_back(i);
741 std::map<std::string, RendererBase*>::iterator r_it =
m_renderers.begin();
743 r_it->second->reset();
749 m_cache[layer]->setLayer(layer);
774 for(int32_t colors = 0; colors != 3; ++colors) {
795 std::vector<uint8_t> colors;
802 for(
uint8_t cc = 0; cc != 4; ++cc) {
803 colors.push_back(255);
909 if (!cacheImage.
get()) {
931 for (
uint8_t i = 0; i < batches; ++i) {
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();
937 if ((*r_it)->isActivedLayer(layer)) {
938 (*r_it)->render(
this, layer, tempList);
944 std::list<RendererBase*>::iterator r_it =
m_pipeline.begin();
946 if ((*r_it)->isActivedLayer(layer)) {
947 (*r_it)->render(
this, layer, instancesToRender);
964 std::list<Layer*>::const_iterator layer_it = layers.begin();
965 for (;layer_it != layers.end(); ++layer_it) {
970 FL_ERR(
_log,
LMsg(
"Layer Cache miss! (This shouldn't happen!)") << (*layer_it)->getId());
997 std::list<Layer*>::const_iterator layer_it = layers.begin();
998 for ( ; layer_it != layers.end(); ++layer_it) {
1000 if ((*layer_it)->isStatic()) {
1008 layer_it = layers.begin();
1009 for ( ; layer_it != layers.end(); ++layer_it) {
1011 if ((*layer_it)->isStatic()) {
1021 for (
uint8_t i = 0; i < batches; ++i) {
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();
1027 if ((*r_it)->isActivedLayer(*layer_it)) {
1028 (*r_it)->render(
this, *layer_it, tempList);
1034 std::list<RendererBase*>::iterator r_it =
m_pipeline.begin();
1036 if ((*r_it)->isActivedLayer(*layer_it)) {
1037 (*r_it)->render(
this, *layer_it, instancesToRender);
void setPosition(const ExactModelCoordinate &position)
Sets map point for the camera.
int32_t getPipelinePosition() const
Gets renderer position in the rendering pipeline.
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.
int32_t getOverlayImage()
Returns the pool id of the overlay image.
std::list< RendererBase * > m_pipeline
uint32_t getHeight() const
RenderBackend * m_renderbackend
Matrix & applyRotate(T angle, T x, T y, T z)
DoubleMatrix m_vs_inverse_matrix
std::vector< RenderItem * > RenderList
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.
void calculateZValue(DoublePoint3D &screen_coords)
calculates z-value for given screenpoint
Layer * getLayer() const
Gets the layer where this location is pointing to.
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
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.
uint32_t m_screenCellHeight
RenderList & getRenderListRef(Layer *layer)
Returns reference to RenderList.
DoublePoint3D toVirtualScreenCoordinates(const ExactModelCoordinate &map_coords)
Transforms given point from map coordinates to virtual screen coordinates.
double getZToY() const
Gets zToY value.
void resetLightingColor()
Resets lighting color.
void setMapCoordinates(const ExactModelCoordinate &coordinates)
Sets map coordinates to this location.
const std::string & getId() const
Get the id of this layer.
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.
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.
Camera(const std::string &id, Map *map, const Rect &viewport, RenderBackend *renderbackend)
Constructor Camera needs to be added to the view.
virtual void detachRenderTarget()=0
Detaches current render surface.
void addChangeListener(MapChangeListener *listener)
Adds new change listener.
const std::list< Layer * > & getLayers() const
Get the layers on this map.
static Logger _log(LM_AUDIO)
void reset()
Resets location (so that layer and coordinate information becomes invalid)
bool contains(const PointType2D< T > &point) const
Checks whether a rectangle contains a Point.
void attach(Instance *instance)
Attaches the camera to an instance.
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.
t_layer_to_instances m_layerToInstances
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...
static ImageManager * instance()
Location & getLocationRef()
Gets reference of current location of instance.
void getMatchingInstances(ScreenPoint screen_coords, Layer &layer, std::list< Instance *> &instances, uint8_t alpha=0)
Returns instances that match given screen coordinate.
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.
uint32_t m_screenCellWidth
virtual void onMapChanged(Map *map, std::vector< Layer *> &changedLayers)
Called when some layer is changed on map.
const uint32_t MAX_BATCH_SIZE
std::map< std::string, RendererBase * > m_renderers
#define FL_ERR(logger, msg)
virtual uint32_t getLightingModel() const =0
Gets the current light model.
bool intersects(const RectType< T > &rect) const
Check whether two rectangles share some area.
void addRenderer(RendererBase *renderer)
Adds new renderer on the view.
std::map< Layer *, LayerCache * > m_cache
PointType2D< int32_t > Point
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.
uint32_t getHeight() const
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.
void removeLayer(Layer *layer)
virtual void onLayerDelete(Map *map, Layer *layer)
Called when some layer gets deleted on map.
Point doublePt2intPt(DoublePoint pt)
Convert from 2D double point to 2D int32_t point.
double getRotation() const
Gets camera rotation.
void setLightingColor(float red, float green, float blue)
Sets lighting color.
void setCacheImage(ImagePtr image)
void resetOverlayImage()
Resets the image overlay.
double getOriginalZToY() const
Gets original zToY transformation value.
void popClipArea()
Pops clip area from clip stack.
ExactModelCoordinate & getExactLayerCoordinatesRef()
Gets reference to exact layer coordinates.
void detach()
Detaches the camera from an instance.
T right() const
The X coordinate of the right edge.
Matrix inverse() const
Adjoint method inverse, constant time inversion implementation.
void renderOverlay()
Renders the overlay(color, image, animation) for the camera.
double getZoom() const
Gets camera zoom.
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.
const Rect & getViewPort() const
Gets the viewport for camera in pixel coordinates.
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.
DoublePoint3D ExactModelCoordinate
CellGrid * getCellGrid() const
Get the Cellgrid.
Matrix & loadScale(T x, T y, T z=1)
Make this a scale matrix.
bool isSharedImage() const
Returns true if this image shares data with another one.
std::vector< ImagePtr > * getAnimationOverlay() const
Returns pointer to AnimationOverlay vector.
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.
double getTilt() const
Gets camera tilt.
bool m_mapViewPortUpdated
ExactModelCoordinate m_position
DoublePoint intPt2doublePt(Point pt)
Convert from 2D int32_t point to 2D double point.
void update(Camera::Transform transform, RenderList &renderlist)
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.
Location getLocation()
Gets the location camera is rendering.
void renderStaticLayer(Layer *layer, bool update)
Renders the layer part that is on screen as one image.
ExactModelCoordinate getMapCoordinates() const
Gets map coordinates set to this location.
ModelCoordinate getLayerCoordinates() const
Gets cell precision layer coordinates set to this location.
DoubleMatrix m_vscreen_2_screen
Point3D getOrigin() const
Gets screen point of the camera.
virtual void onLayerCreate(Map *map, Layer *layer)
Called when some layer gets created on the map.
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.
T * get() const
allows direct access to underlying pointer
std::vector< float > m_light_colors
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.
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)
Transforms given point from screen coordinates to virtual screen coordinates.
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.
Matrix & applyTranslate(T x, T y, T z)
Apply translation into this matrix.
uint32_t getDuration() const
Gets the total duration for the whole animation.
uint32_t getLayerCount() const
Get the overall number of layers.
SDL_Color m_overlay_color
T w
Width of the rectangle.
#define FL_DBG(logger, msg)
bool isEnabled() const
Is renderer enabled.
ExactModelCoordinate getPosition() const
Gets map point of the camera.
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)
Transforms given point from virtual screen coordinates to screen coordinates.
std::vector< float > getLightingColor()
Returns a vector that contain the light color.
T bottom() const
The Y coordinate of the bottom edge.
uint32_t getWidth() const
bool isZToYEnabled() const
Gets if z to y manipulation is enabled / disabled.
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.