2011-11-25 04:13:34 +00:00
|
|
|
#include "actors.hpp"
|
2011-12-14 04:49:03 +00:00
|
|
|
|
2012-07-03 13:32:38 +00:00
|
|
|
#include <OgreSceneNode.h>
|
|
|
|
#include <OgreSceneManager.h>
|
2011-11-25 04:13:34 +00:00
|
|
|
|
2013-01-06 05:12:08 +00:00
|
|
|
#include "../mwworld/ptr.hpp"
|
2013-02-23 13:59:35 +00:00
|
|
|
#include "../mwworld/class.hpp"
|
2013-01-06 05:12:08 +00:00
|
|
|
|
2013-02-27 08:20:42 +00:00
|
|
|
#include "../mwrender/renderingmanager.hpp"
|
|
|
|
|
2013-01-06 05:12:08 +00:00
|
|
|
#include "animation.hpp"
|
2013-01-16 22:37:32 +00:00
|
|
|
#include "activatoranimation.hpp"
|
2013-01-06 05:12:08 +00:00
|
|
|
#include "creatureanimation.hpp"
|
|
|
|
#include "npcanimation.hpp"
|
|
|
|
|
2012-09-13 17:03:31 +00:00
|
|
|
#include "renderconst.hpp"
|
|
|
|
|
2011-12-12 03:40:00 +00:00
|
|
|
|
2013-01-06 05:12:08 +00:00
|
|
|
namespace MWRender
|
|
|
|
{
|
2011-11-25 04:13:34 +00:00
|
|
|
using namespace Ogre;
|
|
|
|
|
2013-01-16 15:30:36 +00:00
|
|
|
Actors::~Actors()
|
|
|
|
{
|
2013-01-15 19:10:41 +00:00
|
|
|
PtrAnimationMap::iterator it = mAllActors.begin();
|
|
|
|
for(;it != mAllActors.end();++it)
|
|
|
|
{
|
2012-03-26 22:31:15 +00:00
|
|
|
delete it->second;
|
|
|
|
it->second = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-26 13:01:10 +00:00
|
|
|
void Actors::setRootNode(Ogre::SceneNode* root)
|
|
|
|
{ mRootNode = root; }
|
2012-01-23 13:33:06 +00:00
|
|
|
|
2013-01-16 15:30:36 +00:00
|
|
|
void Actors::insertBegin(const MWWorld::Ptr &ptr)
|
2013-01-10 19:09:33 +00:00
|
|
|
{
|
2011-11-25 04:13:34 +00:00
|
|
|
Ogre::SceneNode* cellnode;
|
2013-01-15 19:10:41 +00:00
|
|
|
CellSceneNodeMap::const_iterator celliter = mCellSceneNodes.find(ptr.getCell());
|
|
|
|
if(celliter != mCellSceneNodes.end())
|
|
|
|
cellnode = celliter->second;
|
|
|
|
else
|
2011-11-25 04:13:34 +00:00
|
|
|
{
|
|
|
|
//Create the scenenode and put it in the map
|
2013-02-26 13:01:10 +00:00
|
|
|
cellnode = mRootNode->createChildSceneNode();
|
2011-11-25 04:13:34 +00:00
|
|
|
mCellSceneNodes[ptr.getCell()] = cellnode;
|
|
|
|
}
|
|
|
|
|
|
|
|
Ogre::SceneNode* insert = cellnode->createChildSceneNode();
|
|
|
|
const float *f = ptr.getRefData().getPosition().pos;
|
|
|
|
insert->setPosition(f[0], f[1], f[2]);
|
2012-09-17 07:37:50 +00:00
|
|
|
insert->setScale(ptr.getCellRef().mScale, ptr.getCellRef().mScale, ptr.getCellRef().mScale);
|
2011-11-25 04:13:34 +00:00
|
|
|
|
|
|
|
// Convert MW rotation to a quaternion:
|
2012-09-17 07:37:50 +00:00
|
|
|
f = ptr.getCellRef().mPos.rot;
|
2011-11-25 04:13:34 +00:00
|
|
|
|
|
|
|
// Rotate around X axis
|
2013-01-15 19:10:41 +00:00
|
|
|
Ogre::Quaternion xr(Ogre::Radian(-f[0]), Ogre::Vector3::UNIT_X);
|
2011-11-25 04:13:34 +00:00
|
|
|
|
|
|
|
// Rotate around Y axis
|
2013-01-15 19:10:41 +00:00
|
|
|
Ogre::Quaternion yr(Ogre::Radian(-f[1]), Ogre::Vector3::UNIT_Y);
|
2011-11-25 04:13:34 +00:00
|
|
|
|
|
|
|
// Rotate around Z axis
|
2013-01-15 19:10:41 +00:00
|
|
|
Ogre::Quaternion zr(Ogre::Radian(-f[2]), Ogre::Vector3::UNIT_Z);
|
2011-11-25 04:13:34 +00:00
|
|
|
|
|
|
|
// Rotates first around z, then y, then x
|
|
|
|
insert->setOrientation(xr*yr*zr);
|
|
|
|
ptr.getRefData().setBaseNode(insert);
|
2011-12-09 05:08:30 +00:00
|
|
|
}
|
2012-01-23 13:33:06 +00:00
|
|
|
|
2013-11-14 13:41:10 +00:00
|
|
|
void Actors::insertNPC(const MWWorld::Ptr& ptr)
|
2013-01-10 19:09:33 +00:00
|
|
|
{
|
|
|
|
insertBegin(ptr);
|
2013-11-14 13:41:10 +00:00
|
|
|
NpcAnimation* anim = new NpcAnimation(ptr, ptr.getRefData().getBaseNode(), RV_Actors);
|
2013-01-10 19:09:33 +00:00
|
|
|
delete mAllActors[ptr];
|
|
|
|
mAllActors[ptr] = anim;
|
2013-02-27 08:20:42 +00:00
|
|
|
mRendering->addWaterRippleEmitter (ptr);
|
2013-11-14 13:41:10 +00:00
|
|
|
|
|
|
|
// Create CustomData, will do autoEquip and trigger animation parts update
|
|
|
|
ptr.getClass().getInventoryStore(ptr);
|
2013-01-10 19:09:33 +00:00
|
|
|
}
|
|
|
|
void Actors::insertCreature (const MWWorld::Ptr& ptr)
|
|
|
|
{
|
|
|
|
insertBegin(ptr);
|
|
|
|
CreatureAnimation* anim = new CreatureAnimation(ptr);
|
2012-03-26 22:31:15 +00:00
|
|
|
delete mAllActors[ptr];
|
2011-12-25 02:53:12 +00:00
|
|
|
mAllActors[ptr] = anim;
|
2013-02-27 08:20:42 +00:00
|
|
|
mRendering->addWaterRippleEmitter (ptr);
|
2011-11-25 04:13:34 +00:00
|
|
|
}
|
2013-01-16 22:37:32 +00:00
|
|
|
void Actors::insertActivator (const MWWorld::Ptr& ptr)
|
|
|
|
{
|
|
|
|
insertBegin(ptr);
|
|
|
|
ActivatorAnimation* anim = new ActivatorAnimation(ptr);
|
|
|
|
delete mAllActors[ptr];
|
|
|
|
mAllActors[ptr] = anim;
|
|
|
|
}
|
2011-11-25 04:13:34 +00:00
|
|
|
|
|
|
|
bool Actors::deleteObject (const MWWorld::Ptr& ptr)
|
|
|
|
{
|
2013-04-17 15:05:54 +00:00
|
|
|
if (mAllActors.find(ptr) == mAllActors.end())
|
|
|
|
return false;
|
|
|
|
|
2013-02-27 08:20:42 +00:00
|
|
|
mRendering->removeWaterRippleEmitter (ptr);
|
|
|
|
|
2013-01-10 19:09:33 +00:00
|
|
|
delete mAllActors[ptr];
|
|
|
|
mAllActors.erase(ptr);
|
2012-01-23 13:33:06 +00:00
|
|
|
|
2013-01-15 19:10:41 +00:00
|
|
|
if(Ogre::SceneNode *base=ptr.getRefData().getBaseNode())
|
|
|
|
{
|
2011-11-25 04:13:34 +00:00
|
|
|
Ogre::SceneNode *parent = base->getParentSceneNode();
|
2013-01-15 19:10:41 +00:00
|
|
|
CellSceneNodeMap::const_iterator iter(mCellSceneNodes.begin());
|
|
|
|
for(;iter != mCellSceneNodes.end();++iter)
|
|
|
|
{
|
|
|
|
if(iter->second == parent)
|
2011-11-25 04:13:34 +00:00
|
|
|
{
|
|
|
|
base->removeAndDestroyAllChildren();
|
|
|
|
mRend.getScene()->destroySceneNode (base);
|
|
|
|
ptr.getRefData().setBaseNode (0);
|
|
|
|
return true;
|
|
|
|
}
|
2013-01-15 19:10:41 +00:00
|
|
|
}
|
2011-11-25 04:13:34 +00:00
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-01-15 19:10:41 +00:00
|
|
|
void Actors::removeCell(MWWorld::Ptr::CellStore* store)
|
|
|
|
{
|
|
|
|
for(PtrAnimationMap::iterator iter = mAllActors.begin();iter != mAllActors.end();)
|
2012-02-26 22:31:16 +00:00
|
|
|
{
|
2013-01-15 19:10:41 +00:00
|
|
|
if(iter->first.getCell() == store)
|
|
|
|
{
|
2013-02-27 08:20:42 +00:00
|
|
|
mRendering->removeWaterRippleEmitter (iter->first);
|
2012-02-26 22:31:16 +00:00
|
|
|
delete iter->second;
|
|
|
|
mAllActors.erase(iter++);
|
|
|
|
}
|
2012-02-26 21:45:17 +00:00
|
|
|
else
|
|
|
|
++iter;
|
2012-02-26 22:31:16 +00:00
|
|
|
}
|
2013-01-15 19:10:41 +00:00
|
|
|
CellSceneNodeMap::iterator celliter = mCellSceneNodes.find(store);
|
|
|
|
if(celliter != mCellSceneNodes.end())
|
|
|
|
{
|
|
|
|
Ogre::SceneNode *base = celliter->second;
|
|
|
|
base->removeAndDestroyAllChildren();
|
|
|
|
mRend.getScene()->destroySceneNode(base);
|
2013-04-17 15:05:54 +00:00
|
|
|
|
2013-01-15 19:10:41 +00:00
|
|
|
mCellSceneNodes.erase(celliter);
|
|
|
|
}
|
2011-12-27 00:23:46 +00:00
|
|
|
}
|
|
|
|
|
2013-12-26 17:16:28 +00:00
|
|
|
void Actors::update (Ogre::Camera* camera)
|
2013-01-15 19:10:41 +00:00
|
|
|
{
|
2013-12-26 17:16:28 +00:00
|
|
|
for(PtrAnimationMap::iterator iter = mAllActors.begin();iter != mAllActors.end(); ++iter)
|
|
|
|
{
|
|
|
|
iter->second->preRender(camera);
|
|
|
|
}
|
2011-12-27 00:23:46 +00:00
|
|
|
}
|
2012-07-30 19:28:14 +00:00
|
|
|
|
2013-01-16 17:59:19 +00:00
|
|
|
Animation* Actors::getAnimation(const MWWorld::Ptr &ptr)
|
|
|
|
{
|
|
|
|
PtrAnimationMap::const_iterator iter = mAllActors.find(ptr);
|
|
|
|
if(iter != mAllActors.end())
|
|
|
|
return iter->second;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2013-02-24 10:59:21 +00:00
|
|
|
void Actors::updateObjectCell(const MWWorld::Ptr &old, const MWWorld::Ptr &cur)
|
2012-07-30 19:28:14 +00:00
|
|
|
{
|
|
|
|
Ogre::SceneNode *node;
|
2013-02-24 10:59:21 +00:00
|
|
|
MWWorld::CellStore *newCell = cur.getCell();
|
2012-07-30 19:28:14 +00:00
|
|
|
|
2013-01-15 19:10:41 +00:00
|
|
|
CellSceneNodeMap::const_iterator celliter = mCellSceneNodes.find(newCell);
|
|
|
|
if(celliter != mCellSceneNodes.end())
|
|
|
|
node = celliter->second;
|
|
|
|
else
|
|
|
|
{
|
2013-02-26 13:01:10 +00:00
|
|
|
node = mRootNode->createChildSceneNode();
|
2012-07-30 19:28:14 +00:00
|
|
|
mCellSceneNodes[newCell] = node;
|
|
|
|
}
|
2013-02-24 10:59:21 +00:00
|
|
|
node->addChild(cur.getRefData().getBaseNode());
|
2013-01-15 19:10:41 +00:00
|
|
|
|
2013-02-24 10:59:21 +00:00
|
|
|
PtrAnimationMap::iterator iter = mAllActors.find(old);
|
2013-01-15 19:10:41 +00:00
|
|
|
if(iter != mAllActors.end())
|
|
|
|
{
|
2013-02-23 16:03:52 +00:00
|
|
|
Animation *anim = iter->second;
|
2013-01-15 19:10:41 +00:00
|
|
|
mAllActors.erase(iter);
|
2013-02-24 10:59:21 +00:00
|
|
|
anim->updatePtr(cur);
|
|
|
|
mAllActors[cur] = anim;
|
2012-07-30 19:28:14 +00:00
|
|
|
}
|
2013-02-27 08:20:42 +00:00
|
|
|
|
|
|
|
mRendering->updateWaterRippleEmitterPtr (old, cur);
|
2012-07-30 19:28:14 +00:00
|
|
|
}
|
2013-01-06 05:12:08 +00:00
|
|
|
|
|
|
|
}
|