Multiple SceneManagers per physics engine now working.

loadfix
cc9cii 10 years ago
parent a2ac4c7650
commit fbadaf55ee

@ -42,4 +42,7 @@ std::string CSVDoc::SubView::getTitle() const
void CSVDoc::SubView::closeRequest() void CSVDoc::SubView::closeRequest()
{ {
emit closeRequest (this); emit closeRequest (this);
} }
void CSVDoc::SubView::updateScene()
{}

@ -52,6 +52,8 @@ namespace CSVDoc
virtual void updateUserSetting (const QString& name, const QStringList& value); virtual void updateUserSetting (const QString& name, const QStringList& value);
virtual void updateScene();
private: private:
void closeEvent (QCloseEvent *event); void closeEvent (QCloseEvent *event);
@ -66,6 +68,8 @@ namespace CSVDoc
void updateSubViewIndicies (SubView *view = 0); void updateSubViewIndicies (SubView *view = 0);
void refreshSubViews();
protected slots: protected slots:
void closeRequest(); void closeRequest();

@ -16,6 +16,7 @@
#include "../../model/world/idtable.hpp" #include "../../model/world/idtable.hpp"
#include "../world/subviews.hpp" #include "../world/subviews.hpp"
#include "../doc/subview.hpp"
#include "../tools/subviews.hpp" #include "../tools/subviews.hpp"
@ -300,6 +301,15 @@ void CSVDoc::View::setupUi()
setupDebugMenu(); setupDebugMenu();
} }
void CSVDoc::View::refreshSubViews()
{
QList<SubView *>::iterator iter = mSubViews.begin();
for(; iter != mSubViews.end(); ++iter)
{
(*iter)->updateScene();
}
}
void CSVDoc::View::updateTitle() void CSVDoc::View::updateTitle()
{ {
std::ostringstream stream; std::ostringstream stream;
@ -527,6 +537,8 @@ void CSVDoc::View::addSubView (const CSMWorld::UniversalId& id, const std::strin
connect (view, SIGNAL (updateSubViewIndicies (SubView *)), connect (view, SIGNAL (updateSubViewIndicies (SubView *)),
this, SLOT (updateSubViewIndicies (SubView *))); this, SLOT (updateSubViewIndicies (SubView *)));
connect (view, SIGNAL (refreshSubViews()), this, SLOT (refreshSubViews()));
view->show(); view->show();
} }

@ -139,6 +139,8 @@ namespace CSVDoc
// called when subviews are added or removed // called when subviews are added or removed
void updateSubViewIndicies (SubView *view = 0); void updateSubViewIndicies (SubView *view = 0);
void refreshSubViews();
private slots: private slots:
void newView(); void newView();

@ -66,7 +66,7 @@ namespace CSVRender
mOverlaySystem = OverlaySystem::instance().get(); mOverlaySystem = OverlaySystem::instance().get();
mSceneMgr->addRenderQueueListener(mOverlaySystem); mSceneMgr->addRenderQueueListener(mOverlaySystem);
CSVWorld::PhysicsSystem::instance()->addSceneManager(mSceneMgr); CSVWorld::PhysicsSystem::instance()->addSceneManager(mSceneMgr, this);
QTimer *timer = new QTimer (this); QTimer *timer = new QTimer (this);
@ -414,6 +414,12 @@ namespace CSVRender
} }
} }
void SceneWidget::updateScene()
{
flagAsModified();
update();
}
void SceneWidget::updateOverlay() void SceneWidget::updateOverlay()
{ } { }

@ -47,6 +47,8 @@ namespace CSVRender
virtual void setVisibilityMask (unsigned int mask); virtual void setVisibilityMask (unsigned int mask);
virtual void updateScene();
protected: protected:
void setNavigation (Navigation *navigation); void setNavigation (Navigation *navigation);

