1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-01-16 07:49:56 +00:00
openmw-tes3mp/apps/openmw/mwrender/renderingmanager.cpp

421 lines
11 KiB
C++
Raw Normal View History

2011-10-20 19:02:19 +00:00
#include "renderingmanager.hpp"
#include <assert.h>
#include "OgreRoot.h"
#include "OgreRenderWindow.h"
#include "OgreSceneManager.h"
#include "OgreViewport.h"
#include "OgreCamera.h"
#include "OgreTextureManager.h"
#include "../mwworld/world.hpp" // these includes can be removed once the static-hack is gone
#include "../mwworld/ptr.hpp"
#include <components/esm/loadstat.hpp>
#include <components/settings/settings.hpp>
2011-11-01 03:59:16 +00:00
using namespace MWRender;
using namespace Ogre;
2011-10-20 19:02:19 +00:00
namespace MWRender {
2011-12-09 05:08:30 +00:00
RenderingManager::RenderingManager (OEngine::Render::OgreRenderer& _rend, const boost::filesystem::path& resDir, OEngine::Physic::PhysicEngine* engine, MWWorld::Environment& environment)
:mRendering(_rend), mObjects(mRendering), mActors(mRendering, environment), mAmbientMode(0)
2011-10-20 19:02:19 +00:00
{
2011-11-22 07:39:28 +00:00
mRendering.createScene("PlayerCam", 55, 5);
mTerrainManager = new TerrainManager(mRendering.getScene(),
environment);
//The fog type must be set before any terrain objects are created as if the
//fog type is set to FOG_NONE then the initially created terrain won't have any fog
configureFog(1, ColourValue(1,1,1));
// Set default mipmap level (NB some APIs ignore this)
TextureManager::getSingleton().setDefaultNumMipmaps(5);
// Load resources
ResourceGroupManager::getSingleton().initialiseAllResourceGroups();
// Turn the entire scene (represented by the 'root' node) -90
// degrees around the x axis. This makes Z go upwards, and Y go into
// the screen (when x is to the right.) This is the orientation that
// Morrowind uses, and it automagically makes everything work as it
// should.
2011-11-22 07:39:28 +00:00
SceneNode *rt = mRendering.getScene()->getRootSceneNode();
mMwRoot = rt->createChildSceneNode();
mMwRoot->pitch(Degree(-90));
mObjects.setMwRoot(mMwRoot);
2011-11-25 04:13:34 +00:00
mActors.setMwRoot(mMwRoot);
2011-11-22 07:39:28 +00:00
Ogre::SceneNode *playerNode = mMwRoot->createChildSceneNode ("player");
playerNode->pitch(Degree(90));
Ogre::SceneNode *cameraYawNode = playerNode->createChildSceneNode();
Ogre::SceneNode *cameraPitchNode = cameraYawNode->createChildSceneNode();
2011-11-22 07:39:28 +00:00
cameraPitchNode->attachObject(mRendering.getCamera());
//mSkyManager = 0;
2012-03-16 18:02:33 +00:00
mSkyManager = new SkyManager(mMwRoot, mRendering.getCamera(), &environment);
mOcclusionQuery = new OcclusionQuery(&mRendering, mSkyManager->getSunNode());
2012-01-22 20:02:38 +00:00
2012-01-20 04:29:07 +00:00
mWater = 0;
2011-11-02 04:13:33 +00:00
2011-11-22 07:39:28 +00:00
mPlayer = new MWRender::Player (mRendering.getCamera(), playerNode);
2012-02-07 23:32:22 +00:00
mSun = 0;
mDebugging = new Debugging(mMwRoot, environment, engine);
2012-04-02 17:37:24 +00:00
mLocalMap = new MWRender::LocalMap(&mRendering, this, &environment);
2011-10-20 19:02:19 +00:00
}
RenderingManager::~RenderingManager ()
{
2012-02-07 23:32:22 +00:00
//TODO: destroy mSun?
delete mPlayer;
2011-10-20 19:02:19 +00:00
delete mSkyManager;
delete mDebugging;
delete mTerrainManager;
delete mLocalMap;
delete mOcclusionQuery;
2011-10-20 19:02:19 +00:00
}
MWRender::SkyManager* RenderingManager::getSkyManager()
{
return mSkyManager;
2011-11-01 03:59:16 +00:00
}
2011-11-01 03:59:16 +00:00
MWRender::Objects& RenderingManager::getObjects(){
2011-11-22 07:39:28 +00:00
return mObjects;
2011-11-01 03:59:16 +00:00
}
MWRender::Actors& RenderingManager::getActors(){
return mActors;
2011-11-01 03:59:16 +00:00
}
2011-11-01 17:46:57 +00:00
MWRender::Player& RenderingManager::getPlayer(){
return (*mPlayer);
2011-11-01 03:59:16 +00:00
}
OEngine::Render::Fader* RenderingManager::getFader()
{
return mRendering.getFader();
}
void RenderingManager::removeCell (MWWorld::Ptr::CellStore *store)
{
mObjects.removeCell(store);
2011-11-25 04:13:34 +00:00
mActors.removeCell(store);
mDebugging->cellRemoved(store);
if (store->cell->isExterior())
mTerrainManager->cellRemoved(store);
2012-01-22 01:05:08 +00:00
}
void RenderingManager::removeWater ()
{
2012-01-20 04:29:07 +00:00
if(mWater){
2012-04-03 13:13:47 +00:00
mWater->setActive(false);
2012-01-20 04:29:07 +00:00
}
2011-10-20 19:02:19 +00:00
}
void RenderingManager::toggleWater()
{
if (mWater)
mWater->toggle();
}
void RenderingManager::cellAdded (MWWorld::Ptr::CellStore *store)
{
2011-11-22 07:39:28 +00:00
mObjects.buildStaticGeometry (*store);
mDebugging->cellAdded(store);
if (store->cell->isExterior())
mTerrainManager->cellAdded(store);
2012-04-03 14:53:33 +00:00
waterAdded(store);
}
2011-11-11 05:20:53 +00:00
void RenderingManager::addObject (const MWWorld::Ptr& ptr){
2011-11-16 21:22:13 +00:00
const MWWorld::Class& class_ =
MWWorld::Class::get (ptr);
class_.insertObjectRendering(ptr, *this);
2011-10-20 19:02:19 +00:00
}
void RenderingManager::removeObject (const MWWorld::Ptr& ptr)
{
2011-11-22 07:39:28 +00:00
if (!mObjects.deleteObject (ptr))
{
/// \todo delete non-object MW-references
}
2011-11-25 04:13:34 +00:00
if (!mActors.deleteObject (ptr))
{
/// \todo delete non-object MW-references
}
}
2011-10-20 19:02:19 +00:00
void RenderingManager::moveObject (const MWWorld::Ptr& ptr, const Ogre::Vector3& position)
{
/// \todo move this to the rendering-subsystems
2011-11-22 07:39:28 +00:00
mRendering.getScene()->getSceneNode (ptr.getRefData().getHandle())->
setPosition (position);
2011-10-20 19:02:19 +00:00
}
2011-10-20 19:02:19 +00:00
void RenderingManager::scaleObject (const MWWorld::Ptr& ptr, const Ogre::Vector3& scale){
}
void RenderingManager::rotateObject (const MWWorld::Ptr& ptr, const::Ogre::Quaternion& orientation){
}
void RenderingManager::moveObjectToCell (const MWWorld::Ptr& ptr, const Ogre::Vector3& position, MWWorld::Ptr::CellStore *store){
}
void RenderingManager::update (float duration){
mActors.update (duration);
2012-03-25 22:31:03 +00:00
mOcclusionQuery->update(duration);
mSkyManager->update(duration);
mSkyManager->setGlare(mOcclusionQuery->getSunVisibility());
mRendering.update(duration);
2012-03-14 13:51:58 +00:00
mLocalMap->updatePlayer( mRendering.getCamera()->getRealPosition(), mRendering.getCamera()->getRealOrientation() );
checkUnderwater();
2012-01-20 04:29:07 +00:00
}
2012-01-22 20:02:38 +00:00
void RenderingManager::waterAdded (MWWorld::Ptr::CellStore *store){
2012-01-22 01:05:08 +00:00
if(store->cell->data.flags & store->cell->HasWater){
if(mWater == 0)
2012-03-19 01:31:31 +00:00
mWater = new MWRender::Water(mRendering.getCamera(), store->cell);
2012-01-22 21:38:10 +00:00
else
mWater->changeCell(store->cell);
2012-04-03 13:13:47 +00:00
mWater->setActive(true);
2012-01-22 01:05:08 +00:00
}
2012-01-22 21:38:10 +00:00
else
removeWater();
2011-10-20 19:02:19 +00:00
}
2012-03-29 13:49:24 +00:00
void RenderingManager::setWaterHeight(const float height)
{
if (mWater)
mWater->setHeight(height);
}
2011-10-20 19:02:19 +00:00
void RenderingManager::skyEnable ()
{
if(mSkyManager)
2011-10-20 19:02:19 +00:00
mSkyManager->enable();
mOcclusionQuery->setSunNode(mSkyManager->getSunNode());
2011-10-20 19:02:19 +00:00
}
void RenderingManager::skyDisable ()
{
if(mSkyManager)
mSkyManager->disable();
2011-10-20 19:02:19 +00:00
}
void RenderingManager::skySetHour (double hour)
{
if(mSkyManager)
mSkyManager->setHour(hour);
2011-10-20 19:02:19 +00:00
}
void RenderingManager::skySetDate (int day, int month)
{
if(mSkyManager)
mSkyManager->setDate(day, month);
2011-10-20 19:02:19 +00:00
}
int RenderingManager::skyGetMasserPhase() const
{
2011-10-20 19:02:19 +00:00
return mSkyManager->getMasserPhase();
}
int RenderingManager::skyGetSecundaPhase() const
{
return mSkyManager->getSecundaPhase();
}
void RenderingManager::skySetMoonColour (bool red){
if(mSkyManager)
mSkyManager->setMoonColour(red);
2011-10-20 19:02:19 +00:00
}
2012-02-18 15:06:03 +00:00
bool RenderingManager::toggleRenderMode(int mode)
{
if (mode != MWWorld::World::Render_Wireframe)
return mDebugging->toggleRenderMode(mode);
2012-02-18 15:06:03 +00:00
else // if (mode == MWWorld::World::Render_Wireframe)
{
if (mRendering.getCamera()->getPolygonMode() == PM_SOLID)
{
mRendering.getCamera()->setPolygonMode(PM_WIREFRAME);
return true;
}
else
{
mRendering.getCamera()->setPolygonMode(PM_SOLID);
return false;
}
}
2011-10-30 04:25:29 +00:00
}
2011-10-20 19:02:19 +00:00
2011-11-04 03:47:15 +00:00
void RenderingManager::configureFog(ESMS::CellStore<MWWorld::RefData> &mCell)
{
Ogre::ColourValue color;
color.setAsABGR (mCell.cell->ambi.fog);
2012-02-26 12:13:29 +00:00
configureFog(mCell.cell->ambi.fogDensity, color);
}
2011-11-04 03:47:15 +00:00
2012-02-26 12:13:29 +00:00
void RenderingManager::configureFog(const float density, const Ogre::ColourValue& colour)
{
float max = Settings::Manager::getFloat("max viewing distance", "Viewing distance");
float low = max / (density) * Settings::Manager::getFloat("fog start factor", "Viewing distance");
float high = max / (density) * Settings::Manager::getFloat("fog end factor", "Viewing distance");
2012-02-26 12:13:29 +00:00
mRendering.getScene()->setFog (FOG_LINEAR, colour, 0, low, high);
mRendering.getCamera()->setFarClipDistance ( max / density );
2012-02-26 12:13:29 +00:00
mRendering.getViewport()->setBackgroundColour (colour);
2011-11-04 03:47:15 +00:00
}
2012-02-26 12:13:29 +00:00
2011-11-04 03:47:15 +00:00
void RenderingManager::setAmbientMode()
{
switch (mAmbientMode)
{
case 0:
setAmbientColour(mAmbientColor);
2011-11-04 03:47:15 +00:00
break;
case 1:
setAmbientColour(0.7f*mAmbientColor + 0.3f*ColourValue(1,1,1));
2011-11-04 03:47:15 +00:00
break;
case 2:
setAmbientColour(ColourValue(1,1,1));
2011-11-04 03:47:15 +00:00
break;
}
}
void RenderingManager::configureAmbient(ESMS::CellStore<MWWorld::RefData> &mCell)
{
mAmbientColor.setAsABGR (mCell.cell->ambi.ambient);
setAmbientMode();
// Create a "sun" that shines light downwards. It doesn't look
// completely right, but leave it for now.
2012-02-07 23:32:22 +00:00
if(!mSun)
{
mSun = mRendering.getScene()->createLight();
}
2011-11-04 03:47:15 +00:00
Ogre::ColourValue colour;
colour.setAsABGR (mCell.cell->ambi.sunlight);
2012-02-07 23:32:22 +00:00
mSun->setDiffuseColour (colour);
mSun->setType(Ogre::Light::LT_DIRECTIONAL);
mSun->setDirection(0,-1,0);
2011-11-04 03:47:15 +00:00
}
// Switch through lighting modes.
void RenderingManager::toggleLight()
{
if (mAmbientMode==2)
mAmbientMode = 0;
else
++mAmbientMode;
switch (mAmbientMode)
{
case 0: std::cout << "Setting lights to normal\n"; break;
case 1: std::cout << "Turning the lights up\n"; break;
case 2: std::cout << "Turning the lights to full\n"; break;
}
setAmbientMode();
}
void RenderingManager::checkUnderwater(){
2012-01-20 04:29:07 +00:00
if(mWater){
mWater->checkUnderwater( mRendering.getCamera()->getRealPosition().y );
2012-01-20 04:29:07 +00:00
}
2012-01-19 03:42:07 +00:00
}
2011-11-04 03:47:15 +00:00
void RenderingManager::playAnimationGroup (const MWWorld::Ptr& ptr, const std::string& groupName,
int mode, int number)
{
2011-12-27 00:23:46 +00:00
mActors.playAnimationGroup(ptr, groupName, mode, number);
}
2011-11-17 22:10:27 +00:00
void RenderingManager::skipAnimation (const MWWorld::Ptr& ptr)
{
mActors.skipAnimation(ptr);
}
2011-11-17 22:10:27 +00:00
void RenderingManager::setSunColour(const Ogre::ColourValue& colour)
{
mSun->setDiffuseColour(colour);
mTerrainManager->setDiffuse(colour);
}
void RenderingManager::setAmbientColour(const Ogre::ColourValue& colour)
{
mRendering.getScene()->setAmbientLight(colour);
mTerrainManager->setAmbient(colour);
2011-10-20 19:02:19 +00:00
}
void RenderingManager::sunEnable()
{
if (mSun) mSun->setVisible(true);
}
void RenderingManager::sunDisable()
{
if (mSun) mSun->setVisible(false);
2011-10-20 19:02:19 +00:00
}
void RenderingManager::setSunDirection(const Ogre::Vector3& direction)
{
// direction * -1 (because 'direction' is camera to sun vector and not sun to camera),
2012-02-28 19:28:46 +00:00
// then convert from MW to ogre coordinates (swap y,z and make y negative)
if (mSun) mSun->setDirection(Vector3(-direction.x, -direction.z, direction.y));
mSkyManager->setSunDirection(direction);
}
void RenderingManager::setGlare(bool glare)
{
mSkyManager->setGlare(glare);
}
void RenderingManager::requestMap(MWWorld::Ptr::CellStore* cell)
{
if (!(cell->cell->data.flags & ESM::Cell::Interior))
mLocalMap->requestMap(cell);
else
mLocalMap->requestMap(cell, mObjects.getDimensions(cell));
}
void RenderingManager::preCellChange(MWWorld::Ptr::CellStore* cell)
{
mLocalMap->saveFogOfWar(cell);
}
2012-04-02 17:37:24 +00:00
void RenderingManager::disableLights()
{
mObjects.disableLights();
}
void RenderingManager::enableLights()
{
mObjects.enableLights();
}
} // namespace