Changeset 11615 for code/branches/AsteroidMining_HS17/src/modules
- Timestamp:
- Dec 1, 2017, 8:40:42 PM (7 years ago)
- Location:
- code/branches/AsteroidMining_HS17/src/modules/asteroidmining
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/AsteroidMining_HS17/src/modules/asteroidmining/AsteroidMinable.cc
r11609 r11615 43 43 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 44 44 45 KNACKPUNKTE: 45 KNACKPUNKTE: 46 47 o Floating point exception 48 o math.pi richtig einbinden. 46 49 47 50 OFFEN: … … 87 90 o Absturz beim Asteroidengenerieren: Health war auf 0 gesetzt! Wurde nur bei der xml-Variante definiert. 88 91 o Asteroiden fressen Pickups: Argument in Pawn, Test darauf in Tick() von PickupSpawner. 92 o Man kann keine Arrays der Groesse 0 initialisieren, aber auch nicht per IF 2x definieren. 93 o i++ einfach ganz verhindern, ++i stattdessen. 94 89 95 90 96 NOTIZEN: … … 110 116 #include "core/XMLPort.h" 111 117 #include "core/EventIncludes.h" 112 #include "network/NetworkFunction.h" 118 #include "network/NetworkFunction.h" 119 #include "util/Math.h" 120 113 121 114 122 // #include "infos/PlayerInfo.h" … … 128 136 #include "../objects/collisionshapes/SphereCollisionShape.h" 129 137 #include "../../orxonox/graphics/Model.h" 138 130 139 131 140 … … 328 337 329 338 330 void AsteroidMinable::spawnChildren(){ 339 void AsteroidMinable::spawnChildren(){// Spawn smaller Children 340 331 341 332 342 if (this->size <=1){return;} // Absicherung trivialer Fall 333 343 334 // Spawn smaller Children335 344 int massRem = this->size-1; //some mass is lost 336 int num = round( (massRem-1)*(double)rand() / (double)RAND_MAX)+1; // random number of children, at least one // Tweak towards bigger junks?345 int num = round(rnd()*(massRem-1)) + 1; // random number of children, at least one 337 346 if(num > 10){num = 10;} // no max function in C! 338 339 // num = 1; // zum Testen mal nur einen generieren. 340 341 // // TODO: Check this draft for edge cases etc. 342 // // 'Triangular', discrete probability density with max at massRem/num 343 // // Max at a, value 1, subintervals a+b = c 344 // int c = massRem-num; 345 // float probDensity = [c] 346 // int a = round(massRem/num); 347 // int b = c-a; 348 // for(int z = 0; z<=a; z++){probDensity[z] = m*z/a; } // rising part 349 // for(z = a+1; z<c; z++){probDensity[z] = m - m*(z-a)/b;} // falling part 350 351 // double rand = (double)rand() / (double)RAND_MAX; // between 0 and 1 352 // double probSum = 0; 353 // int result = 0; 354 // while(rand>probSum){ 355 // probSum = probSum+probDensity[result]; 356 // result++: 357 // } 358 359 360 massRem = massRem-num; 361 362 int extra = 0; 363 364 //orxout() << "Number of Children: " << num << endl; 365 366 367 for(int fisch=num; fisch>=1; --fisch){ 368 // to distribute remaining mass 369 370 //orxout() << "AsteroidMining::spawnChildren(): Fisch-Variable: " << fisch << endl; 371 372 if(fisch==1){ 373 extra = massRem; 374 }else{ 375 extra = round(massRem*(double)rand() / (double)RAND_MAX); 376 massRem = massRem-extra; 377 378 } 379 380 //orxout() << "Mass chosen: " << extra+1 << endl; 381 382 //orxout() << "AsteroidMining::spawnChildren(): Inside for-loop." << endl; 383 384 //Spawn this child Game crashes! 385 //AsteroidMinable* child = new AsteroidMinable(this->context); 386 int newMass = extra+1; 387 AsteroidMinable* child = new AsteroidMinable(this->context, newMass, this->getPosition() + Vector3(fisch*newMass*2.5, 0, 0)); 388 // if(!(child == nullptr)){//Errorgebastel 389 390 // Position zu spaet gesetzt? Tick nicht atomar -> falsche Groesse evtl? 391 392 // child->setSize(extra + 1); 393 394 // //OFFEN:Kollision der Kinder verhindern 395 // //Relativ zu Elternteil automatisch? 396 // //Typ position:rand()*Vektoriwas? 397 // //pawn->getWorldPosition() + Vector3(30,0,-30); 398 // child->setPosition(this->getPosition() + Vector3(num*5, 0, 0)); 399 // //child->setPosition(Vector3(0,0,0)); 347 int masses[num] = {1}; // Masses of the asteroids, at least one. 348 massRem = massRem-num; 349 350 orxout() << "SpawnChildren(): passed basic stuff. num = " << num << endl; 351 352 // Randomnised spawning points for the new asteroids 353 float phi[num] = {0.0}; // assuming that it gets initialised to 0. Add (= {0.0})? 354 float theta[num] = {0.0}; 355 float pi = 3.14159;//math.pi; 356 357 float d_p = 2*pi/num; 358 float d_t = pi/num; 359 float p = d_p/2; 360 float t = d_t/2; 361 // float phiOffset = rnd()*2*pi; // Added everywhere to become independent of the coordinate system 362 // float thetaOffset = rnd()*pi; 363 float rScaling = tan(t); // scale radius to prevent asteroids from touching. (distance=AsteroidRadius/tan(sector/2)) 364 365 int pos; 366 for(int it = 0; it<num; ++it){ 367 orxout() << "SpawnChildren(): Entering For. " << endl; 368 369 pos = mod((int)(rnd()*num),num); 370 orxout() << "SpawnChildren(): Trying position: " << pos << endl; 371 372 while(phi[pos] != 0.0){// find empty spot in array 373 pos = (int)mod(++pos, num); 374 orxout() << "SpawnChildren(): Inside, testing position: " << pos << endl; 375 } 376 phi[pos] = p + it*d_p;// set angle there 377 378 pos = mod((int)(rnd()*num),num); 379 while(theta[pos] != 0.0){ 380 pos = (int)mod(++pos, num); 381 } 382 theta[pos] = t + it*d_t; 383 } 384 385 orxout() << "SpawnChildren(): passed angle stuff. " << endl; 386 387 // 'Triangular', discrete probability density with max at the expected value massRem/num at a. a+b = c 388 if(massRem>0){ // Required to avoid array of size 0 or access problems 389 int c = massRem; 390 float probDensity[c] = {0.0}; 391 392 int a = round(massRem/num); 393 int b = c-a; 394 int m = 2/c; // Peak value, is reached at the average size. 395 int z = 0; 396 for(z = 0; z<=a; ++z){probDensity[z] = m*z/a; } // rising part 397 for(z = a+1; z<c; ++z){probDensity[z] = m - m*(z-a)/b;} // falling part 398 399 // Distributing the mass 400 for(int trav = 0; trav<num && massRem>0; ++trav){ 401 402 int result = 0; 403 float rVal = rnd();// between 0 and 1 404 float probSum = probDensity[0]; 405 while(rVal>probSum){ 406 probSum = probSum+probDensity[result+1]; 407 ++result; 408 } 409 if(result>massRem){result = massRem;} 410 411 massRem = massRem-result; 412 masses[trav] = masses[trav]+result; 413 414 } 415 } 416 417 orxout() << "SpawnChildren(): passed Mass stuff. " << endl; 418 419 for(int fisch = 0; fisch<num; ++fisch){// create the children 420 421 // Position offset: 422 float r = masses[fisch]/rScaling; 423 Vector3* pos = new Vector3(r*sin(theta[fisch])*cos(phi[fisch]), r*sin(theta[fisch])*sin(phi[fisch]), r*cos(theta[fisch])); 424 425 AsteroidMinable* child = new AsteroidMinable(this->context, masses[fisch], this->getPosition() + *pos); 400 426 401 427 if(child == nullptr){ … … 403 429 } 404 430 405 406 407 //orxout() << "Done: Creating new Asteroid" << endl; 408 409 // } 410 411 412 // Pawn* pawn = this->carrierToPawnHelper(); 413 // if(pawn == nullptr) // If the PickupCarrier is no Pawn, then this pickup is useless and therefore is destroyed. 414 // this->Pickupable::destroy(); 415 416 // //Attach to pawn 417 // Drone* drone = new Drone(pawn->getContext()); // this is neccessary because the projectiles fired need a valid creator for the particlespawner (when colliding against something) 418 // drone->addTemplate(this->getDroneTemplate()); 419 420 421 } 422 // orxout() << "Leaving spawnChildren() method. " << endl; 431 } 432 orxout() << "Leaving spawnChildren() method. " << endl; 423 433 } 424 434 -
code/branches/AsteroidMining_HS17/src/modules/asteroidmining/SpicedAsteroidField.cc
r11610 r11615 42 42 43 43 #include "SpicedAsteroidField.h" 44 #include "AsteroidMinable.h" 44 45 45 46 #include <algorithm> … … 50 51 #include "core/EventIncludes.h" 51 52 #include "network/NetworkFunction.h" 53 #include "util/Math.h" 52 54 53 55 // #include "infos/PlayerInfo.h" … … 61 63 // #include "controllers/FormationController.h" 62 64 63 #include "../pickup/items/HealthPickup.h" 64 #include "../pickup/PickupSpawner.h" 65 #include "../pickup/Pickup.h" 65 66 66 //#include "../pickup/pickup ..... pickupable 67 67 #include "../objects/collisionshapes/SphereCollisionShape.h" … … 110 110 SUPER(SpicedAsteroidField, XMLPort, xmlelement, mode); 111 111 // XMLPortParam(PickupSpawner, "pickup", setPickupTemplateName, getPickupTemplateName, xmlelement, mode); 112 XMLPortParam(SpicedAsteroidField, "size", setSize, getSize, xmlelement, mode); 112 XMLPortParam(SpicedAsteroidField, "count", setCount, getCount, xmlelement, mode); 113 XMLPortParam(SpicedAsteroidField, "mDensity", setMineralDensity, getMineralDensity, xmlelement, mode); 114 XMLPortParam(SpicedAsteroidField, "position", setPosition, getPosition, xmlelement, mode); 115 XMLPortParam(SpicedAsteroidField, "maxSize", setMaxSize, getMaxSize, xmlelement, mode); 116 XMLPortParam(SpicedAsteroidField, "minSize", setMinSize, getMinSize, xmlelement, mode); 117 XMLPortParam(SpicedAsteroidField, "radius", setRadius, getRadius, xmlelement, mode); 118 XMLPortParam(SpicedAsteroidField, "foggy", setFog, isFoggy, xmlelement, mode); 119 113 120 114 121 } 122 123 124 115 125 116 126 void SpicedAsteroidField::XMLEventPort(Element& xmlelement, XMLPort::Mode mode) … … 151 161 } 152 162 153 void SpicedAsteroidField::setSize(float s){154 this->size = s;155 }156 163 157 float SpicedAsteroidField::getSize(){158 return this->size;159 }160 164 161 165 -
code/branches/AsteroidMining_HS17/src/modules/asteroidmining/SpicedAsteroidField.h
r11610 r11615 58 58 59 59 60 inline void setCount(float s){this->count = s;} 61 inline float getCount(){return this->count;} 60 62 61 virtual void setSize(float f);62 virtual float getSize();63 inline void setMineralDensity(float d){this->mDensity = d;} 64 inline float getMineralDensity(){return this->mDensity;} 63 65 66 inline void setPosition(Vector3 v){this->position = v;} 67 inline Vector3 getPosition(){returrn this->position;} 68 69 inline void setMaxSize(int i){this->maxSize = i;} 70 inline int getMaxSize(){return this->maxSize;} 71 72 inline void setMinSize(int i){this->minSize = i;} 73 inline int getMinSize(){return this->minSize;} 74 75 inline void setRadius(float r){this->radius = r;} 76 inline int getRadius(){return this->radius;} 77 78 inline void setFog(bool f){this->foggy = f;} 79 inline bool isFoggy(){return this->foggy;} 64 80 65 81 protected: … … 67 83 //float asteroidVersion; // Bodenstrich-Konvention?, 68 84 // Wert zwischen 1 und 6 (Spezialdinger?), die Mesh-Form 69 float size; 70 bool generateSmaller; 85 float count; 86 float mDensity; // Mineral density, between 0 and 1; 87 88 Vector3 position; 71 89 bool initialised; 90 Context* context; 91 int maxSize; 92 int minSize; 72 93 73 Context* context; 94 float radius; 95 bool foggy; 74 96 75 97 virtual void create();
Note: See TracChangeset
for help on using the changeset viewer.