1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-01-16 16:49:55 +00:00
openmw-tes3mp/apps/openmw/mwrender/water.cpp

96 lines
2.6 KiB
C++
Raw Normal View History

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