mirror of
https://github.com/glest/glest-source.git
synced 2025-08-30 11:19:48 +02:00
Fix for meshBound Particles
There was a bug if you used multiple units of the same type with mesh bound particles. The given model was the same for all units with the same unitType/skill.
This commit is contained in:
@@ -377,6 +377,7 @@ public:
|
||||
float gravity;
|
||||
float rotation;
|
||||
const Model *unitModel;
|
||||
Vec3f meshPos;
|
||||
string meshName;
|
||||
bool isVisibleAtNight;
|
||||
bool isVisibleAtDay;
|
||||
@@ -425,7 +426,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 setMeshPos(Vec3f meshPos) {this->meshPos=meshPos;}
|
||||
string getMeshName() {return meshName;}
|
||||
void setMeshName(string meshName) {this->meshName= meshName;}
|
||||
void setRelative(bool relative) {this->relative= relative;}
|
||||
void setRelativeDirection(bool relativeDirection) {this->relativeDirection= relativeDirection;}
|
||||
|
@@ -1054,6 +1054,7 @@ UnitParticleSystem::UnitParticleSystem(int particleCount) :
|
||||
endTime = 1;
|
||||
unitModel=NULL;
|
||||
meshName="";
|
||||
meshPos=Vec3f(0,0,0);
|
||||
|
||||
radiusBasedStartenergy = false;
|
||||
}
|
||||
@@ -1182,36 +1183,17 @@ void UnitParticleSystem::initParticle(Particle *p, int particleIndex){
|
||||
p->pos.z = truncateDecimal<float>(p->pos.z,6);
|
||||
|
||||
}
|
||||
else {// rotate it according to rotation
|
||||
else {
|
||||
Vec3f combinedOffset=Vec3f(offset);
|
||||
if(meshName!="" && unitModel!=NULL){
|
||||
//printf("meshName set unitModel given\n");
|
||||
bool foundMesh=false;
|
||||
for(unsigned int 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;
|
||||
foundMesh=true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if( foundMesh == false ) {
|
||||
string meshesFound="";
|
||||
for(unsigned i=0; i<unitModel->getMeshCount() ; i++){
|
||||
meshesFound+= unitModel->getMesh(i)->getName()+", ";
|
||||
}
|
||||
|
||||
string errorString = "Warning: Particle system is trying to find mesh'"+meshName+"', but just found:\n'"+meshesFound+"' in file:\n'"+unitModel->getFileName()+"'\n";
|
||||
//throw megaglest_runtime_error(errorString);
|
||||
printf("%s",errorString.c_str());
|
||||
if(meshName!=""){
|
||||
combinedOffset.x+=meshPos.x;
|
||||
combinedOffset.y+=meshPos.y;
|
||||
combinedOffset.z+=meshPos.z;
|
||||
if(meshPos.x==0 && meshPos.y==0 && meshPos.z==0) {
|
||||
printf("meshPosFail\n");
|
||||
}
|
||||
}
|
||||
|
||||
// rotate it according to rotation
|
||||
#ifdef USE_STREFLOP
|
||||
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
|
||||
@@ -1397,9 +1379,13 @@ void UnitParticleSystem::saveGame(XmlNode *rootNode) {
|
||||
unitParticleSystemNode->addAttribute("cRotation",cRotation.getString(), mapTagReplacements);
|
||||
// Vec3f fixedAddition;
|
||||
unitParticleSystemNode->addAttribute("fixedAddition",fixedAddition.getString(), mapTagReplacements);
|
||||
// Vec3f oldPosition;
|
||||
// Vec3f oldPosition;
|
||||
unitParticleSystemNode->addAttribute("oldPosition",oldPosition.getString(), mapTagReplacements);
|
||||
// bool energyUp;
|
||||
// Vec3f meshPos;
|
||||
unitParticleSystemNode->addAttribute("meshPos",meshPos.getString(), mapTagReplacements);
|
||||
// string meshName;
|
||||
unitParticleSystemNode->addAttribute("meshName",meshName, mapTagReplacements);
|
||||
// bool energyUp;
|
||||
unitParticleSystemNode->addAttribute("energyUp",intToStr(energyUp), mapTagReplacements);
|
||||
// float startTime;
|
||||
unitParticleSystemNode->addAttribute("startTime",floatToStr(startTime,6), mapTagReplacements);
|
||||
@@ -1409,7 +1395,7 @@ void UnitParticleSystem::saveGame(XmlNode *rootNode) {
|
||||
unitParticleSystemNode->addAttribute("relative",intToStr(relative), mapTagReplacements);
|
||||
// bool relativeDirection;
|
||||
unitParticleSystemNode->addAttribute("relativeDirection",intToStr(relativeDirection), mapTagReplacements);
|
||||
// bool fixed;
|
||||
// bool fixed;
|
||||
unitParticleSystemNode->addAttribute("fixed",intToStr(fixed), mapTagReplacements);
|
||||
// Shape shape;
|
||||
unitParticleSystemNode->addAttribute("shape",intToStr(shape), mapTagReplacements);
|
||||
@@ -1461,6 +1447,14 @@ void UnitParticleSystem::loadGame(const XmlNode *rootNode) {
|
||||
fixedAddition = Vec3f::strToVec3(unitParticleSystemNode->getAttribute("fixedAddition")->getValue());
|
||||
// Vec3f oldPosition;
|
||||
oldPosition = Vec3f::strToVec3(unitParticleSystemNode->getAttribute("oldPosition")->getValue());
|
||||
// Vec3f meshPos;
|
||||
if(unitParticleSystemNode->hasAttribute("meshPos")){
|
||||
meshPos = Vec3f::strToVec3(unitParticleSystemNode->getAttribute("meshPos")->getValue());
|
||||
}
|
||||
// Vec3f meshName;
|
||||
if(unitParticleSystemNode->hasAttribute("meshName")){
|
||||
meshName = unitParticleSystemNode->getAttribute("meshName")->getValue();
|
||||
}
|
||||
// bool energyUp;
|
||||
energyUp = unitParticleSystemNode->getAttribute("energyUp")->getIntValue() != 0;
|
||||
// float startTime;
|
||||
|
Reference in New Issue
Block a user