From 6c80e75deb1d3e480d351f2991bedfc59aef5407 Mon Sep 17 00:00:00 2001 From: Jason Hooks Date: Fri, 4 Nov 2011 21:48:52 -0400 Subject: [PATCH] More Objects functionality --- apps/openmw/mwrender/objects.cpp | 48 +++++++++++++++++++++++++++++++- apps/openmw/mwrender/objects.hpp | 6 ++-- 2 files changed, 50 insertions(+), 4 deletions(-) diff --git a/apps/openmw/mwrender/objects.cpp b/apps/openmw/mwrender/objects.cpp index 963d03e12..1f2ee1978 100644 --- a/apps/openmw/mwrender/objects.cpp +++ b/apps/openmw/mwrender/objects.cpp @@ -33,8 +33,11 @@ void Objects::insertBegin (const MWWorld::Ptr& ptr, bool enabled, bool static_){ } else { - cellnode = (mCellSceneNodes.find(ptr.getCell()))->second; + cellnode = mCellSceneNodes[ptr.getCell()]; } + + + Ogre::SceneNode* insert = cellnode->createChildSceneNode(); const float *f = ptr.getCellRef().pos.pos; insert->setPosition(f[0], f[1], f[2]); @@ -74,8 +77,23 @@ void Objects::insertMesh (const MWWorld::Ptr& ptr, const std::string& mesh){ } else { + Ogre::StaticGeometry* sg; + if(mSG.find(ptr.getCell()) == mSG.end()) + { + uniqueID = uniqueID +1; + sg = mRend.getScene()->createStaticGeometry( "sg" + Ogre::StringConverter::toString(uniqueID)); + //Create the scenenode and put it in the map + mSG[ptr.getCell()] = sg; + } + else + { + sg = mSG[ptr.getCell()]; + } + sg->addEntity(ent,insert->_getDerivedPosition(),insert->_getDerivedOrientation(),insert->_getDerivedScale()); sg->setRegionDimensions(Ogre::Vector3(100000,10000,100000)); + + sg->build(); //Is this the right place for building? mRend.getScene()->destroyEntity(ent); } @@ -114,3 +132,31 @@ void Objects::insertLight (const MWWorld::Ptr& ptr, float r, float g, float b, f insert->attachObject(light); } +void Objects::deleteObject (const std::string& handle) +{ + if (!handle.empty()) + { + Ogre::SceneNode *node = mRend.getScene()->getSceneNode (handle); + node->removeAndDestroyAllChildren(); + mRend.getScene()->destroySceneNode (node); + } +} + +void Objects::removeCell(const MWWorld::Ptr& ptr){ + if(mCellSceneNodes.find(ptr.getCell()) != mCellSceneNodes.end()) + { + Ogre::SceneNode* base = mCellSceneNodes[ptr.getCell()]; + base->removeAndDestroyAllChildren(); + mRend.getScene()->destroySceneNode(base); + base = 0; + } + + + if(mSG.find(ptr.getCell()) != mSG.end()) + { + Ogre::StaticGeometry* sg = mSG[ptr.getCell()]; + mRend.getScene()->destroyStaticGeometry (sg); + sg = 0; + } +} + diff --git a/apps/openmw/mwrender/objects.hpp b/apps/openmw/mwrender/objects.hpp index 1b1722365..6bd1d31c6 100644 --- a/apps/openmw/mwrender/objects.hpp +++ b/apps/openmw/mwrender/objects.hpp @@ -9,8 +9,8 @@ class Objects{ private: OEngine::Render::OgreRenderer &mRend; std::map mCellSceneNodes; + std::map mSG; bool isStatic; - Ogre::StaticGeometry *sg; static int uniqueID; static bool lightConst; static float lightConstValue; @@ -28,13 +28,13 @@ private: static bool lightOutQuadInLin; public: Objects(OEngine::Render::OgreRenderer& _rend): mRend(_rend){ - uniqueID = uniqueID +1; - sg = mRend.getScene()->createStaticGeometry( "sg" + Ogre::StringConverter::toString(uniqueID)); } ~Objects(){} void insertBegin (const MWWorld::Ptr& ptr, bool enabled, bool static_); void insertMesh (const MWWorld::Ptr& ptr, const std::string& mesh); void insertLight (const MWWorld::Ptr& ptr, float r, float g, float b, float radius); + void deleteObject (const std::string& handle); + void removeCell(const MWWorld::Ptr& ptr); /// insert a light related to the most recent insertBegin call.