2011-11-01 03:59:16 +00:00
|
|
|
#include "objects.hpp"
|
2012-02-06 09:41:13 +00:00
|
|
|
|
2011-11-02 04:13:33 +00:00
|
|
|
#include <OgreSceneNode.h>
|
2012-07-03 13:32:38 +00:00
|
|
|
#include <OgreSceneManager.h>
|
|
|
|
#include <OgreEntity.h>
|
|
|
|
#include <OgreLight.h>
|
|
|
|
#include <OgreSubEntity.h>
|
|
|
|
#include <OgreStaticGeometry.h>
|
2012-02-06 09:41:13 +00:00
|
|
|
|
2011-11-03 23:40:37 +00:00
|
|
|
#include <components/nifogre/ogre_nif_loader.hpp>
|
2012-04-02 12:24:16 +00:00
|
|
|
#include <components/settings/settings.hpp>
|
2012-07-03 11:55:53 +00:00
|
|
|
|
|
|
|
#include "../mwworld/ptr.hpp"
|
2012-07-30 19:28:14 +00:00
|
|
|
#include "../mwworld/class.hpp"
|
2012-07-03 11:55:53 +00:00
|
|
|
|
2012-04-03 13:13:47 +00:00
|
|
|
#include "renderconst.hpp"
|
2011-11-01 03:59:16 +00:00
|
|
|
|
2011-11-08 04:35:39 +00:00
|
|
|
using namespace MWRender;
|
|
|
|
|
2013-01-07 11:17:46 +00:00
|
|
|
/// \todo Replace these, once fallback values from the ini file are available.
|
2011-11-03 23:40:37 +00:00
|
|
|
float Objects::lightLinearValue = 3;
|
|
|
|
float Objects::lightLinearRadiusMult = 1;
|
|
|
|
|
|
|
|
float Objects::lightQuadraticValue = 16;
|
|
|
|
float Objects::lightQuadraticRadiusMult = 1;
|
|
|
|
|
2012-04-19 18:59:57 +00:00
|
|
|
bool Objects::lightOutQuadInLin = true;
|
|
|
|
bool Objects::lightQuadratic = false;
|
2011-11-03 23:40:37 +00:00
|
|
|
|
|
|
|
int Objects::uniqueID = 0;
|
2011-11-01 03:59:16 +00:00
|
|
|
|
2012-02-06 09:29:18 +00:00
|
|
|
void Objects::clearSceneNode (Ogre::SceneNode *node)
|
|
|
|
{
|
|
|
|
for (int i=node->numAttachedObjects()-1; i>=0; --i)
|
|
|
|
{
|
|
|
|
Ogre::MovableObject *object = node->getAttachedObject (i);
|
|
|
|
node->detachObject (object);
|
2012-02-06 09:41:13 +00:00
|
|
|
mRenderer.getScene()->destroyMovableObject (object);
|
2012-02-06 09:29:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-02-06 09:41:13 +00:00
|
|
|
void Objects::setMwRoot(Ogre::SceneNode* root)
|
|
|
|
{
|
2011-11-22 07:39:28 +00:00
|
|
|
mMwRoot = root;
|
2011-11-17 22:10:27 +00:00
|
|
|
}
|
2012-02-06 09:41:13 +00:00
|
|
|
|
|
|
|
void Objects::insertBegin (const MWWorld::Ptr& ptr, bool enabled, bool static_)
|
|
|
|
{
|
2011-11-22 07:39:28 +00:00
|
|
|
Ogre::SceneNode* root = mMwRoot;
|
2011-11-05 01:57:39 +00:00
|
|
|
Ogre::SceneNode* cellnode;
|
|
|
|
if(mCellSceneNodes.find(ptr.getCell()) == mCellSceneNodes.end())
|
|
|
|
{
|
2011-11-21 11:52:28 +00:00
|
|
|
//Create the scenenode and put it in the map
|
|
|
|
cellnode = root->createChildSceneNode();
|
2011-11-05 01:57:39 +00:00
|
|
|
mCellSceneNodes[ptr.getCell()] = cellnode;
|
2011-11-21 11:52:28 +00:00
|
|
|
}
|
|
|
|
else
|
2011-11-05 01:57:39 +00:00
|
|
|
{
|
|
|
|
cellnode = mCellSceneNodes[ptr.getCell()];
|
|
|
|
}
|
2011-11-05 01:48:52 +00:00
|
|
|
|
2011-11-05 01:57:39 +00:00
|
|
|
Ogre::SceneNode* insert = cellnode->createChildSceneNode();
|
2011-11-09 18:53:29 +00:00
|
|
|
const float *f = ptr.getRefData().getPosition().pos;
|
2012-03-25 02:03:08 +00:00
|
|
|
|
2011-11-05 01:57:39 +00:00
|
|
|
insert->setPosition(f[0], f[1], f[2]);
|
2012-09-17 07:37:50 +00:00
|
|
|
insert->setScale(ptr.getCellRef().mScale, ptr.getCellRef().mScale, ptr.getCellRef().mScale);
|
2012-06-29 14:48:50 +00:00
|
|
|
|
2011-11-03 23:40:37 +00:00
|
|
|
|
2011-11-05 01:57:39 +00:00
|
|
|
// Convert MW rotation to a quaternion:
|
2012-09-17 07:37:50 +00:00
|
|
|
f = ptr.getCellRef().mPos.rot;
|
2011-11-03 23:40:37 +00:00
|
|
|
|
2011-11-05 01:57:39 +00:00
|
|
|
// Rotate around X axis
|
2012-02-06 09:41:13 +00:00
|
|
|
Ogre::Quaternion xr(Ogre::Radian(-f[0]), Ogre::Vector3::UNIT_X);
|
2011-11-03 23:40:37 +00:00
|
|
|
|
2011-11-05 01:57:39 +00:00
|
|
|
// Rotate around Y axis
|
2012-02-06 09:41:13 +00:00
|
|
|
Ogre::Quaternion yr(Ogre::Radian(-f[1]), Ogre::Vector3::UNIT_Y);
|
2011-11-03 23:40:37 +00:00
|
|
|
|
2011-11-05 01:57:39 +00:00
|
|
|
// Rotate around Z axis
|
2012-02-06 09:41:13 +00:00
|
|
|
Ogre::Quaternion zr(Ogre::Radian(-f[2]), Ogre::Vector3::UNIT_Z);
|
2011-11-03 23:40:37 +00:00
|
|
|
|
2012-02-06 09:41:13 +00:00
|
|
|
// Rotates first around z, then y, then x
|
2011-11-05 01:57:39 +00:00
|
|
|
insert->setOrientation(xr*yr*zr);
|
2012-02-06 09:29:18 +00:00
|
|
|
|
2011-11-05 01:57:39 +00:00
|
|
|
if (!enabled)
|
|
|
|
insert->setVisible (false);
|
2011-11-03 02:41:48 +00:00
|
|
|
ptr.getRefData().setBaseNode(insert);
|
2012-02-06 09:41:13 +00:00
|
|
|
mIsStatic = static_;
|
2011-11-01 03:59:16 +00:00
|
|
|
}
|
2012-02-06 09:41:13 +00:00
|
|
|
|
|
|
|
void Objects::insertMesh (const MWWorld::Ptr& ptr, const std::string& mesh)
|
|
|
|
{
|
2011-11-11 19:37:42 +00:00
|
|
|
Ogre::SceneNode* insert = ptr.getRefData().getBaseNode();
|
2011-11-05 01:57:39 +00:00
|
|
|
assert(insert);
|
2011-11-03 23:40:37 +00:00
|
|
|
|
2012-07-16 17:48:48 +00:00
|
|
|
Ogre::AxisAlignedBox bounds = Ogre::AxisAlignedBox::BOX_NULL;
|
2012-07-24 00:20:47 +00:00
|
|
|
NifOgre::EntityList entities = NifOgre::NIFLoader::createEntities(insert, NULL, mesh);
|
2012-07-17 20:40:03 +00:00
|
|
|
for(size_t i = 0;i < entities.mEntities.size();i++)
|
2012-07-16 17:48:48 +00:00
|
|
|
{
|
2012-07-17 20:40:03 +00:00
|
|
|
const Ogre::AxisAlignedBox &tmp = entities.mEntities[i]->getBoundingBox();
|
2012-07-16 17:48:48 +00:00
|
|
|
bounds.merge(Ogre::AxisAlignedBox(insert->_getDerivedPosition() + tmp.getMinimum(),
|
|
|
|
insert->_getDerivedPosition() + tmp.getMaximum())
|
|
|
|
);
|
|
|
|
}
|
|
|
|
Ogre::Vector3 extents = bounds.getSize();
|
2012-03-26 22:45:25 +00:00
|
|
|
extents *= insert->getScale();
|
2012-04-02 13:30:29 +00:00
|
|
|
float size = std::max(std::max(extents.x, extents.y), extents.z);
|
2012-03-26 22:45:25 +00:00
|
|
|
|
2012-09-02 09:39:54 +00:00
|
|
|
bool small = (size < Settings::Manager::getInt("small object size", "Viewing distance")) && Settings::Manager::getBool("limit small object distance", "Viewing distance");
|
2012-03-26 22:45:25 +00:00
|
|
|
|
|
|
|
// do not fade out doors. that will cause holes and look stupid
|
|
|
|
if (ptr.getTypeName().find("Door") != std::string::npos)
|
|
|
|
small = false;
|
|
|
|
|
2012-03-29 14:47:59 +00:00
|
|
|
if (mBounds.find(ptr.getCell()) == mBounds.end())
|
|
|
|
mBounds[ptr.getCell()] = Ogre::AxisAlignedBox::BOX_NULL;
|
|
|
|
mBounds[ptr.getCell()].merge(bounds);
|
|
|
|
|
2012-04-04 16:53:40 +00:00
|
|
|
bool transparent = false;
|
2012-07-17 20:40:03 +00:00
|
|
|
for(size_t i = 0;i < entities.mEntities.size();i++)
|
2012-04-04 16:53:40 +00:00
|
|
|
{
|
2012-07-17 20:40:03 +00:00
|
|
|
Ogre::Entity *ent = entities.mEntities[i];
|
2012-07-16 17:48:48 +00:00
|
|
|
for (unsigned int i=0; i<ent->getNumSubEntities(); ++i)
|
2012-04-04 16:53:40 +00:00
|
|
|
{
|
2012-07-16 17:48:48 +00:00
|
|
|
Ogre::MaterialPtr mat = ent->getSubEntity(i)->getMaterial();
|
|
|
|
Ogre::Material::TechniqueIterator techIt = mat->getTechniqueIterator();
|
|
|
|
while (techIt.hasMoreElements())
|
2012-04-04 16:53:40 +00:00
|
|
|
{
|
2012-07-16 17:48:48 +00:00
|
|
|
Ogre::Technique* tech = techIt.getNext();
|
|
|
|
Ogre::Technique::PassIterator passIt = tech->getPassIterator();
|
|
|
|
while (passIt.hasMoreElements())
|
|
|
|
{
|
|
|
|
Ogre::Pass* pass = passIt.getNext();
|
|
|
|
|
|
|
|
if (pass->getDepthWriteEnabled() == false)
|
|
|
|
transparent = true;
|
|
|
|
}
|
2012-04-04 16:53:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-04-19 18:59:57 +00:00
|
|
|
if(!mIsStatic || !Settings::Manager::getBool("use static geometry", "Objects") || transparent)
|
2011-11-05 01:57:39 +00:00
|
|
|
{
|
2012-07-17 20:40:03 +00:00
|
|
|
for(size_t i = 0;i < entities.mEntities.size();i++)
|
2012-07-16 17:48:48 +00:00
|
|
|
{
|
2012-07-17 20:40:03 +00:00
|
|
|
Ogre::Entity *ent = entities.mEntities[i];
|
2012-03-26 22:45:25 +00:00
|
|
|
|
2012-07-16 17:48:48 +00:00
|
|
|
ent->setRenderingDistance(small ? Settings::Manager::getInt("small object distance", "Viewing distance") : 0);
|
|
|
|
ent->setVisibilityFlags(mIsStatic ? (small ? RV_StaticsSmall : RV_Statics) : RV_Misc);
|
|
|
|
ent->setRenderQueueGroup(transparent ? RQG_Alpha : RQG_Main);
|
|
|
|
}
|
2011-11-05 01:57:39 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-11-21 11:52:28 +00:00
|
|
|
Ogre::StaticGeometry* sg = 0;
|
2012-03-26 22:45:25 +00:00
|
|
|
|
2012-04-19 18:59:57 +00:00
|
|
|
if (small)
|
2011-11-05 01:57:39 +00:00
|
|
|
{
|
2012-03-26 22:45:25 +00:00
|
|
|
if( mStaticGeometrySmall.find(ptr.getCell()) == mStaticGeometrySmall.end())
|
|
|
|
{
|
|
|
|
uniqueID = uniqueID +1;
|
|
|
|
sg = mRenderer.getScene()->createStaticGeometry( "sg" + Ogre::StringConverter::toString(uniqueID));
|
|
|
|
mStaticGeometrySmall[ptr.getCell()] = sg;
|
|
|
|
|
2012-04-05 17:07:21 +00:00
|
|
|
sg->setRenderingDistance(Settings::Manager::getInt("small object distance", "Viewing distance"));
|
2012-03-26 22:45:25 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
sg = mStaticGeometrySmall[ptr.getCell()];
|
2011-11-05 01:57:39 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-03-26 22:45:25 +00:00
|
|
|
if( mStaticGeometry.find(ptr.getCell()) == mStaticGeometry.end())
|
|
|
|
{
|
|
|
|
|
|
|
|
uniqueID = uniqueID +1;
|
|
|
|
sg = mRenderer.getScene()->createStaticGeometry( "sg" + Ogre::StringConverter::toString(uniqueID));
|
|
|
|
mStaticGeometry[ptr.getCell()] = sg;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
sg = mStaticGeometry[ptr.getCell()];
|
2011-11-05 01:57:39 +00:00
|
|
|
}
|
|
|
|
|
2012-03-26 22:45:25 +00:00
|
|
|
// This specifies the size of a single batch region.
|
|
|
|
// If it is set too high:
|
|
|
|
// - there will be problems choosing the correct lights
|
|
|
|
// - the culling will be more inefficient
|
|
|
|
// If it is set too low:
|
|
|
|
// - there will be too many batches.
|
|
|
|
sg->setRegionDimensions(Ogre::Vector3(2500,2500,2500));
|
|
|
|
|
2012-04-03 13:13:47 +00:00
|
|
|
sg->setVisibilityFlags(small ? RV_StaticsSmall : RV_Statics);
|
|
|
|
|
2012-04-11 16:53:13 +00:00
|
|
|
sg->setCastShadows(true);
|
|
|
|
|
2012-04-05 17:07:21 +00:00
|
|
|
sg->setRenderQueueGroup(transparent ? RQG_Alpha : RQG_Main);
|
|
|
|
|
2012-07-17 20:40:03 +00:00
|
|
|
for(size_t i = 0;i < entities.mEntities.size();i++)
|
2012-07-16 17:48:48 +00:00
|
|
|
{
|
2012-07-17 20:40:03 +00:00
|
|
|
Ogre::Entity *ent = entities.mEntities[i];
|
|
|
|
insert->detachObject(ent);
|
2012-07-16 17:48:48 +00:00
|
|
|
sg->addEntity(ent,insert->_getDerivedPosition(),insert->_getDerivedOrientation(),insert->_getDerivedScale());
|
|
|
|
|
|
|
|
mRenderer.getScene()->destroyEntity(ent);
|
|
|
|
}
|
2011-11-05 01:57:39 +00:00
|
|
|
}
|
2011-11-01 03:59:16 +00:00
|
|
|
}
|
2012-02-06 09:41:13 +00:00
|
|
|
|
|
|
|
void Objects::insertLight (const MWWorld::Ptr& ptr, float r, float g, float b, float radius)
|
|
|
|
{
|
|
|
|
Ogre::SceneNode* insert = mRenderer.getScene()->getSceneNode(ptr.getRefData().getHandle());
|
2011-11-05 01:57:39 +00:00
|
|
|
assert(insert);
|
2012-02-06 09:41:13 +00:00
|
|
|
Ogre::Light *light = mRenderer.getScene()->createLight();
|
2011-11-05 01:57:39 +00:00
|
|
|
light->setDiffuseColour (r, g, b);
|
2011-11-03 23:40:37 +00:00
|
|
|
|
2012-06-29 16:54:23 +00:00
|
|
|
MWWorld::LiveCellRef<ESM::Light> *ref = ptr.get<ESM::Light>();
|
2012-04-28 18:42:53 +00:00
|
|
|
|
2012-04-19 18:59:57 +00:00
|
|
|
LightInfo info;
|
|
|
|
info.name = light->getName();
|
|
|
|
info.radius = radius;
|
|
|
|
info.colour = Ogre::ColourValue(r, g, b);
|
|
|
|
|
2012-11-05 12:07:59 +00:00
|
|
|
if (ref->mBase->mData.mFlags & ESM::Light::Negative)
|
2012-04-28 18:42:53 +00:00
|
|
|
info.colour *= -1;
|
2011-11-03 23:40:37 +00:00
|
|
|
|
2012-11-05 12:07:59 +00:00
|
|
|
info.interior = !ptr.getCell()->mCell->isExterior();
|
2012-02-06 09:41:13 +00:00
|
|
|
|
2012-11-05 12:07:59 +00:00
|
|
|
if (ref->mBase->mData.mFlags & ESM::Light::Flicker)
|
2012-04-28 18:42:53 +00:00
|
|
|
info.type = LT_Flicker;
|
2012-11-05 12:07:59 +00:00
|
|
|
else if (ref->mBase->mData.mFlags & ESM::Light::FlickerSlow)
|
2012-04-28 18:42:53 +00:00
|
|
|
info.type = LT_FlickerSlow;
|
2012-11-05 12:07:59 +00:00
|
|
|
else if (ref->mBase->mData.mFlags & ESM::Light::Pulse)
|
2012-04-28 18:42:53 +00:00
|
|
|
info.type = LT_Pulse;
|
2012-11-05 12:07:59 +00:00
|
|
|
else if (ref->mBase->mData.mFlags & ESM::Light::PulseSlow)
|
2012-04-28 18:42:53 +00:00
|
|
|
info.type = LT_PulseSlow;
|
|
|
|
else
|
|
|
|
info.type = LT_Normal;
|
|
|
|
|
2013-01-06 18:45:54 +00:00
|
|
|
// randomize lights animations
|
|
|
|
info.time = Ogre::Math::RangeRandom(-500, +500);
|
|
|
|
info.phase = Ogre::Math::RangeRandom(-500, +500);
|
2012-04-28 18:42:53 +00:00
|
|
|
|
|
|
|
// adjust the lights depending if we're in an interior or exterior cell
|
|
|
|
// quadratic means the light intensity falls off quite fast, resulting in a
|
|
|
|
// dark, atmospheric environment (perfect for exteriors)
|
|
|
|
// for interiors, we want more "warm" lights, so use linear attenuation.
|
2012-04-19 18:59:57 +00:00
|
|
|
bool quadratic = false;
|
|
|
|
if (!lightOutQuadInLin)
|
|
|
|
quadratic = lightQuadratic;
|
|
|
|
else
|
|
|
|
{
|
2012-04-28 18:42:53 +00:00
|
|
|
quadratic = !info.interior;
|
2012-04-19 18:59:57 +00:00
|
|
|
}
|
2012-02-06 09:41:13 +00:00
|
|
|
|
2012-04-19 18:59:57 +00:00
|
|
|
if (!quadratic)
|
2012-02-06 09:41:13 +00:00
|
|
|
{
|
2012-04-19 18:59:57 +00:00
|
|
|
float r = radius * lightLinearRadiusMult;
|
|
|
|
float attenuation = lightLinearValue / r;
|
|
|
|
light->setAttenuation(r*10, 0, attenuation, 0);
|
2012-02-06 09:41:13 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-04-19 18:59:57 +00:00
|
|
|
float r = radius * lightQuadraticRadiusMult;
|
|
|
|
float attenuation = lightQuadraticValue / pow(r, 2);
|
|
|
|
light->setAttenuation(r*10, 0, 0, attenuation);
|
2012-02-06 09:41:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
insert->attachObject(light);
|
2012-04-28 18:42:53 +00:00
|
|
|
mLights.push_back(info);
|
2011-11-01 03:59:16 +00:00
|
|
|
}
|
2011-11-02 04:13:33 +00:00
|
|
|
|
2011-11-21 11:52:28 +00:00
|
|
|
bool Objects::deleteObject (const MWWorld::Ptr& ptr)
|
2011-11-05 01:48:52 +00:00
|
|
|
{
|
2011-11-21 11:52:28 +00:00
|
|
|
if (Ogre::SceneNode *base = ptr.getRefData().getBaseNode())
|
2011-11-05 01:48:52 +00:00
|
|
|
{
|
2011-11-21 11:52:28 +00:00
|
|
|
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)
|
|
|
|
{
|
2012-02-06 09:29:18 +00:00
|
|
|
clearSceneNode (base);
|
2011-11-21 11:52:28 +00:00
|
|
|
base->removeAndDestroyAllChildren();
|
2012-02-06 09:41:13 +00:00
|
|
|
mRenderer.getScene()->destroySceneNode (base);
|
2011-11-21 11:52:28 +00:00
|
|
|
ptr.getRefData().setBaseNode (0);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
2011-11-05 01:48:52 +00:00
|
|
|
}
|
2011-11-21 11:52:28 +00:00
|
|
|
|
|
|
|
return true;
|
2011-11-05 01:48:52 +00:00
|
|
|
}
|
|
|
|
|
2012-02-06 09:41:13 +00:00
|
|
|
void Objects::removeCell(MWWorld::Ptr::CellStore* store)
|
|
|
|
{
|
2011-11-21 11:52:28 +00:00
|
|
|
if(mCellSceneNodes.find(store) != mCellSceneNodes.end())
|
2011-11-05 01:48:52 +00:00
|
|
|
{
|
2011-11-19 06:01:19 +00:00
|
|
|
Ogre::SceneNode* base = mCellSceneNodes[store];
|
2012-02-06 09:29:18 +00:00
|
|
|
|
|
|
|
for (int i=0; i<base->numChildren(); ++i)
|
|
|
|
clearSceneNode (static_cast<Ogre::SceneNode *> (base->getChild (i)));
|
|
|
|
|
2011-11-05 01:57:39 +00:00
|
|
|
base->removeAndDestroyAllChildren();
|
2011-11-20 01:22:56 +00:00
|
|
|
mCellSceneNodes.erase(store);
|
2012-02-06 09:41:13 +00:00
|
|
|
mRenderer.getScene()->destroySceneNode(base);
|
2011-11-21 11:52:28 +00:00
|
|
|
base = 0;
|
2011-11-05 01:48:52 +00:00
|
|
|
}
|
|
|
|
|
2012-02-06 09:41:13 +00:00
|
|
|
if(mStaticGeometry.find(store) != mStaticGeometry.end())
|
2011-11-05 01:48:52 +00:00
|
|
|
{
|
2012-02-06 09:41:13 +00:00
|
|
|
Ogre::StaticGeometry* sg = mStaticGeometry[store];
|
|
|
|
mStaticGeometry.erase(store);
|
|
|
|
mRenderer.getScene()->destroyStaticGeometry (sg);
|
2011-11-05 01:48:52 +00:00
|
|
|
sg = 0;
|
|
|
|
}
|
2012-03-26 22:45:25 +00:00
|
|
|
if(mStaticGeometrySmall.find(store) != mStaticGeometrySmall.end())
|
|
|
|
{
|
|
|
|
Ogre::StaticGeometry* sg = mStaticGeometrySmall[store];
|
|
|
|
mStaticGeometrySmall.erase(store);
|
|
|
|
mRenderer.getScene()->destroyStaticGeometry (sg);
|
|
|
|
sg = 0;
|
|
|
|
}
|
2012-03-29 16:04:52 +00:00
|
|
|
|
2012-03-10 14:28:18 +00:00
|
|
|
if(mBounds.find(store) != mBounds.end())
|
|
|
|
mBounds.erase(store);
|
2011-11-05 01:48:52 +00:00
|
|
|
}
|
2012-02-06 09:29:18 +00:00
|
|
|
|
2012-06-29 14:48:50 +00:00
|
|
|
void Objects::buildStaticGeometry(MWWorld::Ptr::CellStore& cell)
|
2012-02-06 09:41:13 +00:00
|
|
|
{
|
|
|
|
if(mStaticGeometry.find(&cell) != mStaticGeometry.end())
|
2011-11-05 18:57:33 +00:00
|
|
|
{
|
2012-02-06 09:41:13 +00:00
|
|
|
Ogre::StaticGeometry* sg = mStaticGeometry[&cell];
|
2011-11-21 11:52:28 +00:00
|
|
|
sg->build();
|
2011-11-05 18:57:33 +00:00
|
|
|
}
|
2012-03-26 22:45:25 +00:00
|
|
|
if(mStaticGeometrySmall.find(&cell) != mStaticGeometrySmall.end())
|
|
|
|
{
|
|
|
|
Ogre::StaticGeometry* sg = mStaticGeometrySmall[&cell];
|
|
|
|
sg->build();
|
|
|
|
}
|
2011-11-05 18:57:33 +00:00
|
|
|
}
|
2012-03-10 14:28:18 +00:00
|
|
|
|
|
|
|
Ogre::AxisAlignedBox Objects::getDimensions(MWWorld::Ptr::CellStore* cell)
|
|
|
|
{
|
|
|
|
return mBounds[cell];
|
|
|
|
}
|
2012-04-02 17:37:24 +00:00
|
|
|
|
|
|
|
void Objects::enableLights()
|
|
|
|
{
|
2012-04-19 18:59:57 +00:00
|
|
|
std::vector<LightInfo>::iterator it = mLights.begin();
|
2012-04-02 17:37:24 +00:00
|
|
|
while (it != mLights.end())
|
|
|
|
{
|
2012-04-19 18:59:57 +00:00
|
|
|
if (mMwRoot->getCreator()->hasLight(it->name))
|
2012-04-02 17:37:24 +00:00
|
|
|
{
|
2012-04-19 18:59:57 +00:00
|
|
|
mMwRoot->getCreator()->getLight(it->name)->setVisible(true);
|
2012-04-02 17:37:24 +00:00
|
|
|
++it;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
it = mLights.erase(it);
|
|
|
|
}
|
2011-11-05 18:57:33 +00:00
|
|
|
}
|
2012-04-02 17:37:24 +00:00
|
|
|
|
|
|
|
void Objects::disableLights()
|
|
|
|
{
|
2012-04-19 18:59:57 +00:00
|
|
|
std::vector<LightInfo>::iterator it = mLights.begin();
|
2012-04-02 17:37:24 +00:00
|
|
|
while (it != mLights.end())
|
|
|
|
{
|
2012-04-19 18:59:57 +00:00
|
|
|
if (mMwRoot->getCreator()->hasLight(it->name))
|
2012-04-02 17:37:24 +00:00
|
|
|
{
|
2012-04-19 18:59:57 +00:00
|
|
|
mMwRoot->getCreator()->getLight(it->name)->setVisible(false);
|
2012-04-02 17:37:24 +00:00
|
|
|
++it;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
it = mLights.erase(it);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-07 11:17:46 +00:00
|
|
|
namespace MWRender
|
2013-01-06 18:45:54 +00:00
|
|
|
{
|
2013-01-07 11:17:46 +00:00
|
|
|
namespace Pulse
|
2013-01-06 18:45:54 +00:00
|
|
|
{
|
2013-01-07 11:17:46 +00:00
|
|
|
static float amplitude (float phase)
|
|
|
|
{
|
|
|
|
return sin (phase);
|
|
|
|
}
|
2013-01-06 18:45:54 +00:00
|
|
|
}
|
|
|
|
|
2013-01-07 11:17:46 +00:00
|
|
|
namespace Flicker
|
2013-01-06 18:45:54 +00:00
|
|
|
{
|
2013-01-07 11:17:46 +00:00
|
|
|
static const float fa = 0.785398f;
|
|
|
|
static const float fb = 1.17024f;
|
2013-01-06 18:45:54 +00:00
|
|
|
|
2013-01-07 11:17:46 +00:00
|
|
|
static const float tdo = 0.94f;
|
|
|
|
static const float tdm = 2.48f;
|
2013-01-06 18:45:54 +00:00
|
|
|
|
2013-01-07 11:17:46 +00:00
|
|
|
static const float f [3] = { 1.5708f, 4.18774f, 5.19934f };
|
|
|
|
static const float o [3] = { 0.804248f, 2.11115f, 3.46832f };
|
|
|
|
static const float m [3] = { 1.0f, 0.785f, 0.876f };
|
|
|
|
static const float s = 0.394f;
|
2013-01-06 18:45:54 +00:00
|
|
|
|
2013-01-07 11:17:46 +00:00
|
|
|
static const float phase_wavelength = 120.0f * 3.14159265359f / fa;
|
2013-01-06 18:45:54 +00:00
|
|
|
|
2013-01-07 11:17:46 +00:00
|
|
|
static float frequency (float x)
|
|
|
|
{
|
|
|
|
return tdo + tdm * sin (fa * x);
|
|
|
|
}
|
2013-01-06 18:45:54 +00:00
|
|
|
|
2013-01-07 11:17:46 +00:00
|
|
|
static float amplitude (float x)
|
|
|
|
{
|
|
|
|
float v = 0.0f;
|
|
|
|
for (int i = 0; i < 3; ++i)
|
|
|
|
v += sin (fb*x*f[i] + o[1])*m[i];
|
|
|
|
return v * s;
|
|
|
|
}
|
2013-01-06 18:45:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-04-19 18:59:57 +00:00
|
|
|
void Objects::update(const float dt)
|
|
|
|
{
|
|
|
|
std::vector<LightInfo>::iterator it = mLights.begin();
|
|
|
|
while (it != mLights.end())
|
|
|
|
{
|
|
|
|
if (mMwRoot->getCreator()->hasLight(it->name))
|
|
|
|
{
|
|
|
|
Ogre::Light* light = mMwRoot->getCreator()->getLight(it->name);
|
|
|
|
|
2013-01-06 18:45:54 +00:00
|
|
|
float brightness;
|
|
|
|
float cycle_time;
|
|
|
|
float time_distortion;
|
|
|
|
|
|
|
|
if ((it->type == LT_Pulse) && (it->type == LT_PulseSlow))
|
|
|
|
{
|
|
|
|
cycle_time = 2 * Ogre::Math::PI;
|
|
|
|
time_distortion = 20.0f;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
cycle_time = 500.0f;
|
2013-01-07 11:17:46 +00:00
|
|
|
it->phase = fmod (it->phase + dt, Flicker::phase_wavelength);
|
|
|
|
time_distortion = Flicker::frequency (it->phase);
|
2013-01-06 18:45:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
it->time += it->dir*dt*time_distortion;
|
|
|
|
if (it->dir > 0 && it->time > +cycle_time)
|
|
|
|
{
|
|
|
|
it->dir = -1.0f;
|
|
|
|
it->time = +2*cycle_time - it->time;
|
|
|
|
}
|
|
|
|
if (it->dir < 0 && it->time < -cycle_time)
|
|
|
|
{
|
|
|
|
it->dir = +1.0f;
|
|
|
|
it->time = -2*cycle_time - it->time;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const float fast = 4.0f/1.0f;
|
|
|
|
static const float slow = 1.0f/1.0f;
|
2012-04-28 18:42:53 +00:00
|
|
|
|
|
|
|
// These formulas are just guesswork, but they work pretty well
|
|
|
|
if (it->type == LT_Normal)
|
2012-04-19 18:59:57 +00:00
|
|
|
{
|
2012-04-28 18:42:53 +00:00
|
|
|
// Less than 1/255 light modifier for a constant light:
|
2013-01-07 11:17:46 +00:00
|
|
|
brightness = (const float)(1.0 + Flicker::amplitude(it->time*slow) / 255.0 );
|
2012-04-19 18:59:57 +00:00
|
|
|
}
|
2012-04-28 18:42:53 +00:00
|
|
|
else if (it->type == LT_Flicker)
|
2012-04-19 18:59:57 +00:00
|
|
|
{
|
2013-01-07 11:17:46 +00:00
|
|
|
brightness = (const float)(0.75 + Flicker::amplitude(it->time*fast) * 0.25);
|
2012-04-19 18:59:57 +00:00
|
|
|
}
|
2012-04-28 18:42:53 +00:00
|
|
|
else if (it->type == LT_FlickerSlow)
|
|
|
|
{
|
2013-01-07 11:17:46 +00:00
|
|
|
brightness = (const float)(0.75 + Flicker::amplitude(it->time*slow) * 0.25);
|
2012-04-28 18:42:53 +00:00
|
|
|
}
|
|
|
|
else if (it->type == LT_Pulse)
|
2012-04-19 18:59:57 +00:00
|
|
|
{
|
2013-01-07 11:17:46 +00:00
|
|
|
brightness = (const float)(1.0 + Pulse::amplitude (it->time*fast) * 0.25);
|
2012-04-19 18:59:57 +00:00
|
|
|
}
|
2012-04-28 18:42:53 +00:00
|
|
|
else if (it->type == LT_PulseSlow)
|
|
|
|
{
|
2013-01-07 11:17:46 +00:00
|
|
|
brightness = (const float)(1.0 + Pulse::amplitude (it->time*slow) * 0.25);
|
2012-04-28 18:42:53 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
assert(0 && "Invalid light type");
|
|
|
|
|
2013-01-06 18:45:54 +00:00
|
|
|
light->setDiffuseColour(it->colour * brightness);
|
2012-04-19 18:59:57 +00:00
|
|
|
|
|
|
|
++it;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
it = mLights.erase(it);
|
|
|
|
}
|
|
|
|
}
|
2012-07-11 00:31:03 +00:00
|
|
|
|
|
|
|
void Objects::rebuildStaticGeometry()
|
|
|
|
{
|
|
|
|
for (std::map<MWWorld::CellStore *, Ogre::StaticGeometry*>::iterator it = mStaticGeometry.begin(); it != mStaticGeometry.end(); ++it)
|
|
|
|
{
|
|
|
|
it->second->destroy();
|
|
|
|
it->second->build();
|
|
|
|
}
|
|
|
|
|
|
|
|
for (std::map<MWWorld::CellStore *, Ogre::StaticGeometry*>::iterator it = mStaticGeometrySmall.begin(); it != mStaticGeometrySmall.end(); ++it)
|
|
|
|
{
|
|
|
|
it->second->destroy();
|
|
|
|
it->second->build();
|
|
|
|
}
|
|
|
|
}
|
2012-07-30 19:28:14 +00:00
|
|
|
|
2013-01-07 11:17:46 +00:00
|
|
|
void Objects::updateObjectCell(const MWWorld::Ptr &ptr)
|
2012-07-30 19:28:14 +00:00
|
|
|
{
|
|
|
|
Ogre::SceneNode *node;
|
|
|
|
MWWorld::CellStore *newCell = ptr.getCell();
|
|
|
|
|
|
|
|
if(mCellSceneNodes.find(newCell) == mCellSceneNodes.end()) {
|
|
|
|
node = mMwRoot->createChildSceneNode();
|
|
|
|
mCellSceneNodes[newCell] = node;
|
|
|
|
} else {
|
|
|
|
node = mCellSceneNodes[newCell];
|
|
|
|
}
|
|
|
|
node->addChild(ptr.getRefData().getBaseNode());
|
|
|
|
|
|
|
|
/// \note Still unaware how to move aabb and static w/o full rebuild,
|
|
|
|
/// moving static objects may cause problems
|
|
|
|
insertMesh(ptr, MWWorld::Class::get(ptr).getModel(ptr));
|
|
|
|
}
|
|
|
|
|