00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef FIFE_VIEW_CAMERA_H
00023 #define FIFE_VIEW_CAMERA_H
00024
00025
00026 #include <string>
00027 #include <map>
00028
00029
00030
00031
00032
00033
00034
00035 #include "model/structures/location.h"
00036 #include "util/structures/rect.h"
00037 #include "util/math/matrix.h"
00038
00039 #include "rendererbase.h"
00040
00041 namespace FIFE {
00042
00043 typedef Point3D ScreenPoint;
00044 class Layer;
00045 class Rect;
00046 class Instance;
00047 class ImagePool;
00048 class AnimationPool;
00049 class RenderBackend;
00050 typedef std::map<Layer*, std::vector<Instance*> > t_layer_to_instances;
00051
00057 class Camera: public IRendererListener, public IRendererContainer {
00058 public:
00071 Camera(const std::string& id,
00072 Layer* layer,
00073 const Rect& viewport,
00074 const ExactModelCoordinate& emc,
00075 RenderBackend* renderbackend,
00076 ImagePool* ipool,
00077 AnimationPool* apool);
00078
00081 virtual ~Camera();
00082
00085 const std::string& getId() const { return m_id; }
00086
00089 void setId(const std::string& id) { m_id = id; }
00090
00095 void setTilt(double tilt);
00096
00100 double getTilt() const;
00101
00107 void setRotation(double rotation);
00108
00112 double getRotation() const;
00113
00117 void setZoom(double zoom);
00118
00122 double getZoom() const;
00123
00129 void setCellImageDimensions(unsigned int width, unsigned int height);
00130
00135 Point getCellImageDimensions();
00136
00140 Point getCellImageDimensions(Layer* layer);
00141
00145 void setLocation(const Location& location);
00146
00150 Location getLocation() const;
00151
00157 Location& getLocationRef();
00158
00163 void attach(Instance *instance);
00164
00167 void detach();
00168
00171 Instance* getAttached() const { return m_attachedto; }
00172
00177 void setViewPort(const Rect& viewport);
00178
00182 const Rect& getViewPort() const;
00183
00189 ExactModelCoordinate toMapCoordinates(ScreenPoint screen_coords, bool z_calculated=true);
00190
00194 ScreenPoint toScreenCoordinates(ExactModelCoordinate map_coords);
00195
00198 void setEnabled(bool enabled);
00199
00202 bool isEnabled();
00203
00209 void getMatchingInstances(ScreenPoint screen_coords, Layer& layer, std::list<Instance*>& instances);
00210
00217 void getMatchingInstances(Rect screen_rect, Layer& layer, std::list<Instance*>& instances);
00218
00225 void getMatchingInstances(Location& loc, std::list<Instance*>& instances, bool use_exactcoordinates=false);
00226
00234 void update();
00235
00241 void refresh();
00242
00245 void resetUpdates();
00246
00249 void addRenderer(RendererBase* renderer);
00250
00253 RendererBase* getRenderer(const std::string& name);
00254
00257 void resetRenderers();
00258
00261 void calculateZValue(ScreenPoint& screen_coords);
00262
00263 void onRendererPipelinePositionChanged(RendererBase* renderer);
00264 void onRendererEnabledChanged(RendererBase* renderer);
00265
00268 void render();
00269
00270 private:
00271 std::string m_id;
00272
00279 void updateMatrices();
00280
00287 void updateReferenceScale();
00288
00291 DoublePoint getLogicalCellDimensions(Layer* layer);
00292
00293 DoubleMatrix m_matrix;
00294 DoubleMatrix m_inverse_matrix;
00295 double m_tilt;
00296 double m_rotation;
00297 double m_zoom;
00298 Location m_location;
00299 ScreenPoint m_prev_origo;
00300 ScreenPoint m_cur_origo;
00301 Rect m_viewport;
00302 bool m_view_updated;
00303 unsigned int m_screen_cell_width;
00304 unsigned int m_screen_cell_height;
00305 double m_reference_scale;
00306 bool m_enabled;
00307 Instance* m_attachedto;
00308
00309 std::map<Layer*, Point> m_image_dimensions;
00310 bool m_iswarped;
00311
00312
00313 std::map<std::string, RendererBase*> m_renderers;
00314 std::list<RendererBase*> m_pipeline;
00315 bool m_updated;
00316
00317 RenderBackend* m_renderbackend;
00318 ImagePool* m_ipool;
00319 AnimationPool* m_apool;
00320
00321
00322 t_layer_to_instances m_layer_to_instances;
00323 };
00324 }
00325 #endif