- Timestamp:
 - Jan 3, 2016, 2:39:10 PM (10 years ago)
 - Location:
 - code/branches/presentationHS15/src/orxonox/worldentities
 - Files:
 - 
          
- 2 edited
 
- 
          ExplosionPart.cc (modified) (5 diffs)
 - 
          ExplosionPart.h (modified) (3 diffs)
 
 
Legend:
- Unmodified
 - Added
 - Removed
 
- 
        
code/branches/presentationHS15/src/orxonox/worldentities/ExplosionPart.cc
r10962 r11025 36 36 { 37 37 38 RegisterClass(ExplosionPart);39 40 ExplosionPart::ExplosionPart(Context* context) : MovableEntity(context)41 {42 RegisterObject(ExplosionPart);43 this->bStop_ = false;38 RegisterClass(ExplosionPart); 39 40 ExplosionPart::ExplosionPart(Context* context) : MovableEntity(context) 41 { 42 RegisterObject(ExplosionPart); 43 this->bStop_ = false; 44 44 this->LOD_ = LODParticle::Normal; 45 this->mesh_ = "";46 this->effect1_ = "";47 this->effect2_ = "";48 this->model_= new Model(this->getContext());49 this->effect1Particle_= NULL;50 this->effect2Particle_= NULL;51 this->explosionEntity_ = new MovableEntity(this->getContext());52 this->posOffset_ = Vector3::ZERO;53 54 55 56 }57 58 59 ExplosionPart::~ExplosionPart()45 this->mesh_ = ""; 46 this->effect1_ = ""; 47 this->effect2_ = ""; 48 this->model_= new Model(this->getContext()); 49 this->effect1Particle_= NULL; 50 this->effect2Particle_= NULL; 51 this->explosionEntity_ = new MovableEntity(this->getContext()); 52 this->posOffset_ = Vector3::ZERO; 53 54 55 56 } 57 58 59 ExplosionPart::~ExplosionPart() 60 60 { 61 61 if (this->isInitialized()) … … 75 75 76 76 77 void ExplosionPart::XMLPort(Element& xmlelement, XMLPort::Mode mode)78 {79 SUPER(ExplosionPart, XMLPort, xmlelement, mode);80 81 XMLPortParam(ExplosionPart, "mesh", setMesh, getMesh, xmlelement, mode).defaultValues(""); //Define mesh file, that is going to fly out82 XMLPortParam(ExplosionPart, "minspeed", setMinSpeed, getMinSpeed, xmlelement, mode).defaultValues(50); //Minimum velocity at which parts fly out83 XMLPortParam(ExplosionPart, "maxspeed", setMaxSpeed, getMaxSpeed, xmlelement, mode).defaultValues(100); //Maximum velocity at which parts fly out, set both minspeed and maxspeed to 0 to have stationary effects84 XMLPortParam(ExplosionPart, "effect1", setEffect1, getEffect1, xmlelement, mode).defaultValues(""); //particle effect 185 XMLPortParam(ExplosionPart, "effect2", setEffect2, getEffect2, xmlelement, mode).defaultValues(""); //particle effect 286 XMLPortParam(ExplosionPart, "offset", setOffset, getOffset, xmlelement, mode).defaultValues(Vector3::ZERO); //Offset of the position if you need to have an explosion off-center 87 XMLPortParam(ExplosionPart, "direction", setDirection, getDirection, xmlelement, mode).defaultValues(Vector3(1,1,1)); //general direction the parts fly in88 XMLPortParam(ExplosionPart, "angle", setAngle, getAngle, xmlelement, mode).defaultValues(180); //defines a cone shape with direction "direction" and angle "angle" inside which the parts fly out of89 XMLPortParam(ExplosionPart, "delay", setDelay, getDelay, xmlelement, mode).defaultValues(0); //delay to the explosion in seconds90 }91 92 93 void ExplosionPart::Explode()94 {95 this->destroyTimer_.setTimer(delay_, false, createExecutor(createFunctor(&ExplosionPart::ActuallyExplode, this)));96 }97 98 void ExplosionPart::stop()99 {100 if (this->effect1Particle_)77 void ExplosionPart::XMLPort(Element& xmlelement, XMLPort::Mode mode) 78 { 79 SUPER(ExplosionPart, XMLPort, xmlelement, mode); 80 81 XMLPortParam(ExplosionPart, "mesh", setMesh, getMesh, xmlelement, mode).defaultValues(""); //Define mesh file, that is going to fly out 82 XMLPortParam(ExplosionPart, "minspeed", setMinSpeed, getMinSpeed, xmlelement, mode).defaultValues(50); //Minimum velocity at which parts fly out 83 XMLPortParam(ExplosionPart, "maxspeed", setMaxSpeed, getMaxSpeed, xmlelement, mode).defaultValues(100); //Maximum velocity at which parts fly out, set both minspeed and maxspeed to 0 to have stationary effects 84 XMLPortParam(ExplosionPart, "effect1", setEffect1, getEffect1, xmlelement, mode).defaultValues(""); //particle effect 1 85 XMLPortParam(ExplosionPart, "effect2", setEffect2, getEffect2, xmlelement, mode).defaultValues(""); //particle effect 2 86 XMLPortParam(ExplosionPart, "offset", setOffset, getOffset, xmlelement, mode).defaultValues(Vector3::ZERO); //Offset of the position if you need to have an explosion off-center 87 XMLPortParam(ExplosionPart, "direction", setDirection, getDirection, xmlelement, mode).defaultValues(Vector3(1,1,1)); //general direction the parts fly in 88 XMLPortParam(ExplosionPart, "angle", setAngle, getAngle, xmlelement, mode).defaultValues(180); //defines a cone shape with direction "direction" and angle "angle" inside which the parts fly out of 89 XMLPortParam(ExplosionPart, "delay", setDelay, getDelay, xmlelement, mode).defaultValues(0); //delay to the explosion in seconds 90 } 91 92 93 void ExplosionPart::Explode() 94 { 95 this->destroyTimer_.setTimer(delay_, false, createExecutor(createFunctor(&ExplosionPart::ActuallyExplode, this))); 96 } 97 98 void ExplosionPart::stop() 99 { 100 if (this->effect1Particle_) 101 101 this->effect1Particle_->setEnabled(false); 102 102 if (this->effect2Particle_) … … 110 110 this->destroyTimer_.setTimer(1.0f, false, createExecutor(createFunctor(&ExplosionPart::destroy, this))); 111 111 } 112 }113 114 void ExplosionPart::ActuallyExplode()115 {116 this->model_->setVisible(true);117 118 //this->explosionEntity_->setSyncMode(0);119 120 //this->model_->setSyncMode(0);121 122 123 if(effect1_ != "")124 {125 this->effect1Particle_ = new ParticleInterface(this->getScene()->getSceneManager(), effect1_, this->LOD_);126 this->effect1Particle_->setDimensions(this->getScale());127 this->model_->attachOgreObject(this->effect1Particle_->getParticleSystem());128 }129 130 if(effect2_ != "")131 {132 this->effect2Particle_ = new ParticleInterface(this->getScene()->getSceneManager(), effect2_, this->LOD_);133 this->effect2Particle_->setDimensions(this->getScale());134 this->model_->attachOgreObject(this->effect2Particle_->getParticleSystem());135 }136 137 138 139 112 } 113 114 void ExplosionPart::ActuallyExplode() 115 { 116 this->model_->setVisible(true); 117 118 //this->explosionEntity_->setSyncMode(0); 119 120 //this->model_->setSyncMode(0); 121 122 123 if(effect1_ != "") 124 { 125 this->effect1Particle_ = new ParticleInterface(this->getScene()->getSceneManager(), effect1_, this->LOD_); 126 this->effect1Particle_->setDimensions(this->getScale()); 127 this->model_->attachOgreObject(this->effect1Particle_->getParticleSystem()); 128 } 129 130 if(effect2_ != "") 131 { 132 this->effect2Particle_ = new ParticleInterface(this->getScene()->getSceneManager(), effect2_, this->LOD_); 133 this->effect2Particle_->setDimensions(this->getScale()); 134 this->model_->attachOgreObject(this->effect2Particle_->getParticleSystem()); 135 } 136 137 138 139 140 140 Vector3 velocityOffset = direction_.perpendicular(); 141 141 velocityOffset.normalise(); … … 147 147 Vector3 finalDirection = direction_ + sin((rnd(0, angle_))*M_PI/180)*velocityOffset; 148 148 149 this->explosionEntity_->setVelocity(finalDirection*rnd(minSpeed_,maxSpeed_));149 this->explosionEntity_->setVelocity(finalDirection*rnd(minSpeed_,maxSpeed_)); 150 150 this->explosionEntity_->setAngularVelocity(Vector3(rnd(-1, 1), rnd(-1, 1), rnd(-1, 1)).normalisedCopy() * Degree(400).valueRadians()); 151 151 this->explosionEntity_->setScale(this->getScale() * 4); … … 161 161 this->destroyTimer_.setTimer(rnd(2, 4), false, createExecutor(createFunctor(&ExplosionPart::stop, this))); 162 162 } 163 }164 165 166 167 168 void ExplosionPart::setMesh(const std::string& newString)169 {170 if(newString != "")171 {172 this->mesh_ = newString;173 this->model_->setMeshSource(mesh_);174 this->model_->setVisible(false);175 }176 }177 178 void ExplosionPart::setEffect1(const std::string& newString)179 {180 this->effect1_ = newString;181 }182 183 void ExplosionPart::setEffect2(const std::string& newString)184 {185 this->effect2_ = newString;186 }187 188 void ExplosionPart::setMinSpeed(float speed)189 {190 this->minSpeed_ = speed;191 }192 193 void ExplosionPart::setMaxSpeed(float speed)194 {195 this->maxSpeed_ = speed;196 }197 198 void ExplosionPart::setOffset(Vector3 newVector)199 {200 this->posOffset_ = newVector;201 this->explosionEntity_->setPosition(this->getPosition() + this->posOffset_ / this->getScale());202 }203 204 void ExplosionPart::setDirection(Vector3 newDirection)205 {206 this->direction_ = newDirection;207 }208 209 void ExplosionPart::setAngle(float newAngle)210 {211 this->angle_ = newAngle;212 }213 214 void ExplosionPart::setDelay(float newDelay)215 {216 this->delay_ = newDelay;217 }218 219 std::string& ExplosionPart::getMesh()220 { return this->mesh_; }221 222 std::string& ExplosionPart::getEffect1()223 { return this->effect1_; }224 225 std::string& ExplosionPart::getEffect2()226 { return this->effect2_; }227 228 float ExplosionPart::getMinSpeed()229 {230 return this->minSpeed_;231 }232 233 float ExplosionPart::getMaxSpeed()234 {235 return this->maxSpeed_;236 }237 238 Vector3 ExplosionPart::getOffset()239 {240 return this->posOffset_;241 }242 243 Vector3 ExplosionPart::getDirection()244 {245 return direction_;246 }247 248 float ExplosionPart::getAngle()249 {250 return angle_;251 }252 253 float ExplosionPart::getDelay()254 {255 return delay_;256 }163 } 164 165 166 167 168 void ExplosionPart::setMesh(const std::string& newString) 169 { 170 if(newString != "") 171 { 172 this->mesh_ = newString; 173 this->model_->setMeshSource(mesh_); 174 this->model_->setVisible(false); 175 } 176 } 177 178 void ExplosionPart::setEffect1(const std::string& newString) 179 { 180 this->effect1_ = newString; 181 } 182 183 void ExplosionPart::setEffect2(const std::string& newString) 184 { 185 this->effect2_ = newString; 186 } 187 188 void ExplosionPart::setMinSpeed(float speed) 189 { 190 this->minSpeed_ = speed; 191 } 192 193 void ExplosionPart::setMaxSpeed(float speed) 194 { 195 this->maxSpeed_ = speed; 196 } 197 198 void ExplosionPart::setOffset(Vector3 newVector) 199 { 200 this->posOffset_ = newVector; 201 this->explosionEntity_->setPosition(this->getPosition() + this->posOffset_ / this->getScale()); 202 } 203 204 void ExplosionPart::setDirection(Vector3 newDirection) 205 { 206 this->direction_ = newDirection; 207 } 208 209 void ExplosionPart::setAngle(float newAngle) 210 { 211 this->angle_ = newAngle; 212 } 213 214 void ExplosionPart::setDelay(float newDelay) 215 { 216 this->delay_ = newDelay; 217 } 218 219 std::string& ExplosionPart::getMesh() 220 { return this->mesh_; } 221 222 std::string& ExplosionPart::getEffect1() 223 { return this->effect1_; } 224 225 std::string& ExplosionPart::getEffect2() 226 { return this->effect2_; } 227 228 float ExplosionPart::getMinSpeed() 229 { 230 return this->minSpeed_; 231 } 232 233 float ExplosionPart::getMaxSpeed() 234 { 235 return this->maxSpeed_; 236 } 237 238 Vector3 ExplosionPart::getOffset() 239 { 240 return this->posOffset_; 241 } 242 243 Vector3 ExplosionPart::getDirection() 244 { 245 return direction_; 246 } 247 248 float ExplosionPart::getAngle() 249 { 250 return angle_; 251 } 252 253 float ExplosionPart::getDelay() 254 { 255 return delay_; 256 } 257 257 258 258  - 
        
code/branches/presentationHS15/src/orxonox/worldentities/ExplosionPart.h
r10962 r11025 82 82 83 83 84 Model* model_;85 ParticleInterface* effect1Particle_;84 Model* model_; 85 ParticleInterface* effect1Particle_; 86 86 ParticleInterface* effect2Particle_; 87 87 … … 89 89 float minSpeed_; 90 90 float maxSpeed_; 91 std::string mesh_;92 std::string effect1_;91 std::string mesh_; 92 std::string effect1_; 93 93 std::string effect2_; 94 94 Vector3 posOffset_; … … 101 101 Timer destroyTimer_; 102 102 103 103 104 104 105 105 };  
Note: See TracChangeset
          for help on using the changeset viewer.
      


            






