1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-01-20 06:23:52 +00:00
openmw-tes3mp/apps/openmw/mwrender/objects.cpp

219 lines
5.8 KiB
C++
Raw Normal View History

2011-11-01 03:59:16 +00:00
#include "objects.hpp"
2012-02-06 09:41:13 +00:00
2013-03-29 08:04:02 +00:00
#include <cmath>
2011-11-02 04:13:33 +00:00
#include <OgreSceneNode.h>
#include <OgreSceneManager.h>
#include <OgreEntity.h>
#include <OgreLight.h>
#include <OgreSubEntity.h>
#include <OgreParticleSystem.h>
#include <OgreParticleEmitter.h>
#include <OgreStaticGeometry.h>
2012-02-06 09:41:13 +00:00
2014-02-23 19:11:05 +00:00
#include <components/esm/loadligh.hpp>
#include <components/esm/loadstat.hpp>
//#include <components/nifogre/ogrenifloader.hpp>
#include <components/settings/settings.hpp>
#include "../mwworld/ptr.hpp"
2012-07-30 19:28:14 +00:00
#include "../mwworld/class.hpp"
2014-02-23 19:11:05 +00:00
#include "../mwworld/cellstore.hpp"
2012-04-03 13:13:47 +00:00
#include "renderconst.hpp"
//#include "animation.hpp"
2011-11-01 03:59:16 +00:00
using namespace MWRender;
int Objects::uniqueID = 0;
2011-11-01 03:59:16 +00:00
2013-02-26 13:01:10 +00:00
void Objects::setRootNode(Ogre::SceneNode* root)
2012-02-06 09:41:13 +00:00
{
2013-02-26 13:01:10 +00:00
mRootNode = root;
2011-11-17 22:10:27 +00:00
}
2012-02-06 09:41:13 +00:00
2013-08-07 10:51:57 +00:00
void Objects::insertBegin(const MWWorld::Ptr& ptr)
2012-02-06 09:41:13 +00:00
{
2013-02-26 13:01:10 +00:00
Ogre::SceneNode* root = mRootNode;
2011-11-05 01:57:39 +00:00
Ogre::SceneNode* cellnode;
if(mCellSceneNodes.find(ptr.getCell()) == mCellSceneNodes.end())
{
//Create the scenenode and put it in the map
cellnode = root->createChildSceneNode();
2011-11-05 01:57:39 +00:00
mCellSceneNodes[ptr.getCell()] = cellnode;
}
else
2011-11-05 01:57:39 +00:00
{
cellnode = mCellSceneNodes[ptr.getCell()];
}
2011-11-05 01:48:52 +00:00
2011-11-05 01:57:39 +00:00
Ogre::SceneNode* insert = cellnode->createChildSceneNode();
2011-11-09 18:53:29 +00:00
const float *f = ptr.getRefData().getPosition().pos;
2012-03-25 02:03:08 +00:00
2011-11-05 01:57:39 +00:00
insert->setPosition(f[0], f[1], f[2]);
insert->setScale(ptr.getCellRef().getScale(), ptr.getCellRef().getScale(), ptr.getCellRef().getScale());
2011-11-05 01:57:39 +00:00
// Convert MW rotation to a quaternion:
f = ptr.getCellRef().getPosition().rot;
2011-11-05 01:57:39 +00:00
// Rotate around X axis
2012-02-06 09:41:13 +00:00
Ogre::Quaternion xr(Ogre::Radian(-f[0]), Ogre::Vector3::UNIT_X);
2011-11-05 01:57:39 +00:00
// Rotate around Y axis
2012-02-06 09:41:13 +00:00
Ogre::Quaternion yr(Ogre::Radian(-f[1]), Ogre::Vector3::UNIT_Y);
2011-11-05 01:57:39 +00:00
// Rotate around Z axis
2012-02-06 09:41:13 +00:00
Ogre::Quaternion zr(Ogre::Radian(-f[2]), Ogre::Vector3::UNIT_Z);
2012-02-06 09:41:13 +00:00
// Rotates first around z, then y, then x
2011-11-05 01:57:39 +00:00
insert->setOrientation(xr*yr*zr);
2011-11-03 02:41:48 +00:00
ptr.getRefData().setBaseNode(insert);
2011-11-01 03:59:16 +00:00
}
2012-02-06 09:41:13 +00:00
void Objects::insertModel(const MWWorld::Ptr &ptr, const std::string &mesh, bool batch)
2012-02-06 09:41:13 +00:00
{
2013-08-07 10:51:57 +00:00
insertBegin(ptr);
/*
2013-08-07 10:02:27 +00:00
std::auto_ptr<ObjectAnimation> anim(new ObjectAnimation(ptr, mesh));
if (!mesh.empty())
2011-11-05 01:57:39 +00:00
{
Ogre::AxisAlignedBox bounds = anim->getWorldBounds();
Ogre::Vector3 extents = bounds.getSize();
extents *= ptr.getRefData().getBaseNode()->getScale();
float size = std::max(std::max(extents.x, extents.y), extents.z);
bool small = (size < Settings::Manager::getInt("small object size", "Viewing distance")) &&
Settings::Manager::getBool("limit small object distance", "Viewing distance");
// do not fade out doors. that will cause holes and look stupid
if(ptr.getTypeName().find("Door") != std::string::npos)
small = false;
if (mBounds.find(ptr.getCell()) == mBounds.end())
mBounds[ptr.getCell()] = Ogre::AxisAlignedBox::BOX_NULL;
mBounds[ptr.getCell()].merge(bounds);
2011-11-05 01:57:39 +00:00
}
2013-02-23 03:06:05 +00:00
if(anim.get() != NULL)
mObjects.insert(std::make_pair(ptr, anim.release()));
*/
2011-11-01 03:59:16 +00:00
}
2012-02-06 09:41:13 +00:00
bool Objects::deleteObject (const MWWorld::Ptr& ptr)
2012-02-06 09:41:13 +00:00
{
/*
if(!ptr.getRefData().getBaseNode())
return true;
2012-04-28 18:42:53 +00:00
PtrAnimationMap::iterator iter = mObjects.find(ptr);
if(iter != mObjects.end())
2012-02-06 09:41:13 +00:00
{
delete iter->second;
mObjects.erase(iter);
2012-02-06 09:41:13 +00:00
mRenderer.getScene()->destroySceneNode(ptr.getRefData().getBaseNode());
ptr.getRefData().setBaseNode(0);
return true;
}
*/
return false;
2011-11-01 03:59:16 +00:00
}
2011-11-02 04:13:33 +00:00
2011-11-05 01:48:52 +00:00
void Objects::removeCell(MWWorld::CellStore* store)
2012-02-06 09:41:13 +00:00
{
/*
for(PtrAnimationMap::iterator iter = mObjects.begin();iter != mObjects.end();)
2011-11-05 01:48:52 +00:00
{
if(iter->first.getCell() == store)
{
delete iter->second;
mObjects.erase(iter++);
}
else
++iter;
2011-11-05 01:48:52 +00:00
}
std::map<MWWorld::CellStore*,Ogre::StaticGeometry*>::iterator geom = mStaticGeometry.find(store);
if(geom != mStaticGeometry.end())
2011-11-05 01:48:52 +00:00
{
Ogre::StaticGeometry *sg = geom->second;
mStaticGeometry.erase(geom);
mRenderer.getScene()->destroyStaticGeometry(sg);
2011-11-05 01:48:52 +00:00
}
geom = mStaticGeometrySmall.find(store);
if(geom != mStaticGeometrySmall.end())
{
Ogre::StaticGeometry *sg = geom->second;
mStaticGeometrySmall.erase(store);
mRenderer.getScene()->destroyStaticGeometry(sg);
}
2012-03-29 16:04:52 +00:00
mBounds.erase(store);
std::map<MWWorld::CellStore*,Ogre::SceneNode*>::iterator cell = mCellSceneNodes.find(store);
if(cell != mCellSceneNodes.end())
{
cell->second->removeAndDestroyAllChildren();
mRenderer.getScene()->destroySceneNode(cell->second);
mCellSceneNodes.erase(cell);
}
*/
2011-11-05 18:57:33 +00:00
}
Ogre::AxisAlignedBox Objects::getDimensions(MWWorld::CellStore* cell)
{
return mBounds[cell];
}
2012-04-02 17:37:24 +00:00
void Objects::update(float dt, Ogre::Camera* camera)
2012-04-19 18:59:57 +00:00
{
/*
PtrAnimationMap::const_iterator it = mObjects.begin();
for(;it != mObjects.end();++it)
it->second->runAnimation(dt);
*/
2012-07-11 00:31:03 +00:00
}
2012-07-30 19:28:14 +00:00
void Objects::updateObjectCell(const MWWorld::Ptr &old, const MWWorld::Ptr &cur)
2012-07-30 19:28:14 +00:00
{
/*
2012-07-30 19:28:14 +00:00
Ogre::SceneNode *node;
MWWorld::CellStore *newCell = cur.getCell();
2012-07-30 19:28:14 +00:00
if(mCellSceneNodes.find(newCell) == mCellSceneNodes.end()) {
2013-02-26 13:01:10 +00:00
node = mRootNode->createChildSceneNode();
2012-07-30 19:28:14 +00:00
mCellSceneNodes[newCell] = node;
} else {
node = mCellSceneNodes[newCell];
}
node->addChild(cur.getRefData().getBaseNode());
PtrAnimationMap::iterator iter = mObjects.find(old);
if(iter != mObjects.end())
{
ObjectAnimation *anim = iter->second;
mObjects.erase(iter);
anim->updatePtr(cur);
mObjects[cur] = anim;
}
*/
2012-07-30 19:28:14 +00:00
}
ObjectAnimation* Objects::getAnimation(const MWWorld::Ptr &ptr)
{
/*
PtrAnimationMap::const_iterator iter = mObjects.find(ptr);
if(iter != mObjects.end())
return iter->second;
*/
return NULL;
2012-07-30 19:28:14 +00:00
}