Merge branch 'master' into levelup
commit
95f3a20e2c
@ -0,0 +1,135 @@
|
||||
#include "characterpreview.hpp"
|
||||
|
||||
|
||||
#include <OgreSceneManager.h>
|
||||
#include <OgreHardwarePixelBuffer.h>
|
||||
|
||||
#include <libs/openengine/ogre/selectionbuffer.hpp>
|
||||
|
||||
|
||||
#include "../mwbase/environment.hpp"
|
||||
#include "../mwbase/world.hpp"
|
||||
#include "../mwworld/player.hpp"
|
||||
|
||||
#include "renderconst.hpp"
|
||||
#include "npcanimation.hpp"
|
||||
|
||||
namespace MWRender
|
||||
{
|
||||
|
||||
CharacterPreview::CharacterPreview(MWWorld::Ptr character, int sizeX, int sizeY, const std::string& name,
|
||||
Ogre::Vector3 position, Ogre::Vector3 lookAt)
|
||||
: mSizeX(sizeX)
|
||||
, mSizeY(sizeY)
|
||||
, mName(name)
|
||||
, mPosition(position)
|
||||
, mLookAt(lookAt)
|
||||
, mCharacter(character)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void CharacterPreview::onSetup()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void CharacterPreview::setup (Ogre::SceneManager *sceneManager)
|
||||
{
|
||||
mSceneMgr = sceneManager;
|
||||
mCamera = mSceneMgr->createCamera (mName);
|
||||
mCamera->setAspectRatio (float(mSizeX) / float(mSizeY));
|
||||
|
||||
mNode = static_cast<Ogre::SceneNode*>(mSceneMgr->getRootSceneNode()->getChild("mwRoot"))->createChildSceneNode ();
|
||||
|
||||
mAnimation = new NpcAnimation(mCharacter, mNode,
|
||||
MWWorld::Class::get(mCharacter).getInventoryStore (mCharacter), RV_PlayerPreview);
|
||||
|
||||
mNode->setVisible (false);
|
||||
|
||||
mCamera->setPosition(mPosition);
|
||||
mCamera->lookAt(mLookAt);
|
||||
|
||||
mCamera->setNearClipDistance (0.01);
|
||||
mCamera->setFarClipDistance (1000);
|
||||
|
||||
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);
|
||||
|
||||
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");
|
||||
mViewport->setVisibilityMask (RV_PlayerPreview);
|
||||
mRenderTarget->setActive(true);
|
||||
mRenderTarget->setAutoUpdated (false);
|
||||
|
||||
onSetup ();
|
||||
}
|
||||
|
||||
CharacterPreview::~CharacterPreview ()
|
||||
{
|
||||
Ogre::TextureManager::getSingleton().remove(mName);
|
||||
}
|
||||
|
||||
|
||||
// --------------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
InventoryPreview::InventoryPreview(MWWorld::Ptr character)
|
||||
: CharacterPreview(character, 512, 1024, "CharacterPreview", Ogre::Vector3(0, 65, -180), Ogre::Vector3(0,65,0))
|
||||
{
|
||||
}
|
||||
|
||||
InventoryPreview::~InventoryPreview()
|
||||
{
|
||||
delete mSelectionBuffer;
|
||||
}
|
||||
|
||||
void InventoryPreview::update(int sizeX, int sizeY)
|
||||
{
|
||||
mAnimation->forceUpdate ();
|
||||
|
||||
mViewport->setDimensions (0, 0, std::min(1.f, float(sizeX) / float(512)), std::min(1.f, float(sizeY) / float(1024)));
|
||||
|
||||
mNode->setOrientation (Ogre::Quaternion::IDENTITY);
|
||||
|
||||
mNode->setVisible (true);
|
||||
|
||||
mRenderTarget->update();
|
||||
mSelectionBuffer->update();
|
||||
|
||||
mNode->setVisible (false);
|
||||
}
|
||||
|
||||
int InventoryPreview::getSlotSelected (int posX, int posY)
|
||||
{
|
||||
return mSelectionBuffer->getSelected (posX, posY);
|
||||
}
|
||||
|
||||
void InventoryPreview::onSetup ()
|
||||
{
|
||||
mSelectionBuffer = new OEngine::Render::SelectionBuffer(mCamera, 512, 1024, RV_PlayerPreview);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------------------------------
|
||||
|
||||
RaceSelectionPreview::RaceSelectionPreview()
|
||||
: CharacterPreview(MWBase::Environment::get().getWorld()->getPlayer().getPlayer(),
|
||||
512, 512, "CharacterHeadPreview", Ogre::Vector3(0, 120, -35), Ogre::Vector3(0,125,0))
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void RaceSelectionPreview::update(float angle)
|
||||
{
|
||||
mNode->roll(Ogre::Radian(angle), Ogre::SceneNode::TS_LOCAL);
|
||||
|
||||
mNode->setVisible (true);
|
||||
mRenderTarget->update();
|
||||
mNode->setVisible (false);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,88 @@
|
||||
#ifndef MWRENDER_CHARACTERPREVIEW_H
|
||||
#define MWRENDER_CHARACTERPREVIEW_H
|
||||
|
||||
#include <OgreRenderTarget.h>
|
||||
#include <OgreMaterialManager.h>
|
||||
|
||||
|
||||
#include "externalrendering.hpp"
|
||||
|
||||
#include "../mwworld/ptr.hpp"
|
||||
|
||||
namespace OEngine
|
||||
{
|
||||
namespace Render
|
||||
{
|
||||
class SelectionBuffer;
|
||||
}
|
||||
}
|
||||
|
||||
namespace MWRender
|
||||
{
|
||||
|
||||
class NpcAnimation;
|
||||
|
||||
class CharacterPreview : public ExternalRendering
|
||||
{
|
||||
public:
|
||||
CharacterPreview(MWWorld::Ptr character, int sizeX, int sizeY, const std::string& name,
|
||||
Ogre::Vector3 position, Ogre::Vector3 lookAt);
|
||||
virtual ~CharacterPreview();
|
||||
|
||||
virtual void setup (Ogre::SceneManager *sceneManager);
|
||||
virtual void onSetup();
|
||||
|
||||
|
||||
protected:
|
||||
Ogre::TexturePtr mTexture;
|
||||
Ogre::RenderTarget* mRenderTarget;
|
||||
Ogre::Viewport* mViewport;
|
||||
|
||||
Ogre::Camera* mCamera;
|
||||
|
||||
Ogre::SceneManager* mSceneMgr;
|
||||
Ogre::SceneNode* mNode;
|
||||
|
||||
Ogre::Vector3 mPosition;
|
||||
Ogre::Vector3 mLookAt;
|
||||
|
||||
MWWorld::Ptr mCharacter;
|
||||
|
||||
MWRender::NpcAnimation* mAnimation;
|
||||
|
||||
std::string mName;
|
||||
|
||||
int mSizeX;
|
||||
int mSizeY;
|
||||
};
|
||||
|
||||
class InventoryPreview : public CharacterPreview
|
||||
{
|
||||
public:
|
||||
|
||||
InventoryPreview(MWWorld::Ptr character);
|
||||
virtual ~InventoryPreview();
|
||||
virtual void onSetup();
|
||||
|
||||
void update(int sizeX, int sizeY);
|
||||
|
||||
int getSlotSelected(int posX, int posY);
|
||||
|
||||
void setNpcAnimation (NpcAnimation* anim);
|
||||
|
||||
private:
|
||||
|
||||
OEngine::Render::SelectionBuffer* mSelectionBuffer;
|
||||
};
|
||||
|
||||
class RaceSelectionPreview : public CharacterPreview
|
||||
{
|
||||
public:
|
||||
RaceSelectionPreview();
|
||||
|
||||
void update(float angle);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
@ -0,0 +1,23 @@
|
||||
#ifndef GAME_RENDERING_EXTERNALRENDERING_H
|
||||
#define GAME_RENDERING_EXTERNALRENDERING_H
|
||||
|
||||
namespace Ogre
|
||||
{
|
||||
class SceneManager;
|
||||
}
|
||||
|
||||
namespace MWRender
|
||||
{
|
||||
/// \brief Base class for out of world rendering
|
||||
class ExternalRendering
|
||||
{
|
||||
public:
|
||||
|
||||
virtual void setup (Ogre::SceneManager *sceneManager) = 0;
|
||||
|
||||
virtual ~ExternalRendering() {}
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -1 +1 @@
|
||||
Subproject commit 7168415233905de2864eec71ed4312cb8f83059b
|
||||
Subproject commit 4750676ac46a7aaa86bca53dc68c5a1ba11f3bc1
|
@ -0,0 +1,8 @@
|
||||
material SelectionColour
|
||||
{
|
||||
pass
|
||||
{
|
||||
vertex_program selection_vertex
|
||||
fragment_program selection_fragment
|
||||
}
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
#include "core.h"
|
||||
|
||||
#ifdef SH_VERTEX_SHADER
|
||||
|
||||
SH_BEGIN_PROGRAM
|
||||
shUniform(float4x4, wvp) @shAutoConstant(wvp, worldviewproj_matrix)
|
||||
|
||||
SH_START_PROGRAM
|
||||
{
|
||||
shOutputPosition = shMatrixMult(wvp, shInputPosition);
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
SH_BEGIN_PROGRAM
|
||||
shUniform(float4, colour) @shAutoConstant(colour, custom, 1)
|
||||
|
||||
SH_START_PROGRAM
|
||||
{
|
||||
shOutputColour(0) = colour;
|
||||
//shOutputColour(0) = float4(1,0,0,1);
|
||||
}
|
||||
|
||||
#endif
|
@ -0,0 +1,15 @@
|
||||
shader_set selection_vertex
|
||||
{
|
||||
source selection.shader
|
||||
type vertex
|
||||
profiles_cg vs_2_0 arbvp1
|
||||
profiles_hlsl vs_2_0
|
||||
}
|
||||
|
||||
shader_set selection_fragment
|
||||
{
|
||||
source selection.shader
|
||||
type fragment
|
||||
profiles_cg ps_2_x ps_2_0 ps arbfp1
|
||||
profiles_hlsl ps_2_0
|
||||
}
|
@ -0,0 +1,122 @@
|
||||
#include "selectionbuffer.hpp"
|
||||
|
||||
#include <OgreHardwarePixelBuffer.h>
|
||||
#include <OgreRenderTexture.h>
|
||||
#include <OgreSubEntity.h>
|
||||
#include <OgreEntity.h>
|
||||
|
||||
#include <extern/shiny/Main/Factory.hpp>
|
||||
|
||||
namespace OEngine
|
||||
{
|
||||
namespace Render
|
||||
{
|
||||
|
||||
SelectionBuffer::SelectionBuffer(Ogre::Camera *camera, int sizeX, int sizeY, int visibilityFlags)
|
||||
{
|
||||
mTexture = Ogre::TextureManager::getSingleton().createManual("SelectionBuffer",
|
||||
Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, Ogre::TEX_TYPE_2D, sizeX, sizeY, 0, Ogre::PF_R8G8B8, Ogre::TU_RENDERTARGET);
|
||||
|
||||
mRenderTarget = mTexture->getBuffer()->getRenderTarget();
|
||||
Ogre::Viewport* vp = mRenderTarget->addViewport(camera);
|
||||
vp->setOverlaysEnabled(false);
|
||||
vp->setBackgroundColour(Ogre::ColourValue(0, 0, 0, 0));
|
||||
vp->setShadowsEnabled(false);
|
||||
vp->setMaterialScheme("selectionbuffer");
|
||||
vp->setVisibilityMask (visibilityFlags);
|
||||
mRenderTarget->setActive(true);
|
||||
mRenderTarget->setAutoUpdated (false);
|
||||
|
||||
mCurrentColour = Ogre::ColourValue(0.3, 0.3, 0.3);
|
||||
}
|
||||
|
||||
SelectionBuffer::~SelectionBuffer()
|
||||
{
|
||||
Ogre::TextureManager::getSingleton ().remove("SelectionBuffer");
|
||||
}
|
||||
|
||||
void SelectionBuffer::update ()
|
||||
{
|
||||
Ogre::MaterialManager::getSingleton ().addListener (this);
|
||||
|
||||
mRenderTarget->update();
|
||||
|
||||
Ogre::MaterialManager::getSingleton ().removeListener (this);
|
||||
|
||||
mTexture->convertToImage(mBuffer);
|
||||
}
|
||||
|
||||
int SelectionBuffer::getSelected(int xPos, int yPos)
|
||||
{
|
||||
Ogre::ColourValue clr = mBuffer.getColourAt (xPos, yPos, 0);
|
||||
clr.a = 1;
|
||||
if (mColourMap.find(clr) != mColourMap.end())
|
||||
return mColourMap[clr];
|
||||
else
|
||||
return -1; // nothing selected
|
||||
}
|
||||
|
||||
Ogre::Technique* SelectionBuffer::handleSchemeNotFound (
|
||||
unsigned short schemeIndex, const Ogre::String &schemeName, Ogre::Material *originalMaterial,
|
||||
unsigned short lodIndex, const Ogre::Renderable *rend)
|
||||
{
|
||||
if (schemeName == "selectionbuffer")
|
||||
{
|
||||
sh::Factory::getInstance ()._ensureMaterial ("SelectionColour", "Default");
|
||||
|
||||
Ogre::MaterialPtr m = Ogre::MaterialManager::getSingleton ().getByName("SelectionColour");
|
||||
|
||||
|
||||
if(typeid(*rend) == typeid(Ogre::SubEntity))
|
||||
{
|
||||
const Ogre::SubEntity *subEntity = static_cast<const Ogre::SubEntity *>(rend);
|
||||
int id = Ogre::any_cast<int>(subEntity->getParent ()->getUserObjectBindings().getUserAny());
|
||||
bool found = false;
|
||||
Ogre::ColourValue colour;
|
||||
for (std::map<Ogre::ColourValue, int>::iterator it = mColourMap.begin(); it != mColourMap.end(); ++it)
|
||||
{
|
||||
if (it->second == id)
|
||||
{
|
||||
found = true;
|
||||
colour = it->first;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (!found)
|
||||
{
|
||||
getNextColour();
|
||||
const_cast<Ogre::SubEntity *>(subEntity)->setCustomParameter(1, Ogre::Vector4(mCurrentColour.r, mCurrentColour.g, mCurrentColour.b, 1.0));
|
||||
mColourMap[mCurrentColour] = id;
|
||||
}
|
||||
else
|
||||
{
|
||||
const_cast<Ogre::SubEntity *>(subEntity)->setCustomParameter(1, Ogre::Vector4(colour.r, colour.g, colour.b, 1.0));
|
||||
}
|
||||
|
||||
assert(m->getTechnique(1));
|
||||
return m->getTechnique(1);
|
||||
}
|
||||
else
|
||||
throw std::runtime_error("selectionbuffer only works with entities");
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void SelectionBuffer::getNextColour ()
|
||||
{
|
||||
Ogre::ARGB color = (float(rand()) / float(RAND_MAX)) * std::numeric_limits<Ogre::uint32>::max();
|
||||
|
||||
if (mCurrentColour.getAsARGB () == color)
|
||||
{
|
||||
getNextColour();
|
||||
return;
|
||||
}
|
||||
|
||||
mCurrentColour.setAsARGB(color);
|
||||
mCurrentColour.a = 1;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,54 @@
|
||||
#ifndef OENGINE_SELECTIONBUFFER_H
|
||||
#define OENGINE_SELECTIONBUFFER_H
|
||||
|
||||
|
||||
#include <OgreTexture.h>
|
||||
#include <OgreRenderTarget.h>
|
||||
#include <OgreMaterialManager.h>
|
||||
|
||||
namespace OEngine
|
||||
{
|
||||
namespace Render
|
||||
{
|
||||
|
||||
struct cmp_ColourValue
|
||||
{
|
||||
bool operator()(const Ogre::ColourValue &a, const Ogre::ColourValue &b) const
|
||||
{
|
||||
return a.getAsBGRA() < b.getAsBGRA();
|
||||
}
|
||||
};
|
||||
|
||||
class SelectionBuffer : public Ogre::MaterialManager::Listener
|
||||
{
|
||||
public:
|
||||
SelectionBuffer(Ogre::Camera* camera, int sizeX, int sizeY, int visibilityFlags);
|
||||
virtual ~SelectionBuffer();
|
||||
|
||||
int getSelected(int xPos, int yPos);
|
||||
///< @return ID of the selected object
|
||||
|
||||
void update();
|
||||
|
||||
virtual Ogre::Technique* handleSchemeNotFound (
|
||||
unsigned short schemeIndex, const Ogre::String &schemeName, Ogre::Material *originalMaterial,
|
||||
unsigned short lodIndex, const Ogre::Renderable *rend);
|
||||
|
||||
|
||||
private:
|
||||
Ogre::TexturePtr mTexture;
|
||||
Ogre::RenderTexture* mRenderTarget;
|
||||
|
||||
Ogre::Image mBuffer;
|
||||
|
||||
std::map<Ogre::ColourValue, int, cmp_ColourValue> mColourMap;
|
||||
|
||||
Ogre::ColourValue mCurrentColour;
|
||||
|
||||
void getNextColour();
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue