openmw-tes3coop/apps/openmw/mwrender/characterpreview.cpp

93 lines
2.9 KiB
C++
Raw Normal View History

2012-09-12 22:54:32 +00:00
#include "characterpreview.hpp"
#include <OgreSceneManager.h>
#include <OgreHardwarePixelBuffer.h>
#include "renderconst.hpp"
2012-09-13 17:03:31 +00:00
#include "npcanimation.hpp"
2012-09-12 22:54:32 +00:00
namespace MWRender
{
2012-09-13 17:03:31 +00:00
CharacterPreview::CharacterPreview(Ogre::SceneManager *sceneMgr, Ogre::SceneNode *node, int sizeX, int sizeY, const std::string& name,
Ogre::Vector3 position, Ogre::Vector3 lookAt)
2012-09-12 22:54:32 +00:00
: mSceneMgr(sceneMgr)
2012-09-13 17:03:31 +00:00
, mSizeX(sizeX)
, mSizeY(sizeY)
2012-09-12 22:54:32 +00:00
{
2012-09-13 17:03:31 +00:00
mCamera = mSceneMgr->createCamera (name);
mCamera->setAspectRatio (float(sizeX) / float(sizeY));
2012-09-12 22:54:32 +00:00
2012-09-13 17:03:31 +00:00
mNode = node;
mNode->setVisible (false);
2012-09-12 22:54:32 +00:00
2012-09-13 17:03:31 +00:00
mCamera->setPosition(position);
mCamera->lookAt(lookAt);
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
2012-09-13 17:03:31 +00:00
mTexture = Ogre::TextureManager::getSingleton().createManual(name,
Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, Ogre::TEX_TYPE_2D, sizeX, sizeY, 0, Ogre::PF_A8R8G8B8, Ogre::TU_RENDERTARGET);
2012-09-12 22:54:32 +00:00
mRenderTarget = mTexture->getBuffer()->getRenderTarget();
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);
}
2012-09-13 17:03:31 +00:00
// --------------------------------------------------------------------------------------------------
InventoryPreview::InventoryPreview(Ogre::SceneManager *sceneMgr, Ogre::SceneNode *node)
: CharacterPreview(sceneMgr, node, 512, 1024, "CharacterPreview", Ogre::Vector3(0, 65, -180), Ogre::Vector3(0,65,0))
, mAnimation(NULL)
{
}
void InventoryPreview::update(int sizeX, int sizeY)
2012-09-12 22:54:32 +00:00
{
2012-09-13 17:03:31 +00:00
if (mAnimation)
mAnimation->forceUpdate ();
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-12 22:54:32 +00:00
mRenderTarget->update();
2012-09-13 17:03:31 +00:00
mNode->setVisible (false);
}
void InventoryPreview::setNpcAnimation (NpcAnimation *anim)
{
mAnimation = anim;
}
// --------------------------------------------------------------------------------------------------
RaceSelectionPreview::RaceSelectionPreview(Ogre::SceneManager *sceneMgr, Ogre::SceneNode *node)
: CharacterPreview(sceneMgr, node, 512, 512, "CharacterHeadPreview", Ogre::Vector3(0, 120, -35), Ogre::Vector3(0,125,0))
{
2012-09-12 22:54:32 +00:00
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
}
}