@ -665,15 +665,16 @@ void CSVRender::WorldspaceWidget::mouseReleaseEvent (QMouseEvent *event)
Ogre::Vector3 pos = mOrigObjPos+planeResult.second-mOrigMousePos; Ogre::Vector3 pos = mOrigObjPos+planeResult.second-mOrigMousePos;
placeObject(mGrabbedSceneNode, pos); placeObject(mGrabbedSceneNode, pos);
//mCurrentObj = mGrabbedSceneNode; // FIXME //mCurrentObj = mGrabbedSceneNode; // FIXME
mCurrentObj = ""; mCurrentObj = ""; // whether the object is selected
// reset states // reset states
mCurrentMousePos = Ogre::Vector3(); mCurrentMousePos = Ogre::Vector3(); // mouse pos to use in wheel event
mOrigMousePos = Ogre::Vector3(); mOrigMousePos = Ogre::Vector3(); // starting pos of mouse in world space
mOrigObjPos = Ogre::Vector3(); mOrigObjPos = Ogre::Vector3(); // starting pos of object in world space
mGrabbedSceneNode = ""; mGrabbedSceneNode = ""; // id of the object
mOldPos = QPoint(0, 0); mZOffset = 0.0f; // used for z-axis movement
mZOffset = 0.0f; mOldPos = QPoint(0, 0); // to calculate relative movement of mouse
// on screen
// FIXME: update document // FIXME: update document
// FIXME: highlight current object? // FIXME: highlight current object?
@ -903,7 +904,6 @@ std::pair<bool, Ogre::Vector3> CSVRender::WorldspaceWidget::mousePositionOnPlane
void CSVRender::WorldspaceWidget::placeObject(const std::string sceneNode, const Ogre::Vector3 &pos) void CSVRender::WorldspaceWidget::placeObject(const std::string sceneNode, const Ogre::Vector3 &pos)
{ {
getSceneManager()->getSceneNode(sceneNode)->setPosition(pos); getSceneManager()->getSceneNode(sceneNode)->setPosition(pos);
flagAsModified();
// update physics // update physics
std::string refId = CSVWorld::PhysicsSystem::instance()->sceneNodeToRefId(sceneNode); std::string refId = CSVWorld::PhysicsSystem::instance()->sceneNodeToRefId(sceneNode);
@ -918,6 +918,9 @@ void CSVRender::WorldspaceWidget::placeObject(const std::string sceneNode, const
std::string mesh = CSVWorld::PhysicsSystem::instance()->sceneNodeToMesh(sceneNode); std::string mesh = CSVWorld::PhysicsSystem::instance()->sceneNodeToMesh(sceneNode);
CSVWorld::PhysicsSystem::instance()->removeObject(sceneNode); CSVWorld::PhysicsSystem::instance()->removeObject(sceneNode);
CSVWorld::PhysicsSystem::instance()->addObject(mesh, sceneNode, refId, cellref.mScale, pos, xr*yr*zr); CSVWorld::PhysicsSystem::instance()->addObject(mesh, sceneNode, refId, cellref.mScale, pos, xr*yr*zr);
// update all SceneWidgets and their SceneManagers
emit signalAsModified();
} }
bool CSVRender::WorldspaceWidget::isDebug() bool CSVRender::WorldspaceWidget::isDebug()

@ -168,7 +168,10 @@ namespace CSVRender
signals: signals:
void closeRequest(); void closeRequest();
void dataDropped(const std::vector<CSMWorld::UniversalId>& data); void dataDropped(const std::vector<CSMWorld::UniversalId>& data);
void signalAsModified();
}; };
} }

