From 83d2474dedb828b8b4255a168ffe5c44a7698df6 Mon Sep 17 00:00:00 2001 From: Mark Vejvoda Date: Wed, 4 Apr 2012 23:43:31 +0000 Subject: [PATCH] - bugfix animated particle model logic --- source/glest_game/graphics/particle_type.cpp | 5 ++++- .../shared_lib/sources/graphics/particle.cpp | 20 ++++++++++++++++--- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/source/glest_game/graphics/particle_type.cpp b/source/glest_game/graphics/particle_type.cpp index b8253cced..7e1826c25 100644 --- a/source/glest_game/graphics/particle_type.cpp +++ b/source/glest_game/graphics/particle_type.cpp @@ -400,7 +400,8 @@ void ParticleSystemTypeProjectile::load(const XmlNode* particleFileNode, const s //trajectory speed const XmlNode *tajectorySpeedNode= tajectoryNode->getChild("speed"); - trajectorySpeed= tajectorySpeedNode->getAttribute("value")->getFloatValue()/GameConstants::updateFps; + trajectorySpeed= tajectorySpeedNode->getAttribute("value")->getFloatValue() / (float)GameConstants::updateFps; + //printf("[%s] trajectorySpeed = %f\n",path.c_str(),trajectorySpeed); if(trajectory=="parabolic" || trajectory=="spiral"){ //trajectory scale @@ -432,6 +433,8 @@ ProjectileParticleSystem *ParticleSystemTypeProjectile::create() { ParticleSystemType::setValues(ps); ps->setTrajectory(ProjectileParticleSystem::strToTrajectory(trajectory)); + + //printf("Setting trajectorySpeed = %f\n",trajectorySpeed); ps->setTrajectorySpeed(trajectorySpeed); ps->setTrajectoryScale(trajectoryScale); ps->setTrajectoryFrequency(trajectoryFrequency); diff --git a/source/shared_lib/sources/graphics/particle.cpp b/source/shared_lib/sources/graphics/particle.cpp index b93c762b9..38353e86c 100644 --- a/source/shared_lib/sources/graphics/particle.cpp +++ b/source/shared_lib/sources/graphics/particle.cpp @@ -776,8 +776,9 @@ void GameParticleSystem::render(ParticleRenderer *pr, ModelRenderer *mr){ } void GameParticleSystem::setTween(float relative,float absolute) { - if(model){ + if(model) { // animation? + //printf("#1 Particle model meshcount [%d] modelCycle = %f, relative = %f, absolute = %f\n",model->getMeshCount(),modelCycle,relative,absolute); if(modelCycle == 0.0f) { tween= relative; } @@ -785,7 +786,7 @@ void GameParticleSystem::setTween(float relative,float absolute) { #ifdef USE_STREFLOP if(streflop::fabs(static_cast(absolute)) <= 0.00001f){ #else - if(fabs(absolute) <= 0.00001f){ + if(fabs(absolute) <= 0.00001f) { #endif tween = 0.0f; } @@ -806,9 +807,12 @@ void GameParticleSystem::setTween(float relative,float absolute) { } tween= clamp(tween, 0.0f, 1.0f); + + //printf("#2 Particle model meshcount [%d] modelCycle = %f, relative = %f, absolute = %f\n",model->getMeshCount(),modelCycle,relative,absolute); } - for(Children::iterator it= children.begin(); it != children.end(); ++it) + for(Children::iterator it= children.begin(); it != children.end(); ++it) { (*it)->setTween(relative,absolute); + } } string GameParticleSystem::getModelFileLoadDeferred() { @@ -1431,12 +1435,15 @@ ProjectileParticleSystem::ProjectileParticleSystem(int particleCount) : setSpeed(0.14f); trajectory= tLinear; + trajectorySpeed= 1.0f; trajectoryScale= 1.0f; trajectoryFrequency= 1.0f; modelCycle=0.0f; nextParticleSystem= NULL; + + //printf("#aXX trajectorySpeed = %f\n",trajectorySpeed); } ProjectileParticleSystem::~ProjectileParticleSystem(){ @@ -1462,11 +1469,18 @@ void ProjectileParticleSystem::update(){ // ratio float relative= clamp(currentVector.length() / targetVector.length(), 0.0f, 1.0f); + + //printf("Update particle targetVector [%s][%f] currentVector [%s][%f] relative = %f\n",targetVector.getString().c_str(),targetVector.length(),currentVector.getString().c_str(),currentVector.length(),relative); + #ifdef USE_STREFLOP float absolute= clamp(streflop::fabs(static_cast(currentVector.length())), 0.0f, 1.0f); #else float absolute= clamp(fabs(currentVector.length()), 0.0f, 1.0f); #endif + + //printf("#a currentVector.length() = %f, targetVector.length() = %f, relative = %f, absolute = %f, trajectorySpeed = %f\n",currentVector.length(),targetVector.length(),relative,absolute,trajectorySpeed); + absolute = relative; + setTween(relative,absolute); // trajectory