forked from teamnwah/openmw-tes3coop
Feature #37 (In Progress) Render Path Grid
now using mwRoot instead of ogre's root, so no more messing with coordinates.
This commit is contained in:
parent
387c84e606
commit
f292a5a7ca
4 changed files with 40 additions and 31 deletions
|
@ -2,12 +2,8 @@
|
||||||
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
|
||||||
#include "OgreRoot.h"
|
#include <OgreNode.h>
|
||||||
#include "OgreRenderWindow.h"
|
#include <OgreSceneManager.h>
|
||||||
#include "OgreSceneManager.h"
|
|
||||||
#include "OgreViewport.h"
|
|
||||||
#include "OgreCamera.h"
|
|
||||||
#include "OgreTextureManager.h"
|
|
||||||
|
|
||||||
#include "../mwworld/world.hpp" // these includes can be removed once the static-hack is gone
|
#include "../mwworld/world.hpp" // these includes can be removed once the static-hack is gone
|
||||||
#include "../mwworld/environment.hpp"
|
#include "../mwworld/environment.hpp"
|
||||||
|
@ -20,8 +16,11 @@
|
||||||
using namespace MWRender;
|
using namespace MWRender;
|
||||||
using namespace Ogre;
|
using namespace Ogre;
|
||||||
|
|
||||||
Debugging::Debugging(MWWorld::Environment &env, SceneManager* sceneMgr, OEngine::Physic::PhysicEngine *engine) :
|
Debugging::Debugging(SceneNode *mwRoot, MWWorld::Environment &env, OEngine::Physic::PhysicEngine *engine) :
|
||||||
mEnvironment(env), mSceneMgr(sceneMgr), mEngine(engine), pathgridEnabled(false)
|
mMwRoot(mwRoot), mEnvironment(env), mEngine(engine),
|
||||||
|
mSceneMgr(mwRoot->getCreator()),
|
||||||
|
pathgridEnabled(false),
|
||||||
|
mInteriorPathgridNode(NULL), mPathGridRoot(NULL)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -65,7 +64,7 @@ void Debugging::togglePathgrid()
|
||||||
if (pathgridEnabled)
|
if (pathgridEnabled)
|
||||||
{
|
{
|
||||||
// add path grid meshes to already loaded cells
|
// add path grid meshes to already loaded cells
|
||||||
mPathGridRoot = mSceneMgr->getRootSceneNode()->createChildSceneNode();
|
mPathGridRoot = mMwRoot->createChildSceneNode();
|
||||||
for(CellList::iterator it = mActiveCells.begin(); it != mActiveCells.end(); it++)
|
for(CellList::iterator it = mActiveCells.begin(); it != mActiveCells.end(); it++)
|
||||||
{
|
{
|
||||||
togglePathgridForCell(*it, true);
|
togglePathgridForCell(*it, true);
|
||||||
|
@ -79,6 +78,7 @@ void Debugging::togglePathgrid()
|
||||||
}
|
}
|
||||||
mPathGridRoot->removeAndDestroyAllChildren();
|
mPathGridRoot->removeAndDestroyAllChildren();
|
||||||
mSceneMgr->destroySceneNode(mPathGridRoot);
|
mSceneMgr->destroySceneNode(mPathGridRoot);
|
||||||
|
mPathGridRoot = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -87,25 +87,24 @@ void Debugging::togglePathgridForCell(MWWorld::Ptr::CellStore *store, bool enabl
|
||||||
ESM::Pathgrid *pathgrid = mEnvironment.mWorld->getStore().pathgrids.search(*store->cell);
|
ESM::Pathgrid *pathgrid = mEnvironment.mWorld->getStore().pathgrids.search(*store->cell);
|
||||||
if (!pathgrid)
|
if (!pathgrid)
|
||||||
{
|
{
|
||||||
std::cout << "No path grid :(" << std::endl;
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
std::cout << "Path grid exists!" << std::endl;
|
|
||||||
|
|
||||||
if (enabled)
|
if (enabled)
|
||||||
{
|
{
|
||||||
Vector3 cellPathGridPos;
|
Vector3 cellPathGridPos;
|
||||||
|
/// \todo replace tests like this with isExterior method of ESM::Cell after merging with terrain branch
|
||||||
if (!(store->cell->data.flags & ESM::Cell::Interior))
|
if (!(store->cell->data.flags & ESM::Cell::Interior))
|
||||||
{
|
{
|
||||||
/// \todo Replace with ESM::Land::REAL_SIZE after merging with terrain branch
|
/// \todo Replace with ESM::Land::REAL_SIZE after merging with terrain branch
|
||||||
cellPathGridPos.x = store->cell->data.gridX * 8192;
|
cellPathGridPos.x = store->cell->data.gridX * 8192;
|
||||||
cellPathGridPos.z = -store->cell->data.gridY * 8192;
|
cellPathGridPos.y = store->cell->data.gridY * 8192;
|
||||||
}
|
}
|
||||||
SceneNode *cellPathGrid = mPathGridRoot->createChildSceneNode(cellPathGridPos);
|
SceneNode *cellPathGrid = mPathGridRoot->createChildSceneNode(cellPathGridPos);
|
||||||
ESM::Pathgrid::PointList points = pathgrid->points;
|
ESM::Pathgrid::PointList points = pathgrid->points;
|
||||||
for (ESM::Pathgrid::PointList::iterator it = points.begin(); it != points.end(); it++)
|
for (ESM::Pathgrid::PointList::iterator it = points.begin(); it != points.end(); it++)
|
||||||
{
|
{
|
||||||
Vector3 position(it->x, it->z, -it->y);
|
Vector3 position(it->x, it->y, it->z);
|
||||||
SceneNode* pointNode = cellPathGrid->createChildSceneNode(position);
|
SceneNode* pointNode = cellPathGrid->createChildSceneNode(position);
|
||||||
pointNode->setScale(0.5, 0.5, 0.5);
|
pointNode->setScale(0.5, 0.5, 0.5);
|
||||||
Entity *pointMesh = mSceneMgr->createEntity(SceneManager::PT_CUBE);
|
Entity *pointMesh = mSceneMgr->createEntity(SceneManager::PT_CUBE);
|
||||||
|
@ -124,18 +123,13 @@ void Debugging::togglePathgridForCell(MWWorld::Ptr::CellStore *store, bool enabl
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/// \todo Don't forget to destroy cubes too!
|
|
||||||
SceneNode *cellPathGridNode;
|
|
||||||
if (!(store->cell->data.flags & ESM::Cell::Interior))
|
if (!(store->cell->data.flags & ESM::Cell::Interior))
|
||||||
{
|
{
|
||||||
ExteriorPathgridNodes::iterator it =
|
ExteriorPathgridNodes::iterator it =
|
||||||
mExteriorPathgridNodes.find(std::make_pair(store->cell->data.gridX, store->cell->data.gridY));
|
mExteriorPathgridNodes.find(std::make_pair(store->cell->data.gridX, store->cell->data.gridY));
|
||||||
if (it != mExteriorPathgridNodes.end())
|
if (it != mExteriorPathgridNodes.end())
|
||||||
{
|
{
|
||||||
cellPathGridNode = it->second;
|
destroyCellPathgridNode(it->second);
|
||||||
mPathGridRoot->removeChild(cellPathGridNode);
|
|
||||||
cellPathGridNode->removeAndDestroyAllChildren();
|
|
||||||
mSceneMgr->destroySceneNode(cellPathGridNode);
|
|
||||||
mExteriorPathgridNodes.erase(it);
|
mExteriorPathgridNodes.erase(it);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -143,11 +137,28 @@ void Debugging::togglePathgridForCell(MWWorld::Ptr::CellStore *store, bool enabl
|
||||||
{
|
{
|
||||||
if (mInteriorPathgridNode)
|
if (mInteriorPathgridNode)
|
||||||
{
|
{
|
||||||
mPathGridRoot->removeChild(mInteriorPathgridNode);
|
destroyCellPathgridNode(mInteriorPathgridNode);
|
||||||
mInteriorPathgridNode->removeAndDestroyAllChildren();
|
|
||||||
mSceneMgr->destroySceneNode(mInteriorPathgridNode);
|
|
||||||
mInteriorPathgridNode = NULL;
|
mInteriorPathgridNode = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Debugging::destroyCellPathgridNode(SceneNode *node)
|
||||||
|
{
|
||||||
|
mPathGridRoot->removeChild(node);
|
||||||
|
|
||||||
|
SceneNode::ChildNodeIterator childIt = node->getChildIterator();
|
||||||
|
while (childIt.hasMoreElements())
|
||||||
|
{
|
||||||
|
SceneNode *child = static_cast<SceneNode *>(childIt.getNext());
|
||||||
|
SceneNode::ObjectIterator objIt = child->getAttachedObjectIterator();
|
||||||
|
while (objIt.hasMoreElements())
|
||||||
|
{
|
||||||
|
MovableObject *mesh = static_cast<MovableObject *>(objIt.getNext());
|
||||||
|
child->getCreator()->destroyMovableObject(mesh);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
node->removeAndDestroyAllChildren();
|
||||||
|
mSceneMgr->destroySceneNode(node);
|
||||||
|
}
|
||||||
|
|
|
@ -33,9 +33,8 @@ namespace MWRender
|
||||||
class Debugging
|
class Debugging
|
||||||
{
|
{
|
||||||
OEngine::Physic::PhysicEngine* mEngine;
|
OEngine::Physic::PhysicEngine* mEngine;
|
||||||
Ogre::SceneManager* mSceneMgr;
|
Ogre::SceneManager *mSceneMgr;
|
||||||
MWWorld::Environment& mEnvironment;
|
MWWorld::Environment& mEnvironment;
|
||||||
//const ESMS::ESMStore& mStore;
|
|
||||||
|
|
||||||
// Path grid stuff
|
// Path grid stuff
|
||||||
bool pathgridEnabled;
|
bool pathgridEnabled;
|
||||||
|
@ -46,6 +45,7 @@ namespace MWRender
|
||||||
|
|
||||||
CellList mActiveCells;
|
CellList mActiveCells;
|
||||||
|
|
||||||
|
Ogre::SceneNode *mMwRoot;
|
||||||
Ogre::SceneNode *mPathGridRoot;
|
Ogre::SceneNode *mPathGridRoot;
|
||||||
Ogre::SceneNode *mInteriorPathgridNode;
|
Ogre::SceneNode *mInteriorPathgridNode;
|
||||||
|
|
||||||
|
@ -54,8 +54,10 @@ namespace MWRender
|
||||||
|
|
||||||
void togglePathgridForCell(MWWorld::Ptr::CellStore *store, bool enabled);
|
void togglePathgridForCell(MWWorld::Ptr::CellStore *store, bool enabled);
|
||||||
|
|
||||||
|
void destroyCellPathgridNode(Ogre::SceneNode *node);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Debugging(MWWorld::Environment &env, Ogre::SceneManager *mSceneMgr, OEngine::Physic::PhysicEngine* engine);
|
Debugging(Ogre::SceneNode* mwRoot, MWWorld::Environment &env, OEngine::Physic::PhysicEngine *engine);
|
||||||
bool toggleRenderMode (int mode);
|
bool toggleRenderMode (int mode);
|
||||||
|
|
||||||
void cellAdded(MWWorld::Ptr::CellStore* store);
|
void cellAdded(MWWorld::Ptr::CellStore* store);
|
||||||
|
|
|
@ -24,8 +24,6 @@ RenderingManager::RenderingManager (OEngine::Render::OgreRenderer& _rend, const
|
||||||
{
|
{
|
||||||
mRendering.createScene("PlayerCam", 55, 5);
|
mRendering.createScene("PlayerCam", 55, 5);
|
||||||
|
|
||||||
mDebugging = new Debugging(environment, mRendering.getScene(), engine);
|
|
||||||
|
|
||||||
// Set default mipmap level (NB some APIs ignore this)
|
// Set default mipmap level (NB some APIs ignore this)
|
||||||
TextureManager::getSingleton().setDefaultNumMipmaps(5);
|
TextureManager::getSingleton().setDefaultNumMipmaps(5);
|
||||||
|
|
||||||
|
@ -57,6 +55,8 @@ RenderingManager::RenderingManager (OEngine::Render::OgreRenderer& _rend, const
|
||||||
|
|
||||||
mPlayer = new MWRender::Player (mRendering.getCamera(), playerNode);
|
mPlayer = new MWRender::Player (mRendering.getCamera(), playerNode);
|
||||||
mSun = 0;
|
mSun = 0;
|
||||||
|
|
||||||
|
mDebugging = new Debugging(mMwRoot, environment, engine);
|
||||||
}
|
}
|
||||||
|
|
||||||
RenderingManager::~RenderingManager ()
|
RenderingManager::~RenderingManager ()
|
||||||
|
|
|
@ -428,12 +428,10 @@ namespace ESMS
|
||||||
if (grid->data.x == 0 && grid->data.y == 0)
|
if (grid->data.x == 0 && grid->data.y == 0)
|
||||||
{
|
{
|
||||||
intGrids[grid->cell] = grid;
|
intGrids[grid->cell] = grid;
|
||||||
std::cout << "int grids size " << intGrids.size() << std::endl;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
extGrids[std::make_pair(grid->data.x, grid->data.y)] = grid;
|
extGrids[std::make_pair(grid->data.x, grid->data.y)] = grid;
|
||||||
std::cout << "ext grids size " << extGrids.size() << std::endl;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -449,8 +447,6 @@ namespace ESMS
|
||||||
|
|
||||||
Pathgrid *search(int cellX, int cellY, const std::string &cellName) const
|
Pathgrid *search(int cellX, int cellY, const std::string &cellName) const
|
||||||
{
|
{
|
||||||
std::cout << "int grids size " << intGrids.size() << std::endl;
|
|
||||||
std::cout << "ext grids size " << extGrids.size() << std::endl;
|
|
||||||
Pathgrid *result = NULL;
|
Pathgrid *result = NULL;
|
||||||
if (cellX == 0 && cellY == 0) // possibly interior
|
if (cellX == 0 && cellY == 0) // possibly interior
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue