OpenMW
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
water.hpp
Go to the documentation of this file.
1 #ifndef OPENMW_MWRENDER_WATER_H
2 #define OPENMW_MWRENDER_WATER_H
3 
4 #include <memory>
5 #include <vector>
6 
7 #include <osg/ref_ptr>
8 #include <osg/Vec3f>
9 #include <osg/Uniform>
10 #include <osg/Camera>
11 
13 
14 namespace osg
15 {
16  class Group;
17  class PositionAttitudeTransform;
18  class Geometry;
19  class Node;
20 }
21 
22 namespace osgUtil
23 {
24  class IncrementalCompileOperation;
25 }
26 
27 namespace Resource
28 {
29  class ResourceSystem;
30 }
31 
32 namespace MWWorld
33 {
34  class CellStore;
35  class Ptr;
36 }
37 
38 namespace Fallback
39 {
40  class Map;
41 }
42 
43 namespace MWRender
44 {
45 
46  class Refraction;
47  class Reflection;
48  class RippleSimulation;
49 
51  class Water
52  {
53  osg::ref_ptr<osg::Uniform> mRainIntensityUniform;
54 
55  osg::ref_ptr<osg::Group> mParent;
56  osg::ref_ptr<osg::Group> mSceneRoot;
57  osg::ref_ptr<osg::PositionAttitudeTransform> mWaterNode;
58  osg::ref_ptr<osg::Geometry> mWaterGeom;
61  osg::ref_ptr<osgUtil::IncrementalCompileOperation> mIncrementalCompileOperation;
62 
63  std::unique_ptr<RippleSimulation> mSimulation;
64 
65  osg::ref_ptr<Refraction> mRefraction;
66  osg::ref_ptr<Reflection> mReflection;
67 
68  const std::string mResourcePath;
69 
70  bool mEnabled;
71  bool mToggled;
72  float mTop;
73 
74  osg::Vec3f getSceneNodeCoordinates(int gridX, int gridY);
75  void updateVisible();
76 
77  void createSimpleWaterStateSet(osg::Node* node, float alpha);
78 
81  void createShaderWaterStateSet(osg::Node* node, Reflection* reflection, Refraction* refraction);
82 
83  void updateWaterMaterial();
84 
85  public:
86  Water(osg::Group* parent, osg::Group* sceneRoot,
87  Resource::ResourceSystem* resourceSystem, osgUtil::IncrementalCompileOperation* ico, const Fallback::Map* fallback,
88  const std::string& resourcePath);
89  ~Water();
90 
91  void listAssetsToPreload(std::vector<std::string>& textures);
92 
93  void setEnabled(bool enabled);
94 
95  bool toggle();
96 
97  bool isUnderwater(const osg::Vec3f& pos) const;
98 
100  void addEmitter (const MWWorld::Ptr& ptr, float scale = 1.f, float force = 1.f);
101  void removeEmitter (const MWWorld::Ptr& ptr);
102  void updateEmitterPtr (const MWWorld::Ptr& old, const MWWorld::Ptr& ptr);
103  void emitRipple(const osg::Vec3f& pos);
104 
105  void removeCell(const MWWorld::CellStore* store);
106 
107  void clearRipples();
108 
109  void changeCell(const MWWorld::CellStore* store);
110  void setHeight(const float height);
111 
112  void update(float dt);
113 
114  osg::Camera *getReflectionCamera();
115  osg::Camera *getRefractionCamera();
116 
118 
119  osg::Uniform *getRainIntensityUniform();
120  };
121 
122 }
123 
124 #endif
bool mEnabled
Definition: water.hpp:70
void update(float dt)
Definition: water.cpp:655
void setEnabled(bool enabled)
Definition: water.cpp:620
osg::ref_ptr< Refraction > mRefraction
Definition: water.hpp:65
~Water()
Definition: water.cpp:590
const Fallback::Map * mFallback
Definition: water.hpp:60
Wrapper class that constructs and provides access to the most commonly used resource subsystems...
Definition: resourcesystem.hpp:30
void setHeight(const float height)
Definition: water.cpp:639
bool mToggled
Definition: water.hpp:71
osg::ref_ptr< osg::Geometry > mWaterGeom
Definition: water.hpp:58
contains settings imported from the Morrowind INI file.
Definition: fallback.hpp:12
const std::string mResourcePath
Definition: water.hpp:68
Water rendering.
Definition: water.hpp:51
Resource::ResourceSystem * mResourceSystem
Definition: water.hpp:59
void processChangedSettings(const Settings::CategorySettingVector &settings)
Definition: water.cpp:585
void removeEmitter(const MWWorld::Ptr &ptr)
Definition: water.cpp:693
osg::ref_ptr< osg::Group > mSceneRoot
Definition: water.hpp:56
std::set< std::pair< std::string, std::string > > CategorySettingVector
Definition: settings.hpp:11
void updateWaterMaterial()
Definition: water.cpp:438
std::unique_ptr< RippleSimulation > mSimulation
Definition: water.hpp:63
Water(osg::Group *parent, osg::Group *sceneRoot, Resource::ResourceSystem *resourceSystem, osgUtil::IncrementalCompileOperation *ico, const Fallback::Map *fallback, const std::string &resourcePath)
Definition: water.cpp:393
bool isUnderwater(const osg::Vec3f &pos) const
Definition: water.cpp:677
void removeCell(const MWWorld::CellStore *store)
remove all emitters in this cell
Definition: water.cpp:708
Definition: water.cpp:304
void updateVisible()
Definition: water.cpp:660
void clearRipples()
Definition: water.cpp:713
void updateEmitterPtr(const MWWorld::Ptr &old, const MWWorld::Ptr &ptr)
Definition: water.cpp:698
osg::ref_ptr< Reflection > mReflection
Definition: water.hpp:66
osg::ref_ptr< osg::Group > mParent
Definition: water.hpp:55
Mutable state of a cell.
Definition: cellstore.hpp:51
void createSimpleWaterStateSet(osg::Node *node, float alpha)
Definition: water.cpp:486
void createShaderWaterStateSet(osg::Node *node, Reflection *reflection, Refraction *refraction)
Definition: water.cpp:526
void listAssetsToPreload(std::vector< std::string > &textures)
Definition: water.cpp:608
osg::ref_ptr< osgUtil::IncrementalCompileOperation > mIncrementalCompileOperation
Definition: water.hpp:61
void addEmitter(const MWWorld::Ptr &ptr, float scale=1.f, float force=1.f)
adds an emitter, position will be tracked automatically using its scene node
Definition: water.cpp:688
osg::ref_ptr< osg::PositionAttitudeTransform > mWaterNode
Definition: water.hpp:57
Definition: water.cpp:214
void changeCell(const MWWorld::CellStore *store)
Definition: water.cpp:626
float mTop
Definition: water.hpp:72
osg::ref_ptr< osg::Uniform > mRainIntensityUniform
Definition: water.hpp:53
Pointer to a LiveCellRef.
Definition: ptr.hpp:19
bool toggle()
Definition: water.cpp:670
osg::Camera * getReflectionCamera()
Definition: water.cpp:476
osg::Camera * getRefractionCamera()
Definition: water.cpp:481
osg::Uniform * getRainIntensityUniform()
Definition: water.cpp:433
void emitRipple(const osg::Vec3f &pos)
Definition: water.cpp:703
osg::Vec3f getSceneNodeCoordinates(int gridX, int gridY)
Definition: water.cpp:682