Changeset 11618 for code/branches/AsteroidMining_HS17
- Timestamp:
- Dec 3, 2017, 7:32:18 PM (7 years ago)
- Location:
- code/branches/AsteroidMining_HS17/src/modules/asteroidmining
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/AsteroidMining_HS17/src/modules/asteroidmining/AsteroidMinable.cc
r11615 r11618 43 43 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 44 44 45 FRAGEN: 46 * Zeilen-Loeschung beim output 47 * orxout()-Problem 48 * dokumentieren mit @brief? 49 * Warnumg aus Asteroidenzerstoerung 50 51 45 52 KNACKPUNKTE: 46 53 47 o Floating point exception48 o math.pi richtig einbinden.49 54 50 55 OFFEN: 56 57 o Mass distribution -> weird for bigger asteroids 58 --> more testing 59 60 o SpicedAsteroidField fertigstellen, Mineraldichten-Parameter 61 51 62 o Add custom pickup 'resources'. Weird template stuff -> Problems setting 'size' and other properties? setNumber of Resources. 52 63 --> PickupTemplateName_ in PickupSpawner ist ein string. Wird via getBaseClassIdentifier ausgelesen, daraus wird ein Pickupable fabriziert. … … 55 66 --> data_extern/images/effects: PNG's für die Pickups und GUI-Dinger. 56 67 68 o inherit parent velocity 69 o set collisionDamage? Just for static entities? 70 o Dokumentieren mit @brief? 71 57 72 o Explosion parts 58 73 o custom HUD 59 o asteroidField.lua anpassen, mit 'Mineraliendichten-Parameter'.60 61 o Dokumentieren mit @brief?62 63 o replace ugly random stuff with math.rnd()64 o set collisionDamage? Just for static entities?65 74 66 75 HANDBUCH: … … 92 101 o Man kann keine Arrays der Groesse 0 initialisieren, aber auch nicht per IF 2x definieren. 93 102 o i++ einfach ganz verhindern, ++i stattdessen. 103 o Discusting mixup with array length, accessing element a[len]... 104 o unitialised mass value -> obese asteroid, physics bug. 94 105 95 106 … … 163 174 this->registerVariables(); 164 175 165 orxout() << "AsteroidMining:: Pseudo-Konstruktor passiert!" << endl;176 //orxout() << "AsteroidMining:: Pseudo-Konstruktor passiert!" << endl; 166 177 167 178 } … … 181 192 // Default Values 182 193 this->generateSmaller = true; 183 //this->setHealth(50);184 194 this->context = c; 185 this->size = size; // customSize186 this->health_ = 15*size; // capped at 200 in pawn or smth?195 this->size = size; 196 this->health_ = 15*size; 187 197 this->maxHealth_ = this->health_; 188 198 this->acceptsPickups_ = false; … … 190 200 this->setPosition(position); 191 201 //this->roll = rand()*5; //etwas Drehung. richtige Variable 192 193 // // Fliegt davon, irgendwieso. Dies scheint auch nicht zu nuetzen.194 // this->setVelocity(Vector3(0,0,0));195 196 202 197 203 … … 200 206 // random one of the 6 shapes 201 207 char meshThingy[] = ""; 202 sprintf(meshThingy, "ast%.0f.mesh", (round((5*(double)rand()/(double)RAND_MAX))+1)); // sprintf(str, "Value of Pi = %f", M_PI);208 sprintf(meshThingy, "ast%.0f.mesh", round(5*rnd())+1); // sprintf(str, "Value of Pi = %f", M_PI); 203 209 hull->setMeshSource(meshThingy); 204 210 hull->setScale(this->size); … … 215 221 this->initialised=true; 216 222 217 orxout() << "AsteroidMining:: Initialisierung Zweitkonstruktor abgeschlosssssen." << endl;223 //orxout() << "AsteroidMining:: Initialisierung Zweitkonstruktor abgeschlosssssen." << endl; 218 224 219 225 } … … 228 234 AsteroidMinable* reborn = new AsteroidMinable(this->context, this->size, this->getPosition()); 229 235 reborn->toggleShattering(true); // mainly here to avoid 'unused' warning. 230 this->~AsteroidMinable(); // seems dangerous .Necessary for efficiency?236 this->~AsteroidMinable(); // seems dangerous, yields warning. Necessary for efficiency? 231 237 232 238 } … … 249 255 void AsteroidMinable::registerVariables() 250 256 { 251 // registerVariable(this->bAlive_, VariableDirection::ToClient);252 // registerVariable(this->bVulnerable_, VariableDirection::ToClient);253 // registerVariable(this->health_, VariableDirection::ToClient);254 // registerVariable(this->maxHealth_, VariableDirection::ToClient);255 257 256 258 registerVariable(this->size, VariableDirection::ToClient); … … 258 260 259 261 registerVariable(this->initialised, VariableDirection::ToClient); 260 //registerVariable(this->context, VariableDirection::ToClient); // can't link that since it's a context261 262 262 263 263 // float size; … … 270 270 void AsteroidMinable::tick(float dt) 271 271 { 272 if(!(this->initialised)){this->putStuff();} 272 if(!(this->initialised)){this->putStuff();} 273 273 274 274 if(this->health_ <=0){this->death();} 275 276 // if(this->initialised){277 // // this->setVelocity(Vector3(0,0,0)); // Funktioniert, scheint aber unsinnig.278 // orxout() << "Flying at speed: " << this->getVelocity() << endl;279 // }280 275 281 276 } … … 328 323 329 324 // Smaller Parts = 'Children' 330 if(this->generateSmaller){ 331 this->spawnChildren(); 332 } 325 if(this->generateSmaller){this->spawnChildren();} 333 326 334 327 // orxout() << "Wieder retour in death() geschafft. " << endl; … … 345 338 int num = round(rnd()*(massRem-1)) + 1; // random number of children, at least one 346 339 if(num > 10){num = 10;} // no max function in C! 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;340 int masses[num]; // Masses of the asteroids, at least one. 341 orxout() << "SpawnChildren(): Passed basic stuff. num = " << num << "; massRem(total) = "<< massRem << endl; 342 343 massRem = massRem-num; // mass is at least one, add again below. 351 344 352 345 // Randomnised spawning points for the new asteroids 353 346 float phi[num] = {0.0}; // assuming that it gets initialised to 0. Add (= {0.0})? 354 347 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 348 float piG = pi; // ist statisch oder so. 349 350 float d_p = 2*piG/num; 351 float d_t = piG/num; 352 float p = d_p/2.0; 353 float t = d_t/2.0; 354 // float phiOffset = rnd()*2*pi; // Added everywhere to become independent of the coordinate system? 362 355 // 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; 356 float rScaling; // scale radius to prevent asteroids from touching. (distance=AsteroidRadius/tan(sector/2)) 357 if(num == 1 ){ 358 rScaling = 1; // avoid tan(90). Unused. 359 }else{ 360 361 rScaling = tan(t); 362 363 int pos; // insert at random position (linear probing) in array, to get some randomness. 364 for(int it = 0; it<num; ++it){ 365 366 pos = mod((int)(rnd()*num),num); 367 while(phi[pos] != 0.0){// find empty spot in array 368 pos = (int)mod(++pos, num); 369 } 370 phi[pos] = p + it*d_p;// set angle there 371 372 pos = mod((int)(rnd()*num),num); 373 while(theta[pos] != 0.0){ 374 pos = (int)mod(++pos, num); 375 } 376 theta[pos] = t + it*d_t; 377 } 378 } 379 380 //orxout() << "SpawnChildren(): Phi: "; printArrayString(phi); 381 //orxout() << "SpawnChildren(): Theta: "; printArrayString(theta); 382 orxout() << "SpawnChildren(): Passed angle stuff. " << endl; 386 383 387 384 // 'Triangular', discrete probability density with max at the expected value massRem/num at a. a+b = c … … 392 389 int a = round(massRem/num); 393 390 int b = c-a; 394 int m = 2/c; // Peak value, is reached at the average size.391 395 392 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 393 float dProbA = 1.0/(a*a + 3.0*a + 2.0); // one 'probability unit' for discrete ramp function. Gauss stuff. 394 for(z = 0; z<=a; ++z){probDensity[z] = (z+1)*dProbA; } // rising part 395 396 float dProbB = 1.0/(b*b +3.0*b + 2.0); 397 for(z = 0; z<b; ++z){probDensity[c-z] = (z+1)*dProbB;} // falling part 398 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]; 399 // Testing 400 for(int globi = 0; globi<c; ++globi){ 401 orxout() << "pDensity at [" << globi << "] is: " << probDensity[globi] << endl; 402 } 403 404 // Distributing the mass to individual asteroids 405 int result; 406 float rVal;// between 0 and 1 407 float probSum; 408 for(int trav = 0; trav<num; ++trav){ 409 result = 0;// reset 410 rVal = rnd();// between 0 and 1 411 orxout() << "Random Value picked: " << rVal << endl; 412 probSum = probDensity[0]; 413 //orxout() << "Sum at start: " << probSum << endl; 414 415 while(rVal>probSum && result<massRem){// Not yet found && there-s smth to distribute (Incrementing once inside!) 416 if(result<(num-2)){probSum = probSum+probDensity[result+1];} // avoid logical/acess error 407 417 ++result; 418 //orxout() << "Sum so far: " << probSum << endl; 408 419 } 409 if(result>massRem){result = massRem;}410 420 411 421 massRem = massRem-result; 412 masses[trav] = masses[trav]+result; 413 414 } 415 } 422 masses[trav] = 1 +result; // at least one 423 orxout() << "Mass chosen for child " << trav << " is: " << masses[trav] << endl; 424 425 } 426 }else{// Everyone has mass 1. Initialising the array to 1 doesn-t seem to work. Hideous C language! 427 for(int schnaegg = 0; schnaegg<num; ++schnaegg){ 428 masses[schnaegg] = 1; 429 } 430 } 431 432 //orxout() << "SpawnChildren(): Masses: "; printArrayString(masses); 433 orxout() << "SpawnChildren(): Passed mass stuff. " << endl; 434 435 // Creating the 'chlidren': 436 for(int fisch = 0; fisch<num; ++fisch){ 437 438 Vector3* pos = new Vector3(0,0,0); // Position offset 439 if(num > 1){// not required if there-s just one child 440 float r = masses[fisch]/rScaling; 441 pos = new Vector3(r*sin(theta[fisch])*cos(phi[fisch]), r*sin(theta[fisch])*sin(phi[fisch]), r*cos(theta[fisch])); // convert spheric coordinates to vector 442 } 416 443 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 444 //orxout() << "Creating asteroid with mass " << masses[fisch] << " at relative postition " << *pos << endl; 425 445 AsteroidMinable* child = new AsteroidMinable(this->context, masses[fisch], this->getPosition() + *pos); 426 446 … … 476 496 } 477 497 478 479 498 void AsteroidMinable::printArrayString(float thingy[]){ // Don-t work! 499 500 orxout() << "[" ; //<< endl; 501 char frag[] = ""; 502 int len = (int)(sizeof(thingy)/sizeof(thingy[0])); 503 for(int m = 0; m< (len-2); ++m){ 504 sprintf(frag, "%.5f, ", thingy[m]); 505 orxout() << frag << endl;//std::flush; 506 } 507 sprintf(frag, "%.5f]", thingy[len-1]); 508 orxout() << frag << endl; // Just print it here! No ugly passing. 509 } 510 511 void AsteroidMinable::printArrayString(int thingy[]){ 512 513 orxout() << "[" ; //<< endl; 514 char frag[] = ""; 515 int len = (int)(sizeof(thingy)/sizeof(thingy[0])); 516 for(int m = 0; m< (len-2); ++m){ 517 sprintf(frag, "%.0i, ", thingy[m]); 518 orxout() << frag << endl;//std::flush; 519 printf("TEst"); 520 } 521 522 sprintf(frag, "%.0i]", thingy[len-1]); // last element 523 orxout() << frag << endl; // Just print it here! No ugly passing. 524 } 525 526 527 // void AsteroidMinable::printArrayString(int thingy[]){ 528 529 // char res[] = "["; 530 // //strcat(res, "["); 531 // char frag[] = ""; 532 533 // int len = (int)(sizeof(thingy)/sizeof(thingy[0])); 534 // for(int m = 0; m< (len-1); ++m){ 535 // sprintf(frag, "%.0i, ", thingy[m]); 536 // strcat(res, frag); 537 // } 538 // sprintf(frag, "%.0i]", thingy[len]); 539 // strcat(res, frag); // last element 540 541 // orxout() << res << endl; // Just print it here! No ugly passing. 542 543 // // static char result[(sizeof(res)/sizeof("")] = res; // define as static, would get deleted otherwise. 544 // // char *result = malloc(sizeof(res)/sizeof("") + 1); 545 // // *result = res; 546 // // return result; 547 // } 480 548 481 549 -
code/branches/AsteroidMining_HS17/src/modules/asteroidmining/AsteroidMinable.h
r11586 r11618 92 92 virtual void spawnChildren(); 93 93 94 void printArrayString(float thingy[]);// Just for testing 95 void printArrayString(int thingy[]);// Just for testing 96 97 98 94 99 95 100
Note: See TracChangeset
for help on using the changeset viewer.