1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-01-10 06:39:49 +00:00
OpenMW/apps/openmw/mwrender/actors.cpp

126 lines
3.6 KiB
C++
Raw Normal View History

2011-11-25 04:13:34 +00:00
#include "actors.hpp"
#include <OgreSceneNode.h>
2011-12-14 04:49:03 +00:00
2011-11-25 04:13:34 +00:00
2011-11-25 04:13:34 +00:00
using namespace Ogre;
using namespace MWRender;
2011-12-09 05:08:30 +00:00
using namespace NifOgre;
2011-11-25 04:13:34 +00:00
void Actors::setMwRoot(Ogre::SceneNode* root){
mMwRoot = root;
}
2011-12-09 05:08:30 +00:00
void Actors::insertNPC(const MWWorld::Ptr& ptr){
2011-12-09 05:08:30 +00:00
insertBegin(ptr, true, true);
2011-12-25 02:53:12 +00:00
NpcAnimation* anim = new MWRender::NpcAnimation(ptr, mEnvironment, mRend);
mAllActors[ptr] = anim;
2011-12-09 05:08:30 +00:00
}
2011-11-25 04:13:34 +00:00
void Actors::insertBegin (const MWWorld::Ptr& ptr, bool enabled, bool static_){
Ogre::SceneNode* cellnode;
if(mCellSceneNodes.find(ptr.getCell()) == mCellSceneNodes.end())
{
//Create the scenenode and put it in the map
cellnode = mMwRoot->createChildSceneNode();
mCellSceneNodes[ptr.getCell()] = cellnode;
}
else
{
cellnode = mCellSceneNodes[ptr.getCell()];
}
Ogre::SceneNode* insert = cellnode->createChildSceneNode();
const float *f = ptr.getRefData().getPosition().pos;
insert->setPosition(f[0], f[1], f[2]);
insert->setScale(ptr.getCellRef().scale, ptr.getCellRef().scale, ptr.getCellRef().scale);
// Convert MW rotation to a quaternion:
f = ptr.getCellRef().pos.rot;
// Rotate around X axis
Quaternion xr(Radian(-f[0]), Vector3::UNIT_X);
// Rotate around Y axis
Quaternion yr(Radian(-f[1]), Vector3::UNIT_Y);
// Rotate around Z axis
Quaternion zr(Radian(-f[2]), Vector3::UNIT_Z);
// Rotates first around z, then y, then x
insert->setOrientation(xr*yr*zr);
if (!enabled)
insert->setVisible (false);
ptr.getRefData().setBaseNode(insert);
2011-12-09 05:08:30 +00:00
}
void Actors::insertCreature (const MWWorld::Ptr& ptr){
insertBegin(ptr, true, true);
2011-12-14 04:49:03 +00:00
CreatureAnimation* anim = new MWRender::CreatureAnimation(ptr, mEnvironment, mRend);
2011-12-15 05:33:10 +00:00
//mAllActors.insert(std::pair<MWWorld::Ptr, Animation*>(ptr,anim));
2011-12-25 02:53:12 +00:00
mAllActors[ptr] = anim;
//mAllActors.push_back(&anim);*/
2011-11-25 04:13:34 +00:00
}
bool Actors::deleteObject (const MWWorld::Ptr& ptr)
{
delete mAllActors[ptr];
2011-12-25 02:53:12 +00:00
mAllActors.erase(ptr);
2011-11-25 04:13:34 +00:00
if (Ogre::SceneNode *base = ptr.getRefData().getBaseNode())
{
2011-11-25 04:13:34 +00:00
Ogre::SceneNode *parent = base->getParentSceneNode();
for (std::map<MWWorld::Ptr::CellStore *, Ogre::SceneNode *>::const_iterator iter (
mCellSceneNodes.begin()); iter!=mCellSceneNodes.end(); ++iter)
if (iter->second==parent)
{
base->removeAndDestroyAllChildren();
mRend.getScene()->destroySceneNode (base);
ptr.getRefData().setBaseNode (0);
return true;
}
return false;
}
return true;
}
void Actors::removeCell(MWWorld::Ptr::CellStore* store){
if(mCellSceneNodes.find(store) != mCellSceneNodes.end())
{
Ogre::SceneNode* base = mCellSceneNodes[store];
base->removeAndDestroyAllChildren();
mCellSceneNodes.erase(store);
mRend.getScene()->destroySceneNode(base);
base = 0;
}
for(std::map<MWWorld::Ptr, Animation*>::iterator iter = mAllActors.begin(); iter != mAllActors.end(); iter++)
{
if(iter->first.getCell() == store){
delete iter->second;
mAllActors.erase(iter);
}
}
2011-12-27 00:23:46 +00:00
}
void Actors::playAnimationGroup (const MWWorld::Ptr& ptr, const std::string& groupName, int mode, int number){
2011-12-27 22:12:47 +00:00
if(mAllActors.find(ptr) != mAllActors.end())
mAllActors[ptr]->startScript(groupName, mode, number);
2011-12-27 00:23:46 +00:00
}
void Actors::skipAnimation (const MWWorld::Ptr& ptr){
if(mAllActors.find(ptr) != mAllActors.end())
mAllActors[ptr]->stopScript();
2011-12-27 00:23:46 +00:00
}
void Actors::update (float duration){
2011-12-27 00:23:46 +00:00
for(std::map<MWWorld::Ptr, Animation*>::iterator iter = mAllActors.begin(); iter != mAllActors.end(); iter++)
{
(iter->second)->runAnimation(duration);
2011-12-27 00:23:46 +00:00
}
}