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

93 lines
2.5 KiB
C++
Raw Normal View History

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