- Timestamp:
- Dec 11, 2017, 6:05:17 PM (7 years ago)
- Location:
- code/branches/AsteroidMining_HS17/src/modules/asteroidmining
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/AsteroidMining_HS17/src/modules/asteroidmining/AsteroidMinable.cc
r11641 r11664 28 28 29 29 /* 30 31 @file AsteroidMinable.cc 30 32 31 33 * … … 45 47 46 48 KNACKPUNKTE: 49 o Super-XML-Argumente werden nicht richtig geparst (Velocity, Pitch, Yaw etc. ) 50 47 51 48 52 OFFEN: … … 58 62 o Density doesn't add up to 1... 59 63 o set collisionDamage? Just for static entities? 60 o AsteroidBelt?61 64 62 65 o Dokumentieren mit @brief? … … 64 67 o Add sound effect (crunching etc. ) (No sound in space...) 65 68 o Explosion parts 66 o custom HUD67 68 69 69 70 HANDBUCH: … … 124 125 #include "util/Math.h" 125 126 126 127 // #include "infos/PlayerInfo.h"128 // #include "controllers/Controller.h"129 // #include "gametypes/Gametype.h"130 // #include "graphics/ParticleSpawner.h"131 // #include "worldentities/ExplosionChunk.h"132 // #include "worldentities/ExplosionPart.h"133 134 // #include "core/object/ObjectListIterator.h"135 // #include "controllers/FormationController.h"136 137 #include "../pickup/items/HealthPickup.h"138 127 #include "../pickup/PickupSpawner.h" 139 128 #include "../pickup/Pickup.h" 140 //#include "../pickup/pickup ..... pickupable 129 141 130 #include "../objects/collisionshapes/SphereCollisionShape.h" 142 131 #include "../../orxonox/graphics/Model.h" 143 132 144 133 145 146 147 148 149 150 namespace orxonox 151 { 134 namespace orxonox{ 135 152 136 RegisterClass(AsteroidMinable); 153 137 … … 156 140 157 141 RegisterObject(AsteroidMinable); 158 159 142 this->context = context; 160 this->initialised = false; 161 this->dropStuff = true; // Default 143 144 // Default Values: 145 this->size = 10; 146 this->dropStuff = true; 147 this->generateSmaller = true; 148 this->health_ = 15*size; 149 this->maxHealth_ = this->health_; 150 this->acceptsPickups_ = false; 162 151 163 152 //Noetig, damit nicht sofort zerstoert? 164 153 this->setCollisionType(WorldEntity::CollisionType::Dynamic); 154 this->enableCollisionCallback(); 155 165 156 166 157 // Old from Pawn 167 158 this->registerVariables(); 168 159 169 //orxout() << "AsteroidMining:: Pseudo-Konstruktor passiert!" << endl;160 this->initialised = false; 170 161 171 162 } … … 184 175 } 185 176 186 this->setCollisionType(WorldEntity::CollisionType::Dynamic);187 this->enableCollisionCallback();188 189 // Default Values190 177 this->context = c; 191 178 this->size = size; … … 197 184 198 185 this->setPosition(position); 199 this->setVelocity(v); // velocity = v; // The right one? 200 //this->roll = rand()*5; //etwas Drehung. richtige Variable 201 202 203 // Add Model //<Model position="0,-40,40" yaw="90" pitch="-90" roll="0" scale="4" mesh="ast6.mesh" /> 186 this->setVelocity(v); 187 //this->roll = rand()*5; //etwas Drehung. Richtige Variable? 188 189 this->setCollisionType(WorldEntity::CollisionType::Dynamic); 190 this->enableCollisionCallback(); 191 192 193 // Add Model, random one of the 6 shapes 204 194 Model* hull = new Model(this->context); 205 // random one of the 6 shapes206 195 char meshThingy[] = ""; 207 sprintf(meshThingy, "ast%.0f.mesh", round(5*rnd())+1); // sprintf(str, "Value of Pi = %f", M_PI);196 sprintf(meshThingy, "ast%.0f.mesh", round(5*rnd())+1); 208 197 hull->setMeshSource(meshThingy); 209 198 hull->setScale(this->size); … … 212 201 // Collision shape 213 202 SphereCollisionShape* cs = new SphereCollisionShape(this->context); 214 cs->setRadius((this->size)*2); //OFFEN: Feinabstimmung der Radien. 2.5 in AsteroidField.lua203 cs->setRadius((this->size)*2); //OFFEN: Feinabstimmung der Radien. 215 204 this->attachCollisionShape(cs); 216 205 217 // Old from Pawn218 206 this->registerVariables(); 219 207 220 208 this->initialised=true; 221 209 222 //orxout() << "AsteroidMining:: Initialisierung Zweitkonstruktor abgeschlosssssen." << endl;223 224 210 } 225 211 … … 227 213 228 214 } 215 229 216 // @brief Helper method. Create a new asteroid to have an appropriate size for the collision shape etc. 230 217 void AsteroidMinable::putStuff(){ … … 232 219 // Just create a new asteroid to avoid Collision shape scale problems etc. 233 220 AsteroidMinable* reborn = new AsteroidMinable(this->context, this->size, this->getPosition(), this->getVelocity(), this->dropStuff); 234 reborn->toggleShattering(true); // mainly here to avoid 'unused' warning.221 (void)reborn; // avoid compiler warning 235 222 this->bAlive_ = false; 236 223 this->destroyLater(); 237 //this->~AsteroidMinable(); // seems dangerous, yields warning. Necessary for efficiency? 238 239 } 240 241 void AsteroidMinable::XMLPort(Element& xmlelement, XMLPort::Mode mode) 242 { 243 SUPER(AsteroidMinable, XMLPort, xmlelement, mode); 244 // XMLPortParam(PickupSpawner, "pickup", setPickupTemplateName, getPickupTemplateName, xmlelement, mode); 224 225 } 226 227 void AsteroidMinable::XMLPort(Element& xmlelement, XMLPort::Mode mode){ 228 229 SUPER(AsteroidMinable, XMLPort, xmlelement, mode); 230 245 231 XMLPortParam(AsteroidMinable, "size", setSize, getSize, xmlelement, mode); 246 247 } 248 249 void AsteroidMinable::XMLEventPort(Element& xmlelement, XMLPort::Mode mode) 250 { 232 XMLPortParam(AsteroidMinable, "generateSmaller", toggleShattering, doesShatter, xmlelement, mode); 233 XMLPortParam(AsteroidMinable, "dropStuff", toggleDropStuff, doesDropStuff, xmlelement, mode); 234 235 } 236 237 void AsteroidMinable::XMLEventPort(Element& xmlelement, XMLPort::Mode mode){ 238 251 239 SUPER(AsteroidMinable, XMLEventPort, xmlelement, mode); 252 240 253 XMLPortEventState(AsteroidMinable, BaseObject, "vulnerability", setVulnerable, xmlelement, mode); 254 } 255 256 void AsteroidMinable::registerVariables() 257 { 241 } 242 243 void AsteroidMinable::registerVariables(){ 258 244 259 245 registerVariable(this->size, VariableDirection::ToClient); 260 246 registerVariable(this->generateSmaller, VariableDirection::ToClient); 261 247 registerVariable(this->dropStuff, VariableDirection::ToClient); 262 248 registerVariable(this->initialised, VariableDirection::ToClient); 263 249 264 // float size; 265 // bool generateSmaller; 266 // bool initialised; 267 268 // Context* context; 269 } 270 271 void AsteroidMinable::tick(float dt) 272 { 250 } 251 252 void AsteroidMinable::tick(float dt){ 253 273 254 if(!(this->initialised)){this->putStuff();} 274 255 … … 277 258 } 278 259 279 280 281 282 void AsteroidMinable::death() //ueberschreiben 283 { 284 285 // orxout() << "AsteroidMinable::Death() aufgerufen." << endl; 286 287 // OFFEN: Sauber kapputten 288 // just copied other stuff: 289 // this->setHealth(1); 260 void AsteroidMinable::death(){ // ueberschreibt das Zeug in Pawn 261 262 // just copied that from somewhere else. 290 263 this->bAlive_ = false; 291 264 this->destroyLater(); … … 312 285 thingy->setRespawnTime(0.2f); 313 286 } 314 // orxout() << "AsteroidMining::Death(): Passed Pickup stuff!" << endl;315 287 316 288 // Smaller Parts = 'Children' 317 289 if(this->generateSmaller){this->spawnChildren();} 318 290 319 // orxout() << "Wieder retour in death() geschafft. " << endl;320 321 291 } 322 292 … … 324 294 void AsteroidMinable::spawnChildren(){// Spawn smaller Children 325 295 326 327 296 if (this->size <=1){return;} // Absicherung trivialer Fall 328 297 … … 331 300 if(num > 10){num = 10;} // no max function in C! 332 301 int masses[num]; // Masses of the asteroids, at least one. 333 //orxout() << "SpawnChildren(): Passed basic stuff. num = " << num << "; massRem(total) = "<< massRem << endl; 302 303 // orxout() << "SpawnChildren(): Passed basic stuff. num = " << num << "; massRem(total) = "<< massRem << endl; 334 304 335 305 massRem = massRem-num; // mass is at least one, add again below. 336 306 337 307 // Randomnised spawning points for the new asteroids 338 float phi[num]; // assuming that it gets initialised to 0. Add (= {0.0})? 339 float theta[num]; 308 float phi[num]; 309 float theta[num]; 310 311 // Discusting C stuff -> use that to initialise dynamic array values to 0. 312 for(int twat = 0; twat<num; ++twat){masses[twat] = 0; phi[twat] = 0.0; theta[twat] = 0.0;} 313 340 314 float piG = 3.1415927410125732421875; //pi; // Math.pi ist statisch oder so. 341 342 315 float d_p = 2*piG/num; 343 316 float d_t = piG/num; … … 347 320 // float thetaOffset = rnd()*pi; 348 321 float rScaling; // scale radius to prevent asteroids from touching. (distance=AsteroidRadius/tan(sector/2)) 322 349 323 if(num == 1 ){ 350 324 rScaling = 1; // avoid tan(90). Unused. … … 404 378 result = 0;// reset 405 379 rVal = rnd();// between 0 and 1 406 // orxout() << "Random Value picked: " << rVal << endl;407 380 probSum = probDensity[0]; 408 //orxout() << "Sum at start: " << probSum << endl; 409 410 while(rVal>probSum && result<massRem){// Not yet found && there-s smth to distribute (Incrementing once inside!) 381 382 while(rVal>probSum && result<massRem){// Not yet found && there-s smth left to distribute (Incrementing once inside!) 411 383 if(result<(massRem-2)){probSum = probSum + probDensity[result+1];} // avoid logical/acess error 412 384 ++result; 413 // orxout() << "Sum so far: " << probSum << ". Just added " << probDensity[result+1] << endl;414 385 } 415 386 416 387 massRem = massRem-result; 417 masses[trav] = 1 +result; // at least one 418 // orxout() << "Mass chosen for child " << trav << " is: " << masses[trav] << endl; 419 420 } 421 }else{// Everyone has mass 1. Initialising the array to 1 doesn-t seem to work. Hideous C language! 422 for(int schnaegg = 0; schnaegg<num; ++schnaegg){ 423 masses[schnaegg] = 1; 424 } 388 masses[trav] = 1 +result; // Fragments have mass of at least one. 389 } 390 }else{ 391 for(int schnaegg = 0; schnaegg<num; ++schnaegg){masses[schnaegg] = 1;} 425 392 } 426 393 … … 437 404 } 438 405 439 // orxout() << "Creating asteroid with mass " << masses[fisch] << " at relative postition " << *pos << endl;440 406 AsteroidMinable* child = new AsteroidMinable(this->context, masses[fisch], this->getPosition() + *pos, this->getVelocity(), this->dropStuff); 441 407 -
code/branches/AsteroidMining_HS17/src/modules/asteroidmining/AsteroidMinable.h
r11646 r11664 26 26 * 27 27 */ 28 29 30 /** 31 @file AsteroidMinable.h 32 33 34 */ 28 35 29 36 #ifndef _AsteroidMinable_H__ … … 64 71 65 72 inline void toggleShattering(bool b){this->generateSmaller = b;} 73 inline bool doesShatter(){return this->generateSmaller;} 74 66 75 inline void toggleDropStuff(bool b){this->dropStuff = b;} 67 76 inline bool doesDropStuff(){return this->dropStuff;} 68 77 69 78 protected: … … 74 83 bool generateSmaller; 75 84 bool dropStuff; 85 76 86 bool initialised; 77 87 -
code/branches/AsteroidMining_HS17/src/modules/asteroidmining/CMakeLists.txt
r11640 r11664 2 2 AsteroidMinable.cc 3 3 SpicedAsteroidField.cc 4 SpicedAsteroidBelt.cc 4 5 ) 5 6 -
code/branches/AsteroidMining_HS17/src/modules/asteroidmining/SpicedAsteroidField.cc
r11646 r11664 27 27 */ 28 28 29 /* 29 /** 30 30 31 * 32 * 33 *<OFFEN Describe 34 Math from asteroidField.lua used. 35 * 36 * 37 38 39 DESCRIPTION 40 o Andere: Simpel wie in asteroidField.lua, oder einfach Asteroiden, die nichts abwerfen? 41 --> Letzteres scheint passender, simpler. 31 @file SpicedAsteroidField.cc 32 @brief Asteroid field with lots of parameters. Derived from asteroidField.lua 42 33 43 34 … … 60 51 #include "util/Math.h" 61 52 62 // #include "infos/PlayerInfo.h" 63 // #include "controllers/Controller.h" 64 // #include "gametypes/Gametype.h" 65 // #include "graphics/ParticleSpawner.h" 66 // #include "worldentities/ExplosionChunk.h" 67 // #include "worldentities/ExplosionPart.h" 68 69 // #include "core/object/ObjectListIterator.h" 70 // #include "controllers/FormationController.h" 53 #include "../../orxonox/graphics/Billboard.h" 71 54 72 55 73 //#include "../pickup/pickup ..... pickupable 74 #include "../objects/collisionshapes/SphereCollisionShape.h" 75 #include "../../orxonox/graphics/Model.h" 56 namespace orxonox{ 76 57 77 78 79 80 81 82 namespace orxonox83 {84 58 RegisterClass(SpicedAsteroidField); 85 59 86 60 SpicedAsteroidField::SpicedAsteroidField(Context* context) : Pawn(context) { 87 61 88 // Da auch noetig? Wegen set in XML-Code?89 62 RegisterObject(SpicedAsteroidField); 63 this->context = context; 90 64 91 this->context = context; 65 // Default Values: 66 this->count = 30; 67 this->mDensity = 0.5; 68 this->position = Vector3(0,0,0); 69 this->maxSize = 40; 70 this->minSize = 1; 71 this->radius = 1000; 92 72 this->foggy = true; 93 73 this->fogDensity = 0.5; 94 this->count = 0;95 74 96 // Old from Pawn97 75 this->registerVariables(); 76 } 98 77 78 SpicedAsteroidField::SpicedAsteroidField(Context* c, Vector3 p, int minS, int maxS, int w, int count, bool f, float mD, float fD): Pawn(c){ 99 79 100 // this->create(); 101 this->bAlive_ = false; 102 this->destroyLater(); 80 this->context = c; 81 this->position = p; 82 this->minSize = minS; 83 this->maxSize = maxS; 84 this->radius = w; 85 this->count = count; 86 this->foggy = f; 87 88 this->mDensity = mD; 89 this->fogDensity = fD; 90 103 91 } 92 104 93 105 94 SpicedAsteroidField::~SpicedAsteroidField(){ … … 115 104 116 105 Vector3* relPos; 106 117 107 118 108 for(int gertrud = 0; gertrud<count; ++gertrud){ … … 131 121 a->toggleDropStuff(spiced); 132 122 133 // @TODO: Fox Fog stuff, error due to billbord 134 135 // Billboard* bb; 136 // if(this->foggy && mod(gertrud, 5) == 0){ 137 // bb = new Billboard(this->context); 138 // bb->setPosition(this-position + *relPos); 139 // bb->setMaterial("Smoke/Smoke"); 140 // bb->setScale(size); // tricky? 141 142 // bb->setColour(ColourValue(this-fogDensity, this->fogDensity, this->fogDensity)); // 4rd argument = transparency? 143 144 // // print("<Billboard ") 145 // // print("position = \"") 146 // // print(posX) print(",") 147 // // print(posY) print(",") 148 // // print(posZ) print("\" ") 149 // // print("colour=\"") 150 // // print(brightness) print(",") 151 // // print(brightness) print(",") 152 // // print(brightness) print("\" ") 153 // // print("material=\"Smoke/Smoke\" scale=") 154 // // print(size) 155 // // print(" />") 156 // } 123 // A problem 124 a->setVelocity(this->getVelocity()); 125 126 // Fog is iplemented with billboards. 127 Billboard* bb; 128 if(this->foggy && mod(gertrud, 5) == 0){ 129 bb = new Billboard(this->context); 130 bb->setPosition(this->position + *relPos); 131 bb->setMaterial("Smoke/Smoke"); 132 bb->setScale(size); 133 bb->setColour(ColourValue(this->fogDensity, this->fogDensity, this->fogDensity)); 134 } 157 135 } 158 136 } 159 137 160 void SpicedAsteroidField::XMLPort(Element& xmlelement, XMLPort::Mode mode) 161 { 162 // SUPER(SpicedAsteroidField, XMLPort, xmlelement, mode);163 // XMLPortParam(PickupSpawner, "pickup", setPickupTemplateName, getPickupTemplateName, xmlelement, mode); 138 void SpicedAsteroidField::XMLPort(Element& xmlelement, XMLPort::Mode mode){ 139 140 SUPER(SpicedAsteroidField, XMLPort, xmlelement, mode); 141 164 142 XMLPortParam(SpicedAsteroidField, "count", setCount, getCount, xmlelement, mode); 165 143 XMLPortParam(SpicedAsteroidField, "mDensity", setMineralDensity, getMineralDensity, xmlelement, mode); … … 174 152 175 153 154 void SpicedAsteroidField::XMLEventPort(Element& xmlelement, XMLPort::Mode mode){ 176 155 177 178 void SpicedAsteroidField::XMLEventPort(Element& xmlelement, XMLPort::Mode mode)179 {180 // SUPER(SpicedAsteroidField, XMLEventPort, xmlelement, mode);181 182 XMLPortEventState(SpicedAsteroidField, BaseObject, "vulnerability", setVulnerable, xmlelement, mode);183 156 } 184 157 185 void SpicedAsteroidField::registerVariables() 186 { 158 void SpicedAsteroidField::registerVariables(){ 187 159 188 160 registerVariable(this->count, VariableDirection::ToClient); … … 195 167 registerVariable(this->fogDensity, VariableDirection::ToClient); 196 168 197 198 169 } 199 170 … … 201 172 202 173 this->create(); 203 // orxout() << "SpicedAsteroidField is done. " << endl;204 205 174 this->bAlive_ = false; 206 175 this->destroyLater(); 207 176 } 208 177 209 210 211 212 213 178 } 214 215 // --[[ fog generator216 // generates fog217 // posX, posY, posZ - position in space218 // size - size of billboard219 // brightness - [0,1] fog brightness220 // --]]221 // function generateFog(posX, posY, posZ, size, brightness)222 // print("<Billboard ")223 // print("position = \"")224 // print(posX) print(",")225 // print(posY) print(",")226 // print(posZ) print("\" ")227 // print("colour=\"")228 // print(brightness) print(",")229 // print(brightness) print(",")230 // print(brightness) print("\" ")231 // print("material=\"Smoke/Smoke\" scale=")232 // print(size)233 // print(" />")234 // end235 236 // --[[ asteroid field generator237 // generates asteroid field238 // posX, posY, posZ - position in space239 // minSize, maxSize - size boundaries of each asteroid240 // radius - size of the cube around position in space241 // count - number of asteroids242 // fog - enable fog 0/1243 // --]]244 // function asteroidField(posX, posY, posZ, minSize, maxSize, radius, count, fog)245 // for i = 1, count, 1 do246 // size = (math.random() * (maxSize - minSize)) + minSize247 // pX = (2 * math.random() * radius) - radius + posX248 // pY = (2 * math.random() * radius) - radius + posY249 // pZ = (2 * math.random() * radius) - radius + posZ250 // print("<StaticEntity ")251 252 // print("position = \"")253 // print(pX) print(",")254 // print(pY) print(",")255 // print(pZ) print("\" ")256 257 // print("scale = \"") print(size) print("\" ")258 259 // print("collisionType = static linearDamping = 0.8 angularDamping = 1 ")260 // print("collisiondamage = 1000 enablecollisiondamage = true>")261 262 // print("<attached>")263 // print("<Model mass=\"") print(size * 10) print("\" ")264 // print("mesh=\"ast") print(math.mod(i,6) + 1) print(".mesh\" />")265 // print("</attached>")266 267 // print("<collisionShapes> ")268 // print("<SphereCollisionShape radius=\"")269 // print(size * 2.5) print("\" />")270 // print("</collisionShapes>")271 272 // print("</StaticEntity>")273 274 // if fog == 1 and i % 5 == 0 then275 // generateFog(pX, pY, pZ, radius*0.04, 0.2)276 // end277 // end278 // end279 280 281 // --[[ asteroid belt generator282 // generates asteroid belt283 // posX, posY, posZ - position in space284 // yaw, pitch - rotation285 // minSize, maxSize - size boundaries of each asteroid286 // radius0, radius1 - inner/outer radius287 // count - number of asteroids288 // fog - enable fog 0/1289 // --]]290 // function asteroidBelt(centerX, centerY, centerZ, yaw, pitch, segments, minSize, maxSize, radius0, radius1, count, fog)291 // dPhi = (2 * math.pi) / segments292 // width = math.abs(radius1 - radius0)293 // radius = (radius1 + radius0) / 2294 // segmentCount = count / segments295 296 // print("<StaticEntity collisionType=static yaw=") print(yaw)297 // print(" pitch=") print(pitch)298 299 // print(" position = \"")300 // print(centerX) print(",")301 // print(centerY) print(",")302 // print(centerZ) print("\"")303 // print(">")304 305 // print("<attached>")306 307 // for i = 0, segments - 1, 1 do308 // asteroidField((radius * math.cos(i * dPhi)),309 // (radius * math.sin(i * dPhi)),310 // 0, minSize, maxSize, width, segmentCount, fog)311 // end312 313 // print("</attached>")314 // print("</StaticEntity>")315 // end -
code/branches/AsteroidMining_HS17/src/modules/asteroidmining/SpicedAsteroidField.h
r11640 r11664 27 27 */ 28 28 29 /** 30 31 @file SpicedAsteroidField.h 32 @brief Asteroid field with lots of parameters. Derived from asteroidField.lua 33 34 35 */ 36 29 37 #ifndef _SpicedAsteroidField_H__ 30 38 #define _SpicedAsteroidField_H__ … … 34 42 #include <string> 35 43 #include <vector> 36 #include "interfaces/PickupCarrier.h" 37 #include "interfaces/RadarViewable.h" 44 38 45 #include "worldentities/ControllableEntity.h" 39 #include "worldentities/ExplosionPart.h"40 41 46 #include "../../orxonox/worldentities/pawns/Pawn.h" 42 47 43 48 namespace orxonox // tolua_export 44 49 { 45 46 50 47 51 // tolua_export … … 51 55 public: 52 56 SpicedAsteroidField(Context* context);// This constructor is for XML access only! 57 SpicedAsteroidField(Context* c, Vector3 p, int minS, int maxS, int w, int count, bool f, float mD, float fD); 53 58 54 59 virtual ~SpicedAsteroidField(); … … 83 88 84 89 protected: 85 // Da neue Argumente reinstellen 86 //float asteroidVersion; // Bodenstrich-Konvention?,87 // Wert zwischen 1 und 6 (Spezialdinger?), die Mesh-Form 90 91 Context* context; 92 88 93 float count; 89 94 float mDensity; // Mineral density, between 0 and 1; 90 95 91 96 Vector3 position; 92 Context* context;93 97 94 98 int maxSize;
Note: See TracChangeset
for help on using the changeset viewer.