OpenMW
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
localmap.hpp
Go to the documentation of this file.
1 #ifndef GAME_RENDER_LOCALMAP_H
2 #define GAME_RENDER_LOCALMAP_H
3 
4 #include <set>
5 #include <vector>
6 #include <map>
7 
8 #include <osg/BoundingBox>
9 #include <osg/Quat>
10 #include <osg/ref_ptr>
11 
12 namespace MWWorld
13 {
14  class CellStore;
15 }
16 
17 namespace ESM
18 {
19  struct FogTexture;
20 }
21 
22 namespace osg
23 {
24  class Texture2D;
25  class Image;
26  class Camera;
27  class Group;
28  class Node;
29 }
30 
31 namespace MWRender
32 {
36  class LocalMap
37  {
38  public:
39  LocalMap(osg::Group* root);
40  ~LocalMap();
41 
45  void clear();
46 
50  void requestMap (std::set<const MWWorld::CellStore*> cells);
51 
55  void removeCell (MWWorld::CellStore* cell);
56 
57  osg::ref_ptr<osg::Texture2D> getMapTexture (int x, int y);
58 
59  osg::ref_ptr<osg::Texture2D> getFogOfWarTexture (int x, int y);
60 
61  void removeCamera(osg::Camera* cam);
62 
66  void markForRemoval(osg::Camera* cam);
67 
73  void cleanupCameras();
74 
80  void updatePlayer (const osg::Vec3f& position, const osg::Quat& orientation,
81  float& u, float& v, int& x, int& y, osg::Vec3f& direction);
82 
87  void saveFogOfWar(MWWorld::CellStore* cell);
88 
92  void worldToInteriorMapPosition (osg::Vec2f pos, float& nX, float& nY, int& x, int& y);
93 
94  osg::Vec2f interiorMapToWorldPosition (float nX, float nY, int x, int y);
95 
99  bool isPositionExplored (float nX, float nY, int x, int y);
100 
101  osg::Group* getRoot();
102 
103  private:
104  osg::ref_ptr<osg::Group> mRoot;
105  osg::ref_ptr<osg::Node> mSceneRoot;
106 
107  typedef std::vector< osg::ref_ptr<osg::Camera> > CameraVector;
108 
110 
112 
113  struct MapSegment
114  {
115  MapSegment();
116  ~MapSegment();
117 
118  void initFogOfWar();
119  void loadFogOfWar(const ESM::FogTexture& fog);
120  void saveFogOfWar(ESM::FogTexture& fog) const;
121  void createFogOfWarTexture();
122 
123  osg::ref_ptr<osg::Texture2D> mMapTexture;
124  osg::ref_ptr<osg::Texture2D> mFogOfWarTexture;
125  osg::ref_ptr<osg::Image> mFogOfWarImage;
126 
128  };
129 
130  typedef std::map<std::pair<int, int>, MapSegment> SegmentMap;
132 
134 
135  // the dynamic texture is a bottleneck, so don't set this too high
136  static const int sFogOfWarResolution = 32;
137 
138  // size of a map segment (for exteriors, 1 cell)
140 
142 
143  float mAngle;
144  const osg::Vec2f rotatePoint(const osg::Vec2f& point, const osg::Vec2f& center, const float angle);
145 
146  void requestExteriorMap(const MWWorld::CellStore* cell);
147  void requestInteriorMap(const MWWorld::CellStore* cell);
148 
149  osg::ref_ptr<osg::Camera> createOrthographicCamera(float left, float top, float width, float height, const osg::Vec3d& upVector, float zmin, float zmax);
150  void setupRenderToTexture(osg::ref_ptr<osg::Camera> camera, int x, int y);
151 
152  bool mInterior;
153  osg::BoundingBox mBounds;
154  };
155 
156 }
157 #endif
osg::BoundingBox mBounds
Definition: localmap.hpp:153
void worldToInteriorMapPosition(osg::Vec2f pos, float &nX, float &nY, int &x, int &y)
Definition: localmap.cpp:464
osg::ref_ptr< osg::Image > mFogOfWarImage
Definition: localmap.hpp:125
bool isPositionExplored(float nX, float nY, int x, int y)
Definition: localmap.cpp:487
int mCellDistance
Definition: localmap.hpp:141
bool mInterior
Definition: localmap.hpp:152
osg::Group * getRoot()
Definition: localmap.cpp:504
SegmentMap mSegments
Definition: localmap.hpp:131
void createFogOfWarTexture()
Definition: localmap.cpp:600
CameraVector mCamerasPendingRemoval
Definition: localmap.hpp:111
void initFogOfWar()
Definition: localmap.cpp:614
void loadFogOfWar(const ESM::FogTexture &fog)
Definition: localmap.cpp:630
CameraVector mActiveCameras
Definition: localmap.hpp:109
void removeCell(MWWorld::CellStore *cell)
Definition: localmap.cpp:246
void saveFogOfWar(MWWorld::CellStore *cell)
Definition: localmap.cpp:104
std::vector< osg::ref_ptr< osg::Camera > > CameraVector
Definition: localmap.hpp:107
osg::ref_ptr< osg::Texture2D > getMapTexture(int x, int y)
Definition: localmap.cpp:256
std::map< std::pair< int, int >, MapSegment > SegmentMap
Definition: localmap.hpp:130
void removeCamera(osg::Camera *cam)
Definition: localmap.cpp:274
static const int sFogOfWarResolution
Definition: localmap.hpp:136
void setupRenderToTexture(osg::ref_ptr< osg::Camera > camera, int x, int y)
Definition: localmap.cpp:214
bool mHasFogState
Definition: localmap.hpp:127
void clear()
Definition: localmap.cpp:99
Definition: fogstate.hpp:11
void requestInteriorMap(const MWWorld::CellStore *cell)
Definition: localmap.cpp:328
osg::ref_ptr< osg::Texture2D > getFogOfWarTexture(int x, int y)
Definition: localmap.cpp:265
osg::ref_ptr< osg::Texture2D > mFogOfWarTexture
Definition: localmap.hpp:124
Local map rendering.
Definition: localmap.hpp:36
osg::ref_ptr< osg::Camera > createOrthographicCamera(float left, float top, float width, float height, const osg::Vec3d &upVector, float zmin, float zmax)
Definition: localmap.cpp:160
Mutable state of a cell.
Definition: cellstore.hpp:53
osg::ref_ptr< osg::Group > mRoot
Definition: localmap.hpp:104
osg::ref_ptr< osg::Texture2D > mMapTexture
Definition: localmap.hpp:123
LocalMap(osg::Group *root)
Definition: localmap.cpp:70
void markForRemoval(osg::Camera *cam)
Definition: localmap.cpp:280
Definition: localmap.hpp:113
int mMapResolution
Definition: localmap.hpp:133
void saveFogOfWar(ESM::FogTexture &fog) const
Definition: localmap.cpp:666
osg::ref_ptr< osg::Node > mSceneRoot
Definition: localmap.hpp:105
void cleanupCameras()
Definition: localmap.cpp:292
void requestMap(std::set< const MWWorld::CellStore * > cells)
Definition: localmap.cpp:234
~LocalMap()
Definition: localmap.cpp:85
const osg::Vec2f rotatePoint(const osg::Vec2f &point, const osg::Vec2f &center, const float angle)
Definition: localmap.cpp:93
osg::Vec2f interiorMapToWorldPosition(float nX, float nY, int x, int y)
Definition: localmap.cpp:477
float mAngle
Definition: localmap.hpp:143
MapSegment()
Definition: localmap.cpp:590
~MapSegment()
Definition: localmap.cpp:595
void updatePlayer(const osg::Vec3f &position, const osg::Quat &orientation, float &u, float &v, int &x, int &y, osg::Vec3f &direction)
Definition: localmap.cpp:509
void requestExteriorMap(const MWWorld::CellStore *cell)
Definition: localmap.cpp:303
float mMapWorldSize
Definition: localmap.hpp:139