mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-01-19 22:23:51 +00:00
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
|
||||
|
||||
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() );
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
void RenderingManager::waterAdded (MWWorld::Ptr::CellStore *store){
|
||||
if(store->cell->data.flags & store->cell->HasWater
|
||||
|| ((!(store->cell->data.flags & ESM::Cell::Interior))
|
||||
|
@ -459,13 +468,6 @@ void RenderingManager::toggleLight()
|
|||
|
||||
setAmbientMode();
|
||||
}
|
||||
void RenderingManager::checkUnderwater()
|
||||
{
|
||||
if(mWater)
|
||||
{
|
||||
mWater->checkUnderwater( mRendering.getCamera()->getRealPosition().y );
|
||||
}
|
||||
}
|
||||
|
||||
void RenderingManager::playAnimationGroup (const MWWorld::Ptr& ptr, const std::string& groupName,
|
||||
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 rotateObject (const MWWorld::Ptr& ptr, const::Ogre::Quaternion& orientation);
|
||||
|
||||
void checkUnderwater();
|
||||
void setWaterHeight(const float height);
|
||||
void toggleWater();
|
||||
|
||||
|
|
|
@ -184,22 +184,16 @@ void Water::toggle()
|
|||
updateVisible();
|
||||
}
|
||||
|
||||
void Water::checkUnderwater(float y)
|
||||
void
|
||||
Water::updateUnderwater(bool underwater)
|
||||
{
|
||||
if (!mActive)
|
||||
{
|
||||
if (!mActive) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ((mIsUnderwater && y > mTop) || !mWater->isVisible() || mCamera->getPolygonMode() != Ogre::PM_SOLID)
|
||||
{
|
||||
mIsUnderwater = false;
|
||||
}
|
||||
|
||||
if (!mIsUnderwater && y < mTop && mWater->isVisible() && mCamera->getPolygonMode() == Ogre::PM_SOLID)
|
||||
{
|
||||
mIsUnderwater = true;
|
||||
}
|
||||
mIsUnderwater =
|
||||
underwater &&
|
||||
mWater->isVisible() &&
|
||||
mCamera->getPolygonMode() == Ogre::PM_SOLID;
|
||||
|
||||
updateVisible();
|
||||
}
|
||||
|
|
|
@ -101,7 +101,8 @@ namespace MWRender {
|
|||
|
||||
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 setHeight(const float height);
|
||||
|
||||
|
|
|
@ -18,6 +18,8 @@
|
|||
#include "manualref.hpp"
|
||||
#include "cellfunctors.hpp"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
using namespace Ogre;
|
||||
|
||||
namespace
|
||||
|
@ -1095,4 +1097,28 @@ namespace MWWorld
|
|||
{
|
||||
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
|
||||
|
||||
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