1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-01-19 22:23:51 +00:00

Implement Light magic effect (Fixes #1122)

This commit is contained in:
scrawl 2014-08-24 01:50:29 +02:00
parent 714c927fda
commit e0e4cbbb41
3 changed files with 44 additions and 0 deletions

View file

@ -1663,6 +1663,9 @@ void CharacterController::updateVisibility()
} }
mAnimation->setAlpha(alpha); mAnimation->setAlpha(alpha);
float light = mPtr.getClass().getCreatureStats(mPtr).getMagicEffects().get(ESM::MagicEffect::Light).getMagnitude();
mAnimation->setLightEffect(light);
} }
void CharacterController::determineAttackType() void CharacterController::determineAttackType()

View file

@ -71,6 +71,7 @@ Animation::Animation(const MWWorld::Ptr &ptr, Ogre::SceneNode *node)
, mNonAccumCtrl(NULL) , mNonAccumCtrl(NULL)
, mAccumulate(0.0f) , mAccumulate(0.0f)
, mNullAnimationTimePtr(OGRE_NEW NullAnimationTime) , mNullAnimationTimePtr(OGRE_NEW NullAnimationTime)
, mGlowLight(NULL)
{ {
for(size_t i = 0;i < sNumGroups;i++) for(size_t i = 0;i < sNumGroups;i++)
mAnimationTimePtr[i].bind(OGRE_NEW AnimationTime(this)); mAnimationTimePtr[i].bind(OGRE_NEW AnimationTime(this));
@ -78,6 +79,8 @@ Animation::Animation(const MWWorld::Ptr &ptr, Ogre::SceneNode *node)
Animation::~Animation() Animation::~Animation()
{ {
setLightEffect(0);
mEffects.clear(); mEffects.clear();
mAnimSources.clear(); mAnimSources.clear();
@ -1397,6 +1400,37 @@ Ogre::Vector3 Animation::getEnchantmentColor(MWWorld::Ptr item)
return result; return result;
} }
void Animation::setLightEffect(float effect)
{
if (effect == 0)
{
if (mGlowLight)
{
mInsert->getCreator()->destroySceneNode(mGlowLight->getParentSceneNode());
mInsert->getCreator()->destroyLight(mGlowLight);
mGlowLight = NULL;
}
}
else
{
if (!mGlowLight)
{
mGlowLight = mInsert->getCreator()->createLight();
Ogre::AxisAlignedBox bounds = Ogre::AxisAlignedBox::BOX_NULL;
for(size_t i = 0;i < mObjectRoot->mEntities.size();i++)
{
Ogre::Entity *ent = mObjectRoot->mEntities[i];
bounds.merge(ent->getBoundingBox());
}
mInsert->createChildSceneNode(bounds.getCenter())->attachObject(mGlowLight);
}
mGlowLight->setType(Ogre::Light::LT_POINT);
effect += 3;
mGlowLight->setAttenuation(1.0f / (0.03 * (0.5/effect)), 0, 0.5/effect, 0);
}
}
ObjectAnimation::ObjectAnimation(const MWWorld::Ptr& ptr, const std::string &model) ObjectAnimation::ObjectAnimation(const MWWorld::Ptr& ptr, const std::string &model)
: Animation(ptr, ptr.getRefData().getBaseNode()) : Animation(ptr, ptr.getRefData().getBaseNode())

View file

@ -126,6 +126,8 @@ protected:
MWWorld::Ptr mPtr; MWWorld::Ptr mPtr;
Ogre::Light* mGlowLight;
Ogre::SceneNode *mInsert; Ogre::SceneNode *mInsert;
Ogre::Entity *mSkelBase; Ogre::Entity *mSkelBase;
NifOgre::ObjectScenePtr mObjectRoot; NifOgre::ObjectScenePtr mObjectRoot;
@ -301,6 +303,11 @@ public:
/// This is typically called as part of runAnimation, but may be called manually if needed. /// This is typically called as part of runAnimation, but may be called manually if needed.
void updateEffects(float duration); void updateEffects(float duration);
// TODO: move outside of this class
/// Makes this object glow, by placing a Light in its center.
/// @param effect Controls the radius and intensity of the light.
void setLightEffect(float effect);
virtual void showWeapons(bool showWeapon); virtual void showWeapons(bool showWeapon);
virtual void showCarriedLeft(bool show) {} virtual void showCarriedLeft(bool show) {}
virtual void attachArrow() {} virtual void attachArrow() {}