Merge remote branch 'jhooks/mwrender' into mwrender
Conflicts: apps/openmw/engine.cpp - fixed code that did not compile - removed tons of tabs - more clean upactorid
commit
51d5c7cd59
@ -1,67 +0,0 @@
|
||||
#include "cellimp.hpp"
|
||||
|
||||
#include <cassert>
|
||||
#include <iostream>
|
||||
#include <exception>
|
||||
|
||||
#include "../mwworld/class.hpp"
|
||||
#include "../mwworld/ptr.hpp"
|
||||
|
||||
using namespace MWRender;
|
||||
|
||||
template<typename T>
|
||||
void insertCellRefList (CellRenderImp& cellRender, MWWorld::Environment& environment,
|
||||
T& cellRefList, ESMS::CellStore<MWWorld::RefData> &cell)
|
||||
{
|
||||
if (!cellRefList.list.empty())
|
||||
{
|
||||
const MWWorld::Class& class_ =
|
||||
MWWorld::Class::get (MWWorld::Ptr (&*cellRefList.list.begin(), &cell));
|
||||
|
||||
for (typename T::List::iterator it = cellRefList.list.begin();
|
||||
it != cellRefList.list.end(); it++)
|
||||
{
|
||||
if (it->mData.getCount() || it->mData.isEnabled())
|
||||
{
|
||||
MWWorld::Ptr ptr (&*it, &cell);
|
||||
|
||||
try
|
||||
{
|
||||
class_.insertObj (ptr, cellRender, environment);
|
||||
class_.enable (ptr, environment);
|
||||
}
|
||||
catch (const std::exception& e)
|
||||
{
|
||||
std::string error ("error during rendering: ");
|
||||
std::cerr << error + e.what() << std::endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CellRenderImp::insertCell(ESMS::CellStore<MWWorld::RefData> &cell,
|
||||
MWWorld::Environment& environment)
|
||||
{
|
||||
// Loop through all references in the cell
|
||||
insertCellRefList (*this, environment, cell.activators, cell);
|
||||
insertCellRefList (*this, environment, cell.potions, cell);
|
||||
insertCellRefList (*this, environment, cell.appas, cell);
|
||||
insertCellRefList (*this, environment, cell.armors, cell);
|
||||
insertCellRefList (*this, environment, cell.books, cell);
|
||||
insertCellRefList (*this, environment, cell.clothes, cell);
|
||||
insertCellRefList (*this, environment, cell.containers, cell);
|
||||
insertCellRefList (*this, environment, cell.creatures, cell);
|
||||
insertCellRefList (*this, environment, cell.doors, cell);
|
||||
insertCellRefList (*this, environment, cell.ingreds, cell);
|
||||
insertCellRefList (*this, environment, cell.creatureLists, cell);
|
||||
insertCellRefList (*this, environment, cell.itemLists, cell);
|
||||
insertCellRefList (*this, environment, cell.lights, cell);
|
||||
insertCellRefList (*this, environment, cell.lockpicks, cell);
|
||||
insertCellRefList (*this, environment, cell.miscItems, cell);
|
||||
insertCellRefList (*this, environment, cell.npcs, cell);
|
||||
insertCellRefList (*this, environment, cell.probes, cell);
|
||||
insertCellRefList (*this, environment, cell.repairs, cell);
|
||||
insertCellRefList (*this, environment, cell.statics, cell);
|
||||
insertCellRefList (*this, environment, cell.weapons, cell);
|
||||
}
|
@ -1,95 +0,0 @@
|
||||
#ifndef _GAME_RENDER_CELLIMP_H
|
||||
#define _GAME_RENDER_CELLIMP_H
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "components/esm_store/cell_store.hpp"
|
||||
|
||||
#include "../mwworld/refdata.hpp"
|
||||
#include <OgreMath.h>
|
||||
|
||||
namespace Ogre
|
||||
{
|
||||
class SceneNode;
|
||||
class Vector3;
|
||||
}
|
||||
|
||||
namespace ESM
|
||||
{
|
||||
class CellRef;
|
||||
}
|
||||
|
||||
namespace MWWorld
|
||||
{
|
||||
class Environment;
|
||||
}
|
||||
namespace MWRender
|
||||
{
|
||||
/// Base class for cell render, that implements inserting references into a cell in a
|
||||
/// cell type- and render-engine-independent way.
|
||||
|
||||
class CellRenderImp
|
||||
{
|
||||
public:
|
||||
CellRenderImp() {}
|
||||
virtual ~CellRenderImp() {}
|
||||
|
||||
/// start inserting a new reference.
|
||||
virtual void insertBegin (ESM::CellRef& ref, MWWorld::RefData& refData, bool static_ = false) = 0;
|
||||
|
||||
virtual void rotateMesh(Ogre::Vector3 axis, Ogre::Radian angle, std::string sceneNodeName[], int elements) = 0;
|
||||
/// insert a mesh related to the most recent insertBegin call.
|
||||
virtual void insertMesh(const std::string &mesh, Ogre::Vector3 vec, Ogre::Vector3 axis, Ogre::Radian angle, std::string sceneNodeName, std::string sceneParent[], int elements, bool translateFirst) = 0;
|
||||
virtual void insertMesh(const std::string &mesh, Ogre::Vector3 vec, Ogre::Vector3 axis, Ogre::Radian angle, std::string sceneNodeName, std::string sceneParent[], int elements) = 0;
|
||||
virtual void insertMesh(const std::string &mesh) = 0;
|
||||
|
||||
virtual void scaleMesh(Ogre::Vector3 axis, std::string sceneNodeName[], int elements) = 0;
|
||||
|
||||
virtual void insertObjectPhysics() = 0;
|
||||
|
||||
virtual void insertActorPhysics() = 0;
|
||||
|
||||
/// insert a light related to the most recent insertBegin call.
|
||||
virtual void insertLight(float r, float g, float b, float radius) = 0;
|
||||
|
||||
/// finish inserting a new reference and return a handle to it.
|
||||
virtual std::string insertEnd (bool Enable) = 0;
|
||||
|
||||
void insertCell(ESMS::CellStore<MWWorld::RefData> &cell, MWWorld::Environment& environment);
|
||||
|
||||
};
|
||||
|
||||
/// Exception-safe rendering
|
||||
class Rendering
|
||||
{
|
||||
CellRenderImp& mCellRender;
|
||||
bool mEnd;
|
||||
|
||||
// not implemented
|
||||
Rendering (const Rendering&);
|
||||
Rendering& operator= (const Rendering&);
|
||||
|
||||
public:
|
||||
|
||||
Rendering (CellRenderImp& cellRender, ESM::CellRef& ref, MWWorld::RefData& refData, bool static_ = false)
|
||||
: mCellRender (cellRender), mEnd (false)
|
||||
{
|
||||
mCellRender.insertBegin (ref, refData, static_);
|
||||
}
|
||||
|
||||
~Rendering()
|
||||
{
|
||||
if (!mEnd)
|
||||
mCellRender.insertEnd (false);
|
||||
}
|
||||
|
||||
std::string end (bool enable)
|
||||
{
|
||||
assert (!mEnd);
|
||||
mEnd = true;
|
||||
return mCellRender.insertEnd (enable);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
@ -0,0 +1,2 @@
|
||||
#include "creatures.hpp"
|
||||
using namespace MWRender;
|
@ -0,0 +1,10 @@
|
||||
#ifndef _GAME_RENDER_CREATURES_H
|
||||
#define _GAME_RENDER_CREATURES_H
|
||||
#include <openengine/ogre/renderer.hpp>
|
||||
|
||||
namespace MWRender{
|
||||
class Creatures{
|
||||
|
||||
};
|
||||
}
|
||||
#endif
|
@ -0,0 +1,38 @@
|
||||
#include "debugging.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 "player.hpp"
|
||||
|
||||
using namespace MWRender;
|
||||
using namespace Ogre;
|
||||
|
||||
Debugging::Debugging(OEngine::Physic::PhysicEngine* engine){
|
||||
eng = engine;
|
||||
}
|
||||
|
||||
|
||||
bool Debugging::toggleRenderMode (int mode){
|
||||
switch (mode)
|
||||
{
|
||||
case MWWorld::World::Render_CollisionDebug:
|
||||
|
||||
// TODO use a proper function instead of accessing the member variable
|
||||
// directly.
|
||||
eng->setDebugRenderingMode (!eng->isDebugCreated);
|
||||
return eng->isDebugCreated;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
@ -0,0 +1,43 @@
|
||||
#ifndef _GAME_RENDER_MWSCENE_H
|
||||
#define _GAME_RENDER_MWSCENE_H
|
||||
|
||||
#include <utility>
|
||||
#include <openengine/ogre/renderer.hpp>
|
||||
#include <openengine/bullet/physic.hpp>
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
namespace Ogre
|
||||
{
|
||||
class Camera;
|
||||
class Viewport;
|
||||
class SceneManager;
|
||||
class SceneNode;
|
||||
class RaySceneQuery;
|
||||
class Quaternion;
|
||||
class Vector3;
|
||||
}
|
||||
|
||||
namespace MWWorld
|
||||
{
|
||||
class World;
|
||||
}
|
||||
|
||||
namespace MWRender
|
||||
{
|
||||
class Player;
|
||||
|
||||
class Debugging{
|
||||
OEngine::Physic::PhysicEngine* eng;
|
||||
|
||||
|
||||
public:
|
||||
Debugging(OEngine::Physic::PhysicEngine* engine);
|
||||
bool toggleRenderMode (int mode);
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
|
||||
#endif
|
@ -1,454 +0,0 @@
|
||||
#include "exterior.hpp"
|
||||
|
||||
#include <OgreEntity.h>
|
||||
#include <OgreLight.h>
|
||||
#include <OgreSceneNode.h>
|
||||
#include <OgreCamera.h>
|
||||
#include <OgreSceneManager.h>
|
||||
|
||||
#include <components/nifogre/ogre_nif_loader.hpp>
|
||||
#include "mwscene.hpp"
|
||||
#include <libs/mangle/vfs/servers/ogre_vfs.hpp>
|
||||
#include "mwscene.hpp"
|
||||
#include <Ogre.h>
|
||||
|
||||
using namespace MWRender;
|
||||
using namespace Ogre;
|
||||
using namespace ESMS;
|
||||
|
||||
bool ExteriorCellRender::lightConst = false;
|
||||
float ExteriorCellRender::lightConstValue = 0.0f;
|
||||
|
||||
bool ExteriorCellRender::lightLinear = true;
|
||||
int ExteriorCellRender::lightLinearMethod = 1;
|
||||
float ExteriorCellRender::lightLinearValue = 3;
|
||||
float ExteriorCellRender::lightLinearRadiusMult = 1;
|
||||
|
||||
bool ExteriorCellRender::lightQuadratic = false;
|
||||
int ExteriorCellRender::lightQuadraticMethod = 2;
|
||||
float ExteriorCellRender::lightQuadraticValue = 16;
|
||||
float ExteriorCellRender::lightQuadraticRadiusMult = 1;
|
||||
|
||||
bool ExteriorCellRender::lightOutQuadInLin = false;
|
||||
|
||||
int ExteriorCellRender::uniqueID = 0;
|
||||
|
||||
ExteriorCellRender::ExteriorCellRender(ESMS::CellStore<MWWorld::RefData> &_cell, MWWorld::Environment& environment,
|
||||
MWScene &_scene, MWWorld::PhysicsSystem *physics)
|
||||
: mCell(_cell), mEnvironment (environment), mScene(_scene), mPhysics(physics), mBase(NULL), mInsert(NULL), mAmbientMode (0)
|
||||
{
|
||||
uniqueID = uniqueID +1;
|
||||
sg = mScene.getMgr()->createStaticGeometry( "sg" + Ogre::StringConverter::toString(uniqueID));
|
||||
}
|
||||
|
||||
|
||||
|
||||
void ExteriorCellRender::insertBegin (ESM::CellRef &ref, MWWorld::RefData& refData, bool static_)
|
||||
{
|
||||
assert (!mInsert);
|
||||
|
||||
isStatic = static_;
|
||||
|
||||
// Create and place scene node for this object
|
||||
mInsert = mBase->createChildSceneNode();
|
||||
|
||||
const float *f = ref.pos.pos;
|
||||
mInsert->setPosition(f[0], f[1], f[2]);
|
||||
mInsert->setScale(ref.scale, ref.scale, ref.scale);
|
||||
|
||||
// Convert MW rotation to a quaternion:
|
||||
f = ref.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
|
||||
mInsert->setOrientation(xr*yr*zr);
|
||||
|
||||
mInsertMesh.clear();
|
||||
}
|
||||
|
||||
|
||||
void ExteriorCellRender::rotateMesh(Ogre::Vector3 axis, Ogre::Radian angle, std::string sceneNodeName[], int elements)
|
||||
{
|
||||
assert(mInsert);
|
||||
Ogre::SceneNode *parent = mInsert;
|
||||
//std::cout << "ELEMENTS:" << elements;
|
||||
for (int i = 0; i < elements; i++){
|
||||
if(sceneNodeName[i] != "" && parent->getChild(sceneNodeName[i]))
|
||||
parent = dynamic_cast<Ogre::SceneNode*> (parent->getChild(sceneNodeName[i]));
|
||||
}
|
||||
parent->rotate(axis, angle);
|
||||
}
|
||||
/*
|
||||
void ExteriorCellRender::insertMesh(const std::string &mesh, Ogre::Vector3 vec, Ogre::Vector3 axis, Ogre::Radian angle, std::string sceneNodeName, std::string sceneParent[], int elements){
|
||||
assert (mInsert);
|
||||
//mInsert->
|
||||
Ogre::SceneNode *parent = mInsert;
|
||||
for (int i = 0; i < elements; i++){
|
||||
if(sceneParent[i] != "" && parent->getChild(sceneParent[i]))
|
||||
parent = dynamic_cast<Ogre::SceneNode*> (parent->getChild(sceneParent[i]));
|
||||
}
|
||||
|
||||
mNpcPart = parent->createChildSceneNode(sceneNodeName);
|
||||
NIFLoader::load(mesh);
|
||||
MovableObject *ent = mScene.getMgr()->createEntity(mesh);
|
||||
|
||||
mNpcPart->translate(vec);
|
||||
mNpcPart->rotate(axis, angle);
|
||||
// mNpcPart->translate(vec);
|
||||
//mNpcPart->rotate(axis, angle);
|
||||
mNpcPart->attachObject(ent);
|
||||
//mNpcPart->
|
||||
|
||||
}
|
||||
*/
|
||||
void ExteriorCellRender::insertMesh(const std::string &mesh, Ogre::Vector3 vec, Ogre::Vector3 axis, Ogre::Radian angle, std::string sceneNodeName, std::string sceneParent[], int elements)
|
||||
{
|
||||
insertMesh(mesh, vec, axis, angle, sceneNodeName, sceneParent, elements, true);
|
||||
}
|
||||
void ExteriorCellRender::insertMesh(const std::string &mesh, Ogre::Vector3 vec, Ogre::Vector3 axis, Ogre::Radian angle, std::string sceneNodeName, std::string sceneParent[], int elements, bool translateFirst){
|
||||
|
||||
assert (mInsert);
|
||||
//mInsert->
|
||||
Ogre::SceneNode *parent = mInsert;
|
||||
for (int i = 0; i < elements; i++){
|
||||
if(sceneParent[i] != "" && parent->getChild(sceneParent[i]))
|
||||
parent = dynamic_cast<Ogre::SceneNode*> (parent->getChild(sceneParent[i]));
|
||||
}
|
||||
|
||||
mNpcPart = parent->createChildSceneNode(sceneNodeName);
|
||||
MeshPtr good2 = NifOgre::NIFLoader::load(mesh);
|
||||
|
||||
MovableObject *ent = mScene.getMgr()->createEntity(mesh);
|
||||
|
||||
|
||||
if(translateFirst){
|
||||
mNpcPart->translate(vec);
|
||||
mNpcPart->rotate(axis, angle);
|
||||
}
|
||||
else{
|
||||
|
||||
mNpcPart->rotate(axis, angle);
|
||||
mNpcPart->translate(vec);
|
||||
}
|
||||
mNpcPart->attachObject(ent);
|
||||
|
||||
Ogre::MeshManager *m = MeshManager::getSingletonPtr();
|
||||
const std::string beast1 ="meshes\\b\\B_N_Khajiit_F_Skins.nif";
|
||||
const std::string beast2 ="meshes\\b\\B_N_Khajiit_M_Skins.nif";
|
||||
const std::string beast3 ="meshes\\b\\B_N_Argonian_F_Skins.nif";
|
||||
const std::string beast4 ="meshes\\b\\B_N_Argonian_M_Skins.nif";
|
||||
|
||||
const std::string beasttail1 ="tail\\b\\B_N_Khajiit_F_Skins.nif";
|
||||
const std::string beasttail2 ="tail\\b\\B_N_Khajiit_M_Skins.nif";
|
||||
const std::string beasttail3 ="tail\\b\\B_N_Argonian_F_Skins.nif";
|
||||
const std::string beasttail4 ="tail\\b\\B_N_Argonian_M_Skins.nif";
|
||||
|
||||
const std::string beastfoot1 ="foot\\b\\B_N_Khajiit_F_Skins.nif";
|
||||
const std::string beastfoot2 ="foot\\b\\B_N_Khajiit_M_Skins.nif";
|
||||
const std::string beastfoot3 ="foot\\b\\B_N_Argonian_F_Skins.nif";
|
||||
const std::string beastfoot4 ="foot\\b\\B_N_Argonian_M_Skins.nif";
|
||||
if(mesh.compare(beast1) == 0 && m->getByName(beasttail1).isNull())
|
||||
{
|
||||
//std::cout << "CLONINGKHAJIITF\n";
|
||||
good2->reload();
|
||||
MeshPtr tail = good2->clone(beasttail1);
|
||||
good2->reload();
|
||||
MeshPtr foot = good2->clone(beastfoot1);
|
||||
good2->reload();
|
||||
}
|
||||
else if(mesh.compare(beast2) == 0 && m->getByName(beasttail2).isNull())
|
||||
{
|
||||
//std::cout << "CLONINGKHAJIITM\n";
|
||||
good2->reload();
|
||||
MeshPtr tail = good2->clone(beasttail2);
|
||||
good2->reload();
|
||||
MeshPtr foot = good2->clone(beastfoot2);
|
||||
good2->reload();
|
||||
}
|
||||
else if(mesh.compare(beast3) == 0 && m->getByName(beasttail3).isNull())
|
||||
{
|
||||
//std::cout << "CLONINGARGONIANF\n";
|
||||
good2->reload();
|
||||
MeshPtr tail = good2->clone(beasttail3);
|
||||
good2->reload();
|
||||
MeshPtr foot = good2->clone(beastfoot3);
|
||||
good2->reload();
|
||||
}
|
||||
else if(mesh.compare(beast4) == 0 && m->getByName(beasttail4).isNull())
|
||||
{
|
||||
//std::cout << "CLONINGARGONIANM\n";
|
||||
good2->reload();
|
||||
MeshPtr tail = good2->clone(beasttail4);
|
||||
good2->reload();
|
||||
MeshPtr foot = good2->clone(beastfoot4);
|
||||
good2->reload();
|
||||
}
|
||||
}
|
||||
// insert a mesh related to the most recent insertBegin call.
|
||||
|
||||
void ExteriorCellRender::scaleMesh(Ogre::Vector3 axis, std::string sceneNodeName[], int elements)
|
||||
{
|
||||
assert(mInsert);
|
||||
Ogre::SceneNode *parent = mInsert;
|
||||
//std::cout << "ELEMENTS:" << elements;
|
||||
for (int i = 0; i < elements; i++){
|
||||
if(sceneNodeName[i] != "" && parent->getChild(sceneNodeName[i]))
|
||||
parent = dynamic_cast<Ogre::SceneNode*> (parent->getChild(sceneNodeName[i]));
|
||||
}
|
||||
parent->scale(axis);
|
||||
}
|
||||
|
||||
// insert a mesh related to the most recent insertBegin call.
|
||||
|
||||
|
||||
void ExteriorCellRender::insertMesh(const std::string &mesh)
|
||||
{
|
||||
assert (mInsert);
|
||||
|
||||
NifOgre::NIFLoader::load(mesh);
|
||||
Entity *ent = mScene.getMgr()->createEntity(mesh);
|
||||
|
||||
if(!isStatic)
|
||||
{
|
||||
mInsert->attachObject(ent);
|
||||
}
|
||||
else
|
||||
{
|
||||
sg->addEntity(ent,mInsert->_getDerivedPosition(),mInsert->_getDerivedOrientation(),mInsert->_getDerivedScale());
|
||||
sg->setRegionDimensions(Ogre::Vector3(100000,10000,100000));
|
||||
mScene.getMgr()->destroyEntity(ent);
|
||||
}
|
||||
if (mInsertMesh.empty())
|
||||
mInsertMesh = mesh;
|
||||
}
|
||||
|
||||
void ExteriorCellRender::insertObjectPhysics()
|
||||
{
|
||||
if (!mInsertMesh.empty())
|
||||
{
|
||||
mPhysics->addObject (mInsert->getName(), mInsertMesh, mInsert->getOrientation(),
|
||||
mInsert->getScale().x, mInsert->getPosition());
|
||||
}
|
||||
}
|
||||
|
||||
void ExteriorCellRender::insertActorPhysics()
|
||||
{
|
||||
mPhysics->addActor (mInsert->getName(), mInsertMesh, mInsert->getPosition());
|
||||
}
|
||||
|
||||
// insert a light related to the most recent insertBegin call.
|
||||
void ExteriorCellRender::insertLight(float r, float g, float b, float radius)
|
||||
{
|
||||
assert (mInsert);
|
||||
|
||||
Ogre::Light *light = mScene.getMgr()->createLight();
|
||||
light->setDiffuseColour (r, g, b);
|
||||
|
||||
float cval=0.0f, lval=0.0f, qval=0.0f;
|
||||
|
||||
if(lightConst)
|
||||
cval = lightConstValue;
|
||||
if(!lightOutQuadInLin)
|
||||
{
|
||||
if(lightLinear)
|
||||
radius *= lightLinearRadiusMult;
|
||||
if(lightQuadratic)
|
||||
radius *= lightQuadraticRadiusMult;
|
||||
|
||||
if(lightLinear)
|
||||
lval = lightLinearValue / pow(radius, lightLinearMethod);
|
||||
if(lightQuadratic)
|
||||
qval = lightQuadraticValue / pow(radius, lightQuadraticMethod);
|
||||
}
|
||||
else
|
||||
{
|
||||
// FIXME:
|
||||
// Do quadratic or linear, depending if we're in an exterior or interior
|
||||
// cell, respectively. Ignore lightLinear and lightQuadratic.
|
||||
}
|
||||
|
||||
light->setAttenuation(10*radius, cval, lval, qval);
|
||||
|
||||
mInsert->attachObject(light);
|
||||
}
|
||||
|
||||
// finish inserting a new reference and return a handle to it.
|
||||
|
||||
std::string ExteriorCellRender::insertEnd (bool enable)
|
||||
{
|
||||
assert (mInsert);
|
||||
|
||||
std::string handle = mInsert->getName();
|
||||
|
||||
if (!enable)
|
||||
mInsert->setVisible (false);
|
||||
|
||||
mInsert = 0;
|
||||
|
||||
return handle;
|
||||
}
|
||||
|
||||
// configure lighting according to cell
|
||||
|
||||
void ExteriorCellRender::configureAmbient()
|
||||
{
|
||||
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.
|
||||
Ogre::Light *light = mScene.getMgr()->createLight();
|
||||
Ogre::ColourValue colour;
|
||||
colour.setAsABGR (mCell.cell->ambi.sunlight);
|
||||
light->setDiffuseColour (colour);
|
||||
light->setType(Ogre::Light::LT_DIRECTIONAL);
|
||||
light->setDirection(0,-1,0);
|
||||
}
|
||||
|
||||
// configure fog according to cell
|
||||
void ExteriorCellRender::configureFog()
|
||||
{
|
||||
Ogre::ColourValue color;
|
||||
color.setAsABGR (mCell.cell->ambi.fog);
|
||||
|
||||
float high = 4500 + 9000 * (1-mCell.cell->ambi.fogDensity);
|
||||
float low = 200;
|
||||
|
||||
mScene.getMgr()->setFog (FOG_LINEAR, color, 0, low, high);
|
||||
mScene.getCamera()->setFarClipDistance (high + 10);
|
||||
mScene.getViewport()->setBackgroundColour (color);
|
||||
}
|
||||
|
||||
void ExteriorCellRender::setAmbientMode()
|
||||
{
|
||||
switch (mAmbientMode)
|
||||
{
|
||||
case 0:
|
||||
|
||||
mScene.getMgr()->setAmbientLight(mAmbientColor);
|
||||
break;
|
||||
|
||||
case 1:
|
||||
|
||||
mScene.getMgr()->setAmbientLight(0.7f*mAmbientColor + 0.3f*ColourValue(1,1,1));
|
||||
break;
|
||||
|
||||
case 2:
|
||||
|
||||
mScene.getMgr()->setAmbientLight(ColourValue(1,1,1));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void ExteriorCellRender::show()
|
||||
{
|
||||
// FIXME: this one may be the bug
|
||||
mBase = mScene.getRoot()->createChildSceneNode();
|
||||
|
||||
configureAmbient();
|
||||
configureFog();
|
||||
|
||||
insertCell(mCell, mEnvironment);
|
||||
|
||||
sg->build();
|
||||
}
|
||||
|
||||
void ExteriorCellRender::hide()
|
||||
{
|
||||
if(mBase)
|
||||
mBase->setVisible(false);
|
||||
}
|
||||
|
||||
void ExteriorCellRender::destroyAllAttachedMovableObjects(Ogre::SceneNode* i_pSceneNode)
|
||||
{
|
||||
if ( !i_pSceneNode )
|
||||
{
|
||||
assert( false );
|
||||
return;
|
||||
}
|
||||
|
||||
// Destroy all the attached objects
|
||||
SceneNode::ObjectIterator itObject = i_pSceneNode->getAttachedObjectIterator();
|
||||
|
||||
while ( itObject.hasMoreElements() )
|
||||
{
|
||||
MovableObject* pObject = static_cast<MovableObject*>(itObject.getNext());
|
||||
i_pSceneNode->getCreator()->destroyMovableObject( pObject );
|
||||
}
|
||||
|
||||
// Recurse to child SceneNodes
|
||||
SceneNode::ChildNodeIterator itChild = i_pSceneNode->getChildIterator();
|
||||
|
||||
while ( itChild.hasMoreElements() )
|
||||
{
|
||||
SceneNode* pChildNode = static_cast<SceneNode*>(itChild.getNext());
|
||||
destroyAllAttachedMovableObjects( pChildNode );
|
||||
}
|
||||
}
|
||||
|
||||
void ExteriorCellRender::destroy()
|
||||
{
|
||||
if(mBase)
|
||||
{
|
||||
destroyAllAttachedMovableObjects(mBase);
|
||||
mBase->removeAndDestroyAllChildren();
|
||||
mScene.getMgr()->destroySceneNode(mBase);
|
||||
}
|
||||
|
||||
mBase = 0;
|
||||
|
||||
if (sg)
|
||||
{
|
||||
mScene.getMgr()->destroyStaticGeometry (sg);
|
||||
sg = 0;
|
||||
}
|
||||
}
|
||||
|
||||
// Switch through lighting modes.
|
||||
|
||||
void ExteriorCellRender::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 ExteriorCellRender::enable (const std::string& handle)
|
||||
{
|
||||
if (!handle.empty())
|
||||
mScene.getMgr()->getSceneNode (handle)->setVisible (true);
|
||||
}
|
||||
|
||||
void ExteriorCellRender::disable (const std::string& handle)
|
||||
{
|
||||
if (!handle.empty())
|
||||
mScene.getMgr()->getSceneNode (handle)->setVisible (false);
|
||||
}
|
||||
|
||||
void ExteriorCellRender::deleteObject (const std::string& handle)
|
||||
{
|
||||
if (!handle.empty())
|
||||
{
|
||||
Ogre::SceneNode *node = mScene.getMgr()->getSceneNode (handle);
|
||||
node->removeAndDestroyAllChildren();
|
||||
mScene.getMgr()->destroySceneNode (node);
|
||||
}
|
||||
}
|
@ -1,138 +0,0 @@
|
||||
#ifndef _GAME_RENDER_EXTERIOR_H
|
||||
#define _GAME_RENDER_EXTERIOR_H
|
||||
|
||||
#include "cell.hpp"
|
||||
#include "cellimp.hpp"
|
||||
#include "../mwworld/physicssystem.hpp"
|
||||
|
||||
#include "OgreColourValue.h"
|
||||
#include <OgreMath.h>
|
||||
#include <Ogre.h>
|
||||
|
||||
namespace Ogre
|
||||
{
|
||||
class SceneNode;
|
||||
}
|
||||
|
||||
namespace MWWorld
|
||||
{
|
||||
class Environment;
|
||||
}
|
||||
|
||||
namespace MWRender
|
||||
{
|
||||
class MWScene;
|
||||
|
||||
/**
|
||||
This class is responsible for inserting meshes and other
|
||||
rendering objects from the given cell into the given rendering
|
||||
scene.
|
||||
*/
|
||||
|
||||
class ExteriorCellRender : public CellRender, private CellRenderImp
|
||||
{
|
||||
|
||||
static bool lightConst;
|
||||
static float lightConstValue;
|
||||
|
||||
static bool lightLinear;
|
||||
static int lightLinearMethod;
|
||||
static float lightLinearValue;
|
||||
static float lightLinearRadiusMult;
|
||||
|
||||
static bool lightQuadratic;
|
||||
static int lightQuadraticMethod;
|
||||
static float lightQuadraticValue;
|
||||
static float lightQuadraticRadiusMult;
|
||||
|
||||
static bool lightOutQuadInLin;
|
||||
|
||||
ESMS::CellStore<MWWorld::RefData> &mCell;
|
||||
MWWorld::Environment &mEnvironment;
|
||||
MWScene &mScene;
|
||||
MWWorld::PhysicsSystem *mPhysics;
|
||||
|
||||
/// The scene node that contains all objects belonging to this
|
||||
/// cell.
|
||||
Ogre::SceneNode *mBase;
|
||||
|
||||
Ogre::SceneNode *mInsert;
|
||||
std::string mInsertMesh;
|
||||
Ogre::SceneNode *mNpcPart;
|
||||
|
||||
//the static geometry
|
||||
Ogre::StaticGeometry *sg;
|
||||
bool isStatic;
|
||||
|
||||
// 0 normal, 1 more bright, 2 max
|
||||
int mAmbientMode;
|
||||
|
||||
Ogre::ColourValue mAmbientColor;
|
||||
|
||||
/// start inserting a new reference.
|
||||
virtual void insertBegin (ESM::CellRef &ref, MWWorld::RefData& refData, bool static_ = false);
|
||||
|
||||
/// insert a mesh related to the most recent insertBegin call.
|
||||
virtual void insertMesh(const std::string &mesh, Ogre::Vector3 vec, Ogre::Vector3 axis, Ogre::Radian angle, std::string sceneNodeName, std::string sceneParent[], int elements);
|
||||
virtual void insertMesh(const std::string &mesh, Ogre::Vector3 vec, Ogre::Vector3 axis, Ogre::Radian angle, std::string sceneNodeName, std::string sceneParent[], int elements, bool translateFirst);
|
||||
|
||||
virtual void insertMesh(const std::string &mesh);
|
||||
|
||||
virtual void rotateMesh(Ogre::Vector3 axis, Ogre::Radian angle, std::string sceneNodeName[], int elements);
|
||||
virtual void scaleMesh(Ogre::Vector3 axis, std::string sceneNodeName[], int elements);
|
||||
|
||||
virtual void insertObjectPhysics();
|
||||
|
||||
virtual void insertActorPhysics();
|
||||
|
||||
/// insert a light related to the most recent insertBegin call.
|
||||
virtual void insertLight(float r, float g, float b, float radius);
|
||||
|
||||
/// finish inserting a new reference and return a handle to it.
|
||||
virtual std::string insertEnd (bool Enable);
|
||||
|
||||
/// configure lighting according to cell
|
||||
void configureAmbient();
|
||||
|
||||
/// configure fog according to cell
|
||||
void configureFog();
|
||||
|
||||
void setAmbientMode();
|
||||
|
||||
|
||||
public:
|
||||
|
||||
ExteriorCellRender(ESMS::CellStore<MWWorld::RefData> &_cell, MWWorld::Environment& environment,
|
||||
MWScene &_scene, MWWorld::PhysicsSystem *physics);
|
||||
|
||||
virtual ~ExteriorCellRender() { destroy(); }
|
||||
|
||||
/// Make the cell visible. Load the cell if necessary.
|
||||
virtual void show();
|
||||
|
||||
/// Remove the cell from rendering, but don't remove it from
|
||||
/// memory.
|
||||
virtual void hide();
|
||||
|
||||
/// Destroy all rendering objects connected with this cell.
|
||||
virtual void destroy(); // comment by Zini: shouldn't this go into the destructor?
|
||||
|
||||
/// Switch through lighting modes.
|
||||
void toggleLight();
|
||||
|
||||
/// Make the reference with the given handle visible.
|
||||
virtual void enable (const std::string& handle);
|
||||
|
||||
/// Make the reference with the given handle invisible.
|
||||
virtual void disable (const std::string& handle);
|
||||
|
||||
/// Remove the reference with the given handle permanently from the scene.
|
||||
virtual void deleteObject (const std::string& handle);
|
||||
|
||||
void destroyAllAttachedMovableObjects(Ogre::SceneNode* i_pSceneNode);
|
||||
|
||||
static int uniqueID;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
@ -1,409 +0,0 @@
|
||||
#include "interior.hpp"
|
||||
|
||||
#include <OgreEntity.h>
|
||||
#include <OgreLight.h>
|
||||
#include <OgreSceneNode.h>
|
||||
#include <OgreCamera.h>
|
||||
#include <OgreSceneManager.h>
|
||||
#include <OgreMath.h>
|
||||
|
||||
#include <components/nifogre/ogre_nif_loader.hpp>
|
||||
#include "mwscene.hpp"
|
||||
#include <Ogre.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include <libs/mangle/vfs/servers/ogre_vfs.hpp>
|
||||
|
||||
using namespace MWRender;
|
||||
using namespace Ogre;
|
||||
using namespace ESMS;
|
||||
|
||||
bool InteriorCellRender::lightConst = false;
|
||||
float InteriorCellRender::lightConstValue = 0.0f;
|
||||
|
||||
bool InteriorCellRender::lightLinear = true;
|
||||
int InteriorCellRender::lightLinearMethod = 1;
|
||||
float InteriorCellRender::lightLinearValue = 3;
|
||||
float InteriorCellRender::lightLinearRadiusMult = 1;
|
||||
|
||||
bool InteriorCellRender::lightQuadratic = false;
|
||||
int InteriorCellRender::lightQuadraticMethod = 2;
|
||||
float InteriorCellRender::lightQuadraticValue = 16;
|
||||
float InteriorCellRender::lightQuadraticRadiusMult = 1;
|
||||
|
||||
bool InteriorCellRender::lightOutQuadInLin = false;
|
||||
|
||||
// start inserting a new reference.
|
||||
|
||||
void InteriorCellRender::insertBegin (ESM::CellRef &ref, MWWorld::RefData& refData, bool static_)
|
||||
{
|
||||
assert (!insert);
|
||||
|
||||
// Create and place scene node for this object
|
||||
insert = base->createChildSceneNode();
|
||||
|
||||
const float *f = refData.getPosition().pos;
|
||||
insert->setPosition(f[0], f[1], f[2]);
|
||||
insert->setScale(ref.scale, ref.scale, ref.scale);
|
||||
|
||||
// Convert MW rotation to a quaternion:
|
||||
f = ref.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);
|
||||
|
||||
mInsertMesh.clear();
|
||||
}
|
||||
|
||||
// insert a mesh related to the most recent insertBegin call.
|
||||
void InteriorCellRender::rotateMesh(Ogre::Vector3 axis, Ogre::Radian angle, std::string sceneNodeName[], int elements)
|
||||
{
|
||||
assert(insert);
|
||||
Ogre::SceneNode *parent = insert;
|
||||
//std::cout << "ELEMENTS:" << elements;
|
||||
for (int i = 0; i < elements; i++){
|
||||
if(sceneNodeName[i] != "" && parent->getChild(sceneNodeName[i]))
|
||||
parent = dynamic_cast<Ogre::SceneNode*> (parent->getChild(sceneNodeName[i]));
|
||||
}
|
||||
parent->rotate(axis, angle);
|
||||
}
|
||||
// insert a mesh related to the most recent insertBegin call.
|
||||
|
||||
void InteriorCellRender::scaleMesh(Ogre::Vector3 axis, std::string sceneNodeName[], int elements)
|
||||
{
|
||||
assert(insert);
|
||||
Ogre::SceneNode *parent = insert;
|
||||
//std::cout << "ELEMENTS:" << elements;
|
||||
for (int i = 0; i < elements; i++){
|
||||
if(sceneNodeName[i] != "" && parent->getChild(sceneNodeName[i]))
|
||||
parent = dynamic_cast<Ogre::SceneNode*> (parent->getChild(sceneNodeName[i]));
|
||||
}
|
||||
parent->scale(axis);
|
||||
}
|
||||
void InteriorCellRender::insertMesh(const std::string &mesh, Ogre::Vector3 vec, Ogre::Vector3 axis, Ogre::Radian angle, std::string sceneNodeName, std::string sceneParent[], int elements)
|
||||
{
|
||||
insertMesh(mesh, vec, axis, angle, sceneNodeName, sceneParent, elements, true);
|
||||
}
|
||||
void InteriorCellRender::insertMesh(const std::string &mesh, Ogre::Vector3 vec, Ogre::Vector3 axis, Ogre::Radian angle, std::string sceneNodeName, std::string sceneParent[], int elements, bool translateFirst){
|
||||
|
||||
assert (insert);
|
||||
//insert->
|
||||
Ogre::SceneNode *parent = insert;
|
||||
for (int i = 0; i < elements; i++){
|
||||
if(sceneParent[i] != "" && parent->getChild(sceneParent[i]))
|
||||
parent = dynamic_cast<Ogre::SceneNode*> (parent->getChild(sceneParent[i]));
|
||||
}
|
||||
|
||||
npcPart = parent->createChildSceneNode(sceneNodeName);
|
||||
//npcPart->showBoundingBox(true);
|
||||
|
||||
MeshPtr good2 = NifOgre::NIFLoader::load(mesh);
|
||||
|
||||
MovableObject *ent = scene.getMgr()->createEntity(mesh);
|
||||
//ent->extr
|
||||
|
||||
// MovableObject *ent2 = scene.getMgr()->createEntity(bounds
|
||||
// );
|
||||
//ent->
|
||||
//std::cout << mesh << bounds << "\n";
|
||||
|
||||
if(translateFirst){
|
||||
npcPart->translate(vec);
|
||||
npcPart->rotate(axis, angle);
|
||||
}
|
||||
else{
|
||||
|
||||
npcPart->rotate(axis, angle);
|
||||
npcPart->translate(vec);
|
||||
}
|
||||
|
||||
npcPart->attachObject(ent);
|
||||
Ogre::MeshManager *m = MeshManager::getSingletonPtr();
|
||||
const std::string beast1 ="meshes\\b\\B_N_Khajiit_F_Skins.nif";
|
||||
const std::string beast2 ="meshes\\b\\B_N_Khajiit_M_Skins.nif";
|
||||
const std::string beast3 ="meshes\\b\\B_N_Argonian_F_Skins.nif";
|
||||
const std::string beast4 ="meshes\\b\\B_N_Argonian_M_Skins.nif";
|
||||
|
||||
const std::string beasttail1 ="tail\\b\\B_N_Khajiit_F_Skins.nif";
|
||||
const std::string beasttail2 ="tail\\b\\B_N_Khajiit_M_Skins.nif";
|
||||
const std::string beasttail3 ="tail\\b\\B_N_Argonian_F_Skins.nif";
|
||||
const std::string beasttail4 ="tail\\b\\B_N_Argonian_M_Skins.nif";
|
||||
|
||||
const std::string beastfoot1 ="foot\\b\\B_N_Khajiit_F_Skins.nif";
|
||||
const std::string beastfoot2 ="foot\\b\\B_N_Khajiit_M_Skins.nif";
|
||||
const std::string beastfoot3 ="foot\\b\\B_N_Argonian_F_Skins.nif";
|
||||
const std::string beastfoot4 ="foot\\b\\B_N_Argonian_M_Skins.nif";
|
||||
if(mesh.compare(beast1) == 0 && m->getByName(beasttail1).isNull())
|
||||
{
|
||||
//std::cout << "CLONINGKHAJIITF\n";
|
||||
good2->reload();
|
||||
MeshPtr tail = good2->clone(beasttail1);
|
||||
good2->reload();
|
||||
MeshPtr foot = good2->clone(beastfoot1);
|
||||
good2->reload();
|
||||
}
|
||||
else if(mesh.compare(beast2) == 0 && m->getByName(beasttail2).isNull())
|
||||
{
|
||||
//std::cout << "CLONINGKHAJIITM\n";
|
||||
good2->reload();
|
||||
MeshPtr tail = good2->clone(beasttail2);
|
||||
good2->reload();
|
||||
MeshPtr foot = good2->clone(beastfoot2);
|
||||
good2->reload();
|
||||
}
|
||||
else if(mesh.compare(beast3) == 0 && m->getByName(beasttail3).isNull())
|
||||
{
|
||||
//std::cout << "CLONINGARGONIANF\n";
|
||||
good2->reload();
|
||||
MeshPtr tail = good2->clone(beasttail3);
|
||||
good2->reload();
|
||||
MeshPtr foot = good2->clone(beastfoot3);
|
||||
good2->reload();
|
||||
}
|
||||
else if(mesh.compare(beast4) == 0 && m->getByName(beasttail4).isNull())
|
||||
{
|
||||
//std::cout << "CLONINGARGONIANM\n";
|
||||
good2->reload();
|
||||
MeshPtr tail = good2->clone(beasttail4);
|
||||
good2->reload();
|
||||
MeshPtr foot = good2->clone(beastfoot4);
|
||||
good2->reload();
|
||||
}
|
||||
}
|
||||
|
||||
void InteriorCellRender::insertMesh(const std::string &mesh)
|
||||
{
|
||||
assert (insert);
|
||||
|
||||
NifOgre::NIFLoader::load(mesh);
|
||||
MovableObject *ent = scene.getMgr()->createEntity(mesh);
|
||||
insert->attachObject(ent);
|
||||
|
||||
if (mInsertMesh.empty())
|
||||
mInsertMesh = mesh;
|
||||
}
|
||||
|
||||
void InteriorCellRender::insertObjectPhysics()
|
||||
{
|
||||
if (!mInsertMesh.empty())
|
||||
{
|
||||
mPhysics->addObject (insert->getName(), mInsertMesh, insert->getOrientation(),
|
||||
insert->getScale().x, insert->getPosition());
|
||||
}
|
||||
}
|
||||
|
||||
void InteriorCellRender::insertActorPhysics()
|
||||
{
|
||||
mPhysics->addActor (insert->getName(), mInsertMesh, insert->getPosition());
|
||||
}
|
||||
|
||||
// insert a light related to the most recent insertBegin call.
|
||||
void InteriorCellRender::insertLight(float r, float g, float b, float radius)
|
||||
{
|
||||
assert (insert);
|
||||
|
||||
Ogre::Light *light = scene.getMgr()->createLight();
|
||||
light->setDiffuseColour (r, g, b);
|
||||
|
||||
float cval=0.0f, lval=0.0f, qval=0.0f;
|
||||
|
||||
if(lightConst)
|
||||
cval = lightConstValue;
|
||||
if(!lightOutQuadInLin)
|
||||
{
|
||||
if(lightLinear)
|
||||
radius *= lightLinearRadiusMult;
|
||||
if(lightQuadratic)
|
||||
radius *= lightQuadraticRadiusMult;
|
||||
|
||||
if(lightLinear)
|
||||
lval = lightLinearValue / pow(radius, lightLinearMethod);
|
||||
if(lightQuadratic)
|
||||
qval = lightQuadraticValue / pow(radius, lightQuadraticMethod);
|
||||
}
|
||||
else
|
||||
{
|
||||
// FIXME:
|
||||
// Do quadratic or linear, depending if we're in an exterior or interior
|
||||
// cell, respectively. Ignore lightLinear and lightQuadratic.
|
||||
}
|
||||
|
||||
light->setAttenuation(10*radius, cval, lval, qval);
|
||||
|
||||
insert->attachObject(light);
|
||||
}
|
||||
|
||||
// finish inserting a new reference and return a handle to it.
|
||||
|
||||
std::string InteriorCellRender::insertEnd (bool enable)
|
||||
{
|
||||
assert (insert);
|
||||
|
||||
std::string handle = insert->getName();
|
||||
|
||||
if (!enable)
|
||||
insert->setVisible (false);
|
||||
|
||||
insert = 0;
|
||||
|
||||
return handle;
|
||||
}
|
||||
|
||||
// configure lighting according to cell
|
||||
|
||||
void InteriorCellRender::configureAmbient()
|
||||
{
|
||||
ambientColor.setAsABGR (cell.cell->ambi.ambient);
|
||||
setAmbientMode();
|
||||
|
||||
// Create a "sun" that shines light downwards. It doesn't look
|
||||
// completely right, but leave it for now.
|
||||
Ogre::Light *light = scene.getMgr()->createLight();
|
||||
Ogre::ColourValue colour;
|
||||
colour.setAsABGR (cell.cell->ambi.sunlight);
|
||||
light->setDiffuseColour (colour);
|
||||
light->setType(Ogre::Light::LT_DIRECTIONAL);
|
||||
light->setDirection(0,-1,0);
|
||||
}
|
||||
|
||||
// configure fog according to cell
|
||||
void InteriorCellRender::configureFog()
|
||||
{
|
||||
Ogre::ColourValue color;
|
||||
color.setAsABGR (cell.cell->ambi.fog);
|
||||
|
||||
float high = 4500 + 9000 * (1-cell.cell->ambi.fogDensity);
|
||||
float low = 200;
|
||||
|
||||
scene.getMgr()->setFog (FOG_LINEAR, color, 0, low, high);
|
||||
scene.getCamera()->setFarClipDistance (high + 10);
|
||||
scene.getViewport()->setBackgroundColour (color);
|
||||
}
|
||||
|
||||
void InteriorCellRender::setAmbientMode()
|
||||
{
|
||||
switch (ambientMode)
|
||||
{
|
||||
case 0:
|
||||
|
||||
scene.getMgr()->setAmbientLight(ambientColor);
|
||||
break;
|
||||
|
||||
case 1:
|
||||
|
||||
scene.getMgr()->setAmbientLight(0.7f*ambientColor + 0.3f*ColourValue(1,1,1));
|
||||
break;
|
||||
|
||||
case 2:
|
||||
|
||||
scene.getMgr()->setAmbientLight(ColourValue(1,1,1));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void InteriorCellRender::show()
|
||||
{
|
||||
base = scene.getRoot()->createChildSceneNode();
|
||||
|
||||
configureAmbient();
|
||||
configureFog();
|
||||
|
||||
insertCell(cell, mEnvironment);
|
||||
}
|
||||
|
||||
void InteriorCellRender::hide()
|
||||
{
|
||||
if(base)
|
||||
base->setVisible(false);
|
||||
}
|
||||
|
||||
void InteriorCellRender::destroy()
|
||||
{
|
||||
if(base)
|
||||
{
|
||||
base->removeAndDestroyAllChildren();
|
||||
scene.getMgr()->destroySceneNode(base);
|
||||
}
|
||||
|
||||
base = NULL;
|
||||
}
|
||||
|
||||
// Switch through lighting modes.
|
||||
|
||||
void InteriorCellRender::toggleLight()
|
||||
{
|
||||
if (ambientMode==2)
|
||||
ambientMode = 0;
|
||||
else
|
||||
++ambientMode;
|
||||
|
||||
switch (ambientMode)
|
||||
{
|
||||
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 InteriorCellRender::enable (const std::string& handle)
|
||||
{
|
||||
if (!handle.empty())
|
||||
scene.getMgr()->getSceneNode (handle)->setVisible (true);
|
||||
}
|
||||
|
||||
void InteriorCellRender::disable (const std::string& handle)
|
||||
{
|
||||
if (!handle.empty())
|
||||
scene.getMgr()->getSceneNode (handle)->setVisible (false);
|
||||
}
|
||||
|
||||
void InteriorCellRender::deleteObject (const std::string& handle)
|
||||
{
|
||||
if (!handle.empty())
|
||||
{
|
||||
Ogre::SceneNode *node = scene.getMgr()->getSceneNode (handle);
|
||||
node->removeAndDestroyAllChildren();
|
||||
scene.getMgr()->destroySceneNode (node);
|
||||
}
|
||||
}
|
||||
|
||||
// Magic function from the internets. Might need this later.
|
||||
/*
|
||||
void Scene::DestroyAllAttachedMovableObjects( SceneNode* i_pSceneNode )
|
||||
{
|
||||
if ( !i_pSceneNode )
|
||||
{
|
||||
ASSERT( false );
|
||||
return;
|
||||
}
|
||||
|
||||
// Destroy all the attached objects
|
||||
SceneNode::ObjectIterator itObject = i_pSceneNode->getAttachedObjectIterator();
|
||||
|
||||
while ( itObject.hasMoreElements() )
|
||||
{
|
||||
MovableObject* pObject = static_cast<MovableObject*>(itObject.getNext());
|
||||
i_pSceneNode->getCreator()->destroyMovableObject( pObject );
|
||||
}
|
||||
|
||||
// Recurse to child SceneNodes
|
||||
SceneNode::ChildNodeIterator itChild = i_pSceneNode->getChildIterator();
|
||||
|
||||
while ( itChild.hasMoreElements() )
|
||||
{
|
||||
SceneNode* pChildNode = static_cast<SceneNode*>(itChild.getNext());
|
||||
DestroyAllAttachedMovableObjects( pChildNode );
|
||||
}
|
||||
}
|
||||
*/
|
@ -1,131 +0,0 @@
|
||||
#ifndef _GAME_RENDER_INTERIOR_H
|
||||
#define _GAME_RENDER_INTERIOR_H
|
||||
|
||||
#include "cell.hpp"
|
||||
#include "cellimp.hpp"
|
||||
#include "../mwworld/physicssystem.hpp"
|
||||
|
||||
#include "OgreColourValue.h"
|
||||
#include <OgreSceneNode.h>
|
||||
|
||||
namespace Ogre
|
||||
{
|
||||
class SceneNode;
|
||||
}
|
||||
|
||||
namespace MWWorld
|
||||
{
|
||||
class Environment;
|
||||
}
|
||||
|
||||
namespace MWRender
|
||||
{
|
||||
class MWScene;
|
||||
|
||||
/**
|
||||
This class is responsible for inserting meshes and other
|
||||
rendering objects from the given cell into the given rendering
|
||||
scene.
|
||||
*/
|
||||
|
||||
class InteriorCellRender : public CellRender, private CellRenderImp
|
||||
{
|
||||
//static bool isChest;
|
||||
static bool lightConst;
|
||||
static float lightConstValue;
|
||||
|
||||
static bool lightLinear;
|
||||
static int lightLinearMethod;
|
||||
static float lightLinearValue;
|
||||
static float lightLinearRadiusMult;
|
||||
|
||||
static bool lightQuadratic;
|
||||
static int lightQuadraticMethod;
|
||||
static float lightQuadraticValue;
|
||||
static float lightQuadraticRadiusMult;
|
||||
|
||||
static bool lightOutQuadInLin;
|
||||
|
||||
ESMS::CellStore<MWWorld::RefData> &cell;
|
||||
MWWorld::Environment &mEnvironment;
|
||||
MWScene &scene;
|
||||
MWWorld::PhysicsSystem *mPhysics;
|
||||
|
||||
/// The scene node that contains all objects belonging to this
|
||||
/// cell.
|
||||
Ogre::SceneNode *base;
|
||||
|
||||
Ogre::SceneNode *insert;
|
||||
std::string mInsertMesh;
|
||||
Ogre::SceneNode *npcPart;
|
||||
|
||||
// 0 normal, 1 more bright, 2 max
|
||||
int ambientMode;
|
||||
|
||||
Ogre::ColourValue ambientColor;
|
||||
|
||||
/// start inserting a new reference.
|
||||
virtual void insertBegin (ESM::CellRef &ref, MWWorld::RefData& refData, bool static_ = false);
|
||||
virtual void rotateMesh(Ogre::Vector3 axis, Ogre::Radian angle, std::string sceneNodeName[], int elements);
|
||||
virtual void scaleMesh(Ogre::Vector3 axis, std::string sceneNodeName[], int elements);
|
||||
/// insert a mesh related to the most recent insertBegin call.
|
||||
virtual void insertMesh(const std::string &mesh);
|
||||
virtual void insertMesh(const std::string &mesh, Ogre::Vector3 vec, Ogre::Vector3 axis, Ogre::Radian angle, std::string sceneNodeName, std::string sceneParent[], int elements);
|
||||
virtual void insertMesh(const std::string &mesh, Ogre::Vector3 vec, Ogre::Vector3 axis, Ogre::Radian angle, std::string sceneNodeName, std::string sceneParent[], int elements, bool translateFirst);
|
||||
|
||||
virtual void insertObjectPhysics();
|
||||
|
||||
virtual void insertActorPhysics();
|
||||
|
||||
/// insert a light related to the most recent insertBegin call.
|
||||
virtual void insertLight(float r, float g, float b, float radius);
|
||||
|
||||
/// finish inserting a new reference and return a handle to it.
|
||||
virtual std::string insertEnd (bool Enable);
|
||||
|
||||
/// configure lighting according to cell
|
||||
void configureAmbient();
|
||||
|
||||
/// configure fog according to cell
|
||||
void configureFog();
|
||||
|
||||
void setAmbientMode();
|
||||
|
||||
|
||||
public:
|
||||
|
||||
InteriorCellRender(ESMS::CellStore<MWWorld::RefData> &_cell, MWWorld::Environment& environment,
|
||||
MWScene &_scene, MWWorld::PhysicsSystem *physics)
|
||||
: cell(_cell), mEnvironment (environment), scene(_scene), base(NULL), insert(NULL), ambientMode (0)
|
||||
{
|
||||
mPhysics = physics;
|
||||
}
|
||||
|
||||
virtual ~InteriorCellRender() { destroy(); }
|
||||
|
||||
/// Make the cell visible. Load the cell if necessary.
|
||||
//virtual void scaleMesh(Ogre::Vector3 axis, std::string sceneNodeName[], int elements);
|
||||
virtual void show();
|
||||
|
||||
/// Remove the cell from rendering, but don't remove it from
|
||||
/// memory.
|
||||
virtual void hide();
|
||||
|
||||
/// Destroy all rendering objects connected with this cell.
|
||||
virtual void destroy(); // comment by Zini: shouldn't this go into the destructor?
|
||||
|
||||
/// Switch through lighting modes.
|
||||
void toggleLight();
|
||||
|
||||
/// Make the reference with the given handle visible.
|
||||
virtual void enable (const std::string& handle);
|
||||
|
||||
/// Make the reference with the given handle invisible.
|
||||
virtual void disable (const std::string& handle);
|
||||
|
||||
/// Remove the reference with the given handle permanently from the scene.
|
||||
virtual void deleteObject (const std::string& handle);
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
@ -1,89 +0,0 @@
|
||||
#include "mwscene.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 "player.hpp"
|
||||
|
||||
using namespace MWRender;
|
||||
using namespace Ogre;
|
||||
|
||||
MWScene::MWScene(OEngine::Render::OgreRenderer &_rend , OEngine::Physic::PhysicEngine* physEng)
|
||||
: rend(_rend)
|
||||
{
|
||||
eng = physEng;
|
||||
rend.createScene("PlayerCam", 55, 5);
|
||||
|
||||
// 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.
|
||||
SceneNode *rt = rend.getScene()->getRootSceneNode();
|
||||
mwRoot = rt->createChildSceneNode();
|
||||
mwRoot->pitch(Degree(-90));
|
||||
|
||||
//used to obtain ingame information of ogre objects (which are faced or selected)
|
||||
mRaySceneQuery = rend.getScene()->createRayQuery(Ray());
|
||||
|
||||
Ogre::SceneNode *playerNode = mwRoot->createChildSceneNode ("player");
|
||||
playerNode->pitch(Degree(90));
|
||||
Ogre::SceneNode *cameraYawNode = playerNode->createChildSceneNode();
|
||||
Ogre::SceneNode *cameraPitchNode = cameraYawNode->createChildSceneNode();
|
||||
cameraPitchNode->attachObject(getCamera());
|
||||
|
||||
|
||||
mPlayer = new MWRender::Player (getCamera(), playerNode->getName());
|
||||
}
|
||||
|
||||
MWScene::~MWScene()
|
||||
{
|
||||
delete mPlayer;
|
||||
}
|
||||
|
||||
std::pair<std::string, float> MWScene::getFacedHandle (MWWorld::World& world)
|
||||
{
|
||||
std::string handle = "";
|
||||
|
||||
//get a ray pointing to the center of the viewport
|
||||
Ray centerRay = getCamera()->getCameraToViewportRay(
|
||||
getViewport()->getWidth()/2,
|
||||
getViewport()->getHeight()/2);
|
||||
//let's avoid the capsule shape of the player.
|
||||
centerRay.setOrigin(centerRay.getOrigin() + 20*centerRay.getDirection());
|
||||
btVector3 from(centerRay.getOrigin().x,-centerRay.getOrigin().z,centerRay.getOrigin().y);
|
||||
btVector3 to(centerRay.getPoint(500).x,-centerRay.getPoint(500).z,centerRay.getPoint(500).y);
|
||||
|
||||
return eng->rayTest(from,to);
|
||||
}
|
||||
|
||||
bool MWScene::toggleRenderMode (int mode)
|
||||
{
|
||||
switch (mode)
|
||||
{
|
||||
case MWWorld::World::Render_CollisionDebug:
|
||||
|
||||
// TODO use a proper function instead of accessing the member variable
|
||||
// directly.
|
||||
eng->setDebugRenderingMode (!eng->isDebugCreated);
|
||||
return eng->isDebugCreated;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
@ -1,74 +0,0 @@
|
||||
#ifndef _GAME_RENDER_MWSCENE_H
|
||||
#define _GAME_RENDER_MWSCENE_H
|
||||
|
||||
#include <utility>
|
||||
#include <openengine/ogre/renderer.hpp>
|
||||
#include <openengine/bullet/physic.hpp>
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
namespace Ogre
|
||||
{
|
||||
class Camera;
|
||||
class Viewport;
|
||||
class SceneManager;
|
||||
class SceneNode;
|
||||
class RaySceneQuery;
|
||||
class Quaternion;
|
||||
class Vector3;
|
||||
}
|
||||
|
||||
namespace MWWorld
|
||||
{
|
||||
class World;
|
||||
}
|
||||
|
||||
namespace MWRender
|
||||
{
|
||||
class Player;
|
||||
|
||||
/// \brief 3D-scene (rendering and physics)
|
||||
|
||||
class MWScene
|
||||
{
|
||||
OEngine::Render::OgreRenderer &rend;
|
||||
|
||||
/// Root node for all objects added to the scene. This is rotated so
|
||||
/// that the OGRE coordinate system matches that used internally in
|
||||
/// Morrowind.
|
||||
Ogre::SceneNode *mwRoot;
|
||||
Ogre::RaySceneQuery *mRaySceneQuery;
|
||||
|
||||
OEngine::Physic::PhysicEngine* eng;
|
||||
|
||||
MWRender::Player *mPlayer;
|
||||
|
||||
public:
|
||||
|
||||
MWScene (OEngine::Render::OgreRenderer &_rend , OEngine::Physic::PhysicEngine* physEng);
|
||||
|
||||
~MWScene();
|
||||
|
||||
Ogre::Camera *getCamera() { return rend.getCamera(); }
|
||||
Ogre::SceneNode *getRoot() { return mwRoot; }
|
||||
Ogre::SceneManager *getMgr() { return rend.getScene(); }
|
||||
Ogre::Viewport *getViewport() { return rend.getViewport(); }
|
||||
Ogre::RaySceneQuery *getRaySceneQuery() { return mRaySceneQuery; }
|
||||
MWRender::Player *getPlayer() { return mPlayer; }
|
||||
|
||||
/// Gets the handle of the object the player is looking at
|
||||
/// pair<name, distance>
|
||||
/// name is empty and distance = -1 if there is no object which
|
||||
/// can be faced
|
||||
std::pair<std::string, float> getFacedHandle (MWWorld::World& world);
|
||||
|
||||
/// Toggle render mode
|
||||
/// \todo Using an int instead of a enum here to avoid cyclic includes. Will be fixed
|
||||
/// when the mw*-refactoring is done.
|
||||
/// \return Resulting mode
|
||||
bool toggleRenderMode (int mode);
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
@ -0,0 +1,2 @@
|
||||
#include "npcs.hpp"
|
||||
using namespace MWRender;
|
@ -0,0 +1,9 @@
|
||||
#ifndef _GAME_RENDER_NPCS_H
|
||||
#define _GAME_RENDER_NPCS_H
|
||||
#include <openengine/ogre/renderer.hpp>
|
||||
namespace MWRender{
|
||||
class Npcs{
|
||||
|
||||
};
|
||||
}
|
||||
#endif
|
@ -0,0 +1,185 @@
|
||||
#include "objects.hpp"
|
||||
#include <OgreSceneNode.h>
|
||||
#include <components/nifogre/ogre_nif_loader.hpp>
|
||||
|
||||
using namespace Ogre;
|
||||
using namespace MWRender;
|
||||
|
||||
|
||||
bool Objects::lightConst = false;
|
||||
float Objects::lightConstValue = 0.0f;
|
||||
|
||||
bool Objects::lightLinear = true;
|
||||
int Objects::lightLinearMethod = 1;
|
||||
float Objects::lightLinearValue = 3;
|
||||
float Objects::lightLinearRadiusMult = 1;
|
||||
|
||||
bool Objects::lightQuadratic = false;
|
||||
int Objects::lightQuadraticMethod = 2;
|
||||
float Objects::lightQuadraticValue = 16;
|
||||
float Objects::lightQuadraticRadiusMult = 1;
|
||||
|
||||
bool Objects::lightOutQuadInLin = false;
|
||||
|
||||
int Objects::uniqueID = 0;
|
||||
|
||||
void Objects::setMwRoot(Ogre::SceneNode* root){
|
||||
mwRoot = root;
|
||||
}
|
||||
void Objects::insertBegin (const MWWorld::Ptr& ptr, bool enabled, bool static_){
|
||||
Ogre::SceneNode* root = mwRoot;
|
||||
Ogre::SceneNode* cellnode;
|
||||
if(mCellSceneNodes.find(ptr.getCell()) == mCellSceneNodes.end())
|
||||
{
|
||||
//Create the scenenode and put it in the map
|
||||
cellnode = root->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);
|
||||
isStatic = static_;
|
||||
|
||||
|
||||
}
|
||||
void Objects::insertMesh (const MWWorld::Ptr& ptr, const std::string& mesh){
|
||||
Ogre::SceneNode* insert = ptr.getRefData().getBaseNode();
|
||||
assert(insert);
|
||||
|
||||
NifOgre::NIFLoader::load(mesh);
|
||||
Entity *ent = mRend.getScene()->createEntity(mesh);
|
||||
|
||||
if(!isStatic)
|
||||
{
|
||||
insert->attachObject(ent);
|
||||
}
|
||||
else
|
||||
{
|
||||
Ogre::StaticGeometry* sg = 0;
|
||||
if(mSG.find(ptr.getCell()) == mSG.end())
|
||||
{
|
||||
uniqueID = uniqueID +1;
|
||||
sg = mRend.getScene()->createStaticGeometry( "sg" + Ogre::StringConverter::toString(uniqueID));
|
||||
//Create the scenenode and put it in the map
|
||||
mSG[ptr.getCell()] = sg;
|
||||
}
|
||||
else
|
||||
{
|
||||
sg = mSG[ptr.getCell()];
|
||||
}
|
||||
|
||||
sg->addEntity(ent,insert->_getDerivedPosition(),insert->_getDerivedOrientation(),insert->_getDerivedScale());
|
||||
sg->setRegionDimensions(Ogre::Vector3(100000,10000,100000));
|
||||
|
||||
|
||||
mRend.getScene()->destroyEntity(ent);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
void Objects::insertLight (const MWWorld::Ptr& ptr, float r, float g, float b, float radius){
|
||||
Ogre::SceneNode* insert = mRend.getScene()->getSceneNode(ptr.getRefData().getHandle());
|
||||
assert(insert);
|
||||
Ogre::Light *light = mRend.getScene()->createLight();
|
||||
light->setDiffuseColour (r, g, b);
|
||||
|
||||
float cval=0.0f, lval=0.0f, qval=0.0f;
|
||||
|
||||
if(lightConst)
|
||||
cval = lightConstValue;
|
||||
if(!lightOutQuadInLin)
|
||||
{
|
||||
if(lightLinear)
|
||||
radius *= lightLinearRadiusMult;
|
||||
if(lightQuadratic)
|
||||
radius *= lightQuadraticRadiusMult;
|
||||
|
||||
if(lightLinear)
|
||||
lval = lightLinearValue / pow(radius, lightLinearMethod);
|
||||
if(lightQuadratic)
|
||||
qval = lightQuadraticValue / pow(radius, lightQuadraticMethod);
|
||||
}
|
||||
else
|
||||
{
|
||||
// FIXME:
|
||||
// Do quadratic or linear, depending if we're in an exterior or interior
|
||||
// cell, respectively. Ignore lightLinear and lightQuadratic.
|
||||
}
|
||||
|
||||
light->setAttenuation(10*radius, cval, lval, qval);
|
||||
|
||||
insert->attachObject(light);
|
||||
}
|
||||
|
||||
bool Objects::deleteObject (const MWWorld::Ptr& ptr)
|
||||
{
|
||||
if (Ogre::SceneNode *base = ptr.getRefData().getBaseNode())
|
||||
{
|
||||
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 Objects::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;
|
||||
}
|
||||
|
||||
|
||||
if(mSG.find(store) != mSG.end())
|
||||
{
|
||||
Ogre::StaticGeometry* sg = mSG[store];
|
||||
mSG.erase(store);
|
||||
mRend.getScene()->destroyStaticGeometry (sg);
|
||||
sg = 0;
|
||||
}
|
||||
}
|
||||
void Objects::buildStaticGeometry(ESMS::CellStore<MWWorld::RefData>& cell){
|
||||
if(mSG.find(&cell) != mSG.end())
|
||||
{
|
||||
Ogre::StaticGeometry* sg = mSG[&cell];
|
||||
sg->build();
|
||||
}
|
||||
}
|
@ -0,0 +1,48 @@
|
||||
#ifndef _GAME_RENDER_OBJECTS_H
|
||||
#define _GAME_RENDER_OBJECTS_H
|
||||
|
||||
#include "components/esm_store/cell_store.hpp"
|
||||
|
||||
#include "../mwworld/refdata.hpp"
|
||||
#include "../mwworld/ptr.hpp"
|
||||
#include <openengine/ogre/renderer.hpp>
|
||||
|
||||
namespace MWRender{
|
||||
|
||||
class Objects{
|
||||
OEngine::Render::OgreRenderer &mRend;
|
||||
std::map<MWWorld::Ptr::CellStore *, Ogre::SceneNode *> mCellSceneNodes;
|
||||
std::map<MWWorld::Ptr::CellStore *, Ogre::StaticGeometry*> mSG;
|
||||
Ogre::SceneNode* mwRoot;
|
||||
bool isStatic;
|
||||
static int uniqueID;
|
||||
static bool lightConst;
|
||||
static float lightConstValue;
|
||||
|
||||
static bool lightLinear;
|
||||
static int lightLinearMethod;
|
||||
static float lightLinearValue;
|
||||
static float lightLinearRadiusMult;
|
||||
|
||||
static bool lightQuadratic;
|
||||
static int lightQuadraticMethod;
|
||||
static float lightQuadraticValue;
|
||||
static float lightQuadraticRadiusMult;
|
||||
|
||||
static bool lightOutQuadInLin;
|
||||
public:
|
||||
Objects(OEngine::Render::OgreRenderer& _rend): mRend(_rend){}
|
||||
~Objects(){}
|
||||
void insertBegin (const MWWorld::Ptr& ptr, bool enabled, bool static_);
|
||||
void insertMesh (const MWWorld::Ptr& ptr, const std::string& mesh);
|
||||
void insertLight (const MWWorld::Ptr& ptr, float r, float g, float b, float radius);
|
||||
|
||||
bool deleteObject (const MWWorld::Ptr& ptr);
|
||||
///< \return found?
|
||||
|
||||
void removeCell(MWWorld::Ptr::CellStore* store);
|
||||
void buildStaticGeometry(ESMS::CellStore<MWWorld::RefData> &cell);
|
||||
void setMwRoot(Ogre::SceneNode* root);
|
||||
};
|
||||
}
|
||||
#endif
|
@ -1,52 +0,0 @@
|
||||
#include "rendering_manager.hpp"
|
||||
|
||||
namespace MWRender {
|
||||
|
||||
RenderingManager::RenderingManager (SkyManager *skyManager) :
|
||||
mSkyManager(skyManager)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
RenderingManager::~RenderingManager ()
|
||||
{
|
||||
delete mSkyManager;
|
||||
}
|
||||
|
||||
void RenderingManager::skyEnable ()
|
||||
{
|
||||
mSkyManager->enable();
|
||||
}
|
||||
|
||||
void RenderingManager::skyDisable ()
|
||||
{
|
||||
mSkyManager->disable();
|
||||
}
|
||||
|
||||
void RenderingManager::skySetHour (double hour)
|
||||
{
|
||||
mSkyManager->setHour(hour);
|
||||
}
|
||||
|
||||
|
||||
void RenderingManager::skySetDate (int day, int month)
|
||||
{
|
||||
mSkyManager->setDate(day, month);
|
||||
}
|
||||
|
||||
int RenderingManager::skyGetMasserPhase() const
|
||||
{
|
||||
return mSkyManager->getMasserPhase();
|
||||
}
|
||||
|
||||
int RenderingManager::skyGetSecundaPhase() const
|
||||
{
|
||||
return mSkyManager->getSecundaPhase();
|
||||
}
|
||||
|
||||
void RenderingManager::skySetMoonColour (bool red)
|
||||
{
|
||||
mSkyManager->setMoonColour(red);
|
||||
}
|
||||
|
||||
}
|
@ -1,51 +0,0 @@
|
||||
#ifndef _GAME_RENDERING_MANAGER_H
|
||||
#define _GAME_RENDERING_MANAGER_H
|
||||
|
||||
|
||||
#include "sky.hpp"
|
||||
|
||||
#include "../mwworld/ptr.hpp"
|
||||
#include <openengine/ogre/renderer.hpp>
|
||||
#include <openengine/bullet/physic.hpp>
|
||||
|
||||
namespace MWRender
|
||||
{
|
||||
|
||||
class RenderingManager {
|
||||
public:
|
||||
RenderingManager(SkyManager *skyManager);
|
||||
~RenderingManager();
|
||||
|
||||
void removeCell (MWWorld::Ptr::CellStore *store); // TODO do we want this?
|
||||
|
||||
void addObject (const MWWorld::Ptr& ptr, MWWorld::Ptr::CellStore *store);
|
||||
void removeObject (const MWWorld::Ptr& ptr, MWWorld::Ptr::CellStore *store);
|
||||
|
||||
void moveObject (const MWWorld::Ptr& ptr, const Ogre::Vector3& position);
|
||||
void scaleObject (const MWWorld::Ptr& ptr, const Ogre::Vector3& scale);
|
||||
void rotateObject (const MWWorld::Ptr& ptr, const::Ogre::Quaternion& orientation);
|
||||
void moveObjectToCell (const MWWorld::Ptr& ptr, const Ogre::Vector3& position, MWWorld::Ptr::CellStore *store);
|
||||
|
||||
void setPhysicsDebugRendering (bool);
|
||||
bool getPhysicsDebugRendering() const;
|
||||
|
||||
void update (float duration);
|
||||
|
||||
void skyEnable ();
|
||||
void skyDisable ();
|
||||
void skySetHour (double hour);
|
||||
void skySetDate (int day, int month);
|
||||
int skyGetMasserPhase() const;
|
||||
int skyGetSecundaPhase() const;
|
||||
void skySetMoonColour (bool red);
|
||||
|
||||
private:
|
||||
|
||||
SkyManager* mSkyManager;
|
||||
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
@ -0,0 +1,17 @@
|
||||
#ifndef _GAME_RENDERING_INTERFACE_H
|
||||
#define _GAME_RENDERING_INTERFACE_H
|
||||
namespace MWRender{
|
||||
class Npcs;
|
||||
class Creatures;
|
||||
class Objects;
|
||||
class Player;
|
||||
class RenderingInterface{
|
||||
public:
|
||||
virtual MWRender::Npcs& getNPCs() = 0;
|
||||
virtual MWRender::Creatures& getCreatures() = 0;
|
||||
virtual MWRender::Objects& getObjects() = 0;
|
||||
virtual MWRender::Player& getPlayer() = 0;
|
||||
virtual ~RenderingInterface(){};
|
||||
};
|
||||
}
|
||||
#endif
|
@ -0,0 +1,230 @@
|
||||
#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>
|
||||
|
||||
|
||||
using namespace MWRender;
|
||||
using namespace Ogre;
|
||||
|
||||
namespace MWRender {
|
||||
|
||||
|
||||
|
||||
RenderingManager::RenderingManager (OEngine::Render::OgreRenderer& _rend, const boost::filesystem::path& resDir, OEngine::Physic::PhysicEngine* engine)
|
||||
:rend(_rend), objects(rend), mDebugging(engine)
|
||||
{
|
||||
rend.createScene("PlayerCam", 55, 5);
|
||||
mSkyManager = MWRender::SkyManager::create(rend.getWindow(), rend.getCamera(), resDir);
|
||||
|
||||
// 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.
|
||||
SceneNode *rt = rend.getScene()->getRootSceneNode();
|
||||
mwRoot = rt->createChildSceneNode();
|
||||
mwRoot->pitch(Degree(-90));
|
||||
objects.setMwRoot(mwRoot);
|
||||
|
||||
//used to obtain ingame information of ogre objects (which are faced or selected)
|
||||
mRaySceneQuery = rend.getScene()->createRayQuery(Ray());
|
||||
|
||||
Ogre::SceneNode *playerNode = mwRoot->createChildSceneNode ("player");
|
||||
playerNode->pitch(Degree(90));
|
||||
Ogre::SceneNode *cameraYawNode = playerNode->createChildSceneNode();
|
||||
Ogre::SceneNode *cameraPitchNode = cameraYawNode->createChildSceneNode();
|
||||
cameraPitchNode->attachObject(rend.getCamera());
|
||||
|
||||
mPlayer = new MWRender::Player (rend.getCamera(), playerNode);
|
||||
}
|
||||
|
||||
RenderingManager::~RenderingManager ()
|
||||
{
|
||||
delete mPlayer;
|
||||
delete mSkyManager;
|
||||
}
|
||||
|
||||
MWRender::Npcs& RenderingManager::getNPCs(){
|
||||
return npcs;
|
||||
}
|
||||
MWRender::Objects& RenderingManager::getObjects(){
|
||||
return objects;
|
||||
}
|
||||
MWRender::Creatures& RenderingManager::getCreatures(){
|
||||
return creatures;
|
||||
}
|
||||
MWRender::Player& RenderingManager::getPlayer(){
|
||||
return (*mPlayer);
|
||||
}
|
||||
|
||||
void RenderingManager::removeCell (MWWorld::Ptr::CellStore *store){
|
||||
objects.removeCell(store);
|
||||
}
|
||||
|
||||
void RenderingManager::cellAdded (MWWorld::Ptr::CellStore *store)
|
||||
{
|
||||
objects.buildStaticGeometry (*store);
|
||||
}
|
||||
|
||||
void RenderingManager::addObject (const MWWorld::Ptr& ptr){
|
||||
const MWWorld::Class& class_ =
|
||||
MWWorld::Class::get (ptr);
|
||||
class_.insertObjectRendering(ptr, *this);
|
||||
|
||||
}
|
||||
void RenderingManager::removeObject (const MWWorld::Ptr& ptr)
|
||||
{
|
||||
if (!objects.deleteObject (ptr))
|
||||
{
|
||||
/// \todo delete non-object MW-references
|
||||
}
|
||||
}
|
||||
|
||||
void RenderingManager::moveObject (const MWWorld::Ptr& ptr, const Ogre::Vector3& position)
|
||||
{
|
||||
/// \todo move this to the rendering-subsystems
|
||||
rend.getScene()->getSceneNode (ptr.getRefData().getHandle())->
|
||||
setPosition (position);
|
||||
}
|
||||
|
||||
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){
|
||||
|
||||
|
||||
}
|
||||
|
||||
void RenderingManager::skyEnable ()
|
||||
{
|
||||
mSkyManager->enable();
|
||||
}
|
||||
|
||||
void RenderingManager::skyDisable ()
|
||||
{
|
||||
mSkyManager->disable();
|
||||
}
|
||||
|
||||
void RenderingManager::skySetHour (double hour)
|
||||
{
|
||||
mSkyManager->setHour(hour);
|
||||
}
|
||||
|
||||
|
||||
void RenderingManager::skySetDate (int day, int month)
|
||||
{
|
||||
mSkyManager->setDate(day, month);
|
||||
}
|
||||
|
||||
int RenderingManager::skyGetMasserPhase() const
|
||||
{
|
||||
return mSkyManager->getMasserPhase();
|
||||
}
|
||||
|
||||
int RenderingManager::skyGetSecundaPhase() const
|
||||
{
|
||||
return mSkyManager->getSecundaPhase();
|
||||
}
|
||||
|
||||
void RenderingManager::skySetMoonColour (bool red)
|
||||
{
|
||||
mSkyManager->setMoonColour(red);
|
||||
}
|
||||
bool RenderingManager::toggleRenderMode(int mode){
|
||||
return mDebugging.toggleRenderMode(mode);
|
||||
}
|
||||
|
||||
void RenderingManager::configureFog(ESMS::CellStore<MWWorld::RefData> &mCell)
|
||||
{
|
||||
Ogre::ColourValue color;
|
||||
color.setAsABGR (mCell.cell->ambi.fog);
|
||||
|
||||
float high = 4500 + 9000 * (1-mCell.cell->ambi.fogDensity);
|
||||
float low = 200;
|
||||
|
||||
rend.getScene()->setFog (FOG_LINEAR, color, 0, low, high);
|
||||
rend.getCamera()->setFarClipDistance (high + 10);
|
||||
rend.getViewport()->setBackgroundColour (color);
|
||||
}
|
||||
|
||||
void RenderingManager::setAmbientMode()
|
||||
{
|
||||
switch (mAmbientMode)
|
||||
{
|
||||
case 0:
|
||||
|
||||
rend.getScene()->setAmbientLight(mAmbientColor);
|
||||
break;
|
||||
|
||||
case 1:
|
||||
|
||||
rend.getScene()->setAmbientLight(0.7f*mAmbientColor + 0.3f*ColourValue(1,1,1));
|
||||
break;
|
||||
|
||||
case 2:
|
||||
|
||||
rend.getScene()->setAmbientLight(ColourValue(1,1,1));
|
||||
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.
|
||||
Ogre::Light *light = rend.getScene()->createLight();
|
||||
Ogre::ColourValue colour;
|
||||
colour.setAsABGR (mCell.cell->ambi.sunlight);
|
||||
light->setDiffuseColour (colour);
|
||||
light->setType(Ogre::Light::LT_DIRECTIONAL);
|
||||
light->setDirection(0,-1,0);
|
||||
}
|
||||
// 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();
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,125 @@
|
||||
#ifndef _GAME_RENDERING_MANAGER_H
|
||||
#define _GAME_RENDERING_MANAGER_H
|
||||
|
||||
|
||||
#include "sky.hpp"
|
||||
#include "debugging.hpp"
|
||||
|
||||
#include "../mwworld/class.hpp"
|
||||
|
||||
#include <utility>
|
||||
#include <openengine/ogre/renderer.hpp>
|
||||
#include <openengine/bullet/physic.hpp>
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
#include "../mwworld/ptr.hpp"
|
||||
|
||||
#include <boost/filesystem.hpp>
|
||||
|
||||
#include "renderinginterface.hpp"
|
||||
#include "npcs.hpp"
|
||||
#include "creatures.hpp"
|
||||
#include "objects.hpp"
|
||||
#include "player.hpp"
|
||||
|
||||
namespace Ogre
|
||||
{
|
||||
class Camera;
|
||||
class Viewport;
|
||||
class SceneManager;
|
||||
class SceneNode;
|
||||
class RaySceneQuery;
|
||||
class Quaternion;
|
||||
class Vector3;
|
||||
}
|
||||
|
||||
namespace MWWorld
|
||||
{
|
||||
class World;
|
||||
}
|
||||
|
||||
namespace MWRender
|
||||
{
|
||||
|
||||
|
||||
|
||||
class RenderingManager: private RenderingInterface {
|
||||
|
||||
private:
|
||||
|
||||
virtual MWRender::Npcs& getNPCs();
|
||||
virtual MWRender::Creatures& getCreatures();
|
||||
virtual MWRender::Objects& getObjects();
|
||||
|
||||
public:
|
||||
RenderingManager(OEngine::Render::OgreRenderer& _rend, const boost::filesystem::path& resDir, OEngine::Physic::PhysicEngine* engine);
|
||||
virtual ~RenderingManager();
|
||||
|
||||
virtual MWRender::Player& getPlayer(); /// \todo move this to private again as soon as
|
||||
/// MWWorld::Player has been rewritten to not need access
|
||||
/// to internal details of the rendering system anymore
|
||||
|
||||
void toggleLight();
|
||||
bool toggleRenderMode(int mode);
|
||||
|
||||
void removeCell (MWWorld::Ptr::CellStore *store);
|
||||
|
||||
/// \todo this function should be removed later. Instead the rendering subsystems should track
|
||||
/// when rebatching is needed and update automatically at the end of each frame.
|
||||
void cellAdded (MWWorld::Ptr::CellStore *store);
|
||||
|
||||
void addObject (const MWWorld::Ptr& ptr);
|
||||
void removeObject (const MWWorld::Ptr& ptr);
|
||||
|
||||
void moveObject (const MWWorld::Ptr& ptr, const Ogre::Vector3& position);
|
||||
void scaleObject (const MWWorld::Ptr& ptr, const Ogre::Vector3& scale);
|
||||
void rotateObject (const MWWorld::Ptr& ptr, const::Ogre::Quaternion& orientation);
|
||||
|
||||
/// \param store Cell the object was in previously (\a ptr has already been updated to the new cell).
|
||||
void moveObjectToCell (const MWWorld::Ptr& ptr, const Ogre::Vector3& position, MWWorld::Ptr::CellStore *store);
|
||||
|
||||
void update (float duration);
|
||||
|
||||
void skyEnable ();
|
||||
void skyDisable ();
|
||||
void skySetHour (double hour);
|
||||
void skySetDate (int day, int month);
|
||||
int skyGetMasserPhase() const;
|
||||
int skyGetSecundaPhase() const;
|
||||
void skySetMoonColour (bool red);
|
||||
void configureAmbient(ESMS::CellStore<MWWorld::RefData> &mCell);
|
||||
/// configure fog according to cell
|
||||
void configureFog(ESMS::CellStore<MWWorld::RefData> &mCell);
|
||||
|
||||
private:
|
||||
|
||||
void setAmbientMode();
|
||||
SkyManager* mSkyManager;
|
||||
OEngine::Render::OgreRenderer &rend;
|
||||
Ogre::Camera* camera;
|
||||
MWRender::Npcs npcs;
|
||||
MWRender::Creatures creatures;
|
||||
MWRender::Objects objects;
|
||||
|
||||
// 0 normal, 1 more bright, 2 max
|
||||
int mAmbientMode;
|
||||
|
||||
Ogre::ColourValue mAmbientColor;
|
||||
|
||||
/// Root node for all objects added to the scene. This is rotated so
|
||||
/// that the OGRE coordinate system matches that used internally in
|
||||
/// Morrowind.
|
||||
Ogre::SceneNode *mwRoot;
|
||||
Ogre::RaySceneQuery *mRaySceneQuery;
|
||||
|
||||
OEngine::Physic::PhysicEngine* eng;
|
||||
|
||||
MWRender::Player *mPlayer;
|
||||
MWRender::Debugging mDebugging;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue