unit particles can be bound to first vertice of meshes ( <meshName value="part1.001" /> )

This commit is contained in:
titiger
2014-01-04 18:40:00 +01:00
parent 37494a9c37
commit ba1d03118e
6 changed files with 75 additions and 4 deletions

View File

@@ -37,6 +37,7 @@ UnitParticleSystemType::UnitParticleSystemType() : ParticleSystemType() {
minRadius = 0; minRadius = 0;
emissionRateFade = 0; emissionRateFade = 0;
relative = false; relative = false;
meshName = "";
relativeDirection = false; relativeDirection = false;
fixed = false; fixed = false;
staticParticleCount = 0; staticParticleCount = 0;
@@ -111,6 +112,15 @@ void UnitParticleSystemType::load(const XmlNode *particleSystemNode, const strin
relative= relativeNode->getAttribute("value")->getBoolValue(); relative= relativeNode->getAttribute("value")->getBoolValue();
//meshName
if(particleSystemNode->hasChild("meshName")){
const XmlNode *tmpNode= particleSystemNode->getChild("meshName");
meshName= tmpNode->getAttribute("value")->getValue();
}
else{
meshName="";
}
//relativeDirection //relativeDirection
if(particleSystemNode->hasChild("relativeDirection")){ if(particleSystemNode->hasChild("relativeDirection")){
const XmlNode *relativeDirectionNode= particleSystemNode->getChild("relativeDirection"); const XmlNode *relativeDirectionNode= particleSystemNode->getChild("relativeDirection");
@@ -231,6 +241,7 @@ const void UnitParticleSystemType::setValues(UnitParticleSystem *ups){
ups->setVarParticleEnergy(energyVar); ups->setVarParticleEnergy(energyVar);
ups->setFixed(fixed); ups->setFixed(fixed);
ups->setRelative(relative); ups->setRelative(relative);
ups->setMeshName(meshName);
ups->setRelativeDirection(relativeDirection); ups->setRelativeDirection(relativeDirection);
ups->setDelay(delay); ups->setDelay(delay);
ups->setLifetime(lifetime); ups->setLifetime(lifetime);
@@ -303,6 +314,11 @@ void UnitParticleSystemType::loadGame(const XmlNode *rootNode) {
emissionRateFade = unitParticleSystemTypeNode->getAttribute("emissionRateFade")->getFloatValue(); emissionRateFade = unitParticleSystemTypeNode->getAttribute("emissionRateFade")->getFloatValue();
direction = Vec3f::strToVec3(unitParticleSystemTypeNode->getAttribute("direction")->getValue()); direction = Vec3f::strToVec3(unitParticleSystemTypeNode->getAttribute("direction")->getValue());
relative = (unitParticleSystemTypeNode->getAttribute("relative")->getIntValue() != 0); relative = (unitParticleSystemTypeNode->getAttribute("relative")->getIntValue() != 0);
if(unitParticleSystemTypeNode->hasAttribute("meshName")){
meshName = unitParticleSystemTypeNode->getAttribute("meshName")->getValue();}
else {
meshName = "";
}
relativeDirection = (unitParticleSystemTypeNode->getAttribute("relativeDirection")->getIntValue() != 0); relativeDirection = (unitParticleSystemTypeNode->getAttribute("relativeDirection")->getIntValue() != 0);
fixed = (unitParticleSystemTypeNode->getAttribute("fixed")->getIntValue() != 0); fixed = (unitParticleSystemTypeNode->getAttribute("fixed")->getIntValue() != 0);
staticParticleCount = unitParticleSystemTypeNode->getAttribute("staticParticleCount")->getIntValue(); staticParticleCount = unitParticleSystemTypeNode->getAttribute("staticParticleCount")->getIntValue();
@@ -336,6 +352,8 @@ void UnitParticleSystemType::saveGame(XmlNode *rootNode) {
unitParticleSystemTypeNode->addAttribute("direction",direction.getString(), mapTagReplacements); unitParticleSystemTypeNode->addAttribute("direction",direction.getString(), mapTagReplacements);
// bool relative; // bool relative;
unitParticleSystemTypeNode->addAttribute("relative",intToStr(relative), mapTagReplacements); unitParticleSystemTypeNode->addAttribute("relative",intToStr(relative), mapTagReplacements);
// string meshName;
unitParticleSystemTypeNode->addAttribute("meshName",meshName, mapTagReplacements);
// bool relativeDirection; // bool relativeDirection;
unitParticleSystemTypeNode->addAttribute("relativeDirection",intToStr(relativeDirection), mapTagReplacements); unitParticleSystemTypeNode->addAttribute("relativeDirection",intToStr(relativeDirection), mapTagReplacements);
// bool fixed; // bool fixed;

View File

@@ -58,6 +58,7 @@ protected:
float emissionRateFade; float emissionRateFade;
Vec3f direction; Vec3f direction;
bool relative; bool relative;
string meshName;
bool relativeDirection; bool relativeDirection;
bool fixed; bool fixed;
int staticParticleCount; int staticParticleCount;
@@ -70,6 +71,7 @@ protected:
float startTime; float startTime;
float endTime; float endTime;
public: public:
UnitParticleSystemType(); UnitParticleSystemType();
virtual ~UnitParticleSystemType() {}; virtual ~UnitParticleSystemType() {};

View File

@@ -332,6 +332,8 @@ void UnitAttackBoostEffect::applyLoadedAttackBoostParticles(UnitParticleSystemTy
ups->setParticleOwner(unit); ups->setParticleOwner(unit);
upst->setValues(ups); upst->setValues(ups);
ups->setPos(unit->getCurrVector()); ups->setPos(unit->getCurrVector());
ups->setRotation(unit->getRotation());
ups->setUnitModel(unit->getCurrentModelPtr());
if (unit->getFaction()->getTexture()) { if (unit->getFaction()->getTexture()) {
ups->setFactionColor(unit->getFaction()->getTexture()->getPixmapConst()->getPixel3f(0, 0)); ups->setFactionColor(unit->getFaction()->getTexture()->getPixmapConst()->getPixel3f(0, 0));
} }
@@ -1290,6 +1292,8 @@ void Unit::setCurrSkill(const SkillType *currSkill) {
ups->setParticleOwner(this); ups->setParticleOwner(this);
(*it)->setValues(ups); (*it)->setValues(ups);
ups->setPos(getCurrVector()); ups->setPos(getCurrVector());
ups->setRotation(getRotation());
ups->setUnitModel(getCurrentModelPtr());
if(getFaction()->getTexture()) { if(getFaction()->getTexture()) {
ups->setFactionColor(getFaction()->getTexture()->getPixmapConst()->getPixel3f(0,0)); ups->setFactionColor(getFaction()->getTexture()->getPixmapConst()->getPixel3f(0,0));
} }
@@ -2334,6 +2338,9 @@ void Unit::updateAttackBoostProgress(const Game* game) {
currentAttackBoostOriginatorEffect.currentAppliedEffect->ups); currentAttackBoostOriginatorEffect.currentAppliedEffect->ups);
currentAttackBoostOriginatorEffect.currentAppliedEffect->ups->setPos( currentAttackBoostOriginatorEffect.currentAppliedEffect->ups->setPos(
getCurrVector()); getCurrVector());
currentAttackBoostOriginatorEffect.currentAppliedEffect->ups->setRotation(getRotation());
currentAttackBoostOriginatorEffect.currentAppliedEffect->ups->setUnitModel(getCurrentModelPtr());
if (getFaction()->getTexture()) { if (getFaction()->getTexture()) {
currentAttackBoostOriginatorEffect. currentAttackBoostOriginatorEffect.
currentAppliedEffect->ups->setFactionColor( currentAppliedEffect->ups->setFactionColor(
@@ -2442,6 +2449,9 @@ void Unit::updateAttackBoostProgress(const Game* game) {
currentAttackBoostOriginatorEffect.currentAppliedEffect->ups); currentAttackBoostOriginatorEffect.currentAppliedEffect->ups);
currentAttackBoostOriginatorEffect.currentAppliedEffect->ups->setPos( currentAttackBoostOriginatorEffect.currentAppliedEffect->ups->setPos(
getCurrVector()); getCurrVector());
currentAttackBoostOriginatorEffect.currentAppliedEffect->ups->setRotation(getRotation());
currentAttackBoostOriginatorEffect.currentAppliedEffect->ups->setUnitModel(getCurrentModelPtr());
if (getFaction()->getTexture()) { if (getFaction()->getTexture()) {
currentAttackBoostOriginatorEffect.currentAppliedEffect->ups->setFactionColor( currentAttackBoostOriginatorEffect.currentAppliedEffect->ups->setFactionColor(
getFaction()->getTexture()->getPixmapConst()->getPixel3f( getFaction()->getTexture()->getPixmapConst()->getPixel3f(
@@ -2608,12 +2618,14 @@ bool Unit::update() {
if(Renderer::getInstance().validateParticleSystemStillExists((*it),rsGame) == true) { if(Renderer::getInstance().validateParticleSystemStillExists((*it),rsGame) == true) {
(*it)->setPos(getCurrVector()); (*it)->setPos(getCurrVector());
(*it)->setRotation(getRotation()); (*it)->setRotation(getRotation());
(*it)->setUnitModel(getCurrentModelPtr());
} }
} }
for(UnitParticleSystems::iterator it= damageParticleSystems.begin(); it != damageParticleSystems.end(); ++it) { for(UnitParticleSystems::iterator it= damageParticleSystems.begin(); it != damageParticleSystems.end(); ++it) {
if(Renderer::getInstance().validateParticleSystemStillExists((*it),rsGame) == true) { if(Renderer::getInstance().validateParticleSystemStillExists((*it),rsGame) == true) {
(*it)->setPos(getCurrVector()); (*it)->setPos(getCurrVector());
(*it)->setRotation(getRotation()); (*it)->setRotation(getRotation());
(*it)->setUnitModel(getCurrentModelPtr());
} }
} }
@@ -2621,6 +2633,7 @@ bool Unit::update() {
if(Renderer::getInstance().validateParticleSystemStillExists((*it),rsGame) == true) { if(Renderer::getInstance().validateParticleSystemStillExists((*it),rsGame) == true) {
(*it)->setPos(getCurrVector()); (*it)->setPos(getCurrVector());
(*it)->setRotation(getRotation()); (*it)->setRotation(getRotation());
(*it)->setUnitModel(getCurrentModelPtr());
} }
} }
@@ -2632,6 +2645,7 @@ bool Unit::update() {
if(particleValid == true) { if(particleValid == true) {
effect->ups->setPos(getCurrVector()); effect->ups->setPos(getCurrVector());
effect->ups->setRotation(getRotation()); effect->ups->setRotation(getRotation());
effect->ups->setUnitModel(getCurrentModelPtr());
} }
//printf("i = %d particleValid = %d\n",i,particleValid); //printf("i = %d particleValid = %d\n",i,particleValid);
@@ -2646,6 +2660,7 @@ bool Unit::update() {
if(particleValid == true) { if(particleValid == true) {
currentAttackBoostOriginatorEffect.currentAppliedEffect->ups->setPos(getCurrVector()); currentAttackBoostOriginatorEffect.currentAppliedEffect->ups->setPos(getCurrVector());
currentAttackBoostOriginatorEffect.currentAppliedEffect->ups->setRotation(getRotation()); currentAttackBoostOriginatorEffect.currentAppliedEffect->ups->setRotation(getRotation());
currentAttackBoostOriginatorEffect.currentAppliedEffect->ups->setUnitModel(getCurrentModelPtr());
} }
} }
} }
@@ -2699,6 +2714,9 @@ void Unit::updateTimedParticles() {
ups->setParticleOwner(this); ups->setParticleOwner(this);
pst->setValues(ups); pst->setValues(ups);
ups->setPos(getCurrVector()); ups->setPos(getCurrVector());
ups->setRotation(getRotation());
ups->setUnitModel(getCurrentModelPtr());
if(getFaction()->getTexture()) { if(getFaction()->getTexture()) {
ups->setFactionColor(getFaction()->getTexture()->getPixmapConst()->getPixel3f(0,0)); 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->ups->setParticleOwner(this);
effect->upst->setValues(effect->ups); effect->upst->setValues(effect->ups);
effect->ups->setPos(getCurrVector()); effect->ups->setPos(getCurrVector());
effect->ups->setRotation(getRotation());
effect->ups->setUnitModel(getCurrentModelPtr());
if(getFaction()->getTexture()) { if(getFaction()->getTexture()) {
effect->ups->setFactionColor(getFaction()->getTexture()->getPixmapConst()->getPixel3f(0,0)); effect->ups->setFactionColor(getFaction()->getTexture()->getPixmapConst()->getPixel3f(0,0));
} }
@@ -3963,6 +3983,8 @@ void Unit::checkCustomizedParticleTriggers(bool force) {
ups->setParticleOwner(this); ups->setParticleOwner(this);
pst->setValues(ups); pst->setValues(ups);
ups->setPos(getCurrVector()); ups->setPos(getCurrVector());
ups->setRotation(getRotation());
ups->setUnitModel(getCurrentModelPtr());
if(getFaction()->getTexture()) { if(getFaction()->getTexture()) {
ups->setFactionColor(getFaction()->getTexture()->getPixmapConst()->getPixel3f(0,0)); ups->setFactionColor(getFaction()->getTexture()->getPixmapConst()->getPixel3f(0,0));
} }
@@ -3988,6 +4010,8 @@ void Unit::startDamageParticles() {
ups->setParticleOwner(this); ups->setParticleOwner(this);
pst->setValues(ups); pst->setValues(ups);
ups->setPos(getCurrVector()); ups->setPos(getCurrVector());
ups->setRotation(getRotation());
ups->setUnitModel(getCurrentModelPtr());
if(getFaction()->getTexture()) { if(getFaction()->getTexture()) {
ups->setFactionColor(getFaction()->getTexture()->getPixmapConst()->getPixel3f(0,0)); 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->setColorNoEnergy(Vec4f(0.0f, 0.0f, 0.0f, 0.13f));
ups->setColor(Vec4f(0.115f, 0.115f, 0.115f, 0.22f)); ups->setColor(Vec4f(0.115f, 0.115f, 0.115f, 0.22f));
ups->setPos(getCurrVector()); ups->setPos(getCurrVector());
ups->setRotation(getRotation());
ups->setUnitModel(getCurrentModelPtr());
ups->setBlendMode(ups->strToBlendMode("black")); ups->setBlendMode(ups->strToBlendMode("black"));
ups->setOffset(Vec3f(0,2,0)); ups->setOffset(Vec3f(0,2,0));
ups->setDirection(Vec3f(0,1,-0.2f)); ups->setDirection(Vec3f(0,1,-0.2f));

View File

@@ -133,6 +133,7 @@ public:
bool getTwoSided() const {return twoSided;} bool getTwoSided() const {return twoSided;}
bool getCustomTexture() const {return customColor;} bool getCustomTexture() const {return customColor;}
bool getNoSelect() const {return noSelect;} bool getNoSelect() const {return noSelect;}
string getName() const {return name;}
uint32 getTextureFlags() const { return textureFlags; } uint32 getTextureFlags() const { return textureFlags; }

View File

@@ -20,6 +20,7 @@
#include "randomgen.h" #include "randomgen.h"
#include "xml_parser.h" #include "xml_parser.h"
#include "leak_dumper.h" #include "leak_dumper.h"
#include "interpolation.h"
using std::list; using std::list;
using Shared::Util::RandomGen; using Shared::Util::RandomGen;
@@ -351,6 +352,8 @@ public:
float sizeNoEnergy; float sizeNoEnergy;
float gravity; float gravity;
float rotation; float rotation;
const Model *unitModel;
string meshName;
bool isVisibleAtNight; bool isVisibleAtNight;
bool isVisibleAtDay; bool isVisibleAtDay;
bool isDaylightAffected; bool isDaylightAffected;
@@ -391,6 +394,8 @@ public:
void setSizeNoEnergy(float sizeNoEnergy) {this->sizeNoEnergy= sizeNoEnergy;} void setSizeNoEnergy(float sizeNoEnergy) {this->sizeNoEnergy= sizeNoEnergy;}
void setGravity(float gravity) {this->gravity= gravity;} void setGravity(float gravity) {this->gravity= gravity;}
void setRotation(float rotation); 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 setRelative(bool relative) {this->relative= relative;}
void setRelativeDirection(bool relativeDirection) {this->relativeDirection= relativeDirection;} void setRelativeDirection(bool relativeDirection) {this->relativeDirection= relativeDirection;}
void setFixed(bool fixed) {this->fixed= fixed;} void setFixed(bool fixed) {this->fixed= fixed;}

View File

@@ -1029,6 +1029,8 @@ UnitParticleSystem::UnitParticleSystem(int particleCount) :
startTime = 0; startTime = 0;
endTime = 1; endTime = 1;
unitModel=NULL;
meshName="";
radiusBasedStartenergy = false; radiusBasedStartenergy = false;
} }
@@ -1062,6 +1064,7 @@ void UnitParticleSystem::setRotation(float rotation){
void UnitParticleSystem::fade(){ void UnitParticleSystem::fade(){
if(!parent || (lifetime<=0 && !(emissionRateFade && emissionRate > 0))){ // particle has its own lifetime? if(!parent || (lifetime<=0 && !(emissionRateFade && emissionRate > 0))){ // particle has its own lifetime?
unitModel=NULL;
GameParticleSystem::fade(); GameParticleSystem::fade();
} }
} }
@@ -1156,11 +1159,27 @@ void UnitParticleSystem::initParticle(Particle *p, int particleIndex){
} }
else {// rotate it according to rotation else {// rotate it according to rotation
Vec3f combinedOffset=Vec3f(offset);
if(meshName!="" && unitModel!=NULL){
//printf("meshName set unitModel given\n");
for(uint i=0; i<unitModel->getMeshCount() ; 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 #ifdef USE_STREFLOP
p->pos= Vec3f(pos.x+x+offset.z*streflop::sinf(static_cast<streflop::Simple>(rad))+offset.x*streflop::cosf(static_cast<streflop::Simple>(rad)), pos.y+random.randRange(-radius/2, radius/2)+offset.y, pos.z+y+(offset.z*streflop::cosf(static_cast<streflop::Simple>(rad))-offset.x*streflop::sinf(static_cast<streflop::Simple>(rad)))); p->pos= Vec3f(pos.x+x+combinedOffset.z*streflop::sinf(static_cast<streflop::Simple>(rad))+combinedOffset.x*streflop::cosf(static_cast<streflop::Simple>(rad)), pos.y+random.randRange(-radius/2, radius/2)+combinedOffset.y, pos.z+y+(combinedOffset.z*streflop::cosf(static_cast<streflop::Simple>(rad))-combinedOffset.x*streflop::sinf(static_cast<streflop::Simple>(rad))));
#else #else
p->pos= Vec3f(pos.x + x + offset.z * sinf(rad) + offset.x * cosf(rad), pos.y + random.randRange(-radius / 2, p->pos= Vec3f(pos.x + x + combinedOffset.z * sinf(rad) + combinedOffset.x * cosf(rad), pos.y + random.randRange(-radius / 2,
radius / 2) + offset.y, pos.z + y + (offset.z * cosf(rad) - offset.x * sinf(rad))); radius / 2) + combinedOffset.y, pos.z + y + (combinedOffset.z * cosf(rad) - combinedOffset.x * sinf(rad)));
#endif #endif
p->pos.x = truncateDecimal<float>(p->pos.x,6); p->pos.x = truncateDecimal<float>(p->pos.x,6);