diff --git a/source/glest_game/graphics/particle_type.cpp b/source/glest_game/graphics/particle_type.cpp index 14dac232..5519383d 100644 --- a/source/glest_game/graphics/particle_type.cpp +++ b/source/glest_game/graphics/particle_type.cpp @@ -244,6 +244,8 @@ ProjectileParticleSystem *ParticleSystemTypeProjectile::create() { ps->setTrajectoryScale(trajectoryScale); ps->setTrajectoryFrequency(trajectoryFrequency); + ps->initParticleSystem(); + return ps; } @@ -297,6 +299,8 @@ SplashParticleSystem *ParticleSystemTypeSplash::create(){ ps->setHorizontalSpreadA(horizontalSpreadA); ps->setHorizontalSpreadB(horizontalSpreadB); + ps->initParticleSystem(); + return ps; } diff --git a/source/shared_lib/include/graphics/particle.h b/source/shared_lib/include/graphics/particle.h index 01ed8b27..68a71a07 100644 --- a/source/shared_lib/include/graphics/particle.h +++ b/source/shared_lib/include/graphics/particle.h @@ -370,7 +370,7 @@ public: void setPrimitive(Primitive primitive) {this->primitive= primitive;} 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); }; @@ -401,6 +401,8 @@ private: Vec3f yVector; Vec3f zVector; + float modelCycle; + Trajectory trajectory; float trajectorySpeed; @@ -424,6 +426,8 @@ public: void setTrajectorySpeed(float trajectorySpeed) {this->trajectorySpeed= trajectorySpeed;} void setTrajectoryScale(float trajectoryScale) {this->trajectoryScale= trajectoryScale;} void setTrajectoryFrequency(float trajectoryFrequency) {this->trajectoryFrequency= trajectoryFrequency;} + + void setModelCycle(float modelCycle) {this->modelCycle= modelCycle;} void setPath(Vec3f startPos, Vec3f endPos); static Trajectory strToTrajectory(const string &str); diff --git a/source/shared_lib/sources/graphics/interpolation.cpp b/source/shared_lib/sources/graphics/interpolation.cpp index 603ee58b..24fe6272 100644 --- a/source/shared_lib/sources/graphics/interpolation.cpp +++ b/source/shared_lib/sources/graphics/interpolation.cpp @@ -73,6 +73,9 @@ void InterpolationData::update(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); uint32 frameCount= mesh->getFrameCount(); diff --git a/source/shared_lib/sources/graphics/particle.cpp b/source/shared_lib/sources/graphics/particle.cpp index eac0e079..5a5cace5 100644 --- a/source/shared_lib/sources/graphics/particle.cpp +++ b/source/shared_lib/sources/graphics/particle.cpp @@ -747,6 +747,7 @@ ProjectileParticleSystem::~ProjectileParticleSystem(){ void ProjectileParticleSystem::link(SplashParticleSystem *particleSystem){ nextParticleSystem= particleSystem; + nextParticleSystem->setVisible(false); nextParticleSystem->setState(sPause); nextParticleSystem->prevParticleSystem= this; } @@ -761,17 +762,30 @@ void ProjectileParticleSystem::update(){ Vec3f currentVector= flatPos - startPos; // 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 - switch(trajectory){ + switch(trajectory) { case tLinear: { pos= flatPos; } break; case tParabolic: { - float scaledT= 2.0f * (tween - 0.5f); + float scaledT= 2.0f * (t - 0.5f); float paraboleY= (1.0f - scaledT * scaledT) * trajectoryScale; pos= flatPos; @@ -808,6 +822,7 @@ void ProjectileParticleSystem::update(){ } if(nextParticleSystem != NULL){ + nextParticleSystem->setVisible(true); nextParticleSystem->setState(sPlay); nextParticleSystem->setPos(endPos); } @@ -917,7 +932,7 @@ void SplashParticleSystem::initParticleSystem() { startEmissionRate = emissionRate; } -void SplashParticleSystem::update(){ +void SplashParticleSystem::update() { ParticleSystem::update(); if(state != sPause) { emissionRate-= emissionRateFade;