- updated patch from willvarfar for animated models in particles

This commit is contained in:
Mark Vejvoda 2011-06-11 00:26:26 +00:00
parent 90fcb0abe7
commit 4aca4af404
4 changed files with 31 additions and 5 deletions

View File

@ -244,6 +244,8 @@ ProjectileParticleSystem *ParticleSystemTypeProjectile::create() {
ps->setTrajectoryScale(trajectoryScale); ps->setTrajectoryScale(trajectoryScale);
ps->setTrajectoryFrequency(trajectoryFrequency); ps->setTrajectoryFrequency(trajectoryFrequency);
ps->initParticleSystem();
return ps; return ps;
} }
@ -297,6 +299,8 @@ SplashParticleSystem *ParticleSystemTypeSplash::create(){
ps->setHorizontalSpreadA(horizontalSpreadA); ps->setHorizontalSpreadA(horizontalSpreadA);
ps->setHorizontalSpreadB(horizontalSpreadB); ps->setHorizontalSpreadB(horizontalSpreadB);
ps->initParticleSystem();
return ps; return ps;
} }

View File

@ -370,7 +370,7 @@ public:
void setPrimitive(Primitive primitive) {this->primitive= primitive;} void setPrimitive(Primitive primitive) {this->primitive= primitive;}
float getTween() { return tween; } // 0.0 -> 1.0 for animation of model float getTween() { return tween; } // 0.0 -> 1.0 for animation of model
virtual void initParticleSystem() {} // opportunity to do any initialisation when the system has been created and all settings set virtual void initParticleSystem() {} // opportunity to do any initialization when the system has been created and all settings set
static Primitive strToPrimitive(const string &str); static Primitive strToPrimitive(const string &str);
}; };
@ -401,6 +401,8 @@ private:
Vec3f yVector; Vec3f yVector;
Vec3f zVector; Vec3f zVector;
float modelCycle;
Trajectory trajectory; Trajectory trajectory;
float trajectorySpeed; float trajectorySpeed;
@ -424,6 +426,8 @@ public:
void setTrajectorySpeed(float trajectorySpeed) {this->trajectorySpeed= trajectorySpeed;} void setTrajectorySpeed(float trajectorySpeed) {this->trajectorySpeed= trajectorySpeed;}
void setTrajectoryScale(float trajectoryScale) {this->trajectoryScale= trajectoryScale;} void setTrajectoryScale(float trajectoryScale) {this->trajectoryScale= trajectoryScale;}
void setTrajectoryFrequency(float trajectoryFrequency) {this->trajectoryFrequency= trajectoryFrequency;} void setTrajectoryFrequency(float trajectoryFrequency) {this->trajectoryFrequency= trajectoryFrequency;}
void setModelCycle(float modelCycle) {this->modelCycle= modelCycle;}
void setPath(Vec3f startPos, Vec3f endPos); void setPath(Vec3f startPos, Vec3f endPos);
static Trajectory strToTrajectory(const string &str); static Trajectory strToTrajectory(const string &str);

View File

@ -73,6 +73,9 @@ void InterpolationData::update(float t, bool cycle){
} }
void InterpolationData::updateVertices(float t, bool cycle) { void InterpolationData::updateVertices(float t, bool cycle) {
if(t <0.0f || t>1.0f) {
printf("ERROR t = [%f] for cycle [%d] f [%d] v [%d]\n",t,cycle,mesh->getFrameCount(),mesh->getVertexCount());
}
assert(t>=0.0f && t<=1.0f); assert(t>=0.0f && t<=1.0f);
uint32 frameCount= mesh->getFrameCount(); uint32 frameCount= mesh->getFrameCount();

View File

@ -747,6 +747,7 @@ ProjectileParticleSystem::~ProjectileParticleSystem(){
void ProjectileParticleSystem::link(SplashParticleSystem *particleSystem){ void ProjectileParticleSystem::link(SplashParticleSystem *particleSystem){
nextParticleSystem= particleSystem; nextParticleSystem= particleSystem;
nextParticleSystem->setVisible(false);
nextParticleSystem->setState(sPause); nextParticleSystem->setState(sPause);
nextParticleSystem->prevParticleSystem= this; nextParticleSystem->prevParticleSystem= this;
} }
@ -761,17 +762,30 @@ void ProjectileParticleSystem::update(){
Vec3f currentVector= flatPos - startPos; Vec3f currentVector= flatPos - startPos;
// ratio // ratio
tween = clamp(currentVector.length() / targetVector.length(), 0.0f, 1.0f); float t= clamp(currentVector.length() / targetVector.length(), 0.0f, 1.0f);
// animation?
if(modelCycle == 0.0f) {
tween= t;
}
else {
#ifdef USE_STREFLOP
tween= streflop::fmod(currentVector.length(), modelCycle);
#else
tween= fmod(currentVector.length(), modelCycle);
#endif
tween= clamp(tween / currentVector.length(), 0.0f, 1.0f);
}
// trajectory // trajectory
switch(trajectory){ switch(trajectory) {
case tLinear: { case tLinear: {
pos= flatPos; pos= flatPos;
} }
break; break;
case tParabolic: { case tParabolic: {
float scaledT= 2.0f * (tween - 0.5f); float scaledT= 2.0f * (t - 0.5f);
float paraboleY= (1.0f - scaledT * scaledT) * trajectoryScale; float paraboleY= (1.0f - scaledT * scaledT) * trajectoryScale;
pos= flatPos; pos= flatPos;
@ -808,6 +822,7 @@ void ProjectileParticleSystem::update(){
} }
if(nextParticleSystem != NULL){ if(nextParticleSystem != NULL){
nextParticleSystem->setVisible(true);
nextParticleSystem->setState(sPlay); nextParticleSystem->setState(sPlay);
nextParticleSystem->setPos(endPos); nextParticleSystem->setPos(endPos);
} }
@ -917,7 +932,7 @@ void SplashParticleSystem::initParticleSystem() {
startEmissionRate = emissionRate; startEmissionRate = emissionRate;
} }
void SplashParticleSystem::update(){ void SplashParticleSystem::update() {
ParticleSystem::update(); ParticleSystem::update();
if(state != sPause) { if(state != sPause) {
emissionRate-= emissionRateFade; emissionRate-= emissionRateFade;