|
|
@ -1,74 +1,82 @@
|
|
|
|
#include "localmap.hpp"
|
|
|
|
#include "localmap.hpp"
|
|
|
|
|
|
|
|
|
|
|
|
#include <OgreMaterialManager.h>
|
|
|
|
#include <iostream>
|
|
|
|
#include <OgreHardwarePixelBuffer.h>
|
|
|
|
|
|
|
|
#include <OgreSceneManager.h>
|
|
|
|
#include <osg/LightModel>
|
|
|
|
#include <OgreSceneNode.h>
|
|
|
|
#include <osg/Texture2D>
|
|
|
|
#include <OgreCamera.h>
|
|
|
|
#include <osg/ComputeBoundsVisitor>
|
|
|
|
#include <OgreTextureManager.h>
|
|
|
|
|
|
|
|
#include <OgreRenderTexture.h>
|
|
|
|
#include <osgViewer/Viewer>
|
|
|
|
#include <OgreViewport.h>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include <components/esm/fogstate.hpp>
|
|
|
|
#include <components/esm/fogstate.hpp>
|
|
|
|
#include <components/settings/settings.hpp>
|
|
|
|
#include <components/settings/settings.hpp>
|
|
|
|
|
|
|
|
#include <components/sceneutil/visitor.hpp>
|
|
|
|
|
|
|
|
|
|
|
|
#include "../mwbase/environment.hpp"
|
|
|
|
#include "../mwbase/environment.hpp"
|
|
|
|
#include "../mwbase/world.hpp"
|
|
|
|
#include "../mwbase/world.hpp"
|
|
|
|
#include "../mwbase/windowmanager.hpp"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include "../mwworld/esmstore.hpp"
|
|
|
|
|
|
|
|
#include "../mwworld/cellstore.hpp"
|
|
|
|
#include "../mwworld/cellstore.hpp"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include "vismask.hpp"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class CameraUpdateCallback : public osg::NodeCallback
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
CameraUpdateCallback(osg::Camera* cam, MWRender::LocalMap* parent)
|
|
|
|
|
|
|
|
: mCamera(cam), mParent(parent)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
virtual void operator()(osg::Node*, osg::NodeVisitor*)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
mParent->markForRemoval(mCamera);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Note, we intentionally do not traverse children here. The map camera's scene data is the same as the master camera's,
|
|
|
|
|
|
|
|
// so it has been updated already.
|
|
|
|
|
|
|
|
//traverse(node, nv);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
osg::ref_ptr<osg::Camera> mCamera;
|
|
|
|
|
|
|
|
MWRender::LocalMap* mParent;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
using namespace MWRender;
|
|
|
|
namespace MWRender
|
|
|
|
using namespace Ogre;
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
LocalMap::LocalMap()
|
|
|
|
LocalMap::LocalMap(osgViewer::Viewer* viewer)
|
|
|
|
: mMapResolution(Settings::Manager::getInt("local map resolution", "Map"))
|
|
|
|
: mViewer(viewer)
|
|
|
|
|
|
|
|
, mMapResolution(Settings::Manager::getInt("local map resolution", "Map"))
|
|
|
|
|
|
|
|
, mMapWorldSize(8192.f)
|
|
|
|
, mAngle(0.f)
|
|
|
|
, mAngle(0.f)
|
|
|
|
, mInterior(false)
|
|
|
|
, mInterior(false)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
// mCellCamera = mRendering->getScene()->createCamera("CellCamera");
|
|
|
|
mRoot = mViewer->getSceneData()->asGroup();
|
|
|
|
mCellCamera->setProjectionType(PT_ORTHOGRAPHIC);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mCameraNode->attachObject(mCellCamera);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mLight->setType (Ogre::Light::LT_DIRECTIONAL);
|
|
|
|
|
|
|
|
mLight->setDirection (Ogre::Vector3(0.3f, 0.3f, -0.7f));
|
|
|
|
|
|
|
|
mLight->setVisible (false);
|
|
|
|
|
|
|
|
mLight->setDiffuseColour (ColourValue(0.7f,0.7f,0.7f));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mRenderTexture = TextureManager::getSingleton().createManual(
|
|
|
|
|
|
|
|
"localmap/rtt",
|
|
|
|
|
|
|
|
ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
|
|
|
|
|
|
|
|
TEX_TYPE_2D,
|
|
|
|
|
|
|
|
mMapResolution, mMapResolution,
|
|
|
|
|
|
|
|
0,
|
|
|
|
|
|
|
|
PF_R8G8B8,
|
|
|
|
|
|
|
|
TU_RENDERTARGET);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mRenderTarget = mRenderTexture->getBuffer()->getRenderTarget();
|
|
|
|
|
|
|
|
mRenderTarget->setAutoUpdated(false);
|
|
|
|
|
|
|
|
Viewport* vp = mRenderTarget->addViewport(mCellCamera);
|
|
|
|
|
|
|
|
vp->setOverlaysEnabled(false);
|
|
|
|
|
|
|
|
vp->setShadowsEnabled(false);
|
|
|
|
|
|
|
|
vp->setBackgroundColour(ColourValue(0, 0, 0));
|
|
|
|
|
|
|
|
vp->setMaterialScheme("local_map");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
LocalMap::~LocalMap()
|
|
|
|
SceneUtil::FindByNameVisitor find("Scene Root");
|
|
|
|
{
|
|
|
|
mRoot->accept(find);
|
|
|
|
|
|
|
|
mSceneRoot = find.mFoundNode;
|
|
|
|
|
|
|
|
if (!mSceneRoot)
|
|
|
|
|
|
|
|
throw std::runtime_error("no scene root found");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const Ogre::Vector2 LocalMap::rotatePoint(const Ogre::Vector2& p, const Ogre::Vector2& c, const float angle)
|
|
|
|
LocalMap::~LocalMap()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return Vector2( Math::Cos(angle) * (p.x - c.x) - Math::Sin(angle) * (p.y - c.y) + c.x,
|
|
|
|
for (CameraVector::iterator it = mActiveCameras.begin(); it != mActiveCameras.end(); ++it)
|
|
|
|
Math::Sin(angle) * (p.x - c.x) + Math::Cos(angle) * (p.y - c.y) + c.y);
|
|
|
|
mRoot->removeChild(*it);
|
|
|
|
|
|
|
|
for (CameraVector::iterator it = mCamerasPendingRemoval.begin(); it != mCamerasPendingRemoval.end(); ++it)
|
|
|
|
|
|
|
|
mRoot->removeChild(*it);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
std::string LocalMap::coordStr(const int x, const int y)
|
|
|
|
const osg::Vec2f LocalMap::rotatePoint(const osg::Vec2f& p, const osg::Vec2f& c, const float angle)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return StringConverter::toString(x) + "_" + StringConverter::toString(y);
|
|
|
|
return osg::Vec2f( std::cos(angle) * (p.x() - c.x()) - std::sin(angle) * (p.y() - c.y()) + c.x(),
|
|
|
|
|
|
|
|
std::sin(angle) * (p.x() - c.x()) + std::cos(angle) * (p.y() - c.y()) + c.y());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void LocalMap::clear()
|
|
|
|
void LocalMap::clear()
|
|
|
@ -103,8 +111,8 @@ void LocalMap::saveFogOfWar(MWWorld::CellStore* cell)
|
|
|
|
Vector2 min(mBounds.getMinimum().x, mBounds.getMinimum().y);
|
|
|
|
Vector2 min(mBounds.getMinimum().x, mBounds.getMinimum().y);
|
|
|
|
Vector2 max(mBounds.getMaximum().x, mBounds.getMaximum().y);
|
|
|
|
Vector2 max(mBounds.getMaximum().x, mBounds.getMaximum().y);
|
|
|
|
Vector2 length = max-min;
|
|
|
|
Vector2 length = max-min;
|
|
|
|
const int segsX = static_cast<int>(std::ceil(length.x / sSize));
|
|
|
|
const int segsX = static_cast<int>(std::ceil(length.x / mMapWorldSize));
|
|
|
|
const int segsY = static_cast<int>(std::ceil(length.y / sSize));
|
|
|
|
const int segsY = static_cast<int>(std::ceil(length.y / mMapWorldSize));
|
|
|
|
|
|
|
|
|
|
|
|
mInteriorName = cell->getCell()->mName;
|
|
|
|
mInteriorName = cell->getCell()->mName;
|
|
|
|
|
|
|
|
|
|
|
@ -148,24 +156,145 @@ void LocalMap::saveFogOfWar(MWWorld::CellStore* cell)
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void LocalMap::requestMap(MWWorld::CellStore* cell, float zMin, float zMax)
|
|
|
|
osg::ref_ptr<osg::Camera> LocalMap::createOrthographicCamera(float x, float y, float width, float height, const osg::Vec3d& upVector, float zmin, float zmax)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
mInterior = false;
|
|
|
|
osg::ref_ptr<osg::Camera> camera (new osg::Camera);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
camera->setProjectionMatrixAsOrtho(-width/2, width/2, -height/2, height/2, 5, (zmax-zmin) + 10);
|
|
|
|
|
|
|
|
camera->setComputeNearFarMode(osg::Camera::DO_NOT_COMPUTE_NEAR_FAR);
|
|
|
|
|
|
|
|
camera->setViewMatrixAsLookAt(osg::Vec3d(x, y, zmax + 5), osg::Vec3d(x, y, zmin), upVector);
|
|
|
|
|
|
|
|
camera->setReferenceFrame(osg::Camera::ABSOLUTE_RF);
|
|
|
|
|
|
|
|
camera->setRenderTargetImplementation(osg::Camera::FRAME_BUFFER_OBJECT, osg::Camera::PIXEL_BUFFER_RTT);
|
|
|
|
|
|
|
|
camera->setClearColor(osg::Vec4(0.f, 0.f, 0.f, 1.f));
|
|
|
|
|
|
|
|
camera->setClearMask(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
|
|
|
|
|
|
|
camera->setRenderOrder(osg::Camera::PRE_RENDER);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
camera->setCullMask(MWRender::Mask_Scene);
|
|
|
|
|
|
|
|
camera->setNodeMask(Mask_RenderToTexture);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
osg::ref_ptr<osg::StateSet> stateset = new osg::StateSet;
|
|
|
|
|
|
|
|
stateset->setMode(GL_LIGHTING, osg::StateAttribute::ON);
|
|
|
|
|
|
|
|
stateset->setMode(GL_NORMALIZE, osg::StateAttribute::ON);
|
|
|
|
|
|
|
|
stateset->setMode(GL_CULL_FACE, osg::StateAttribute::ON);
|
|
|
|
|
|
|
|
stateset->setMode(GL_FOG, osg::StateAttribute::OFF|osg::StateAttribute::OVERRIDE);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
osg::ref_ptr<osg::LightModel> lightmodel = new osg::LightModel;
|
|
|
|
|
|
|
|
lightmodel->setAmbientIntensity(osg::Vec4(0.3f, 0.3f, 0.3f, 1.f));
|
|
|
|
|
|
|
|
stateset->setAttributeAndModes(lightmodel, osg::StateAttribute::ON|osg::StateAttribute::OVERRIDE);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
osg::ref_ptr<osg::Light> light = new osg::Light;
|
|
|
|
|
|
|
|
light->setPosition(osg::Vec4(-0.3f, -0.3f, 0.7f, 0.f));
|
|
|
|
|
|
|
|
light->setDiffuse(osg::Vec4(0.7f, 0.7f, 0.7f, 1.f));
|
|
|
|
|
|
|
|
light->setAmbient(osg::Vec4(0,0,0,1));
|
|
|
|
|
|
|
|
light->setSpecular(osg::Vec4(0,0,0,0));
|
|
|
|
|
|
|
|
light->setLightNum(0);
|
|
|
|
|
|
|
|
light->setConstantAttenuation(1.f);
|
|
|
|
|
|
|
|
light->setLinearAttenuation(0.f);
|
|
|
|
|
|
|
|
light->setQuadraticAttenuation(0.f);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
osg::ref_ptr<osg::LightSource> lightSource = new osg::LightSource;
|
|
|
|
|
|
|
|
lightSource->setLight(light);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
lightSource->setStateSetModes(*stateset, osg::StateAttribute::ON|osg::StateAttribute::OVERRIDE);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
camera->addChild(lightSource);
|
|
|
|
|
|
|
|
camera->setStateSet(stateset);
|
|
|
|
|
|
|
|
camera->setGraphicsContext(mViewer->getCamera()->getGraphicsContext());
|
|
|
|
|
|
|
|
camera->setViewport(0, 0, mMapResolution, mMapResolution);
|
|
|
|
|
|
|
|
camera->setUpdateCallback(new CameraUpdateCallback(camera, this));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return camera;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
mCameraRotNode->setOrientation(Quaternion::IDENTITY);
|
|
|
|
void LocalMap::setupRenderToTexture(osg::ref_ptr<osg::Camera> camera, int x, int y)
|
|
|
|
mCellCamera->setOrientation(Quaternion(Ogre::Math::Cos(Ogre::Degree(0)/2.f), 0, 0, -Ogre::Math::Sin(Ogre::Degree(0)/2.f)));
|
|
|
|
{
|
|
|
|
|
|
|
|
osg::ref_ptr<osg::Texture2D> texture (new osg::Texture2D);
|
|
|
|
|
|
|
|
texture->setTextureSize(mMapResolution, mMapResolution);
|
|
|
|
|
|
|
|
texture->setInternalFormat(GL_RGB);
|
|
|
|
|
|
|
|
texture->setFilter(osg::Texture::MIN_FILTER, osg::Texture::LINEAR);
|
|
|
|
|
|
|
|
texture->setFilter(osg::Texture::MAG_FILTER, osg::Texture::LINEAR);
|
|
|
|
|
|
|
|
texture->setWrap(osg::Texture::WRAP_S, osg::Texture::CLAMP_TO_EDGE);
|
|
|
|
|
|
|
|
texture->setWrap(osg::Texture::WRAP_T, osg::Texture::CLAMP_TO_EDGE);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
camera->attach(osg::Camera::COLOR_BUFFER, texture);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
camera->addChild(mSceneRoot);
|
|
|
|
|
|
|
|
mRoot->addChild(camera);
|
|
|
|
|
|
|
|
mActiveCameras.push_back(camera);
|
|
|
|
|
|
|
|
mTextures[std::make_pair(x, y)] = texture;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void LocalMap::requestMap(std::set<MWWorld::CellStore*> cells)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
for (std::set<MWWorld::CellStore*>::iterator it = cells.begin(); it != cells.end(); ++it)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
MWWorld::CellStore* cell = *it;
|
|
|
|
|
|
|
|
if (cell->isExterior())
|
|
|
|
|
|
|
|
requestExteriorMap(cell);
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
requestInteriorMap(cell);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void LocalMap::removeCell(MWWorld::CellStore *cell)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if (cell->isExterior())
|
|
|
|
|
|
|
|
mTextures.erase(std::make_pair(cell->getCell()->getGridX(), cell->getCell()->getGridY()));
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
mTextures.clear();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
osg::ref_ptr<osg::Texture2D> LocalMap::getMapTexture(bool interior, int x, int y)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
TextureMap::iterator found = mTextures.find(std::make_pair(x, y));
|
|
|
|
|
|
|
|
if (found == mTextures.end())
|
|
|
|
|
|
|
|
return osg::ref_ptr<osg::Texture2D>();
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
return found->second;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void LocalMap::markForRemoval(osg::Camera *cam)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
CameraVector::iterator found = std::find(mActiveCameras.begin(), mActiveCameras.end(), cam);
|
|
|
|
|
|
|
|
if (found == mActiveCameras.end())
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
std::cerr << "trying to remove an inactive camera" << std::endl;
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
mActiveCameras.erase(found);
|
|
|
|
|
|
|
|
mCamerasPendingRemoval.push_back(cam);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void LocalMap::cleanupCameras()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if (mCamerasPendingRemoval.empty())
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (CameraVector::iterator it = mCamerasPendingRemoval.begin(); it != mCamerasPendingRemoval.end(); ++it)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
(*it)->removeChildren(0, (*it)->getNumChildren());
|
|
|
|
|
|
|
|
(*it)->setGraphicsContext(NULL);
|
|
|
|
|
|
|
|
mRoot->removeChild(*it);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mCamerasPendingRemoval.clear();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void LocalMap::requestExteriorMap(MWWorld::CellStore* cell)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
mInterior = false;
|
|
|
|
|
|
|
|
|
|
|
|
int x = cell->getCell()->getGridX();
|
|
|
|
int x = cell->getCell()->getGridX();
|
|
|
|
int y = cell->getCell()->getGridY();
|
|
|
|
int y = cell->getCell()->getGridY();
|
|
|
|
|
|
|
|
|
|
|
|
std::string name = "Cell_"+coordStr(x, y);
|
|
|
|
osg::BoundingSphere bound = mViewer->getSceneData()->getBound();
|
|
|
|
|
|
|
|
float zmin = bound.center().z() - bound.radius();
|
|
|
|
|
|
|
|
float zmax = bound.center().z() + bound.radius();
|
|
|
|
|
|
|
|
|
|
|
|
mCameraPosNode->setPosition(Vector3(0,0,0));
|
|
|
|
osg::ref_ptr<osg::Camera> camera = createOrthographicCamera(x*mMapWorldSize + mMapWorldSize/2.f, y*mMapWorldSize + mMapWorldSize/2.f, mMapWorldSize, mMapWorldSize,
|
|
|
|
|
|
|
|
osg::Vec3d(0,1,0), zmin, zmax);
|
|
|
|
// Note: using force=true for exterior cell maps.
|
|
|
|
setupRenderToTexture(camera, cell->getCell()->getGridX(), cell->getCell()->getGridY());
|
|
|
|
// They must be updated even if they were visited before, because the set of surrounding active cells might be different
|
|
|
|
|
|
|
|
// (and objects in a different cell can "bleed" into another cell's map if they cross the border)
|
|
|
|
|
|
|
|
render((x+0.5f)*sSize, (y+0.5f)*sSize, zMin, zMax, static_cast<float>(sSize), static_cast<float>(sSize), name, true);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
/*
|
|
|
|
if (mBuffers.find(name) == mBuffers.end())
|
|
|
|
if (mBuffers.find(name) == mBuffers.end())
|
|
|
@ -178,12 +307,17 @@ void LocalMap::requestMap(MWWorld::CellStore* cell, float zMin, float zMax)
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void LocalMap::requestMap(MWWorld::CellStore* cell,
|
|
|
|
void LocalMap::requestInteriorMap(MWWorld::CellStore* cell)
|
|
|
|
AxisAlignedBox bounds)
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
osg::ComputeBoundsVisitor computeBoundsVisitor;
|
|
|
|
|
|
|
|
computeBoundsVisitor.setTraversalMask(Mask_Scene);
|
|
|
|
|
|
|
|
mSceneRoot->accept(computeBoundsVisitor);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
osg::BoundingBox bounds = computeBoundsVisitor.getBoundingBox();
|
|
|
|
|
|
|
|
|
|
|
|
// If we're in an empty cell, bail out
|
|
|
|
// If we're in an empty cell, bail out
|
|
|
|
// The operations in this function are only valid for finite bounds
|
|
|
|
// The operations in this function are only valid for finite bounds
|
|
|
|
if (bounds.isNull ())
|
|
|
|
if (!bounds.valid() || bounds.radius2() == 0.0)
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
mInterior = true;
|
|
|
|
mInterior = true;
|
|
|
@ -191,41 +325,31 @@ void LocalMap::requestMap(MWWorld::CellStore* cell,
|
|
|
|
mBounds = bounds;
|
|
|
|
mBounds = bounds;
|
|
|
|
|
|
|
|
|
|
|
|
// Get the cell's NorthMarker rotation. This is used to rotate the entire map.
|
|
|
|
// Get the cell's NorthMarker rotation. This is used to rotate the entire map.
|
|
|
|
const Vector2& north = MWBase::Environment::get().getWorld()->getNorthVector(cell);
|
|
|
|
osg::Vec2f north = MWBase::Environment::get().getWorld()->getNorthVector(cell);
|
|
|
|
Radian angle = Ogre::Math::ATan2 (north.x, north.y);
|
|
|
|
|
|
|
|
mAngle = angle.valueRadians();
|
|
|
|
mAngle = std::atan2(north.x(), north.y());
|
|
|
|
|
|
|
|
|
|
|
|
// Rotate the cell and merge the rotated corners to the bounding box
|
|
|
|
// Rotate the cell and merge the rotated corners to the bounding box
|
|
|
|
Vector2 _center(bounds.getCenter().x, bounds.getCenter().y);
|
|
|
|
osg::Vec2f _center(bounds.center().x(), bounds.center().y());
|
|
|
|
Vector3 _c1 = bounds.getCorner(AxisAlignedBox::FAR_LEFT_BOTTOM);
|
|
|
|
for (int i=0; i<8; ++i)
|
|
|
|
Vector3 _c2 = bounds.getCorner(AxisAlignedBox::FAR_RIGHT_BOTTOM);
|
|
|
|
{
|
|
|
|
Vector3 _c3 = bounds.getCorner(AxisAlignedBox::FAR_LEFT_TOP);
|
|
|
|
osg::Vec3f corner = mBounds.corner(i);
|
|
|
|
Vector3 _c4 = bounds.getCorner(AxisAlignedBox::FAR_RIGHT_TOP);
|
|
|
|
osg::Vec2f corner2d (corner.x(), corner.y());
|
|
|
|
|
|
|
|
corner2d = rotatePoint(corner2d, _center, mAngle);
|
|
|
|
Vector2 c1(_c1.x, _c1.y);
|
|
|
|
mBounds.expandBy(osg::Vec3f(corner2d.x(), corner2d.y(), 0));
|
|
|
|
Vector2 c2(_c2.x, _c2.y);
|
|
|
|
}
|
|
|
|
Vector2 c3(_c3.x, _c3.y);
|
|
|
|
|
|
|
|
Vector2 c4(_c4.x, _c4.y);
|
|
|
|
|
|
|
|
c1 = rotatePoint(c1, _center, mAngle);
|
|
|
|
|
|
|
|
c2 = rotatePoint(c2, _center, mAngle);
|
|
|
|
|
|
|
|
c3 = rotatePoint(c3, _center, mAngle);
|
|
|
|
|
|
|
|
c4 = rotatePoint(c4, _center, mAngle);
|
|
|
|
|
|
|
|
mBounds.merge(Vector3(c1.x, c1.y, 0));
|
|
|
|
|
|
|
|
mBounds.merge(Vector3(c2.x, c2.y, 0));
|
|
|
|
|
|
|
|
mBounds.merge(Vector3(c3.x, c3.y, 0));
|
|
|
|
|
|
|
|
mBounds.merge(Vector3(c4.x, c4.y, 0));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Do NOT change padding! This will break older savegames.
|
|
|
|
// Do NOT change padding! This will break older savegames.
|
|
|
|
// If the padding really needs to be changed, then it must be saved in the ESM::FogState and
|
|
|
|
// If the padding really needs to be changed, then it must be saved in the ESM::FogState and
|
|
|
|
// assume the old (500) value as default for older savegames.
|
|
|
|
// assume the old (500) value as default for older savegames.
|
|
|
|
const Ogre::Real padding = 500.0f;
|
|
|
|
const float padding = 500.0f;
|
|
|
|
|
|
|
|
|
|
|
|
// Apply a little padding
|
|
|
|
// Apply a little padding
|
|
|
|
mBounds.setMinimum (mBounds.getMinimum() - Vector3(padding,padding,0));
|
|
|
|
mBounds.set(mBounds._min - osg::Vec3f(padding,padding,0.f),
|
|
|
|
mBounds.setMaximum (mBounds.getMaximum() + Vector3(padding,padding,0));
|
|
|
|
mBounds._max + osg::Vec3f(padding,padding,0.f));
|
|
|
|
|
|
|
|
|
|
|
|
float zMin = mBounds.getMinimum().z;
|
|
|
|
float zMin = mBounds.zMin();
|
|
|
|
float zMax = mBounds.getMaximum().z;
|
|
|
|
float zMax = mBounds.zMax();
|
|
|
|
|
|
|
|
|
|
|
|
// If there is fog state in the CellStore (e.g. when it came from a savegame) we need to do some checks
|
|
|
|
// If there is fog state in the CellStore (e.g. when it came from a savegame) we need to do some checks
|
|
|
|
// to see if this state is still valid.
|
|
|
|
// to see if this state is still valid.
|
|
|
@ -244,8 +368,8 @@ void LocalMap::requestMap(MWWorld::CellStore* cell,
|
|
|
|
Ogre::Vector3 minDiff = newMin - mBounds.getMinimum();
|
|
|
|
Ogre::Vector3 minDiff = newMin - mBounds.getMinimum();
|
|
|
|
Ogre::Vector3 maxDiff = newMax - mBounds.getMaximum();
|
|
|
|
Ogre::Vector3 maxDiff = newMax - mBounds.getMaximum();
|
|
|
|
|
|
|
|
|
|
|
|
if (std::abs(minDiff.x) > 500 || std::abs(minDiff.y) > 500
|
|
|
|
if (std::abs(minDiff.x) > padding || std::abs(minDiff.y) > padding
|
|
|
|
|| std::abs(maxDiff.x) > 500 || std::abs(maxDiff.y) > 500
|
|
|
|
|| std::abs(maxDiff.x) > padding || std::abs(maxDiff.y) > padding
|
|
|
|
|| std::abs(mAngle - fog->mNorthMarkerAngle) > Ogre::Degree(5).valueRadians())
|
|
|
|
|| std::abs(mAngle - fog->mNorthMarkerAngle) > Ogre::Degree(5).valueRadians())
|
|
|
|
{
|
|
|
|
{
|
|
|
|
// Nuke it
|
|
|
|
// Nuke it
|
|
|
@ -260,35 +384,35 @@ void LocalMap::requestMap(MWWorld::CellStore* cell,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
Vector2 center(mBounds.getCenter().x, mBounds.getCenter().y);
|
|
|
|
osg::Vec2f min(mBounds.xMin(), mBounds.yMin());
|
|
|
|
|
|
|
|
osg::Vec2f max(mBounds.xMax(), mBounds.yMax());
|
|
|
|
Vector2 min(mBounds.getMinimum().x, mBounds.getMinimum().y);
|
|
|
|
|
|
|
|
Vector2 max(mBounds.getMaximum().x, mBounds.getMaximum().y);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Vector2 length = max-min;
|
|
|
|
osg::Vec2f length = max-min;
|
|
|
|
|
|
|
|
|
|
|
|
mCellCamera->setOrientation(Quaternion::IDENTITY);
|
|
|
|
osg::Vec2f center(bounds.center().x(), bounds.center().y());
|
|
|
|
mCameraRotNode->setOrientation(Quaternion(Math::Cos(mAngle/2.f), 0, 0, -Math::Sin(mAngle/2.f)));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mCameraPosNode->setPosition(Vector3(center.x, center.y, 0));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// divide into segments
|
|
|
|
// divide into segments
|
|
|
|
const int segsX = static_cast<int>(std::ceil(length.x / sSize));
|
|
|
|
const int segsX = static_cast<int>(std::ceil(length.x() / mMapWorldSize));
|
|
|
|
const int segsY = static_cast<int>(std::ceil(length.y / sSize));
|
|
|
|
const int segsY = static_cast<int>(std::ceil(length.y() / mMapWorldSize));
|
|
|
|
|
|
|
|
|
|
|
|
mInteriorName = cell->getCell()->mName;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int i=0;
|
|
|
|
|
|
|
|
for (int x=0; x<segsX; ++x)
|
|
|
|
for (int x=0; x<segsX; ++x)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
for (int y=0; y<segsY; ++y)
|
|
|
|
for (int y=0; y<segsY; ++y)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Vector2 start = min + Vector2(static_cast<Ogre::Real>(sSize*x), static_cast<Ogre::Real>(sSize*y));
|
|
|
|
osg::Vec2f start = min + osg::Vec2f(mMapWorldSize*x, mMapWorldSize*y);
|
|
|
|
Vector2 newcenter = start + sSize/2;
|
|
|
|
osg::Vec2f newcenter = start + osg::Vec2f(mMapWorldSize/2.f, mMapWorldSize/2.f);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
osg::Quat cameraOrient (mAngle, osg::Vec3d(0,0,-1));
|
|
|
|
|
|
|
|
osg::Vec2f a = newcenter - center;
|
|
|
|
|
|
|
|
osg::Vec3f rotatedCenter = cameraOrient * (osg::Vec3f(a.x(), a.y(), 0));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
osg::Vec2f pos = osg::Vec2f(rotatedCenter.x(), rotatedCenter.y()) + center;
|
|
|
|
|
|
|
|
|
|
|
|
std::string texturePrefix = cell->getCell()->mName + "_" + coordStr(x,y);
|
|
|
|
osg::ref_ptr<osg::Camera> camera = createOrthographicCamera(pos.x(), pos.y(),
|
|
|
|
|
|
|
|
mMapWorldSize, mMapWorldSize,
|
|
|
|
|
|
|
|
osg::Vec3f(north.x(), north.y(), 0.f), zMin, zMax);
|
|
|
|
|
|
|
|
|
|
|
|
render(newcenter.x - center.x, newcenter.y - center.y, zMin, zMax, static_cast<float>(sSize), static_cast<float>(sSize), texturePrefix);
|
|
|
|
setupRenderToTexture(camera, x, y);
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
/*
|
|
|
|
if (!cell->getFog())
|
|
|
|
if (!cell->getFog())
|
|
|
@ -305,14 +429,13 @@ void LocalMap::requestMap(MWWorld::CellStore* cell,
|
|
|
|
loadFogOfWar(texturePrefix, esm);
|
|
|
|
loadFogOfWar(texturePrefix, esm);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
++i;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
void LocalMap::createFogOfWar(const std::string& texturePrefix)
|
|
|
|
void LocalMap::createFogOfWar(const std::string& texturePrefix)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
|
|
|
|
const std::string texName = texturePrefix + "_fog";
|
|
|
|
const std::string texName = texturePrefix + "_fog";
|
|
|
|
TexturePtr tex = createFogOfWarTexture(texName);
|
|
|
|
TexturePtr tex = createFogOfWarTexture(texName);
|
|
|
|
|
|
|
|
|
|
|
@ -328,34 +451,12 @@ void LocalMap::createFogOfWar(const std::string& texturePrefix)
|
|
|
|
tex->getBuffer()->unlock();
|
|
|
|
tex->getBuffer()->unlock();
|
|
|
|
|
|
|
|
|
|
|
|
mBuffers[texturePrefix] = buffer;
|
|
|
|
mBuffers[texturePrefix] = buffer;
|
|
|
|
*/
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Ogre::TexturePtr LocalMap::createFogOfWarTexture(const std::string &texName)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
TexturePtr tex;// = TextureManager::getSingleton().getByName(texName);
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
|
|
* if (tex.isNull())
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
tex = TextureManager::getSingleton().createManual(
|
|
|
|
|
|
|
|
texName,
|
|
|
|
|
|
|
|
ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
|
|
|
|
|
|
|
|
TEX_TYPE_2D,
|
|
|
|
|
|
|
|
sFogOfWarResolution, sFogOfWarResolution,
|
|
|
|
|
|
|
|
0,
|
|
|
|
|
|
|
|
PF_A8R8G8B8,
|
|
|
|
|
|
|
|
TU_DYNAMIC_WRITE_ONLY,
|
|
|
|
|
|
|
|
this // ManualResourceLoader required if the texture contents are lost (due to lost devices nonsense that can occur with D3D)
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return tex;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
void LocalMap::loadFogOfWar (const std::string& texturePrefix, ESM::FogTexture& esm)
|
|
|
|
void LocalMap::loadFogOfWar (const std::string& texturePrefix, ESM::FogTexture& esm)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
|
|
|
|
std::vector<char>& data = esm.mImageData;
|
|
|
|
std::vector<char>& data = esm.mImageData;
|
|
|
|
Ogre::DataStreamPtr stream(new Ogre::MemoryDataStream(&data[0], data.size()));
|
|
|
|
Ogre::DataStreamPtr stream(new Ogre::MemoryDataStream(&data[0], data.size()));
|
|
|
|
Ogre::Image image;
|
|
|
|
Ogre::Image image;
|
|
|
@ -377,89 +478,35 @@ void LocalMap::loadFogOfWar (const std::string& texturePrefix, ESM::FogTexture&
|
|
|
|
memcpy(&buffer[0], image.getData(), image.getSize());
|
|
|
|
memcpy(&buffer[0], image.getData(), image.getSize());
|
|
|
|
|
|
|
|
|
|
|
|
mBuffers[texturePrefix] = buffer;
|
|
|
|
mBuffers[texturePrefix] = buffer;
|
|
|
|
*/
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void LocalMap::render(const float x, const float y,
|
|
|
|
|
|
|
|
const float zlow, const float zhigh,
|
|
|
|
|
|
|
|
const float xw, const float yw, const std::string& texture, bool force)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
mCellCamera->setFarClipDistance( (zhigh-zlow) + 2000 );
|
|
|
|
|
|
|
|
mCellCamera->setNearClipDistance(50);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mCellCamera->setOrthoWindow(xw, yw);
|
|
|
|
|
|
|
|
mCameraNode->setPosition(Vector3(x, y, zhigh+1000));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// disable fog (only necessary for fixed function, the shader based
|
|
|
|
|
|
|
|
// materials already do this through local_map material configuration)
|
|
|
|
|
|
|
|
//mRendering->getScene()->setFog(FOG_NONE);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// set up lighting
|
|
|
|
|
|
|
|
//Ogre::ColourValue oldAmbient = mRendering->getScene()->getAmbientLight();
|
|
|
|
|
|
|
|
//mRendering->getScene()->setAmbientLight(Ogre::ColourValue(0.3f, 0.3f, 0.3f));
|
|
|
|
|
|
|
|
//mRenderingManager->disableLights(true);
|
|
|
|
|
|
|
|
mLight->setVisible(true);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
TexturePtr tex;
|
|
|
|
|
|
|
|
// try loading from memory
|
|
|
|
|
|
|
|
tex = TextureManager::getSingleton().getByName(texture);
|
|
|
|
|
|
|
|
if (tex.isNull())
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
// render
|
|
|
|
|
|
|
|
mRenderTarget->update();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// create a new texture and blit to it
|
|
|
|
|
|
|
|
Ogre::TexturePtr tex = TextureManager::getSingleton().createManual(
|
|
|
|
|
|
|
|
texture,
|
|
|
|
|
|
|
|
ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
|
|
|
|
|
|
|
|
TEX_TYPE_2D,
|
|
|
|
|
|
|
|
mMapResolution, mMapResolution,
|
|
|
|
|
|
|
|
0,
|
|
|
|
|
|
|
|
PF_R8G8B8);
|
|
|
|
|
|
|
|
tex->getBuffer()->blit(mRenderTexture->getBuffer());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else if (force)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
mRenderTarget->update();
|
|
|
|
|
|
|
|
tex->getBuffer()->blit(mRenderTexture->getBuffer());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//mRenderingManager->enableLights(true);
|
|
|
|
|
|
|
|
mLight->setVisible(false);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// re-enable fog
|
|
|
|
|
|
|
|
//mRendering->getScene()->setFog(FOG_LINEAR, oldFogColour, 0, oldFogStart, oldFogEnd);
|
|
|
|
|
|
|
|
//mRendering->getScene()->setAmbientLight(oldAmbient);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
void LocalMap::worldToInteriorMapPosition (Ogre::Vector2 pos, float& nX, float& nY, int& x, int& y)
|
|
|
|
void LocalMap::worldToInteriorMapPosition (osg::Vec2f pos, float& nX, float& nY, int& x, int& y)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
pos = rotatePoint(pos, Vector2(mBounds.getCenter().x, mBounds.getCenter().y), mAngle);
|
|
|
|
pos = rotatePoint(pos, osg::Vec2f(mBounds.center().x(), mBounds.center().y()), mAngle);
|
|
|
|
|
|
|
|
|
|
|
|
Vector2 min(mBounds.getMinimum().x, mBounds.getMinimum().y);
|
|
|
|
osg::Vec2f min(mBounds.xMin(), mBounds.yMin());
|
|
|
|
|
|
|
|
|
|
|
|
x = static_cast<int>(std::ceil((pos.x - min.x) / sSize) - 1);
|
|
|
|
x = static_cast<int>(std::ceil((pos.x() - min.x()) / mMapWorldSize) - 1);
|
|
|
|
y = static_cast<int>(std::ceil((pos.y - min.y) / sSize) - 1);
|
|
|
|
y = static_cast<int>(std::ceil((pos.y() - min.y()) / mMapWorldSize) - 1);
|
|
|
|
|
|
|
|
|
|
|
|
nX = (pos.x - min.x - sSize*x)/sSize;
|
|
|
|
nX = (pos.x() - min.x() - mMapWorldSize*x)/mMapWorldSize;
|
|
|
|
nY = 1.0f-(pos.y - min.y - sSize*y)/sSize;
|
|
|
|
nY = 1.0f-(pos.y() - min.y() - mMapWorldSize*y)/mMapWorldSize;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Ogre::Vector2 LocalMap::interiorMapToWorldPosition (float nX, float nY, int x, int y)
|
|
|
|
osg::Vec2f LocalMap::interiorMapToWorldPosition (float nX, float nY, int x, int y)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Vector2 min(mBounds.getMinimum().x, mBounds.getMinimum().y);
|
|
|
|
osg::Vec2f min(mBounds.xMin(), mBounds.yMin());
|
|
|
|
Ogre::Vector2 pos;
|
|
|
|
osg::Vec2f pos (mMapWorldSize * (nX + x) + min.x(),
|
|
|
|
|
|
|
|
mMapWorldSize * (1.0f-nY + y) + min.y());
|
|
|
|
|
|
|
|
|
|
|
|
pos.x = sSize * (nX + x) + min.x;
|
|
|
|
pos = rotatePoint(pos, osg::Vec2f(mBounds.center().x(), mBounds.center().y()), -mAngle);
|
|
|
|
pos.y = sSize * (1.0f-nY + y) + min.y;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pos = rotatePoint(pos, Vector2(mBounds.getCenter().x, mBounds.getCenter().y), -mAngle);
|
|
|
|
|
|
|
|
return pos;
|
|
|
|
return pos;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool LocalMap::isPositionExplored (float nX, float nY, int x, int y, bool interior)
|
|
|
|
bool LocalMap::isPositionExplored (float nX, float nY, int x, int y, bool interior)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
return true;
|
|
|
|
/*
|
|
|
|
/*
|
|
|
|
std::string texName = (interior ? mInteriorName + "_" : "Cell_") + coordStr(x, y);
|
|
|
|
std::string texName = (interior ? mInteriorName + "_" : "Cell_") + coordStr(x, y);
|
|
|
|
|
|
|
|
|
|
|
@ -478,33 +525,8 @@ bool LocalMap::isPositionExplored (float nX, float nY, int x, int y, bool interi
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void LocalMap::loadResource(Ogre::Resource* resource)
|
|
|
|
void LocalMap::updatePlayer (const osg::Vec3f& position, const osg::Quat& orientation,
|
|
|
|
{
|
|
|
|
float& u, float& v, int& x, int& y, osg::Vec3f& direction)
|
|
|
|
/*
|
|
|
|
|
|
|
|
std::string resourceName = resource->getName();
|
|
|
|
|
|
|
|
size_t pos = resourceName.find("_fog");
|
|
|
|
|
|
|
|
if (pos != std::string::npos)
|
|
|
|
|
|
|
|
resourceName = resourceName.substr(0, pos);
|
|
|
|
|
|
|
|
if (mBuffers.find(resourceName) == mBuffers.end())
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
// create a buffer to use for dynamic operations
|
|
|
|
|
|
|
|
std::vector<uint32> buffer;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// initialize to (0, 0, 0, 1)
|
|
|
|
|
|
|
|
buffer.resize(sFogOfWarResolution*sFogOfWarResolution, 0xFF000000);
|
|
|
|
|
|
|
|
mBuffers[resourceName] = buffer;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
std::vector<uint32>& buffer = mBuffers[resourceName];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Ogre::Texture* tex = static_cast<Ogre::Texture*>(resource);
|
|
|
|
|
|
|
|
tex->createInternalResources();
|
|
|
|
|
|
|
|
memcpy(tex->getBuffer()->lock(HardwareBuffer::HBL_DISCARD), &buffer[0], sFogOfWarResolution*sFogOfWarResolution*4);
|
|
|
|
|
|
|
|
tex->getBuffer()->unlock();
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void LocalMap::updatePlayer (const Ogre::Vector3& position, const Ogre::Quaternion& orientation)
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
/*
|
|
|
|
if (sFogOfWarSkip != 0)
|
|
|
|
if (sFogOfWarSkip != 0)
|
|
|
@ -513,42 +535,32 @@ void LocalMap::updatePlayer (const Ogre::Vector3& position, const Ogre::Quaterni
|
|
|
|
if (++count % sFogOfWarSkip != 0)
|
|
|
|
if (++count % sFogOfWarSkip != 0)
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
// retrieve the x,y grid coordinates the player is in
|
|
|
|
// retrieve the x,y grid coordinates the player is in
|
|
|
|
int x,y;
|
|
|
|
osg::Vec2f pos(position.x(), position.y());
|
|
|
|
float u,v;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Vector2 pos(position.x, position.y);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (mInterior)
|
|
|
|
if (mInterior)
|
|
|
|
worldToInteriorMapPosition(pos, u,v, x,y);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Vector3 playerdirection = mCameraRotNode->convertWorldToLocalOrientation(orientation).yAxis();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!mInterior)
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
x = static_cast<int>(std::ceil(pos.x / sSize) - 1);
|
|
|
|
worldToInteriorMapPosition(pos, u,v, x,y);
|
|
|
|
y = static_cast<int>(std::ceil(pos.y / sSize) - 1);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
MWBase::Environment::get().getWindowManager()->setActiveMap(x,y,mInterior);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// convert from world coordinates to texture UV coordinates
|
|
|
|
osg::Quat cameraOrient (mAngle, osg::Vec3(0,0,-1));
|
|
|
|
std::string texBaseName;
|
|
|
|
direction = orientation * cameraOrient.inverse() * osg::Vec3f(0,1,0);
|
|
|
|
if (!mInterior)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
u = std::abs((pos.x - (sSize*x))/sSize);
|
|
|
|
|
|
|
|
v = 1.0f-std::abs((pos.y - (sSize*y))/sSize);
|
|
|
|
|
|
|
|
texBaseName = "Cell_";
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
else
|
|
|
|
{
|
|
|
|
{
|
|
|
|
texBaseName = mInteriorName + "_";
|
|
|
|
direction = orientation * osg::Vec3f(0,1,0);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
x = static_cast<int>(std::ceil(pos.x() / mMapWorldSize) - 1);
|
|
|
|
|
|
|
|
y = static_cast<int>(std::ceil(pos.y() / mMapWorldSize) - 1);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// convert from world coordinates to texture UV coordinates
|
|
|
|
|
|
|
|
u = std::abs((pos.x() - (mMapWorldSize*x))/mMapWorldSize);
|
|
|
|
|
|
|
|
v = 1.0f-std::abs((pos.y() - (mMapWorldSize*y))/mMapWorldSize);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
MWBase::Environment::get().getWindowManager()->setPlayerPos(x, y, u, v);
|
|
|
|
|
|
|
|
MWBase::Environment::get().getWindowManager()->setPlayerDir(playerdirection.x, playerdirection.y);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
// explore radius (squared)
|
|
|
|
// explore radius (squared)
|
|
|
|
const float exploreRadius = (mInterior ? 0.1f : 0.3f) * (sFogOfWarResolution-1); // explore radius from 0 to sFogOfWarResolution-1
|
|
|
|
const float exploreRadius = (mInterior ? 0.1f : 0.3f) * (sFogOfWarResolution-1); // explore radius from 0 to sFogOfWarResolution-1
|
|
|
|
const float sqrExploreRadius = Math::Sqr(exploreRadius);
|
|
|
|
const float sqrExploreRadius = Math::Sqr(exploreRadius);
|
|
|
@ -614,3 +626,5 @@ void LocalMap::updatePlayer (const Ogre::Vector3& position, const Ogre::Quaterni
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|