|
|
|
@ -8,7 +8,8 @@ namespace MWRender
|
|
|
|
|
|
|
|
|
|
Water::Water (Ogre::Camera *camera, const ESM::Cell* cell) :
|
|
|
|
|
mCamera (camera), mViewport (camera->getViewport()), mSceneManager (camera->getSceneManager()),
|
|
|
|
|
mIsUnderwater(false)
|
|
|
|
|
mIsUnderwater(false), mReflectDistance(0), mVisibilityFlags(0), mOldCameraFarClip(0),
|
|
|
|
|
mReflectionTarget(0), mRefractionTarget(0), mActive(1)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
@ -25,9 +26,16 @@ Water::Water (Ogre::Camera *camera, const ESM::Cell* cell) :
|
|
|
|
|
MeshManager::getSingleton().createPlane("water", ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, mWaterPlane, CELL_SIZE*5, CELL_SIZE * 5, 10, 10, true, 1, 3,5, Vector3::UNIT_Z);
|
|
|
|
|
|
|
|
|
|
mWater = mSceneManager->createEntity("water");
|
|
|
|
|
|
|
|
|
|
mWater->setVisibilityFlags(RV_Water);
|
|
|
|
|
mWater->setMaterialName("Examples/Water0");
|
|
|
|
|
|
|
|
|
|
mVisibilityFlags = RV_Terrain * Settings::Manager::getBool("reflect terrain", "Water")
|
|
|
|
|
+ RV_Statics * Settings::Manager::getBool("reflect statics", "Water")
|
|
|
|
|
+ RV_StaticsSmall * Settings::Manager::getBool("reflect small statics", "Water")
|
|
|
|
|
+ RV_Actors * Settings::Manager::getBool("reflect actors", "Water")
|
|
|
|
|
+ RV_Misc * Settings::Manager::getBool("reflect misc", "Water");
|
|
|
|
|
mReflectDistance = Settings::Manager::getInt("reflect distance", "Water");
|
|
|
|
|
|
|
|
|
|
mWaterNode = mSceneManager->getRootSceneNode()->createChildSceneNode();
|
|
|
|
|
mWaterNode->setPosition(0, mTop, 0);
|
|
|
|
|
|
|
|
|
@ -43,7 +51,7 @@ Water::Water (Ogre::Camera *camera, const ESM::Cell* cell) :
|
|
|
|
|
{
|
|
|
|
|
if (i==0 && !Settings::Manager::getBool("reflection", "Water")) continue;
|
|
|
|
|
if (i==1 && !Settings::Manager::getBool("refraction", "Water")) continue;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
TexturePtr tex = TextureManager::getSingleton().createManual(i == 0 ? "WaterReflection" : "WaterRefraction",
|
|
|
|
|
ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, TEX_TYPE_2D, rttsize, rttsize, 0, PF_R8G8B8, TU_RENDERTARGET);
|
|
|
|
|
|
|
|
|
@ -52,7 +60,7 @@ Water::Water (Ogre::Camera *camera, const ESM::Cell* cell) :
|
|
|
|
|
vp->setOverlaysEnabled(false);
|
|
|
|
|
vp->setBackgroundColour(ColourValue(0.8f, 0.9f, 1.0f));
|
|
|
|
|
vp->setShadowsEnabled(false);
|
|
|
|
|
//vp->setVisibilityMask( ... );
|
|
|
|
|
vp->setVisibilityMask( (i == 0) ? mVisibilityFlags : RV_All);
|
|
|
|
|
rtt->addListener(this);
|
|
|
|
|
rtt->setActive(true);
|
|
|
|
|
|
|
|
|
@ -61,6 +69,13 @@ Water::Water (Ogre::Camera *camera, const ESM::Cell* cell) :
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Water::setActive(bool active)
|
|
|
|
|
{
|
|
|
|
|
mActive = active;
|
|
|
|
|
if (mReflectionTarget) mReflectionTarget->setActive(active);
|
|
|
|
|
if (mRefractionTarget) mRefractionTarget->setActive(active);
|
|
|
|
|
mWater->setVisible(active);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Water::~Water()
|
|
|
|
|
{
|
|
|
|
@ -91,11 +106,13 @@ void Water::setHeight(const float height)
|
|
|
|
|
|
|
|
|
|
void Water::toggle()
|
|
|
|
|
{
|
|
|
|
|
mWater->setVisible(!mWater->getVisible());
|
|
|
|
|
if (mActive)
|
|
|
|
|
mWater->setVisible(!mWater->getVisible());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Water::checkUnderwater(float y)
|
|
|
|
|
{
|
|
|
|
|
if (!mActive) return;
|
|
|
|
|
if ((mIsUnderwater && y > mTop) || !mWater->isVisible() || mCamera->getPolygonMode() != Ogre::PM_SOLID)
|
|
|
|
|
{
|
|
|
|
|
try {
|
|
|
|
@ -122,6 +139,10 @@ void Water::preRenderTargetUpdate(const RenderTargetEvent& evt)
|
|
|
|
|
{
|
|
|
|
|
mWater->setVisible(false);
|
|
|
|
|
|
|
|
|
|
mOldCameraFarClip = mCamera->getFarClipDistance();
|
|
|
|
|
if (mReflectDistance != 0)
|
|
|
|
|
mCamera->setFarClipDistance(mReflectDistance);
|
|
|
|
|
|
|
|
|
|
if (evt.source == mReflectionTarget)
|
|
|
|
|
{
|
|
|
|
|
mCamera->enableCustomNearClipPlane(mWaterPlane);
|
|
|
|
@ -133,6 +154,8 @@ void Water::postRenderTargetUpdate(const RenderTargetEvent& evt)
|
|
|
|
|
{
|
|
|
|
|
mWater->setVisible(true);
|
|
|
|
|
|
|
|
|
|
mCamera->setFarClipDistance(mOldCameraFarClip);
|
|
|
|
|
|
|
|
|
|
if (evt.source == mReflectionTarget)
|
|
|
|
|
{
|
|
|
|
|
mCamera->disableReflection();
|
|
|
|
|