From f497813043cd62a96e2ac7c1180529ea6eba9c9b Mon Sep 17 00:00:00 2001 From: scrawl Date: Thu, 29 Mar 2012 15:49:24 +0200 Subject: [PATCH] formatting, added Water::setHeight --- apps/openmw/mwrender/renderingmanager.cpp | 6 + apps/openmw/mwrender/renderingmanager.hpp | 7 +- apps/openmw/mwrender/water.cpp | 152 +++++++++++----------- apps/openmw/mwrender/water.hpp | 2 +- apps/openmw/mwworld/world.cpp | 6 + apps/openmw/mwworld/world.hpp | 2 + 6 files changed, 91 insertions(+), 84 deletions(-) diff --git a/apps/openmw/mwrender/renderingmanager.cpp b/apps/openmw/mwrender/renderingmanager.cpp index 4e8118c02..4b197205a 100644 --- a/apps/openmw/mwrender/renderingmanager.cpp +++ b/apps/openmw/mwrender/renderingmanager.cpp @@ -171,6 +171,12 @@ void RenderingManager::waterAdded (MWWorld::Ptr::CellStore *store){ } +void RenderingManager::setWaterHeight(const float height) +{ + if (mWater) + mWater->setHeight(height); +} + void RenderingManager::skyEnable () { if(mSkyManager) diff --git a/apps/openmw/mwrender/renderingmanager.hpp b/apps/openmw/mwrender/renderingmanager.hpp index 880070717..8a6a7aed1 100644 --- a/apps/openmw/mwrender/renderingmanager.hpp +++ b/apps/openmw/mwrender/renderingmanager.hpp @@ -92,6 +92,7 @@ class RenderingManager: private RenderingInterface { void scaleObject (const MWWorld::Ptr& ptr, const Ogre::Vector3& scale); void rotateObject (const MWWorld::Ptr& ptr, const::Ogre::Quaternion& orientation); void checkUnderwater(); + void setWaterHeight(const float height); /// \param store Cell the object was in previously (\a ptr has already been updated to the new cell). void moveObjectToCell (const MWWorld::Ptr& ptr, const Ogre::Vector3& position, MWWorld::Ptr::CellStore *store); @@ -141,17 +142,13 @@ class RenderingManager: private RenderingInterface { SkyManager* mSkyManager; - Ogre::Camera* camera; - MWRender::Water *mWater; + MWRender::Water *mWater; - - OEngine::Render::OgreRenderer &mRendering; MWRender::Objects mObjects; MWRender::Actors mActors; - // 0 normal, 1 more bright, 2 max int mAmbientMode; diff --git a/apps/openmw/mwrender/water.cpp b/apps/openmw/mwrender/water.cpp index 307504157..c77a99006 100644 --- a/apps/openmw/mwrender/water.cpp +++ b/apps/openmw/mwrender/water.cpp @@ -1,92 +1,88 @@ #include "water.hpp" -namespace MWRender { - Water::Water (Ogre::Camera *camera, const ESM::Cell* cell) : mCamera (camera), mViewport (camera->getViewport()), mSceneManager (camera->getSceneManager()) { - try { - Ogre::CompositorManager::getSingleton().addCompositor(mViewport, "Water", -1); - Ogre::CompositorManager::getSingleton().setCompositorEnabled(mViewport, "Water", false); - } catch(...) { - } - mTop = cell->water; - - - mIsUnderwater = false; - //mCamera->addListener(this); - - mWaterPlane = Ogre::Plane(Ogre::Vector3::UNIT_Y, 0); - - Ogre::MeshManager::getSingleton().createPlane("water", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, mWaterPlane, CELL_SIZE*5, CELL_SIZE * 5, 10, 10, true, 1, 3,5, Ogre::Vector3::UNIT_Z); - - - mWater = mSceneManager->createEntity("water"); - - mWater->setMaterialName("Examples/Water0"); - - - - - mWaterNode = mSceneManager->getRootSceneNode()->createChildSceneNode(); - mWaterNode->setPosition(0, mTop, 0); - - - if(!(cell->data.flags & cell->Interior)) - { - mWaterNode->setPosition(getSceneNodeCoordinates(cell->data.gridX, cell->data.gridY)); - } - mWaterNode->attachObject(mWater); - - } - - - Water::~Water() { - Ogre::MeshManager::getSingleton().remove("water"); - - mWaterNode->detachObject(mWater); - mSceneManager->destroyEntity(mWater); - mSceneManager->destroySceneNode(mWaterNode); - - - Ogre::CompositorManager::getSingleton().removeCompositorChain(mViewport); - } - - void Water::changeCell(const ESM::Cell* cell){ - mTop = cell->water; - - - +namespace MWRender +{ + Water::Water (Ogre::Camera *camera, const ESM::Cell* cell) : mCamera (camera), mViewport (camera->getViewport()), mSceneManager (camera->getSceneManager()) + { + try + { + Ogre::CompositorManager::getSingleton().addCompositor(mViewport, "Water", -1); + Ogre::CompositorManager::getSingleton().setCompositorEnabled(mViewport, "Water", false); + } catch(...) {} + + mTop = cell->water; + + mIsUnderwater = false; + + mWaterPlane = Ogre::Plane(Ogre::Vector3::UNIT_Y, 0); + + Ogre::MeshManager::getSingleton().createPlane("water", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, mWaterPlane, CELL_SIZE*5, CELL_SIZE * 5, 10, 10, true, 1, 3,5, Ogre::Vector3::UNIT_Z); + + + mWater = mSceneManager->createEntity("water"); + + mWater->setMaterialName("Examples/Water0"); + + mWaterNode = mSceneManager->getRootSceneNode()->createChildSceneNode(); + mWaterNode->setPosition(0, mTop, 0); + if(!(cell->data.flags & cell->Interior)) + { mWaterNode->setPosition(getSceneNodeCoordinates(cell->data.gridX, cell->data.gridY)); - else - mWaterNode->setPosition(0, mTop, 0); - } + } + mWaterNode->attachObject(mWater); + } + + Water::~Water() + { + Ogre::MeshManager::getSingleton().remove("water"); + mWaterNode->detachObject(mWater); + mSceneManager->destroyEntity(mWater); + mSceneManager->destroySceneNode(mWaterNode); - void Water::checkUnderwater(float y) { + Ogre::CompositorManager::getSingleton().removeCompositorChain(mViewport); + } - if (mIsUnderwater && y > mTop) { - try { - Ogre::CompositorManager::getSingleton().setCompositorEnabled(mViewport, "Water", false); - } catch(...) { - } - mIsUnderwater = false; - } + void Water::changeCell(const ESM::Cell* cell) + { + mTop = cell->water; - if (!mIsUnderwater && y < mTop) { - try { - Ogre::CompositorManager::getSingleton().setCompositorEnabled(mViewport, "Water", true); - } catch(...) { - } - mIsUnderwater = true; + if(!(cell->data.flags & cell->Interior)) + mWaterNode->setPosition(getSceneNodeCoordinates(cell->data.gridX, cell->data.gridY)); + else + setHeight(mTop); + } + + void Water::setHeight(const float height) + { + mTop = height; + mWaterNode->setPosition(0, height, 0); } - } - - Ogre::Vector3 Water::getSceneNodeCoordinates(int gridX, int gridY){ - Ogre::Vector3 out = Ogre::Vector3(gridX * CELL_SIZE + (CELL_SIZE / 2), mTop, -gridY * CELL_SIZE - (CELL_SIZE / 2)); - - return out; - } + void Water::checkUnderwater(float y) + { + if (mIsUnderwater && y > mTop) + { + try { + Ogre::CompositorManager::getSingleton().setCompositorEnabled(mViewport, "Water", false); + } catch(...) {} + mIsUnderwater = false; + } + if (!mIsUnderwater && y < mTop) + { + try { + Ogre::CompositorManager::getSingleton().setCompositorEnabled(mViewport, "Water", true); + } catch(...) {} + mIsUnderwater = true; + } + } + + Ogre::Vector3 Water::getSceneNodeCoordinates(int gridX, int gridY) + { + return Ogre::Vector3(gridX * CELL_SIZE + (CELL_SIZE / 2), mTop, -gridY * CELL_SIZE - (CELL_SIZE / 2)); + } } diff --git a/apps/openmw/mwrender/water.hpp b/apps/openmw/mwrender/water.hpp index 48b0af984..fc644e265 100644 --- a/apps/openmw/mwrender/water.hpp +++ b/apps/openmw/mwrender/water.hpp @@ -35,7 +35,7 @@ namespace MWRender { void checkUnderwater(float y); void changeCell(const ESM::Cell* cell); - + void setHeight(const float height); }; } diff --git a/apps/openmw/mwworld/world.cpp b/apps/openmw/mwworld/world.cpp index 63d54ea92..c62e2e05d 100644 --- a/apps/openmw/mwworld/world.cpp +++ b/apps/openmw/mwworld/world.cpp @@ -755,4 +755,10 @@ namespace MWWorld { return mRendering->getFader(); } + + void World::setWaterHeight(const float height) + { + mRendering->setWaterHeight(height); + } + } diff --git a/apps/openmw/mwworld/world.hpp b/apps/openmw/mwworld/world.hpp index 71cca3545..5025fded4 100644 --- a/apps/openmw/mwworld/world.hpp +++ b/apps/openmw/mwworld/world.hpp @@ -112,6 +112,8 @@ namespace MWWorld Ptr::CellStore *getExterior (int x, int y); Ptr::CellStore *getInterior (const std::string& name); + + void setWaterHeight(const float height); void adjustSky();