1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-01-26 09:35:28 +00:00

96 lines
2.6 KiB
C++
Raw Normal View History

2012-01-14 18:34:14 -05:00
#include "water.hpp"
2012-03-29 15:49:24 +02:00
namespace MWRender
{
Water::Water (Ogre::Camera *camera, const ESM::Cell* cell) :
mCamera (camera), mViewport (camera->getViewport()), mSceneManager (camera->getSceneManager()),
mIsUnderwater(false)
{
try
{
Ogre::CompositorManager::getSingleton().addCompositor(mViewport, "Water", -1);
Ogre::CompositorManager::getSingleton().setCompositorEnabled(mViewport, "Water", false);
} catch(...) {}
2012-03-29 15:49:24 +02:00
mTop = cell->water;
2012-03-29 15:49:24 +02:00
mIsUnderwater = false;
2012-03-29 15:49:24 +02:00
mWaterPlane = Ogre::Plane(Ogre::Vector3::UNIT_Y, 0);
2012-03-29 15:49:24 +02:00
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);
2012-03-29 15:49:24 +02:00
mWater = mSceneManager->createEntity("water");
2012-03-29 15:49:24 +02:00
mWater->setMaterialName("Examples/Water0");
2012-03-29 15:49:24 +02:00
mWaterNode = mSceneManager->getRootSceneNode()->createChildSceneNode();
mWaterNode->setPosition(0, mTop, 0);
2012-03-29 15:49:24 +02:00
if(!(cell->data.flags & cell->Interior))
{
mWaterNode->setPosition(getSceneNodeCoordinates(cell->data.gridX, cell->data.gridY));
2012-03-29 15:49:24 +02:00
}
mWaterNode->attachObject(mWater);
}
2012-03-29 15:49:24 +02:00
2012-01-22 16:38:10 -05:00
Water::~Water()
{
Ogre::MeshManager::getSingleton().remove("water");
2012-01-14 18:34:14 -05:00
mWaterNode->detachObject(mWater);
mSceneManager->destroyEntity(mWater);
mSceneManager->destroySceneNode(mWaterNode);
2012-01-14 18:34:14 -05:00
Ogre::CompositorManager::getSingleton().removeCompositorChain(mViewport);
}
2012-01-20 17:59:56 -05:00
void Water::changeCell(const ESM::Cell* cell)
{
mTop = cell->water;
2012-01-14 18:34:14 -05:00
if(!(cell->data.flags & cell->Interior))
mWaterNode->setPosition(getSceneNodeCoordinates(cell->data.gridX, cell->data.gridY));
else
setHeight(mTop);
}
2012-03-29 15:49:24 +02:00
void Water::setHeight(const float height)
{
mTop = height;
mWaterNode->setPosition(0, height, 0);
}
2012-01-14 18:34:14 -05:00
void Water::toggle()
{
mWater->setVisible(!mWater->getVisible());
}
2012-01-14 18:34:14 -05:00
void Water::checkUnderwater(float y)
{
2012-04-02 14:32:21 +02:00
if ((mIsUnderwater && y > mTop) || !mWater->isVisible() || mCamera->getPolygonMode() != Ogre::PM_SOLID)
2012-03-29 15:49:24 +02:00
{
try {
Ogre::CompositorManager::getSingleton().setCompositorEnabled(mViewport, "Water", false);
} catch(...) {}
mIsUnderwater = false;
}
2012-03-29 15:49:24 +02:00
2012-04-02 14:32:21 +02:00
if (!mIsUnderwater && y < mTop && mWater->isVisible() && mCamera->getPolygonMode() == Ogre::PM_SOLID)
2012-03-29 15:49:24 +02:00
{
try {
Ogre::CompositorManager::getSingleton().setCompositorEnabled(mViewport, "Water", true);
} catch(...) {}
mIsUnderwater = true;
2012-03-29 15:49:24 +02:00
}
2012-01-14 18:34:14 -05:00
}
Ogre::Vector3 Water::getSceneNodeCoordinates(int gridX, int gridY)
{
return Ogre::Vector3(gridX * CELL_SIZE + (CELL_SIZE / 2), mTop, -gridY * CELL_SIZE - (CELL_SIZE / 2));
}
} // namespace