forked from teamnwah/openmw-tes3coop
World::isUnderwater(), World::isSwimming()
This commit is contained in:
parent
f2a2e5f57d
commit
ff62770657
7 changed files with 52 additions and 24 deletions
|
@ -249,6 +249,9 @@ namespace MWBase
|
||||||
///< @return true if it is possible to place on object at specified cursor location
|
///< @return true if it is possible to place on object at specified cursor location
|
||||||
|
|
||||||
virtual void processChangedSettings (const Settings::CategorySettingVector& settings) = 0;
|
virtual void processChangedSettings (const Settings::CategorySettingVector& settings) = 0;
|
||||||
|
|
||||||
|
virtual bool isSwimming(const MWWorld::Ptr &object) = 0;
|
||||||
|
virtual bool isUnderwater(const ESM::Cell &cell, const Ogre::Vector3 &pos) = 0;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -275,11 +275,20 @@ void RenderingManager::update (float duration){
|
||||||
|
|
||||||
mLocalMap->updatePlayer( mRendering.getCamera()->getRealPosition(), mRendering.getCamera()->getRealOrientation() );
|
mLocalMap->updatePlayer( mRendering.getCamera()->getRealPosition(), mRendering.getCamera()->getRealOrientation() );
|
||||||
|
|
||||||
checkUnderwater();
|
if (mWater) {
|
||||||
|
Ogre::Vector3 cam = mRendering.getCamera()->getRealPosition();
|
||||||
|
|
||||||
if (mWater)
|
MWBase::World *world = MWBase::Environment::get().getWorld();
|
||||||
|
|
||||||
|
mWater->updateUnderwater(
|
||||||
|
world->isUnderwater(
|
||||||
|
*world->getPlayer().getPlayer().getCell()->cell,
|
||||||
|
Ogre::Vector3(cam.x, -cam.z, cam.y))
|
||||||
|
);
|
||||||
mWater->update(duration);
|
mWater->update(duration);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void RenderingManager::waterAdded (MWWorld::Ptr::CellStore *store){
|
void RenderingManager::waterAdded (MWWorld::Ptr::CellStore *store){
|
||||||
if(store->cell->data.flags & store->cell->HasWater
|
if(store->cell->data.flags & store->cell->HasWater
|
||||||
|| ((!(store->cell->data.flags & ESM::Cell::Interior))
|
|| ((!(store->cell->data.flags & ESM::Cell::Interior))
|
||||||
|
@ -459,13 +468,6 @@ void RenderingManager::toggleLight()
|
||||||
|
|
||||||
setAmbientMode();
|
setAmbientMode();
|
||||||
}
|
}
|
||||||
void RenderingManager::checkUnderwater()
|
|
||||||
{
|
|
||||||
if(mWater)
|
|
||||||
{
|
|
||||||
mWater->checkUnderwater( mRendering.getCamera()->getRealPosition().y );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void RenderingManager::playAnimationGroup (const MWWorld::Ptr& ptr, const std::string& groupName,
|
void RenderingManager::playAnimationGroup (const MWWorld::Ptr& ptr, const std::string& groupName,
|
||||||
int mode, int number)
|
int mode, int number)
|
||||||
|
|
|
@ -91,7 +91,6 @@ class RenderingManager: private RenderingInterface, public Ogre::WindowEventList
|
||||||
void scaleObject (const MWWorld::Ptr& ptr, const Ogre::Vector3& scale);
|
void scaleObject (const MWWorld::Ptr& ptr, const Ogre::Vector3& scale);
|
||||||
void rotateObject (const MWWorld::Ptr& ptr, const::Ogre::Quaternion& orientation);
|
void rotateObject (const MWWorld::Ptr& ptr, const::Ogre::Quaternion& orientation);
|
||||||
|
|
||||||
void checkUnderwater();
|
|
||||||
void setWaterHeight(const float height);
|
void setWaterHeight(const float height);
|
||||||
void toggleWater();
|
void toggleWater();
|
||||||
|
|
||||||
|
|
|
@ -184,22 +184,16 @@ void Water::toggle()
|
||||||
updateVisible();
|
updateVisible();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Water::checkUnderwater(float y)
|
void
|
||||||
|
Water::updateUnderwater(bool underwater)
|
||||||
{
|
{
|
||||||
if (!mActive)
|
if (!mActive) {
|
||||||
{
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
mIsUnderwater =
|
||||||
if ((mIsUnderwater && y > mTop) || !mWater->isVisible() || mCamera->getPolygonMode() != Ogre::PM_SOLID)
|
underwater &&
|
||||||
{
|
mWater->isVisible() &&
|
||||||
mIsUnderwater = false;
|
mCamera->getPolygonMode() == Ogre::PM_SOLID;
|
||||||
}
|
|
||||||
|
|
||||||
if (!mIsUnderwater && y < mTop && mWater->isVisible() && mCamera->getPolygonMode() == Ogre::PM_SOLID)
|
|
||||||
{
|
|
||||||
mIsUnderwater = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
updateVisible();
|
updateVisible();
|
||||||
}
|
}
|
||||||
|
|
|
@ -101,7 +101,8 @@ namespace MWRender {
|
||||||
|
|
||||||
void processChangedSettings(const Settings::CategorySettingVector& settings);
|
void processChangedSettings(const Settings::CategorySettingVector& settings);
|
||||||
|
|
||||||
void checkUnderwater(float y);
|
/// Updates underwater state accordingly
|
||||||
|
void updateUnderwater(bool underwater);
|
||||||
void changeCell(const ESM::Cell* cell);
|
void changeCell(const ESM::Cell* cell);
|
||||||
void setHeight(const float height);
|
void setHeight(const float height);
|
||||||
|
|
||||||
|
|
|
@ -18,6 +18,8 @@
|
||||||
#include "manualref.hpp"
|
#include "manualref.hpp"
|
||||||
#include "cellfunctors.hpp"
|
#include "cellfunctors.hpp"
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
using namespace Ogre;
|
using namespace Ogre;
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
|
@ -1095,4 +1097,28 @@ namespace MWWorld
|
||||||
{
|
{
|
||||||
mRendering->getTriangleBatchCount(triangles, batches);
|
mRendering->getTriangleBatchCount(triangles, batches);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
World::isSwimming(const MWWorld::Ptr &object)
|
||||||
|
{
|
||||||
|
/// \todo add check ifActor() - only actors can swim
|
||||||
|
float *fpos = object.getRefData().getPosition().pos;
|
||||||
|
Ogre::Vector3 pos(fpos[0], fpos[1], fpos[2]);
|
||||||
|
|
||||||
|
/// \fixme should rely on object height
|
||||||
|
pos.z += 30;
|
||||||
|
|
||||||
|
return isUnderwater(*object.getCell()->cell, pos);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
World::isUnderwater(const ESM::Cell &cell, const Ogre::Vector3 &pos)
|
||||||
|
{
|
||||||
|
if (cell.data.flags & ESM::Cell::HasWater == 0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
bool res = pos.z < cell.water;
|
||||||
|
std::cout << "World::isUnderwater(" << pos.z << "):" << res << std::endl;
|
||||||
|
return res;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -270,6 +270,9 @@ namespace MWWorld
|
||||||
///< @return true if it is possible to place on object at specified cursor location
|
///< @return true if it is possible to place on object at specified cursor location
|
||||||
|
|
||||||
virtual void processChangedSettings(const Settings::CategorySettingVector& settings);
|
virtual void processChangedSettings(const Settings::CategorySettingVector& settings);
|
||||||
|
|
||||||
|
virtual bool isSwimming(const MWWorld::Ptr &object);
|
||||||
|
virtual bool isUnderwater(const ESM::Cell &cell, const Ogre::Vector3 &pos);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue