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 
11 
12 namespace osg
13 {
14  class Group;
15  class PositionAttitudeTransform;
16  class Geometry;
17  class Node;
18 }
19 
20 namespace osgUtil
21 {
22  class IncrementalCompileOperation;
23 }
24 
25 namespace Resource
26 {
27  class ResourceSystem;
28 }
29 
30 namespace MWWorld
31 {
32  class CellStore;
33  class Ptr;
34 }
35 
36 namespace Fallback
37 {
38  class Map;
39 }
40 
41 namespace MWRender
42 {
43 
44  class Refraction;
45  class Reflection;
46  class RippleSimulation;
47 
49  class Water
50  {
51  static const int CELL_SIZE = 8192;
52 
53  osg::ref_ptr<osg::Group> mParent;
54  osg::ref_ptr<osg::Group> mSceneRoot;
55  osg::ref_ptr<osg::PositionAttitudeTransform> mWaterNode;
56  osg::ref_ptr<osg::Geometry> mWaterGeom;
59  osg::ref_ptr<osgUtil::IncrementalCompileOperation> mIncrementalCompileOperation;
60 
61  std::auto_ptr<RippleSimulation> mSimulation;
62 
63  osg::ref_ptr<Refraction> mRefraction;
64  osg::ref_ptr<Reflection> mReflection;
65 
66  const std::string mResourcePath;
67 
68  bool mEnabled;
69  bool mToggled;
70  float mTop;
71 
72  osg::Vec3f getSceneNodeCoordinates(int gridX, int gridY);
73  void updateVisible();
74 
75  void createSimpleWaterStateSet(osg::Node* node, float alpha);
76 
79  void createShaderWaterStateSet(osg::Node* node, Reflection* reflection, Refraction* refraction);
80 
81  void updateWaterMaterial();
82 
83  public:
84  Water(osg::Group* parent, osg::Group* sceneRoot,
85  Resource::ResourceSystem* resourceSystem, osgUtil::IncrementalCompileOperation* ico, const Fallback::Map* fallback,
86  const std::string& resourcePath);
87  ~Water();
88 
89  void listAssetsToPreload(std::vector<std::string>& textures);
90 
91  void setEnabled(bool enabled);
92 
93  bool toggle();
94 
95  bool isUnderwater(const osg::Vec3f& pos) const;
96 
98  void addEmitter (const MWWorld::Ptr& ptr, float scale = 1.f, float force = 1.f);
99  void removeEmitter (const MWWorld::Ptr& ptr);
100  void updateEmitterPtr (const MWWorld::Ptr& old, const MWWorld::Ptr& ptr);
101  void emitRipple(const osg::Vec3f& pos);
102 
103  void removeCell(const MWWorld::CellStore* store);
104 
105  void clearRipples();
106 
107  void changeCell(const MWWorld::CellStore* store);
108  void setHeight(const float height);
109 
110  void update(float dt);
111 
113  };
114 
115 }
116 
117 #endif
bool mEnabled
Definition: water.hpp:68
void update(float dt)
Definition: water.cpp:627
void setEnabled(bool enabled)
Definition: water.cpp:592
osg::ref_ptr< Refraction > mRefraction
Definition: water.hpp:63
~Water()
Definition: water.cpp:562
const Fallback::Map * mFallback
Definition: water.hpp:58
Wrapper class that constructs and provides access to the most commonly used resource subsystems...
Definition: resourcesystem.hpp:24
void setHeight(const float height)
Definition: water.cpp:611
bool mToggled
Definition: water.hpp:69
osg::ref_ptr< osg::Geometry > mWaterGeom
Definition: water.hpp:56
contains settings imported from the Morrowind INI file.
Definition: fallback.hpp:12
const std::string mResourcePath
Definition: water.hpp:66
Water rendering.
Definition: water.hpp:49
static const int CELL_SIZE
Definition: water.hpp:51
Resource::ResourceSystem * mResourceSystem
Definition: water.hpp:57
void processChangedSettings(const Settings::CategorySettingVector &settings)
Definition: water.cpp:557
void removeEmitter(const MWWorld::Ptr &ptr)
Definition: water.cpp:664
osg::ref_ptr< osg::Group > mSceneRoot
Definition: water.hpp:54
std::set< std::pair< std::string, std::string > > CategorySettingVector
Definition: settings.hpp:11
void updateWaterMaterial()
Definition: water.cpp:422
Water(osg::Group *parent, osg::Group *sceneRoot, Resource::ResourceSystem *resourceSystem, osgUtil::IncrementalCompileOperation *ico, const Fallback::Map *fallback, const std::string &resourcePath)
Definition: water.cpp:385
bool isUnderwater(const osg::Vec3f &pos) const
Definition: water.cpp:649
void removeCell(const MWWorld::CellStore *store)
remove all emitters in this cell
Definition: water.cpp:679
Definition: water.cpp:297
void updateVisible()
Definition: water.cpp:632
void clearRipples()
Definition: water.cpp:684
void updateEmitterPtr(const MWWorld::Ptr &old, const MWWorld::Ptr &ptr)
Definition: water.cpp:669
osg::ref_ptr< Reflection > mReflection
Definition: water.hpp:64
osg::ref_ptr< osg::Group > mParent
Definition: water.hpp:53
Mutable state of a cell.
Definition: cellstore.hpp:53
void createSimpleWaterStateSet(osg::Node *node, float alpha)
Definition: water.cpp:460
void createShaderWaterStateSet(osg::Node *node, Reflection *reflection, Refraction *refraction)
Definition: water.cpp:502
void listAssetsToPreload(std::vector< std::string > &textures)
Definition: water.cpp:580
osg::ref_ptr< osgUtil::IncrementalCompileOperation > mIncrementalCompileOperation
Definition: water.hpp:59
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:659
osg::ref_ptr< osg::PositionAttitudeTransform > mWaterNode
Definition: water.hpp:55
Definition: water.cpp:215
void changeCell(const MWWorld::CellStore *store)
Definition: water.cpp:598
float mTop
Definition: water.hpp:70
Pointer to a LiveCellRef.
Definition: ptr.hpp:19
bool toggle()
Definition: water.cpp:642
std::auto_ptr< RippleSimulation > mSimulation
Definition: water.hpp:61
void emitRipple(const osg::Vec3f &pos)
Definition: water.cpp:674
osg::Vec3f getSceneNodeCoordinates(int gridX, int gridY)
Definition: water.cpp:654