96 m_mapViewPortUpdated(false),
97 m_screen_cell_width(1),
98 m_screen_cell_height(1),
100 m_referenceScaleY(1),
103 m_image_dimensions(),
104 m_transform(NoneTransform),
108 m_renderbackend(renderbackend),
109 m_layerToInstances(),
112 m_col_overlay(false),
113 m_img_overlay(false),
114 m_ani_overlay(false) {
127 std::map<std::string, RendererBase*>::iterator r_it =
m_renderers.begin();
129 r_it->second->reset();
188 return matrix.
m9 * -1.0;
229 throw Exception(
"Location without layer given to Camera::setLocation");
232 throw Exception(
"Camera layer has no cellgrid specified");
257 for(std::list<Layer*>::const_iterator i = layers.begin(); i !=layers.end(); ++i) {
263 const std::list<Layer*>& layers = map->
getLayers();
264 for(std::list<Layer*>::const_iterator i = layers.begin(); i !=layers.end(); ++i) {
314 std::vector<ExactModelCoordinate> coords;
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));
345 emc.
x = mapView.
x+mapView.
w;
346 emc.
y = mapView.
y+mapView.
h;
402 for(int32_t i=0; i!=N; ++i) {
450 std::vector<ExactModelCoordinate> vertices;
462 for (
uint32_t i = 0; i < vertices.size(); i++) {
464 vertices[i] = mtx * vertices[i];
466 x1 = x2 = vertices[0].x;
467 y1 = y2 = vertices[0].y;
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);
483 loc.setLayerCoordinates(cell);
486 loc.setLayerCoordinates(cell);
504 loc.setLayerCoordinates(cell);
507 loc.setLayerCoordinates(cell);
533 bool special_alpha = alpha != 0;
536 RenderList::const_iterator instance_it = layer_instances.end();
537 while (instance_it != layer_instances.begin()) {
539 Instance* i = (*instance_it)->instance;
549 double fx =
static_cast<double>(x);
550 double fy =
static_cast<double>(y);
555 x =
static_cast<int32_t
>(round(fx / fsw * fow));
556 y =
static_cast<int32_t
>(round(fy / fsh * foh));
560 std::vector<ImagePtr>::iterator it = ao->begin();
561 for (; it != ao->end(); ++it) {
562 if ((*it)->isSharedImage()) {
563 (*it)->forceLoadInternal();
565 (*it)->getPixelRGBA(x, y, &r, &g, &b, &a);
567 if (a == 0 || (special_alpha && a < alpha)) {
570 instances.push_back(i);
576 if (a == 0 || (special_alpha && a < alpha)) {
579 instances.push_back(i);
588 bool special_alpha = alpha != 0;
591 RenderList::const_iterator instance_it = layer_instances.end();
592 while (instance_it != layer_instances.begin()) {
594 Instance* i = (*instance_it)->instance;;
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++) {
607 double fx =
static_cast<double>(x);
608 double fy =
static_cast<double>(y);
613 x =
static_cast<int32_t
>(round(fx / fsw * fow));
614 y =
static_cast<int32_t
>(round(fy / fsh * foh));
618 std::vector<ImagePtr>::iterator it = ao->begin();
619 for (; it != ao->end(); ++it) {
620 if ((*it)->isSharedImage()) {
621 (*it)->forceLoadInternal();
623 (*it)->getPixelRGBA(x, y, &r, &g, &b, &a);
625 if (a == 0 || (special_alpha && a < alpha)) {
628 instances.push_back(i);
629 goto found_non_transparent_pixel;
634 if (a == 0 || (special_alpha && a < alpha)) {
637 instances.push_back(i);
638 goto found_non_transparent_pixel;
643 found_non_transparent_pixel:;
656 RenderList::const_iterator instance_it = layer_instances.end();
657 while (instance_it != layer_instances.begin()) {
659 Instance* i = (*instance_it)->instance;
660 if (use_exactcoordinates) {
662 instances.push_back(i);
666 instances.push_back(i);
675 FL_WARN(
_log,
"Tried to attach camera to instance on different layer.");
746 std::map<std::string, RendererBase*>::iterator r_it =
m_renderers.begin();
748 r_it->second->reset();
754 m_cache[layer]->setLayer(layer);
776 for(int32_t colors = 0; colors != 3; ++colors) {
797 std::vector<uint8_t> colors;
804 for(
uint8_t cc = 0; cc != 4; ++cc) {
805 colors.push_back(255);
911 if (!cacheImage.
get()) {
933 for (
uint8_t i = 0; i < batches; ++i) {
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();
939 if ((*r_it)->isActivedLayer(layer)) {
940 (*r_it)->render(
this, layer, tempList);
946 std::list<RendererBase*>::iterator r_it =
m_pipeline.begin();
948 if ((*r_it)->isActivedLayer(layer)) {
949 (*r_it)->render(
this, layer, instancesToRender);
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) {
973 FL_ERR(
_log,
LMsg(
"Layer Cache miss! (This shouldn't happen!)") << (*layer_it)->getId());
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) {
1003 if ((*layer_it)->isStatic()) {
1011 layer_it = layers.begin();
1012 for ( ; layer_it != layers.end(); ++layer_it) {
1014 if ((*layer_it)->isStatic()) {
1024 for (
uint8_t i = 0; i < batches; ++i) {
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();
1030 if ((*r_it)->isActivedLayer(*layer_it)) {
1031 (*r_it)->render(
this, *layer_it, tempList);
1037 std::list<RendererBase*>::iterator r_it =
m_pipeline.begin();
1039 if ((*r_it)->isActivedLayer(*layer_it)) {
1040 (*r_it)->render(
this, *layer_it, instancesToRender);
std::vector< ImagePtr > * getAnimationOverlay() const
Returns pointer to AnimationOverlay vector.
#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.
t_layer_to_instances m_layerToInstances
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.
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.
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.
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)
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.
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)
Transforms given point from virtual screen coordinates to screen coordinates.
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.