@ -15,7 +15,7 @@ namespace CSVWorld
{ {
PhysicsSystem *PhysicsSystem::mPhysicsSystemInstance = 0; PhysicsSystem *PhysicsSystem::mPhysicsSystemInstance = 0;
PhysicsSystem::PhysicsSystem() : mSceneMgr(0) PhysicsSystem::PhysicsSystem()
{ {
assert(!mPhysicsSystemInstance); assert(!mPhysicsSystemInstance);
mPhysicsSystemInstance = this; mPhysicsSystemInstance = this;
@ -28,6 +28,7 @@ namespace CSVWorld
PhysicsSystem::~PhysicsSystem() PhysicsSystem::~PhysicsSystem()
{ {
delete mEngine; delete mEngine;
// FIXME: update maps when SceneManagers are destroyed
} }
PhysicsSystem *PhysicsSystem::instance() PhysicsSystem *PhysicsSystem::instance()
@ -39,7 +40,7 @@ namespace CSVWorld
// FIXME: looks up the scene manager based on the scene node name (highly inefficient) // FIXME: looks up the scene manager based on the scene node name (highly inefficient)
// NOTE: referenceId is assumed to be unique per document // NOTE: referenceId is assumed to be unique per document
// NOTE: searching is done here rather than after rayTest, so slower to load but // NOTE: searching is done here rather than after rayTest, so slower to load but
// faster to find (not verified w/ perf test) // faster to find (not verified w/ perf test)
void PhysicsSystem::addObject(const std::string &mesh, void PhysicsSystem::addObject(const std::string &mesh,
const std::string &sceneNodeName, const std::string &referenceId, float scale, const std::string &sceneNodeName, const std::string &referenceId, float scale,
const Ogre::Vector3 &position, const Ogre::Quaternion &rotation, bool placeable) const Ogre::Vector3 &position, const Ogre::Quaternion &rotation, bool placeable)
@ -58,21 +59,67 @@ namespace CSVWorld
} }
} }
if(foundSceneManager) if(!foundSceneManager)
return; // FIXME: this should be an exception
// update physics, only one physics model per referenceId
if(mEngine->getRigidBody(referenceId, true) == NULL)
{ {
mEngine->createAndAdjustRigidBody(mesh, mEngine->createAndAdjustRigidBody(mesh,
referenceId, scale, position, rotation, referenceId, scale, position, rotation,
0, // scaledBoxTranslation 0, // scaledBoxTranslation
0, // boxRotation 0, // boxRotation
true, // raycasting true, // raycasting
placeable); placeable);
// update other scene managers if they have the referenceId (may have moved)
iter = mSceneManagers.begin();
for(; iter != mSceneManagers.end(); ++iter)
{
std::string name = refIdToSceneNode(referenceId, *iter);
if(name != sceneNodeName && (*iter)->hasSceneNode(name))
{
// FIXME: rotation or scale not updated
(*iter)->getSceneNode(name)->setPosition(position);
}
}
} }
} }
void PhysicsSystem::removeObject(const std::string &sceneNodeName) void PhysicsSystem::removeObject(const std::string &sceneNodeName)
{ {
mEngine->removeRigidBody(sceneNodeName); std::string referenceId = sceneNodeToRefId(sceneNodeName);
mEngine->deleteRigidBody(sceneNodeName); if(referenceId != "")
{
mEngine->removeRigidBody(referenceId);
mEngine->deleteRigidBody(referenceId);
Ogre::SceneManager *sceneManager = NULL;
std::list<Ogre::SceneManager *>::const_iterator iter = mSceneManagers.begin();
for(; iter != mSceneManagers.end(); ++iter)
{
if((*iter)->hasSceneNode(sceneNodeName))
{
sceneManager = *iter;
break;
}
}
if(!sceneManager)
return; // FIXME: maybe this should be an exception
std::map<std::string, std::map<Ogre::SceneManager *, std::string> >::iterator itRef =
mRefIdToSceneNode.begin();
for(; itRef != mRefIdToSceneNode.end(); ++itRef)
{
if((*itRef).second.find(sceneManager) != (*itRef).second.end())
{
(*itRef).second.erase(sceneManager);
return;
}
}
}
} }
void PhysicsSystem::moveObject(const std::string &sceneNodeName, void PhysicsSystem::moveObject(const std::string &sceneNodeName,
@ -135,7 +182,15 @@ namespace CSVWorld
if(result.first == "") if(result.first == "")
return std::make_pair("", Ogre::Vector3(0,0,0)); return std::make_pair("", Ogre::Vector3(0,0,0));
else else
return std::make_pair(refIdToSceneNode(result.first, sceneMgr), ray.getPoint(farClipDist*result.second)); {
std::string name = refIdToSceneNode(result.first, sceneMgr);
if(name == "")
name = result.first;
else
name = refIdToSceneNode(result.first, sceneMgr);
return std::make_pair(name, ray.getPoint(farClipDist*result.second));
}
} }
std::string PhysicsSystem::refIdToSceneNode(std::string referenceId, Ogre::SceneManager *sceneMgr) std::string PhysicsSystem::refIdToSceneNode(std::string referenceId, Ogre::SceneManager *sceneMgr)
@ -153,15 +208,20 @@ namespace CSVWorld
return mSceneNodeToMesh[sceneNodeName]; return mSceneNodeToMesh[sceneNodeName];
} }
void PhysicsSystem::addSceneManager(Ogre::SceneManager *sceneMgr) void PhysicsSystem::addSceneManager(Ogre::SceneManager *sceneMgr, CSVRender::SceneWidget * scene)
{ {
mSceneManagers.push_back(sceneMgr); mSceneManagers.push_back(sceneMgr);
} }
std::list<CSVRender::SceneWidget *> PhysicsSystem::sceneWidgets()
{
return mSceneWidgets;
}
void PhysicsSystem::toggleDebugRendering(Ogre::SceneManager *sceneMgr) void PhysicsSystem::toggleDebugRendering(Ogre::SceneManager *sceneMgr)
{ {
// FIXME: should check if sceneMgr is in the list // FIXME: should check if sceneMgr is in the list
if(!mSceneMgr) if(!sceneMgr)
return; // FIXME: maybe this should be an exception return; // FIXME: maybe this should be an exception
mEngine->setSceneManager(sceneMgr); mEngine->setSceneManager(sceneMgr);

@ -21,6 +21,11 @@ namespace OEngine
} }
} }
namespace CSVRender
{
class SceneWidget;
}
namespace CSVWorld namespace CSVWorld
{ {
class PhysicsSystem class PhysicsSystem
@ -30,10 +35,9 @@ namespace CSVWorld
std::map<std::string, std::map<Ogre::SceneManager *, std::string> > mRefIdToSceneNode; std::map<std::string, std::map<Ogre::SceneManager *, std::string> > mRefIdToSceneNode;
std::map<std::string, std::string> mSceneNodeToMesh; std::map<std::string, std::string> mSceneNodeToMesh;
std::list<Ogre::SceneManager *> mSceneManagers; // FIXME: change to list per OEngine std::list<Ogre::SceneManager *> mSceneManagers; // FIXME: change to list per OEngine
std::list<CSVRender::SceneWidget *> mSceneWidgets; // FIXME: change to list per OEngine
OEngine::Physic::PhysicEngine* mEngine; OEngine::Physic::PhysicEngine* mEngine;
Ogre::SceneManager *mSceneMgr;
public: public:
PhysicsSystem(); PhysicsSystem();
@ -41,7 +45,7 @@ namespace CSVWorld
static PhysicsSystem *instance(); static PhysicsSystem *instance();
void addSceneManager(Ogre::SceneManager *sceneMgr); void addSceneManager(Ogre::SceneManager *sceneMgr, CSVRender::SceneWidget * scene);
void addObject(const std::string &mesh, void addObject(const std::string &mesh,
const std::string &sceneNodeName, const std::string &referenceId, float scale, const std::string &sceneNodeName, const std::string &referenceId, float scale,
@ -65,8 +69,11 @@ namespace CSVWorld
float mouseY, Ogre::SceneManager *sceneMgr, Ogre::Camera *camera); float mouseY, Ogre::SceneManager *sceneMgr, Ogre::Camera *camera);
std::string sceneNodeToRefId(std::string sceneNodeName); std::string sceneNodeToRefId(std::string sceneNodeName);
std::string sceneNodeToMesh(std::string sceneNodeName); std::string sceneNodeToMesh(std::string sceneNodeName);
std::list<CSVRender::SceneWidget *> sceneWidgets();
private: private:
void updateSelectionHighlight(std::string sceneNode, const Ogre::Vector3 &position); void updateSelectionHighlight(std::string sceneNode, const Ogre::Vector3 &position);

@ -38,7 +38,7 @@ CSVWorld::SceneSubView::SceneSubView (const CSMWorld::UniversalId& id, CSMDoc::D
mLayout->setContentsMargins (QMargins (0, 0, 0, 0)); mLayout->setContentsMargins (QMargins (0, 0, 0, 0));
CSVRender::WorldspaceWidget* wordspaceWidget = NULL; CSVRender::WorldspaceWidget* worldspaceWidget = NULL;
widgetType whatWidget; widgetType whatWidget;
if (id.getId()=="sys::default") if (id.getId()=="sys::default")
@ -47,7 +47,7 @@ CSVWorld::SceneSubView::SceneSubView (const CSMWorld::UniversalId& id, CSMDoc::D
CSVRender::PagedWorldspaceWidget *newWidget = new CSVRender::PagedWorldspaceWidget (this, document); CSVRender::PagedWorldspaceWidget *newWidget = new CSVRender::PagedWorldspaceWidget (this, document);
wordspaceWidget = newWidget; worldspaceWidget = newWidget;
makeConnections(newWidget); makeConnections(newWidget);
} }
@ -57,12 +57,14 @@ CSVWorld::SceneSubView::SceneSubView (const CSMWorld::UniversalId& id, CSMDoc::D
CSVRender::UnpagedWorldspaceWidget *newWidget = new CSVRender::UnpagedWorldspaceWidget (id.getId(), document, this); CSVRender::UnpagedWorldspaceWidget *newWidget = new CSVRender::UnpagedWorldspaceWidget (id.getId(), document, this);
wordspaceWidget = newWidget; worldspaceWidget = newWidget;
makeConnections(newWidget); makeConnections(newWidget);
} }
replaceToolbarAndWorldspace(wordspaceWidget, makeToolbar(wordspaceWidget, whatWidget)); connect (worldspaceWidget, SIGNAL (signalAsModified()), this, SIGNAL (refreshSubViews()));
replaceToolbarAndWorldspace(worldspaceWidget, makeToolbar(worldspaceWidget, whatWidget));
layout->insertLayout (0, mLayout, 1); layout->insertLayout (0, mLayout, 1);
@ -137,7 +139,6 @@ void CSVWorld::SceneSubView::setEditLock (bool locked)
void CSVWorld::SceneSubView::updateEditorSetting(const QString &settingName, const QString &settingValue) void CSVWorld::SceneSubView::updateEditorSetting(const QString &settingName, const QString &settingValue)
{ {
} }
void CSVWorld::SceneSubView::setStatusBar (bool show) void CSVWorld::SceneSubView::setStatusBar (bool show)
@ -150,6 +151,11 @@ void CSVWorld::SceneSubView::useHint (const std::string& hint)
mScene->useViewHint (hint); mScene->useViewHint (hint);
} }
void CSVWorld::SceneSubView::updateScene()
{
if(mScene) mScene->updateScene();
}
std::string CSVWorld::SceneSubView::getTitle() const std::string CSVWorld::SceneSubView::getTitle() const
{ {
return mTitle; return mTitle;

@ -60,6 +60,8 @@ namespace CSVWorld
virtual std::string getTitle() const; virtual std::string getTitle() const;
virtual void updateScene();
private: private:
void makeConnections(CSVRender::PagedWorldspaceWidget* widget); void makeConnections(CSVRender::PagedWorldspaceWidget* widget);

Loading…
Cancel
Save