|
楼主 |
发表于 2009-12-21 09:10:00
|
显示全部楼层
Re:天龙八部粒子特效还原技术
04,
1,打开文件夹..\ogre-v1-6-4\ogre\PlugIns\ParticleFX\src
2,找到OgreColourFaderAffector.cpp,复制一份并改名为OgreScaleInterpolatorAffector.cpp
3,用下面的源码替换OgreScaleInterpolatorAffector.cpp中的源码
#include "OgreScaleInterpolatorAffector.h"
#include "OgreParticleSystem.h"
#include "OgreStringConverter.h"
#include "OgreParticle.h"
#include <windows.h>
namespace Ogre {
ScaleInterpolatorAffector::CmdColourAdjust
ScaleInterpolatorAffector::msColourCmd[MAX_STAGESA];
ScaleInterpolatorAffector::CmdTimeAdjust
ScaleInterpolatorAffector::msTimeCmd[MAX_STAGESA];
ScaleInterpolatorAffector::Cmdwidth_range_startAdjust
ScaleInterpolatorAffector::mswidth_range_startCmd;
ScaleInterpolatorAffector::Cmdwidth_range_endAdjust
ScaleInterpolatorAffector::mswidth_range_endCmd;
ScaleInterpolatorAffector::Cmdheight_range_startAdjust
ScaleInterpolatorAffector::msheight_range_startCmd;
ScaleInterpolatorAffector::Cmdheight_range_endAdjust
ScaleInterpolatorAffector::msheight_range_endCmd;
ScaleInterpolatorAffector::ScaleInterpolatorAffector(ParticleSystem* psys)
: ParticleAffector(psys)
{
for (int i=0;i<MAX_STAGESA;i++)
{
mColourAdj = 1.0f;
mTimeAdj = 1.0f;
}
mType = "ScaleInterpolator";
if (createParamDictionary("ScaleInterpolatorAffector"))
{
ParamDictionary* dict = getParamDictionary();
for (int i=0;i<MAX_STAGESA;i++)
{
msColourCmd.mIndex = i;
msTimeCmd.mIndex = i;
StringUtil::StrStreamType stage;
stage << i;
String colour_title = String("scale") + stage.str();
String time_title = String("time") + stage.str();
String colour_descr = String("Stage ") + stage.str() +
String(" scale.");
String time_descr = String("Stage ") + stage.str()
+ String(" time.");
dict->addParameter(ParameterDef(colour_title, colour_descr,
PT_COLOURVALUE), &msColourCmd);
dict->addParameter(ParameterDef
(time_title, time_descr, PT_REAL), &msTimeCmd);
}
dict->addParameter(ParameterDef("width_range_start",
"The amount by which
to adjust the width_range_start component of particles per second.",
PT_REAL),
&mswidth_range_startCmd);
dict->addParameter(ParameterDef("width_range_end",
"The amount by which to adjust the width_range_end component of particles per
second.",
PT_REAL), &mswidth_range_endCmd);
dict->addParameter
(ParameterDef("height_range_start",
"The amount by which to adjust the
height_range_start component of particles per second.",
PT_REAL),
&msheight_range_startCmd);
dict->addParameter(ParameterDef("height_range_end",
"The amount by which to adjust the height_range_end component of particles per
second.",
PT_REAL), &msheight_range_endCmd);
}
}
void ScaleInterpolatorAffector::setColourAdjust(size_t index, Real colour)
{
mColourAdj[index] = colour;
}
Real ScaleInterpolatorAffector::getColourAdjust(size_t index) const
{
return mColourAdj[index];
}
void ScaleInterpolatorAffector::setTimeAdjust(size_t index, Real time)
{
mTimeAdj[index] = time;
}
Real ScaleInterpolatorAffector::getTimeAdjust(size_t index) const
{
return mTimeAdj[index];
}
void ScaleInterpolatorAffector::setwidth_range_startAdjust(float width)
{
width_range_start = width;
}
float ScaleInterpolatorAffector::getwidth_range_startAdjust(void) const
{
return width_range_start;
}
void ScaleInterpolatorAffector::setwidth_range_endAdjust(float width)
{
width_range_end = width;
}
float ScaleInterpolatorAffector::getwidth_range_endAdjust(void) const
{
return width_range_end;
}
void ScaleInterpolatorAffector::setheight_range_startAdjust(float height)
{
height_range_start = height;
}
float ScaleInterpolatorAffector::getheight_range_startAdjust(void) const
{
return height_range_start;
}
void ScaleInterpolatorAffector::setheight_range_endAdjust(float height)
{
height_range_end = height;
}
float ScaleInterpolatorAffector::getheight_range_endAdjust(void) const
{
return height_range_end;
}
String ScaleInterpolatorAffector::Cmdwidth_range_startAdjust::doGet(const void* target)
const
{
return StringConverter::toString(
static_cast<const ScaleInterpolatorAffector*>(target)->getwidth_range_startAdjust()
);
}
void ScaleInterpolatorAffector::Cmdwidth_range_startAdjust::doSet(void* target, const
String& val)
{
static_cast<ScaleInterpolatorAffector*>(target)->setwidth_range_startAdjust(
StringConverter::parseReal(val));
}
String ScaleInterpolatorAffector::Cmdwidth_range_endAdjust::doGet(const void* target) const
{
return StringConverter::toString(
static_cast<const ScaleInterpolatorAffector*>(target)->getwidth_range_endAdjust() );
}
void ScaleInterpolatorAffector::Cmdwidth_range_endAdjust::doSet(void* target, const String&
val)
{
static_cast<ScaleInterpolatorAffector*>(target)->setwidth_range_endAdjust(
StringConverter::parseReal(val));
}
String ScaleInterpolatorAffector::Cmdheight_range_startAdjust::doGet(const void* target)
const
{
return StringConverter::toString(
static_cast<const ScaleInterpolatorAffector*>(target)->getheight_range_startAdjust()
);
}
void ScaleInterpolatorAffector::Cmdheight_range_startAdjust::doSet(void* target, const
String& val)
{
static_cast<ScaleInterpolatorAffector*>(target)->setheight_range_startAdjust(
StringConverter::parseReal(val));
}
String ScaleInterpolatorAffector::Cmdheight_range_endAdjust::doGet(const void* target) const
{
return StringConverter::toString(
static_cast<const ScaleInterpolatorAffector*>(target)->getheight_range_endAdjust()
);
}
void ScaleInterpolatorAffector::Cmdheight_range_endAdjust::doSet(void* target, const String&
val)
{
static_cast<ScaleInterpolatorAffector*>(target)->setheight_range_endAdjust(
StringConverter::parseReal(val));
}
String ScaleInterpolatorAffector::CmdColourAdjust::doGet(const void* target) const
{
return StringConverter::toString(
static_cast<const ScaleInterpolatorAffector*>(target)->getColourAdjust(mIndex) );
} void ScaleInterpolatorAffector::CmdColourAdjust::doSet(void* target, const String& val)
{ static_cast<ScaleInterpolatorAffector*>(target)->setColourAdjust(mIndex,
StringConverter::parseReal(val));
}
String ScaleInterpolatorAffector::CmdTimeAdjust::doGet(const void* target) const
{
return StringConverter::toString(
static_cast<const ScaleInterpolatorAffector*>(target)->getTimeAdjust(mIndex) );
}
void ScaleInterpolatorAffector::CmdTimeAdjust::doSet(void* target, const String& val)
{
static_cast<ScaleInterpolatorAffector*>(target)->setTimeAdjust(mIndex,
StringConverter::parseReal(val));
}
void ScaleInterpolatorAffector::_affectParticles(ParticleSystem* pSystem, Real timeElapsed)
{
Particle* p;
ParticleIterator pi = pSystem->_getIterator
();
Real dsw,dsh;
Real mScaleAdj;
Real NewWide, NewHigh;
Real width_range=Math::RangeRandom (width_range_start,width_range_end);
Real height_range=Math::RangeRandom (height_range_start,height_range_end);
while (!pi.end())
{
p = pi.getNext();
if(p->timeToLive<=mTimeAdj[0])
{
mScaleAdj=mColourAdj[0];
}
else if(p->timeToLive<=mTimeAdj[1])
{
mScaleAdj=mColourAdj[1];
}
else if(p->timeToLive<=mTimeAdj[2])
{
mScaleAdj=mColourAdj[2];
}
else if(p->timeToLive<=mTimeAdj[3])
{
mScaleAdj=mColourAdj[3];
}
else if(p->timeToLive<=mTimeAdj[4])
{
mScaleAdj=mColourAdj[4];
}
else
{
mScaleAdj=mColourAdj[5];
}
dsw=-width_range*mScaleAdj*timeElapsed;
dsh=-height_range*mScaleAdj*timeElapsed;
if( p->hasOwnDimensions() == false )
{
NewWide = pSystem->getDefaultWidth() + dsw;
NewHigh = pSystem->getDefaultHeight() + dsh;
}
else
{
NewWide = p->getOwnWidth()+ dsw;
NewHigh = p->getOwnHeight() + dsh;
}
p->setDimensions( NewWide, NewHigh );
}
}
} |
|