forked from teamnwah/openmw-tes3coop
updated the fading calculation (the alpha value stays now, even after the specified time - this is how it is in morrowind)
This commit is contained in:
parent
b77f5c06cc
commit
eb61ba59e6
2 changed files with 64 additions and 29 deletions
|
@ -18,10 +18,12 @@ using namespace Ogre;
|
||||||
using namespace OEngine::Render;
|
using namespace OEngine::Render;
|
||||||
|
|
||||||
Fader::Fader() :
|
Fader::Fader() :
|
||||||
mMode(FadingMode_None),
|
mMode(FadingMode_In),
|
||||||
mRemainingTime(0.f),
|
mRemainingTime(0.f),
|
||||||
mTargetTime(0.f),
|
mTargetTime(0.f),
|
||||||
mTargetAlpha(0.f)
|
mTargetAlpha(0.f),
|
||||||
|
mCurrentAlpha(0.f),
|
||||||
|
mStartAlpha(0.f)
|
||||||
{
|
{
|
||||||
|
|
||||||
// Create the fading material
|
// Create the fading material
|
||||||
|
@ -50,35 +52,46 @@ Fader::Fader() :
|
||||||
}
|
}
|
||||||
|
|
||||||
void Fader::update(float dt)
|
void Fader::update(float dt)
|
||||||
{
|
{
|
||||||
if (mMode == FadingMode_None) return;
|
|
||||||
|
|
||||||
if (mRemainingTime > 0)
|
if (mRemainingTime > 0)
|
||||||
{
|
{
|
||||||
mOverlay->show();
|
|
||||||
float alpha;
|
|
||||||
if (mMode == FadingMode_In)
|
if (mMode == FadingMode_In)
|
||||||
alpha = (mRemainingTime/mTargetTime) * 1.f;
|
{
|
||||||
|
mCurrentAlpha -= dt/mTargetTime * (mStartAlpha-mTargetAlpha);
|
||||||
|
if (mCurrentAlpha < mTargetAlpha) mCurrentAlpha = mTargetAlpha;
|
||||||
|
}
|
||||||
else if (mMode == FadingMode_Out)
|
else if (mMode == FadingMode_Out)
|
||||||
alpha = (1-(mRemainingTime/mTargetTime)) * 1.f;
|
{
|
||||||
else if (mMode == FadingMode_To)
|
mCurrentAlpha += dt/mTargetTime * (mTargetAlpha-mStartAlpha);
|
||||||
alpha = (1-(mRemainingTime/mTargetTime)) * mTargetAlpha;
|
if (mCurrentAlpha > mTargetAlpha) mCurrentAlpha = mTargetAlpha;
|
||||||
|
}
|
||||||
mFadeTextureUnit->setAlphaOperation(LBX_SOURCE1, LBS_MANUAL, LBS_CURRENT, alpha);
|
|
||||||
|
applyAlpha();
|
||||||
|
|
||||||
mRemainingTime -= dt;
|
mRemainingTime -= dt;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
if (mCurrentAlpha == 0.f) mOverlay->hide();
|
||||||
mMode = FadingMode_None;
|
}
|
||||||
mOverlay->hide();
|
|
||||||
}
|
void Fader::applyAlpha()
|
||||||
|
{
|
||||||
|
mOverlay->show();
|
||||||
|
mFadeTextureUnit->setAlphaOperation(LBX_SOURCE1, LBS_MANUAL, LBS_CURRENT, mCurrentAlpha);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Fader::fadeIn(float time)
|
void Fader::fadeIn(float time)
|
||||||
{
|
{
|
||||||
if (time<=0) return;
|
if (time<0.f) return;
|
||||||
|
if (time==0.f)
|
||||||
|
{
|
||||||
|
mCurrentAlpha = 0.f;
|
||||||
|
applyAlpha();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
mStartAlpha = mCurrentAlpha;
|
||||||
|
mTargetAlpha = 0.f;
|
||||||
mMode = FadingMode_In;
|
mMode = FadingMode_In;
|
||||||
mTargetTime = time;
|
mTargetTime = time;
|
||||||
mRemainingTime = time;
|
mRemainingTime = time;
|
||||||
|
@ -86,8 +99,16 @@ void Fader::fadeIn(float time)
|
||||||
|
|
||||||
void Fader::fadeOut(const float time)
|
void Fader::fadeOut(const float time)
|
||||||
{
|
{
|
||||||
if (time<=0) return;
|
if (time<0.f) return;
|
||||||
|
if (time==0.f)
|
||||||
|
{
|
||||||
|
mCurrentAlpha = 1.f;
|
||||||
|
applyAlpha();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
mStartAlpha = mCurrentAlpha;
|
||||||
|
mTargetAlpha = 1.f;
|
||||||
mMode = FadingMode_Out;
|
mMode = FadingMode_Out;
|
||||||
mTargetTime = time;
|
mTargetTime = time;
|
||||||
mRemainingTime = time;
|
mRemainingTime = time;
|
||||||
|
@ -95,10 +116,21 @@ void Fader::fadeOut(const float time)
|
||||||
|
|
||||||
void Fader::fadeTo(const int percent, const float time)
|
void Fader::fadeTo(const int percent, const float time)
|
||||||
{
|
{
|
||||||
if (time<=0) return;
|
if (time<0.f) return;
|
||||||
|
if (time==0.f)
|
||||||
|
{
|
||||||
|
mCurrentAlpha = percent/100.f;
|
||||||
|
applyAlpha();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
mStartAlpha = mCurrentAlpha;
|
||||||
|
mTargetAlpha = percent/100.f;
|
||||||
|
|
||||||
|
if (mTargetAlpha == mStartAlpha) return;
|
||||||
|
else if (mTargetAlpha > mStartAlpha) mMode = FadingMode_Out;
|
||||||
|
else mMode = FadingMode_In;
|
||||||
|
|
||||||
mMode = FadingMode_To;
|
|
||||||
mTargetTime = time;
|
mTargetTime = time;
|
||||||
mRemainingTime = time;
|
mRemainingTime = time;
|
||||||
mTargetAlpha = percent/100.f;
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,23 +30,26 @@ namespace Render
|
||||||
void fadeIn(const float time);
|
void fadeIn(const float time);
|
||||||
void fadeOut(const float time);
|
void fadeOut(const float time);
|
||||||
void fadeTo(const int percent, const float time);
|
void fadeTo(const int percent, const float time);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
enum FadingMode
|
enum FadingMode
|
||||||
{
|
{
|
||||||
FadingMode_In,
|
FadingMode_In,
|
||||||
FadingMode_Out,
|
FadingMode_Out
|
||||||
FadingMode_To,
|
|
||||||
FadingMode_None // no fading
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
void applyAlpha();
|
||||||
|
|
||||||
Ogre::TextureUnitState* mFadeTextureUnit;
|
Ogre::TextureUnitState* mFadeTextureUnit;
|
||||||
Ogre::Overlay* mOverlay;
|
Ogre::Overlay* mOverlay;
|
||||||
|
|
||||||
FadingMode mMode;
|
FadingMode mMode;
|
||||||
|
|
||||||
float mRemainingTime;
|
float mRemainingTime;
|
||||||
float mTargetTime;
|
float mTargetTime;
|
||||||
float mTargetAlpha;
|
float mTargetAlpha;
|
||||||
|
float mCurrentAlpha;
|
||||||
|
float mStartAlpha;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue