restored toggleWater

actorid
scrawl 13 years ago
parent 95f87a8abf
commit a96ad7fb82

@ -11,7 +11,7 @@ namespace MWRender
Water::Water (Ogre::Camera *camera, SkyManager* sky, const ESM::Cell* cell) : Water::Water (Ogre::Camera *camera, SkyManager* sky, const ESM::Cell* cell) :
mCamera (camera), mViewport (camera->getViewport()), mSceneManager (camera->getSceneManager()), mCamera (camera), mViewport (camera->getViewport()), mSceneManager (camera->getSceneManager()),
mIsUnderwater(false), mVisibilityFlags(0), mIsUnderwater(false), mVisibilityFlags(0),
mReflectionTarget(0), mActive(1) mReflectionTarget(0), mActive(1), mToggled(1)
{ {
mSky = sky; mSky = sky;
@ -93,32 +93,32 @@ Water::Water (Ogre::Camera *camera, SkyManager* sky, const ESM::Cell* cell) :
// destroy if already exists // destroy if already exists
if (overlay = mgr.getByName("ReflectionDebugOverlay")) if (overlay = mgr.getByName("ReflectionDebugOverlay"))
mgr.destroy(overlay); mgr.destroy(overlay);
overlay = mgr.create("ReflectionDebugOverlay"); overlay = mgr.create("ReflectionDebugOverlay");
if (MaterialManager::getSingleton().resourceExists("Ogre/ReflectionDebugTexture")) if (MaterialManager::getSingleton().resourceExists("Ogre/ReflectionDebugTexture"))
MaterialManager::getSingleton().remove("Ogre/ReflectionDebugTexture"); MaterialManager::getSingleton().remove("Ogre/ReflectionDebugTexture");
MaterialPtr debugMat = MaterialManager::getSingleton().create( MaterialPtr debugMat = MaterialManager::getSingleton().create(
"Ogre/ReflectionDebugTexture", "Ogre/ReflectionDebugTexture",
ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME); ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
debugMat->getTechnique(0)->getPass(0)->setLightingEnabled(false); debugMat->getTechnique(0)->getPass(0)->setLightingEnabled(false);
TextureUnitState *t = debugMat->getTechnique(0)->getPass(0)->createTextureUnitState(tex->getName()); TextureUnitState *t = debugMat->getTechnique(0)->getPass(0)->createTextureUnitState(tex->getName());
t->setTextureAddressingMode(TextureUnitState::TAM_CLAMP); t->setTextureAddressingMode(TextureUnitState::TAM_CLAMP);
OverlayContainer* debugPanel; OverlayContainer* debugPanel;
// destroy container if exists // destroy container if exists
try try
{ {
if (debugPanel = if (debugPanel =
static_cast<OverlayContainer*>( static_cast<OverlayContainer*>(
mgr.getOverlayElement("Ogre/ReflectionDebugTexPanel" mgr.getOverlayElement("Ogre/ReflectionDebugTexPanel"
))) )))
mgr.destroyOverlayElement(debugPanel); mgr.destroyOverlayElement(debugPanel);
} }
catch (Ogre::Exception&) {} catch (Ogre::Exception&) {}
debugPanel = (OverlayContainer*) debugPanel = (OverlayContainer*)
(OverlayManager::getSingleton().createOverlayElement("Panel", "Ogre/ReflectionDebugTexPanel")); (OverlayManager::getSingleton().createOverlayElement("Panel", "Ogre/ReflectionDebugTexPanel"));
debugPanel->_setPosition(0, 0.55); debugPanel->_setPosition(0, 0.55);
@ -134,8 +134,7 @@ Water::Water (Ogre::Camera *camera, SkyManager* sky, const ESM::Cell* cell) :
void Water::setActive(bool active) void Water::setActive(bool active)
{ {
mActive = active; mActive = active;
if (mReflectionTarget) mReflectionTarget->setActive(active && !mIsUnderwater); updateVisible();
mWater->setVisible(active);
} }
Water::~Water() Water::~Water()
@ -167,8 +166,8 @@ void Water::setHeight(const float height)
void Water::toggle() void Water::toggle()
{ {
if (mActive) mToggled = !mToggled;
mWater->setVisible(!mWater->getVisible()); updateVisible();
} }
void Water::checkUnderwater(float y) void Water::checkUnderwater(float y)
@ -183,13 +182,10 @@ void Water::checkUnderwater(float y)
if (pass->hasFragmentProgram() && pass->getFragmentProgramParameters()->_findNamedConstantDefinition("isUnderwater", false)) if (pass->hasFragmentProgram() && pass->getFragmentProgramParameters()->_findNamedConstantDefinition("isUnderwater", false))
pass->getFragmentProgramParameters()->setNamedConstant("isUnderwater", Real(0)); pass->getFragmentProgramParameters()->setNamedConstant("isUnderwater", Real(0));
if (mReflectionTarget)
mReflectionTarget->setActive(mActive);
mWater->setRenderQueueGroup(RQG_Water); mWater->setRenderQueueGroup(RQG_Water);
mIsUnderwater = false; mIsUnderwater = false;
} }
if (!mIsUnderwater && y < mTop && mWater->isVisible() && mCamera->getPolygonMode() == Ogre::PM_SOLID) if (!mIsUnderwater && y < mTop && mWater->isVisible() && mCamera->getPolygonMode() == Ogre::PM_SOLID)
{ {
@ -201,13 +197,12 @@ void Water::checkUnderwater(float y)
if (pass->hasFragmentProgram() && pass->getFragmentProgramParameters()->_findNamedConstantDefinition("isUnderwater", false)) if (pass->hasFragmentProgram() && pass->getFragmentProgramParameters()->_findNamedConstantDefinition("isUnderwater", false))
pass->getFragmentProgramParameters()->setNamedConstant("isUnderwater", Real(1)); pass->getFragmentProgramParameters()->setNamedConstant("isUnderwater", Real(1));
if (mReflectionTarget)
mReflectionTarget->setActive(false);
mWater->setRenderQueueGroup(RQG_UnderWater); mWater->setRenderQueueGroup(RQG_UnderWater);
mIsUnderwater = true; mIsUnderwater = true;
} }
updateVisible();
} }
Vector3 Water::getSceneNodeCoordinates(int gridX, int gridY) Vector3 Water::getSceneNodeCoordinates(int gridX, int gridY)
@ -217,15 +212,14 @@ Vector3 Water::getSceneNodeCoordinates(int gridX, int gridY)
void Water::preRenderTargetUpdate(const RenderTargetEvent& evt) void Water::preRenderTargetUpdate(const RenderTargetEvent& evt)
{ {
mReflectionCamera->setOrientation(mCamera->getDerivedOrientation());
mReflectionCamera->setPosition(mCamera->getDerivedPosition());
mReflectionCamera->setNearClipDistance(mCamera->getNearClipDistance());
mReflectionCamera->setFarClipDistance(mCamera->getFarClipDistance());
mReflectionCamera->setAspectRatio(mCamera->getAspectRatio());
mReflectionCamera->setFOVy(mCamera->getFOVy());
if (evt.source == mReflectionTarget) if (evt.source == mReflectionTarget)
{ {
mWater->setVisible(false); mReflectionCamera->setOrientation(mCamera->getDerivedOrientation());
mReflectionCamera->setPosition(mCamera->getDerivedPosition());
mReflectionCamera->setNearClipDistance(mCamera->getNearClipDistance());
mReflectionCamera->setFarClipDistance(mCamera->getFarClipDistance());
mReflectionCamera->setAspectRatio(mCamera->getAspectRatio());
mReflectionCamera->setFOVy(mCamera->getFOVy());
// Some messy code to get the skybox to show up at all // Some messy code to get the skybox to show up at all
// The problem here is that it gets clipped by the water plane // The problem here is that it gets clipped by the water plane
@ -242,8 +236,6 @@ void Water::preRenderTargetUpdate(const RenderTargetEvent& evt)
void Water::postRenderTargetUpdate(const RenderTargetEvent& evt) void Water::postRenderTargetUpdate(const RenderTargetEvent& evt)
{ {
mWater->setVisible(true);
if (evt.source == mReflectionTarget) if (evt.source == mReflectionTarget)
{ {
mSky->resetSkyPosition(); mSky->resetSkyPosition();
@ -291,4 +283,11 @@ void Water::setViewportBackground(const ColourValue& bg)
mReflectionTarget->getViewport(0)->setBackgroundColour(bg); mReflectionTarget->getViewport(0)->setBackgroundColour(bg);
} }
void Water::updateVisible()
{
mWater->setVisible(mToggled && mActive);
if (mReflectionTarget)
mReflectionTarget->setActive(mToggled && mActive && !mIsUnderwater);
}
} // namespace } // namespace

@ -24,6 +24,7 @@ namespace MWRender {
bool mIsUnderwater; bool mIsUnderwater;
bool mActive; bool mActive;
bool mToggled;
int mTop; int mTop;
Ogre::Vector3 getSceneNodeCoordinates(int gridX, int gridY); Ogre::Vector3 getSceneNodeCoordinates(int gridX, int gridY);
@ -31,6 +32,7 @@ namespace MWRender {
protected: protected:
void preRenderTargetUpdate(const Ogre::RenderTargetEvent& evt); void preRenderTargetUpdate(const Ogre::RenderTargetEvent& evt);
void postRenderTargetUpdate(const Ogre::RenderTargetEvent& evt); void postRenderTargetUpdate(const Ogre::RenderTargetEvent& evt);
void updateVisible();
SkyManager* mSky; SkyManager* mSky;

Loading…
Cancel
Save