OpenMW
apps/openmw/mwrender/renderingmanager.hpp
Go to the documentation of this file.
00001 #ifndef _GAME_RENDERING_MANAGER_H
00002 #define _GAME_RENDERING_MANAGER_H
00003 
00004 #include "sky.hpp"
00005 #include "debugging.hpp"
00006 
00007 #include <openengine/ogre/fader.hpp>
00008 
00009 #include <components/settings/settings.hpp>
00010 
00011 #include <boost/filesystem.hpp>
00012 
00013 #include <OgreRenderTargetListener.h>
00014 
00015 #include "renderinginterface.hpp"
00016 
00017 #include "objects.hpp"
00018 #include "actors.hpp"
00019 #include "camera.hpp"
00020 #include "occlusionquery.hpp"
00021 
00022 namespace Ogre
00023 {
00024     class SceneManager;
00025     class SceneNode;
00026     class Quaternion;
00027     class Vector3;
00028 }
00029 
00030 namespace MWWorld
00031 {
00032     class Ptr;
00033     class CellStore;
00034 }
00035 
00036 namespace sh
00037 {
00038     class Factory;
00039 }
00040 
00041 namespace Terrain
00042 {
00043     class World;
00044 }
00045 
00046 namespace MWRender
00047 {
00048     class Shadows;
00049     class LocalMap;
00050     class Water;
00051     class ExternalRendering;
00052     class GlobalMap;
00053     class VideoPlayer;
00054     class Animation;
00055 
00056 class RenderingManager: private RenderingInterface, public Ogre::RenderTargetListener, public OEngine::Render::WindowSizeListener
00057 {
00058 private:
00059     virtual MWRender::Objects& getObjects();
00060     virtual MWRender::Actors& getActors();
00061 
00062 public:
00063     RenderingManager(OEngine::Render::OgreRenderer& _rend, const boost::filesystem::path& resDir,
00064                      const boost::filesystem::path& cacheDir, OEngine::Physic::PhysicEngine* engine,
00065                      MWWorld::Fallback* fallback);
00066     virtual ~RenderingManager();
00067 
00068     void togglePOV()
00069     { mCamera->toggleViewMode(); }
00070 
00071     void togglePreviewMode(bool enable)
00072     { mCamera->togglePreviewMode(enable); }
00073 
00074     bool toggleVanityMode(bool enable)
00075     { return mCamera->toggleVanityMode(enable); }
00076 
00077     void allowVanityMode(bool allow)
00078     { mCamera->allowVanityMode(allow); }
00079 
00080     void togglePlayerLooking(bool enable)
00081     { mCamera->togglePlayerLooking(enable); }
00082 
00083     void changeVanityModeScale(float factor)
00084     {
00085         if(mCamera->isVanityOrPreviewModeEnabled())
00086             mCamera->setCameraDistance(-factor/120.f*10, true, true);
00087     }
00088 
00089     void resetCamera();
00090 
00091     bool vanityRotateCamera(const float *rot);
00092     void setCameraDistance(float dist, bool adjust = false, bool override = true);
00093     float getCameraDistance() const;
00094 
00095     void setupPlayer(const MWWorld::Ptr &ptr);
00096     void renderPlayer(const MWWorld::Ptr &ptr);
00097 
00098     SkyManager* getSkyManager();
00099 
00100     void toggleLight();
00101     bool toggleRenderMode(int mode);
00102 
00103     OEngine::Render::Fader* getFader();
00104 
00105     void removeCell (MWWorld::CellStore *store);
00106 
00109     void cellAdded (MWWorld::CellStore *store);
00110     void waterAdded(MWWorld::CellStore *store);
00111 
00112     void enableTerrain(bool enable);
00113 
00114     void removeWater();
00115 
00116     void preCellChange (MWWorld::CellStore* store);
00118 
00119     void addObject (const MWWorld::Ptr& ptr);
00120     void removeObject (const MWWorld::Ptr& ptr);
00121 
00122     void moveObject (const MWWorld::Ptr& ptr, const Ogre::Vector3& position);
00123     void scaleObject (const MWWorld::Ptr& ptr, const Ogre::Vector3& scale);
00124 
00126     void rotateObject (const MWWorld::Ptr& ptr);
00127 
00128     void setWaterHeight(const float height);
00129     void toggleWater();
00130 
00134     void updateObjectCell(const MWWorld::Ptr &old, const MWWorld::Ptr &cur);
00135 
00137     void updatePlayerPtr(const MWWorld::Ptr &ptr);
00138 
00141     void rebuildPtr(const MWWorld::Ptr &ptr);
00142 
00143     void update (float duration, bool paused);
00144 
00145     void setAmbientColour(const Ogre::ColourValue& colour);
00146     void setSunColour(const Ogre::ColourValue& colour);
00147     void setSunDirection(const Ogre::Vector3& direction);
00148     void sunEnable(bool real); 
00149     void sunDisable(bool real);
00150 
00151     void disableLights(bool sun); 
00152     void enableLights(bool sun);
00153 
00154 
00155     void preRenderTargetUpdate(const Ogre::RenderTargetEvent& evt);
00156     void postRenderTargetUpdate(const Ogre::RenderTargetEvent& evt);
00157 
00158     bool occlusionQuerySupported() { return mOcclusionQuery->supported(); }
00159     OcclusionQuery* getOcclusionQuery() { return mOcclusionQuery; }
00160 
00161     float getTerrainHeightAt (Ogre::Vector3 worldPos);
00162 
00163     Shadows* getShadows();
00164 
00165     void switchToInterior();
00166     void switchToExterior();
00167 
00168     void getTriangleBatchCount(unsigned int &triangles, unsigned int &batches);
00169 
00170     void setGlare(bool glare);
00171     void skyEnable ();
00172     void skyDisable ();
00173     void skySetHour (double hour);
00174     void skySetDate (int day, int month);
00175     int skyGetMasserPhase() const;
00176     int skyGetSecundaPhase() const;
00177     void skySetMoonColour (bool red);
00178     void configureAmbient(MWWorld::CellStore &mCell);
00179 
00180     void addWaterRippleEmitter (const MWWorld::Ptr& ptr, float scale = 1.f, float force = 1.f);
00181     void removeWaterRippleEmitter (const MWWorld::Ptr& ptr);
00182     void updateWaterRippleEmitterPtr (const MWWorld::Ptr& old, const MWWorld::Ptr& ptr);
00183 
00184     void requestMap (MWWorld::CellStore* cell);
00186 
00188     void configureFog(MWWorld::CellStore &mCell);
00189 
00191     void configureFog(const float density, const Ogre::ColourValue& colour);
00192 
00193     Ogre::Vector4 boundingBoxToScreen(Ogre::AxisAlignedBox bounds);
00196 
00197     void processChangedSettings(const Settings::CategorySettingVector& settings);
00198 
00199     Ogre::Viewport* getViewport() { return mRendering.getViewport(); }
00200 
00201     void getInteriorMapPosition (Ogre::Vector2 position, float& nX, float& nY, int &x, int& y);
00203 
00204     bool isPositionExplored (float nX, float nY, int x, int y, bool interior);
00206 
00207     void setupExternalRendering (MWRender::ExternalRendering& rendering);
00208 
00209     Animation* getAnimation(const MWWorld::Ptr &ptr);
00210 
00211     void playVideo(const std::string& name, bool allowSkipping);
00212     void stopVideo();
00213     void frameStarted(float dt, bool paused);
00214 
00215 protected:
00216     virtual void windowResized(int x, int y);
00217 
00218 private:
00219     sh::Factory* mFactory;
00220 
00221     void setAmbientMode();
00222     void applyFog(bool underwater);
00223 
00224     void setMenuTransparency(float val);
00225 
00226     bool mSunEnabled;
00227 
00228     MWWorld::Fallback* mFallback;
00229 
00230     SkyManager* mSkyManager;
00231 
00232     OcclusionQuery* mOcclusionQuery;
00233 
00234     Terrain::World* mTerrain;
00235 
00236     MWRender::Water *mWater;
00237 
00238     GlobalMap* mGlobalMap;
00239 
00240     OEngine::Render::OgreRenderer &mRendering;
00241 
00242     MWRender::Objects* mObjects;
00243     MWRender::Actors* mActors;
00244 
00245     MWRender::NpcAnimation *mPlayerAnimation;
00246 
00247     // 0 normal, 1 more bright, 2 max
00248     int mAmbientMode;
00249 
00250     Ogre::ColourValue mAmbientColor;
00251     Ogre::Light* mSun;
00252 
00253     Ogre::SceneNode *mRootNode;
00254 
00255     Ogre::ColourValue mFogColour;
00256     float mFogStart;
00257     float mFogEnd;
00258 
00259     OEngine::Physic::PhysicEngine* mPhysicsEngine;
00260 
00261     MWRender::Camera *mCamera;
00262 
00263     MWRender::Debugging *mDebugging;
00264 
00265     MWRender::LocalMap* mLocalMap;
00266 
00267     MWRender::Shadows* mShadows;
00268 
00269     VideoPlayer* mVideoPlayer;
00270 };
00271 
00272 }
00273 
00274 #endif