OpenMW
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
renderingmanager.hpp
Go to the documentation of this file.
1 #ifndef OPENMW_MWRENDER_RENDERINGMANAGER_H
2 #define OPENMW_MWRENDER_RENDERINGMANAGER_H
3 
4 #include <osg/ref_ptr>
5 #include <osg/Light>
6 
8 
9 #include "objects.hpp"
10 
11 #include "renderinginterface.hpp"
12 #include "rendermode.hpp"
13 
14 namespace osg
15 {
16  class Group;
17  class PositionAttitudeTransform;
18 }
19 
20 namespace Resource
21 {
22  class ResourceSystem;
23 }
24 
25 namespace osgViewer
26 {
27  class Viewer;
28 }
29 
30 namespace ESM
31 {
32  struct Cell;
33 }
34 
35 namespace Terrain
36 {
37  class World;
38 }
39 
40 namespace Fallback
41 {
42  class Map;
43 }
44 
45 namespace SceneUtil
46 {
47  class WorkQueue;
48  class UnrefQueue;
49 }
50 
51 namespace MWRender
52 {
53 
54  class StateUpdater;
55 
56  class EffectManager;
57  class SkyManager;
58  class NpcAnimation;
59  class Pathgrid;
60  class Camera;
61  class Water;
62 
64  {
65  public:
66  RenderingManager(osgViewer::Viewer* viewer, osg::ref_ptr<osg::Group> rootNode, Resource::ResourceSystem* resourceSystem,
67  const Fallback::Map* fallback, const std::string& resourcePath);
69 
71 
73 
77 
78  void preloadCommonAssets();
79 
80  double getReferenceTime() const;
81 
82  osg::Group* getLightRoot();
83 
84  void setNightEyeFactor(float factor);
85 
86  void setAmbientColour(const osg::Vec4f& colour);
87 
88  void skySetDate(int day, int month);
89  int skyGetMasserPhase() const;
90  int skyGetSecundaPhase() const;
91  void skySetMoonColour(bool red);
92 
93  void setSunDirection(const osg::Vec3f& direction);
94  void setSunColour(const osg::Vec4f& diffuse, const osg::Vec4f& specular);
95 
96  void configureAmbient(const ESM::Cell* cell);
97  void configureFog(const ESM::Cell* cell);
98  void configureFog(float fogDepth, float underwaterFog, const osg::Vec4f& colour);
99 
100  void addCell(const MWWorld::CellStore* store);
101  void removeCell(const MWWorld::CellStore* store);
102 
103  void updatePtr(const MWWorld::Ptr& old, const MWWorld::Ptr& updated);
104 
105  void rotateObject(const MWWorld::Ptr& ptr, const osg::Quat& rot);
106  void moveObject(const MWWorld::Ptr& ptr, const osg::Vec3f& pos);
107  void scaleObject(const MWWorld::Ptr& ptr, const osg::Vec3f& scale);
108 
109  void removeObject(const MWWorld::Ptr& ptr);
110 
111  void setWaterEnabled(bool enabled);
112  void setWaterHeight(float level);
113 
115  void screenshot(osg::Image* image, int w, int h);
116 
117  struct RayResult
118  {
119  bool mHit;
120  osg::Vec3f mHitNormalWorld;
121  osg::Vec3f mHitPointWorld;
123  float mRatio;
124  };
125 
126  RayResult castRay(const osg::Vec3f& origin, const osg::Vec3f& dest, bool ignorePlayer, bool ignoreActors=false);
127 
130  RayResult castCameraToViewportRay(const float nX, const float nY, float maxDistance, bool ignorePlayer, bool ignoreActors=false);
131 
133  osg::Vec4f getScreenBounds(const MWWorld::Ptr& ptr);
134 
135  void setSkyEnabled(bool enabled);
136 
137  bool toggleRenderMode(RenderMode mode);
138 
140 
141  void spawnEffect(const std::string &model, const std::string &texture, const osg::Vec3f &worldPosition, float scale = 1.f, bool isMagicVFX = true);
142 
144  void clear();
145 
148 
149  void update(float dt, bool paused);
150 
151  Animation* getAnimation(const MWWorld::Ptr& ptr);
152  const Animation* getAnimation(const MWWorld::ConstPtr& ptr) const;
153 
154  void addWaterRippleEmitter(const MWWorld::Ptr& ptr);
155  void removeWaterRippleEmitter(const MWWorld::Ptr& ptr);
156  void emitWaterRipple(const osg::Vec3f& pos);
157 
158  void updatePlayerPtr(const MWWorld::Ptr &ptr);
159 
160  void removePlayer(const MWWorld::Ptr& player);
161  void setupPlayer(const MWWorld::Ptr& player);
162  void renderPlayer(const MWWorld::Ptr& player);
163 
164  void rebuildPtr(const MWWorld::Ptr& ptr);
165 
167 
168  float getNearClipDistance() const;
169 
170  float getTerrainHeightAt(const osg::Vec3f& pos);
171 
172  // camera stuff
173  bool vanityRotateCamera(const float *rot);
174  void setCameraDistance(float dist, bool adjust, bool override);
175  void resetCamera();
176  float getCameraDistance() const;
177  Camera* getCamera();
178  const osg::Vec3f& getCameraPosition() const;
179  void togglePOV();
180  void togglePreviewMode(bool enable);
181  bool toggleVanityMode(bool enable);
182  void allowVanityMode(bool allow);
183  void togglePlayerLooking(bool enable);
184  void changeVanityModeScale(float factor);
185 
187  void overrideFieldOfView(float val);
189  void resetFieldOfView();
190 
191  private:
192  void updateProjectionMatrix();
193  void updateTextureFiltering();
194  void updateAmbient();
195  void setFogColor(const osg::Vec4f& color);
196 
197  osg::ref_ptr<osgViewer::Viewer> mViewer;
198  osg::ref_ptr<osg::Group> mRootNode;
199  osg::ref_ptr<osg::Group> mSceneRoot;
201 
202  osg::ref_ptr<SceneUtil::WorkQueue> mWorkQueue;
203  osg::ref_ptr<SceneUtil::UnrefQueue> mUnrefQueue;
204 
205  osg::ref_ptr<osg::Light> mSunLight;
206 
207  std::auto_ptr<Pathgrid> mPathgrid;
208  std::auto_ptr<Objects> mObjects;
209  std::auto_ptr<Water> mWater;
210  std::auto_ptr<Terrain::World> mTerrain;
211  std::auto_ptr<SkyManager> mSky;
212  std::auto_ptr<EffectManager> mEffectManager;
213  std::auto_ptr<NpcAnimation> mPlayerAnimation;
214  osg::ref_ptr<SceneUtil::PositionAttitudeTransform> mPlayerNode;
215  std::auto_ptr<Camera> mCamera;
216  osg::Vec3f mCurrentCameraPos;
217 
218  osg::ref_ptr<StateUpdater> mStateUpdater;
219 
220  float mFogDepth;
221  osg::Vec4f mUnderwaterColor;
225  osg::Vec4f mFogColor;
226 
227  osg::Vec4f mAmbientColor;
229 
230  float mNearClip;
236 
237  void operator = (const RenderingManager&);
239  };
240 
241 }
242 
243 #endif
bool toggleRenderMode(RenderMode mode)
Definition: renderingmanager.cpp:397
const osg::Vec3f & getCameraPosition() const
Definition: renderingmanager.cpp:954
Wrapper class that constructs and provides access to the most commonly used resource subsystems...
Definition: resourcesystem.hpp:24
void removePlayer(const MWWorld::Ptr &player)
Definition: renderingmanager.cpp:500
float mViewDistance
Definition: renderingmanager.hpp:231
RayResult castCameraToViewportRay(const float nX, const float nY, float maxDistance, bool ignorePlayer, bool ignoreActors=false)
Definition: renderingmanager.cpp:721
RenderingManager(osgViewer::Viewer *viewer, osg::ref_ptr< osg::Group > rootNode, Resource::ResourceSystem *resourceSystem, const Fallback::Map *fallback, const std::string &resourcePath)
Definition: renderingmanager.cpp:154
float mUnderwaterFog
Definition: renderingmanager.hpp:223
osg::ref_ptr< SceneUtil::UnrefQueue > mUnrefQueue
Definition: renderingmanager.hpp:203
RayResult castRay(const osg::Vec3f &origin, const osg::Vec3f &dest, bool ignorePlayer, bool ignoreActors=false)
Definition: renderingmanager.cpp:710
osg::Vec4f mUnderwaterColor
Definition: renderingmanager.hpp:221
bool toggleVanityMode(bool enable)
Definition: renderingmanager.cpp:969
void renderPlayer(const MWWorld::Ptr &player)
Definition: renderingmanager.cpp:796
Definition: animation.hpp:77
The basic interface for a terrain world. How the terrain chunks are paged and displayed is up to the ...
Definition: world.hpp:32
Definition: renderingmanager.hpp:63
A work queue that users can push work items onto, to be completed by one or more background threads...
Definition: workqueue.hpp:45
void emitWaterRipple(const osg::Vec3f &pos)
Definition: renderingmanager.cpp:833
osg::Vec3f mHitNormalWorld
Definition: renderingmanager.hpp:120
float mNearClip
Definition: renderingmanager.hpp:230
void scaleObject(const MWWorld::Ptr &ptr, const osg::Vec3f &scale)
Definition: renderingmanager.cpp:521
float getNearClipDistance() const
Definition: renderingmanager.cpp:904
float mFieldOfView
Definition: renderingmanager.hpp:234
void togglePlayerLooking(bool enable)
Definition: renderingmanager.cpp:979
contains settings imported from the Morrowind INI file.
Definition: fallback.hpp:12
float getCameraDistance() const
Definition: renderingmanager.cpp:944
std::auto_ptr< NpcAnimation > mPlayerAnimation
Definition: renderingmanager.hpp:213
Animation * getAnimation(const MWWorld::Ptr &ptr)
Definition: renderingmanager.cpp:763
osg::ref_ptr< osg::Light > mSunLight
Definition: renderingmanager.hpp:205
Definition: renderinginterface.hpp:9
osg::Vec3f mCurrentCameraPos
Definition: renderingmanager.hpp:216
osg::ref_ptr< osg::Group > mSceneRoot
Definition: renderingmanager.hpp:199
void screenshot(osg::Image *image, int w, int h)
Take a screenshot of w*h onto the given image, not including the GUI.
Definition: renderingmanager.cpp:577
int skyGetSecundaPhase() const
Definition: renderingmanager.cpp:336
float mFogDepth
Definition: renderingmanager.hpp:220
float getTerrainHeightAt(const osg::Vec3f &pos)
Definition: renderingmanager.cpp:909
~RenderingManager()
Definition: renderingmanager.cpp:259
The SkyManager handles rendering of the sky domes, celestial bodies as well as other objects that nee...
Definition: sky.hpp:107
void skySetMoonColour(bool red)
Definition: renderingmanager.cpp:341
void resetCamera()
Definition: renderingmanager.cpp:939
void moveObject(const MWWorld::Ptr &ptr, const osg::Vec3f &pos)
Definition: renderingmanager.cpp:516
void updatePtr(const MWWorld::Ptr &old, const MWWorld::Ptr &updated)
Definition: renderingmanager.cpp:740
void configureFog(const ESM::Cell *cell)
Definition: renderingmanager.cpp:434
void clear()
Clear all savegame-specific data.
Definition: renderingmanager.cpp:756
void setFogColor(const osg::Vec4f &color)
Definition: renderingmanager.cpp:873
Definition: renderingmanager.hpp:117
std::set< std::pair< std::string, std::string > > CategorySettingVector
Definition: settings.hpp:11
void changeVanityModeScale(float factor)
Definition: renderingmanager.cpp:984
float mFirstPersonFieldOfView
Definition: renderingmanager.hpp:235
void removeWaterRippleEmitter(const MWWorld::Ptr &ptr)
Definition: renderingmanager.cpp:828
void updateProjectionMatrix()
Definition: renderingmanager.cpp:838
std::auto_ptr< Water > mWater
Definition: renderingmanager.hpp:209
osg::Vec4f mFogColor
Definition: renderingmanager.hpp:225
osg::ref_ptr< SceneUtil::PositionAttitudeTransform > mPlayerNode
Definition: renderingmanager.hpp:214
void setSunColour(const osg::Vec4f &diffuse, const osg::Vec4f &specular)
Definition: renderingmanager.cpp:356
void addWaterRippleEmitter(const MWWorld::Ptr &ptr)
Definition: renderingmanager.cpp:823
void rebuildPtr(const MWWorld::Ptr &ptr)
Definition: renderingmanager.cpp:805
float mUnderwaterWeight
Definition: renderingmanager.hpp:222
void preloadCommonAssets()
Definition: renderingmanager.cpp:290
std::auto_ptr< Camera > mCamera
Definition: renderingmanager.hpp:215
bool mHit
Definition: renderingmanager.hpp:119
float mFieldOfViewOverride
Definition: renderingmanager.hpp:232
void operator=(const RenderingManager &)
void removeObject(const MWWorld::Ptr &ptr)
Definition: renderingmanager.cpp:529
osg::Group * getLightRoot()
Definition: renderingmanager.cpp:306
void skySetDate(int day, int month)
Definition: renderingmanager.cpp:326
float mRatio
Definition: renderingmanager.hpp:123
void togglePOV()
Definition: renderingmanager.cpp:959
osg::ref_ptr< SceneUtil::WorkQueue > mWorkQueue
Definition: renderingmanager.hpp:202
void removeCell(const MWWorld::CellStore *store)
Definition: renderingmanager.cpp:381
Mutable state of a cell.
Definition: cellstore.hpp:53
void resetFieldOfView()
reset a previous overrideFieldOfView() call, i.e. revert to field of view specified in the settings f...
Definition: renderingmanager.cpp:1000
void setWaterHeight(float level)
Definition: renderingmanager.cpp:541
void setSunDirection(const osg::Vec3f &direction)
Definition: renderingmanager.cpp:363
void addCell(const MWWorld::CellStore *store)
Definition: renderingmanager.cpp:372
float mUnderwaterIndoorFog
Definition: renderingmanager.hpp:224
MWRender::Objects & getObjects()
Definition: renderingmanager.cpp:265
void configureAmbient(const ESM::Cell *cell)
Definition: renderingmanager.cpp:346
std::auto_ptr< SkyManager > mSky
Definition: renderingmanager.hpp:211
std::auto_ptr< Objects > mObjects
Definition: renderingmanager.hpp:208
Pointer to a const LiveCellRef.
Definition: ptr.hpp:90
SkyManager * getSkyManager()
Definition: renderingmanager.cpp:448
osg::Vec3f mHitPointWorld
Definition: renderingmanager.hpp:121
Definition: loadcell.hpp:64
SceneUtil::WorkQueue * getWorkQueue()
Definition: renderingmanager.cpp:275
void setupPlayer(const MWWorld::Ptr &player)
Definition: renderingmanager.cpp:779
osg::ref_ptr< StateUpdater > mStateUpdater
Definition: renderingmanager.hpp:218
osg::ref_ptr< osg::Group > mRootNode
Definition: renderingmanager.hpp:198
void processChangedSettings(const Settings::CategorySettingVector &settings)
Definition: renderingmanager.cpp:880
void setNightEyeFactor(float factor)
Definition: renderingmanager.cpp:311
void spawnEffect(const std::string &model, const std::string &texture, const osg::Vec3f &worldPosition, float scale=1.f, bool isMagicVFX=true)
Definition: renderingmanager.cpp:745
double getReferenceTime() const
Definition: renderingmanager.cpp:301
Camera control.
Definition: camera.hpp:24
Resource::ResourceSystem * getResourceSystem()
Definition: renderingmanager.cpp:270
void notifyWorldSpaceChanged()
Clear all worldspace-specific data.
Definition: renderingmanager.cpp:750
osg::ref_ptr< osgViewer::Viewer > mViewer
Definition: renderingmanager.hpp:197
void rotateObject(const MWWorld::Ptr &ptr, const osg::Quat &rot)
Definition: renderingmanager.cpp:505
bool mFieldOfViewOverridden
Definition: renderingmanager.hpp:233
std::auto_ptr< Pathgrid > mPathgrid
Definition: renderingmanager.hpp:207
MWWorld::Ptr mHitObject
Definition: renderingmanager.hpp:122
bool vanityRotateCamera(const float *rot)
Definition: renderingmanager.cpp:914
Camera * getCamera()
Definition: renderingmanager.cpp:949
void allowVanityMode(bool allow)
Definition: renderingmanager.cpp:974
void updateTextureFiltering()
Definition: renderingmanager.cpp:847
osg::Vec4f mAmbientColor
Definition: renderingmanager.hpp:227
Handles unreferencing of objects through the WorkQueue. Typical use scenario would be the main thread...
Definition: unrefqueue.hpp:19
osg::Vec4f getScreenBounds(const MWWorld::Ptr &ptr)
Get the bounding box of the given object in screen coordinates as (minX, minY, maxX, maxY), with (0,0) being the top left corner.
Definition: renderingmanager.cpp:626
float mNightEyeFactor
Definition: renderingmanager.hpp:228
void setSkyEnabled(bool enabled)
Definition: renderingmanager.cpp:392
Pointer to a LiveCellRef.
Definition: ptr.hpp:19
void update(float dt, bool paused)
Definition: renderingmanager.cpp:453
std::auto_ptr< Terrain::World > mTerrain
Definition: renderingmanager.hpp:210
std::auto_ptr< EffectManager > mEffectManager
Definition: renderingmanager.hpp:212
void enable(CodeContainer &code, Literals &literals, const std::string &id)
Definition: generator.cpp:870
Terrain::World * getTerrain()
Definition: renderingmanager.cpp:285
void setAmbientColour(const osg::Vec4f &colour)
Definition: renderingmanager.cpp:320
Resource::ResourceSystem * mResourceSystem
Definition: renderingmanager.hpp:200
void setCameraDistance(float dist, bool adjust, bool override)
Definition: renderingmanager.cpp:923
void updateAmbient()
Definition: renderingmanager.cpp:863
RenderMode
Definition: rendermode.hpp:7
void updatePlayerPtr(const MWWorld::Ptr &ptr)
Definition: renderingmanager.cpp:492
SceneUtil::UnrefQueue * getUnrefQueue()
Definition: renderingmanager.cpp:280
void overrideFieldOfView(float val)
temporarily override the field of view with given value.
Definition: renderingmanager.cpp:990
void togglePreviewMode(bool enable)
Definition: renderingmanager.cpp:964
Definition: objects.hpp:64
int skyGetMasserPhase() const
Definition: renderingmanager.cpp:331
void setWaterEnabled(bool enabled)
Definition: renderingmanager.cpp:535