1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-01-16 11:19:55 +00:00
openmw-tes3mp/apps/openmw/mwrender/characterpreview.cpp

179 lines
5.4 KiB
C++
Raw Normal View History

2012-09-12 22:54:32 +00:00
#include "characterpreview.hpp"
#include <OgreSceneManager.h>
#include <OgreRoot.h>
2012-09-12 22:54:32 +00:00
#include <OgreHardwarePixelBuffer.h>
2012-09-14 12:34:18 +00:00
#include <libs/openengine/ogre/selectionbuffer.hpp>
2012-09-12 22:54:32 +00:00
#include "../mwbase/environment.hpp"
#include "../mwbase/world.hpp"
#include "../mwworld/player.hpp"
#include "../mwworld/class.hpp"
2012-09-12 22:54:32 +00:00
#include "renderconst.hpp"
2012-09-13 17:03:31 +00:00
#include "npcanimation.hpp"
2012-09-12 22:54:32 +00:00
namespace MWRender
{
CharacterPreview::CharacterPreview(MWWorld::Ptr character, int sizeX, int sizeY, const std::string& name,
2012-09-13 17:03:31 +00:00
Ogre::Vector3 position, Ogre::Vector3 lookAt)
: mSizeX(sizeX)
2012-09-13 17:03:31 +00:00
, mSizeY(sizeY)
, mName(name)
, mPosition(position)
, mLookAt(lookAt)
, mCharacter(character)
2012-09-23 22:42:05 +00:00
, mAnimation(NULL)
{
}
void CharacterPreview::onSetup()
2012-09-12 22:54:32 +00:00
{
}
void CharacterPreview::setup ()
{
mSceneMgr = Ogre::Root::getSingleton().createSceneManager(Ogre::ST_GENERIC);
mCamera = mSceneMgr->createCamera (mName);
mCamera->setAspectRatio (float(mSizeX) / float(mSizeY));
Ogre::SceneNode* renderRoot = mSceneMgr->getRootSceneNode()->createChildSceneNode("renderRoot");
//we do this with mwRoot in renderingManager, do it here too.
renderRoot->pitch(Ogre::Degree(-90));
mNode = renderRoot->createChildSceneNode();
mAnimation = new NpcAnimation(mCharacter, mNode,
MWWorld::Class::get(mCharacter).getInventoryStore (mCharacter), RV_PlayerPreview);
2012-09-13 17:03:31 +00:00
mNode->setVisible (false);
2012-09-12 22:54:32 +00:00
Ogre::Vector3 scale = mNode->getScale();
mCamera->setPosition(mPosition * scale);
mCamera->lookAt(mLookAt * scale);
2012-09-12 22:54:32 +00:00
2012-09-13 17:03:31 +00:00
mCamera->setNearClipDistance (0.01);
mCamera->setFarClipDistance (1000);
2012-09-12 22:54:32 +00:00
mTexture = Ogre::TextureManager::getSingleton().getByName (mName);
if (mTexture.isNull ())
mTexture = Ogre::TextureManager::getSingleton().createManual(mName,
Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, Ogre::TEX_TYPE_2D, mSizeX, mSizeY, 0, Ogre::PF_A8R8G8B8, Ogre::TU_RENDERTARGET);
2012-09-12 22:54:32 +00:00
mRenderTarget = mTexture->getBuffer()->getRenderTarget();
mRenderTarget->removeAllViewports ();
2012-09-12 22:54:32 +00:00
mViewport = mRenderTarget->addViewport(mCamera);
mViewport->setOverlaysEnabled(false);
mViewport->setBackgroundColour(Ogre::ColourValue(0, 0, 0, 0));
mViewport->setShadowsEnabled(false);
mViewport->setMaterialScheme("local_map");
2012-09-13 17:03:31 +00:00
mViewport->setVisibilityMask (RV_PlayerPreview);
2012-09-12 22:54:32 +00:00
mRenderTarget->setActive(true);
mRenderTarget->setAutoUpdated (false);
onSetup ();
}
CharacterPreview::~CharacterPreview ()
{
2012-09-23 23:07:33 +00:00
//Ogre::TextureManager::getSingleton().remove(mName);
mSceneMgr->destroyCamera (mName);
delete mAnimation;
Ogre::Root::getSingleton().destroySceneManager(mSceneMgr);
2012-09-12 22:54:32 +00:00
}
void CharacterPreview::rebuild()
{
assert(mAnimation);
delete mAnimation;
mAnimation = new NpcAnimation(mCharacter, mNode,
MWWorld::Class::get(mCharacter).getInventoryStore (mCharacter), RV_PlayerPreview);
mNode->setVisible (false);
Ogre::Vector3 scale = mNode->getScale();
mCamera->setPosition(mPosition * scale);
mCamera->lookAt(mLookAt * scale);
onSetup();
}
2012-09-13 17:03:31 +00:00
// --------------------------------------------------------------------------------------------------
InventoryPreview::InventoryPreview(MWWorld::Ptr character)
: CharacterPreview(character, 512, 1024, "CharacterPreview", Ogre::Vector3(0, 65, -180), Ogre::Vector3(0,65,0))
2012-09-13 17:03:31 +00:00
{
2012-09-14 12:34:18 +00:00
}
2012-09-13 17:03:31 +00:00
2012-09-14 12:34:18 +00:00
InventoryPreview::~InventoryPreview()
{
delete mSelectionBuffer;
2012-09-13 17:03:31 +00:00
}
void InventoryPreview::update(int sizeX, int sizeY)
2012-09-12 22:54:32 +00:00
{
mAnimation->runAnimation(0.0f);
mAnimation->forceUpdate();
2012-09-13 17:03:31 +00:00
2012-09-13 12:56:50 +00:00
mViewport->setDimensions (0, 0, std::min(1.f, float(sizeX) / float(512)), std::min(1.f, float(sizeY) / float(1024)));
2012-09-12 22:54:32 +00:00
2012-09-13 17:03:31 +00:00
mNode->setOrientation (Ogre::Quaternion::IDENTITY);
mNode->setVisible (true);
2012-09-14 12:34:18 +00:00
2012-09-12 22:54:32 +00:00
mRenderTarget->update();
2012-09-14 12:34:18 +00:00
mSelectionBuffer->update();
2012-09-13 17:03:31 +00:00
mNode->setVisible (false);
}
int InventoryPreview::getSlotSelected (int posX, int posY)
2012-09-13 17:03:31 +00:00
{
return mSelectionBuffer->getSelected (posX, posY);
2012-09-13 17:03:31 +00:00
}
void InventoryPreview::onSetup ()
2012-09-14 12:34:18 +00:00
{
mSelectionBuffer = new OEngine::Render::SelectionBuffer(mCamera, 512, 1024, RV_PlayerPreview);
2013-01-22 06:51:13 +00:00
mAnimation->play("inventoryhandtohand", "start", false);
2012-09-14 12:34:18 +00:00
}
2012-09-13 17:03:31 +00:00
// --------------------------------------------------------------------------------------------------
RaceSelectionPreview::RaceSelectionPreview()
: CharacterPreview(MWBase::Environment::get().getWorld()->getPlayer().getPlayer(),
512, 512, "CharacterHeadPreview", Ogre::Vector3(0, 120, -35), Ogre::Vector3(0,125,0))
, mRef(&mBase)
2012-09-13 17:03:31 +00:00
{
mBase = *mCharacter.get<ESM::NPC>()->mBase;
mCharacter = MWWorld::Ptr(&mRef, mCharacter.getCell());
2012-09-13 17:03:31 +00:00
}
void RaceSelectionPreview::update(float angle)
{
mNode->roll(Ogre::Radian(angle), Ogre::SceneNode::TS_LOCAL);
mNode->setVisible (true);
mRenderTarget->update();
mNode->setVisible (false);
2012-09-12 22:54:32 +00:00
}
void RaceSelectionPreview::setPrototype(const ESM::NPC &proto)
{
mBase = proto;
mBase.mId = "player";
rebuild();
update(0);
}
2012-09-12 22:54:32 +00:00
}