From ba1d03118ec554e225148f0f3431e4d35f700d92 Mon Sep 17 00:00:00 2001 From: titiger Date: Sat, 4 Jan 2014 18:40:00 +0100 Subject: [PATCH] unit particles can be bound to first vertice of meshes ( ) --- .../graphics/unit_particle_type.cpp | 20 +++++++++++++- .../glest_game/graphics/unit_particle_type.h | 2 ++ source/glest_game/type_instances/unit.cpp | 26 +++++++++++++++++++ source/shared_lib/include/graphics/model.h | 1 + source/shared_lib/include/graphics/particle.h | 5 ++++ .../shared_lib/sources/graphics/particle.cpp | 25 +++++++++++++++--- 6 files changed, 75 insertions(+), 4 deletions(-) diff --git a/source/glest_game/graphics/unit_particle_type.cpp b/source/glest_game/graphics/unit_particle_type.cpp index 58bd8808..01f3d406 100644 --- a/source/glest_game/graphics/unit_particle_type.cpp +++ b/source/glest_game/graphics/unit_particle_type.cpp @@ -37,6 +37,7 @@ UnitParticleSystemType::UnitParticleSystemType() : ParticleSystemType() { minRadius = 0; emissionRateFade = 0; relative = false; + meshName = ""; relativeDirection = false; fixed = false; staticParticleCount = 0; @@ -111,6 +112,15 @@ void UnitParticleSystemType::load(const XmlNode *particleSystemNode, const strin relative= relativeNode->getAttribute("value")->getBoolValue(); + //meshName + if(particleSystemNode->hasChild("meshName")){ + const XmlNode *tmpNode= particleSystemNode->getChild("meshName"); + meshName= tmpNode->getAttribute("value")->getValue(); + } + else{ + meshName=""; + } + //relativeDirection if(particleSystemNode->hasChild("relativeDirection")){ const XmlNode *relativeDirectionNode= particleSystemNode->getChild("relativeDirection"); @@ -119,7 +129,7 @@ void UnitParticleSystemType::load(const XmlNode *particleSystemNode, const strin else{ relativeDirection=true; } - + if(particleSystemNode->hasChild("static-particle-count")){ //staticParticleCount const XmlNode *staticParticleCountNode= particleSystemNode->getChild("static-particle-count"); @@ -231,6 +241,7 @@ const void UnitParticleSystemType::setValues(UnitParticleSystem *ups){ ups->setVarParticleEnergy(energyVar); ups->setFixed(fixed); ups->setRelative(relative); + ups->setMeshName(meshName); ups->setRelativeDirection(relativeDirection); ups->setDelay(delay); ups->setLifetime(lifetime); @@ -303,6 +314,11 @@ void UnitParticleSystemType::loadGame(const XmlNode *rootNode) { emissionRateFade = unitParticleSystemTypeNode->getAttribute("emissionRateFade")->getFloatValue(); direction = Vec3f::strToVec3(unitParticleSystemTypeNode->getAttribute("direction")->getValue()); relative = (unitParticleSystemTypeNode->getAttribute("relative")->getIntValue() != 0); + if(unitParticleSystemTypeNode->hasAttribute("meshName")){ + meshName = unitParticleSystemTypeNode->getAttribute("meshName")->getValue();} + else { + meshName = ""; + } relativeDirection = (unitParticleSystemTypeNode->getAttribute("relativeDirection")->getIntValue() != 0); fixed = (unitParticleSystemTypeNode->getAttribute("fixed")->getIntValue() != 0); staticParticleCount = unitParticleSystemTypeNode->getAttribute("staticParticleCount")->getIntValue(); @@ -336,6 +352,8 @@ void UnitParticleSystemType::saveGame(XmlNode *rootNode) { unitParticleSystemTypeNode->addAttribute("direction",direction.getString(), mapTagReplacements); // bool relative; unitParticleSystemTypeNode->addAttribute("relative",intToStr(relative), mapTagReplacements); +// string meshName; + unitParticleSystemTypeNode->addAttribute("meshName",meshName, mapTagReplacements); // bool relativeDirection; unitParticleSystemTypeNode->addAttribute("relativeDirection",intToStr(relativeDirection), mapTagReplacements); // bool fixed; diff --git a/source/glest_game/graphics/unit_particle_type.h b/source/glest_game/graphics/unit_particle_type.h index c6dfda8c..159d96a8 100644 --- a/source/glest_game/graphics/unit_particle_type.h +++ b/source/glest_game/graphics/unit_particle_type.h @@ -58,6 +58,7 @@ protected: float emissionRateFade; Vec3f direction; bool relative; + string meshName; bool relativeDirection; bool fixed; int staticParticleCount; @@ -70,6 +71,7 @@ protected: float startTime; float endTime; + public: UnitParticleSystemType(); virtual ~UnitParticleSystemType() {}; diff --git a/source/glest_game/type_instances/unit.cpp b/source/glest_game/type_instances/unit.cpp index 221beb66..3a793be6 100644 --- a/source/glest_game/type_instances/unit.cpp +++ b/source/glest_game/type_instances/unit.cpp @@ -332,6 +332,8 @@ void UnitAttackBoostEffect::applyLoadedAttackBoostParticles(UnitParticleSystemTy ups->setParticleOwner(unit); upst->setValues(ups); ups->setPos(unit->getCurrVector()); + ups->setRotation(unit->getRotation()); + ups->setUnitModel(unit->getCurrentModelPtr()); if (unit->getFaction()->getTexture()) { ups->setFactionColor(unit->getFaction()->getTexture()->getPixmapConst()->getPixel3f(0, 0)); } @@ -1290,6 +1292,8 @@ void Unit::setCurrSkill(const SkillType *currSkill) { ups->setParticleOwner(this); (*it)->setValues(ups); ups->setPos(getCurrVector()); + ups->setRotation(getRotation()); + ups->setUnitModel(getCurrentModelPtr()); if(getFaction()->getTexture()) { ups->setFactionColor(getFaction()->getTexture()->getPixmapConst()->getPixel3f(0,0)); } @@ -2334,6 +2338,9 @@ void Unit::updateAttackBoostProgress(const Game* game) { currentAttackBoostOriginatorEffect.currentAppliedEffect->ups); currentAttackBoostOriginatorEffect.currentAppliedEffect->ups->setPos( getCurrVector()); + currentAttackBoostOriginatorEffect.currentAppliedEffect->ups->setRotation(getRotation()); + currentAttackBoostOriginatorEffect.currentAppliedEffect->ups->setUnitModel(getCurrentModelPtr()); + if (getFaction()->getTexture()) { currentAttackBoostOriginatorEffect. currentAppliedEffect->ups->setFactionColor( @@ -2442,6 +2449,9 @@ void Unit::updateAttackBoostProgress(const Game* game) { currentAttackBoostOriginatorEffect.currentAppliedEffect->ups); currentAttackBoostOriginatorEffect.currentAppliedEffect->ups->setPos( getCurrVector()); + currentAttackBoostOriginatorEffect.currentAppliedEffect->ups->setRotation(getRotation()); + currentAttackBoostOriginatorEffect.currentAppliedEffect->ups->setUnitModel(getCurrentModelPtr()); + if (getFaction()->getTexture()) { currentAttackBoostOriginatorEffect.currentAppliedEffect->ups->setFactionColor( getFaction()->getTexture()->getPixmapConst()->getPixel3f( @@ -2608,12 +2618,14 @@ bool Unit::update() { if(Renderer::getInstance().validateParticleSystemStillExists((*it),rsGame) == true) { (*it)->setPos(getCurrVector()); (*it)->setRotation(getRotation()); + (*it)->setUnitModel(getCurrentModelPtr()); } } for(UnitParticleSystems::iterator it= damageParticleSystems.begin(); it != damageParticleSystems.end(); ++it) { if(Renderer::getInstance().validateParticleSystemStillExists((*it),rsGame) == true) { (*it)->setPos(getCurrVector()); (*it)->setRotation(getRotation()); + (*it)->setUnitModel(getCurrentModelPtr()); } } @@ -2621,6 +2633,7 @@ bool Unit::update() { if(Renderer::getInstance().validateParticleSystemStillExists((*it),rsGame) == true) { (*it)->setPos(getCurrVector()); (*it)->setRotation(getRotation()); + (*it)->setUnitModel(getCurrentModelPtr()); } } @@ -2632,6 +2645,7 @@ bool Unit::update() { if(particleValid == true) { effect->ups->setPos(getCurrVector()); effect->ups->setRotation(getRotation()); + effect->ups->setUnitModel(getCurrentModelPtr()); } //printf("i = %d particleValid = %d\n",i,particleValid); @@ -2646,6 +2660,7 @@ bool Unit::update() { if(particleValid == true) { currentAttackBoostOriginatorEffect.currentAppliedEffect->ups->setPos(getCurrVector()); currentAttackBoostOriginatorEffect.currentAppliedEffect->ups->setRotation(getRotation()); + currentAttackBoostOriginatorEffect.currentAppliedEffect->ups->setUnitModel(getCurrentModelPtr()); } } } @@ -2699,6 +2714,9 @@ void Unit::updateTimedParticles() { ups->setParticleOwner(this); pst->setValues(ups); ups->setPos(getCurrVector()); + ups->setRotation(getRotation()); + ups->setUnitModel(getCurrentModelPtr()); + if(getFaction()->getTexture()) { ups->setFactionColor(getFaction()->getTexture()->getPixmapConst()->getPixel3f(0,0)); } @@ -2837,6 +2855,8 @@ bool Unit::applyAttackBoost(const AttackBoost *boost, const Unit *source) { effect->ups->setParticleOwner(this); effect->upst->setValues(effect->ups); effect->ups->setPos(getCurrVector()); + effect->ups->setRotation(getRotation()); + effect->ups->setUnitModel(getCurrentModelPtr()); if(getFaction()->getTexture()) { effect->ups->setFactionColor(getFaction()->getTexture()->getPixmapConst()->getPixel3f(0,0)); } @@ -3963,6 +3983,8 @@ void Unit::checkCustomizedParticleTriggers(bool force) { ups->setParticleOwner(this); pst->setValues(ups); ups->setPos(getCurrVector()); + ups->setRotation(getRotation()); + ups->setUnitModel(getCurrentModelPtr()); if(getFaction()->getTexture()) { ups->setFactionColor(getFaction()->getTexture()->getPixmapConst()->getPixel3f(0,0)); } @@ -3988,6 +4010,8 @@ void Unit::startDamageParticles() { ups->setParticleOwner(this); pst->setValues(ups); ups->setPos(getCurrVector()); + ups->setRotation(getRotation()); + ups->setUnitModel(getCurrentModelPtr()); if(getFaction()->getTexture()) { ups->setFactionColor(getFaction()->getTexture()->getPixmapConst()->getPixel3f(0,0)); } @@ -4019,6 +4043,8 @@ void Unit::startDamageParticles() { ups->setColorNoEnergy(Vec4f(0.0f, 0.0f, 0.0f, 0.13f)); ups->setColor(Vec4f(0.115f, 0.115f, 0.115f, 0.22f)); ups->setPos(getCurrVector()); + ups->setRotation(getRotation()); + ups->setUnitModel(getCurrentModelPtr()); ups->setBlendMode(ups->strToBlendMode("black")); ups->setOffset(Vec3f(0,2,0)); ups->setDirection(Vec3f(0,1,-0.2f)); diff --git a/source/shared_lib/include/graphics/model.h b/source/shared_lib/include/graphics/model.h index e5323852..22e720ba 100644 --- a/source/shared_lib/include/graphics/model.h +++ b/source/shared_lib/include/graphics/model.h @@ -133,6 +133,7 @@ public: bool getTwoSided() const {return twoSided;} bool getCustomTexture() const {return customColor;} bool getNoSelect() const {return noSelect;} + string getName() const {return name;} uint32 getTextureFlags() const { return textureFlags; } diff --git a/source/shared_lib/include/graphics/particle.h b/source/shared_lib/include/graphics/particle.h index 86e28f0e..3b3b8576 100644 --- a/source/shared_lib/include/graphics/particle.h +++ b/source/shared_lib/include/graphics/particle.h @@ -20,6 +20,7 @@ #include "randomgen.h" #include "xml_parser.h" #include "leak_dumper.h" +#include "interpolation.h" using std::list; using Shared::Util::RandomGen; @@ -351,6 +352,8 @@ public: float sizeNoEnergy; float gravity; float rotation; + const Model *unitModel; + string meshName; bool isVisibleAtNight; bool isVisibleAtDay; bool isDaylightAffected; @@ -391,6 +394,8 @@ public: void setSizeNoEnergy(float sizeNoEnergy) {this->sizeNoEnergy= sizeNoEnergy;} void setGravity(float gravity) {this->gravity= gravity;} void setRotation(float rotation); + const void setUnitModel(const Model* unitModel) {this->unitModel= unitModel;} + void setMeshName(string meshName) {this->meshName= meshName;} void setRelative(bool relative) {this->relative= relative;} void setRelativeDirection(bool relativeDirection) {this->relativeDirection= relativeDirection;} void setFixed(bool fixed) {this->fixed= fixed;} diff --git a/source/shared_lib/sources/graphics/particle.cpp b/source/shared_lib/sources/graphics/particle.cpp index 11bab51e..717e20af 100644 --- a/source/shared_lib/sources/graphics/particle.cpp +++ b/source/shared_lib/sources/graphics/particle.cpp @@ -1029,6 +1029,8 @@ UnitParticleSystem::UnitParticleSystem(int particleCount) : startTime = 0; endTime = 1; + unitModel=NULL; + meshName=""; radiusBasedStartenergy = false; } @@ -1062,6 +1064,7 @@ void UnitParticleSystem::setRotation(float rotation){ void UnitParticleSystem::fade(){ if(!parent || (lifetime<=0 && !(emissionRateFade && emissionRate > 0))){ // particle has its own lifetime? + unitModel=NULL; GameParticleSystem::fade(); } } @@ -1156,11 +1159,27 @@ void UnitParticleSystem::initParticle(Particle *p, int particleIndex){ } else {// rotate it according to rotation + Vec3f combinedOffset=Vec3f(offset); + if(meshName!="" && unitModel!=NULL){ + //printf("meshName set unitModel given\n"); + for(uint i=0; igetMeshCount() ; i++){ + //printf("meshName=%s\n",unitModel->getMesh(i)->getName().c_str()); + if(unitModel->getMesh(i)->getName()==meshName){ + const InterpolationData *data=unitModel->getMesh(i)->getInterpolationData(); + const Vec3f *verticepos=data->getVertices(); + //printf("verticepos %f %f %f\n",verticepos->x,verticepos->y,verticepos->z); + combinedOffset.x+=verticepos->x; + combinedOffset.y+=verticepos->y; + combinedOffset.z+=verticepos->z; + } + } + } + #ifdef USE_STREFLOP - p->pos= Vec3f(pos.x+x+offset.z*streflop::sinf(static_cast(rad))+offset.x*streflop::cosf(static_cast(rad)), pos.y+random.randRange(-radius/2, radius/2)+offset.y, pos.z+y+(offset.z*streflop::cosf(static_cast(rad))-offset.x*streflop::sinf(static_cast(rad)))); + p->pos= Vec3f(pos.x+x+combinedOffset.z*streflop::sinf(static_cast(rad))+combinedOffset.x*streflop::cosf(static_cast(rad)), pos.y+random.randRange(-radius/2, radius/2)+combinedOffset.y, pos.z+y+(combinedOffset.z*streflop::cosf(static_cast(rad))-combinedOffset.x*streflop::sinf(static_cast(rad)))); #else - p->pos= Vec3f(pos.x + x + offset.z * sinf(rad) + offset.x * cosf(rad), pos.y + random.randRange(-radius / 2, - radius / 2) + offset.y, pos.z + y + (offset.z * cosf(rad) - offset.x * sinf(rad))); + p->pos= Vec3f(pos.x + x + combinedOffset.z * sinf(rad) + combinedOffset.x * cosf(rad), pos.y + random.randRange(-radius / 2, + radius / 2) + combinedOffset.y, pos.z + y + (combinedOffset.z * cosf(rad) - combinedOffset.x * sinf(rad))); #endif p->pos.x = truncateDecimal(p->pos.x,6);