camera.h
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 Instance;
00046 class ImagePool;
00047 class AnimationPool;
00048 class RenderBackend;
00049 class LayerCache;
00050 class MapObserver;
00051 typedef std::map<Layer*, RenderList > t_layer_to_instances;
00052
00058 class Camera: public IRendererListener, public IRendererContainer {
00059 public:
00060 enum Transform {
00061 NormalTransform = 0,
00062 WarpedTransform = 1
00063 };
00064
00077 Camera(const std::string& id,
00078 Layer* layer,
00079 const Rect& viewport,
00080 RenderBackend* renderbackend,
00081 ImagePool* ipool,
00082 AnimationPool* apool);
00083
00086 virtual ~Camera();
00087
00090 const std::string& getId() const { return m_id; }
00091
00094 void setId(const std::string& id) { m_id = id; }
00095
00100 void setTilt(double tilt);
00101
00105 double getTilt() const;
00106
00112 void setRotation(double rotation);
00113
00117 double getRotation() const;
00118
00122 void setZoom(double zoom);
00123
00127 double getZoom() const;
00128
00134 void setCellImageDimensions(unsigned int width, unsigned int height);
00135
00140 Point getCellImageDimensions();
00141
00145 Point getCellImageDimensions(Layer* layer);
00146
00150 void setLocation(const Location& location);
00151
00155 Location getLocation() const;
00156
00157 Point3D getOrigin() const;
00158
00164 Location& getLocationRef();
00165
00170 void attach(Instance *instance);
00171
00174 void detach();
00175
00178 Instance* getAttached() const { return m_attachedto; }
00179
00184 void setViewPort(const Rect& viewport);
00185
00189 const Rect& getViewPort() const;
00190
00196 ExactModelCoordinate toMapCoordinates(ScreenPoint screen_coords, bool z_calculated=true);
00197
00201 ScreenPoint toScreenCoordinates(ExactModelCoordinate map_coords);
00202
00206 DoublePoint3D toVirtualScreenCoordinates(ExactModelCoordinate map_coords);
00207
00208 ScreenPoint virtualScreenToScreen(const DoublePoint3D& p);
00209 DoublePoint3D screenToVirtualScreen(const ScreenPoint& p);
00210
00213 void setEnabled(bool enabled);
00214
00217 bool isEnabled();
00218
00224 void getMatchingInstances(ScreenPoint screen_coords, Layer& layer, std::list<Instance*>& instances);
00225
00232 void getMatchingInstances(Rect screen_rect, Layer& layer, std::list<Instance*>& instances);
00233
00240 void getMatchingInstances(Location& loc, std::list<Instance*>& instances, bool use_exactcoordinates=false);
00241
00249 void update();
00250
00256 void refresh();
00257
00260 void resetUpdates();
00261
00264 void addRenderer(RendererBase* renderer);
00265
00268 RendererBase* getRenderer(const std::string& name);
00269
00272 void resetRenderers();
00273
00276 void calculateZValue(ScreenPoint& screen_coords);
00277
00278 void onRendererPipelinePositionChanged(RendererBase* renderer);
00279 void onRendererEnabledChanged(RendererBase* renderer);
00280
00284 bool testRenderedViewPort();
00285
00286 void setLightingColor(float red, float green, float blue, float alpha);
00287 void resetLightingColor();
00288 std::vector<float> getLightingColor();
00289
00292 void render();
00293
00294 private:
00295 friend class MapObserver;
00296 void addLayer(Layer* layer);
00297 void removeLayer(Layer* layer);
00298 void updateMap(Map* map);
00299 std::string m_id;
00300
00301
00308 void updateMatrices();
00309
00316 void updateReferenceScale();
00317
00320 DoublePoint getLogicalCellDimensions(Layer* layer);
00321
00322 DoubleMatrix m_matrix;
00323 DoubleMatrix m_inverse_matrix;
00324
00325 DoubleMatrix m_vs_matrix;
00326 DoubleMatrix m_vs_inverse_matrix;
00327 DoubleMatrix m_vscreen_2_screen;
00328 DoubleMatrix m_screen_2_vscreen;
00329
00330 double m_tilt;
00331 double m_rotation;
00332 double m_zoom;
00333 Location m_location;
00334 ScreenPoint m_prev_origo;
00335 ScreenPoint m_cur_origo;
00336 Rect m_viewport;
00337 bool m_view_updated;
00338 unsigned int m_screen_cell_width;
00339 unsigned int m_screen_cell_height;
00340 double m_reference_scale;
00341 bool m_enabled;
00342 Instance* m_attachedto;
00343 bool m_backendSDL;
00344
00345 std::map<Layer*, Point> m_image_dimensions;
00346 bool m_iswarped;
00347
00348
00349 std::map<std::string, RendererBase*> m_renderers;
00350 std::list<RendererBase*> m_pipeline;
00351 bool m_updated;
00352
00353 RenderBackend* m_renderbackend;
00354 ImagePool* m_ipool;
00355 AnimationPool* m_apool;
00356
00357
00358 t_layer_to_instances m_layer_to_instances;
00359
00360 std::map<Layer*,LayerCache*> m_cache;
00361 MapObserver* m_map_observer;
00362 Map* m_map;
00363
00364
00365 bool m_lighting;
00366
00367 std::vector<float> m_light_colors;
00368 };
00369 }
00370 #endif