[Orxonox-commit 6994] r11615 - code/branches/AsteroidMining_HS17/src/modules/asteroidmining
remartin at orxonox.net
remartin at orxonox.net
Fri Dec 1 20:40:43 CET 2017
Author: remartin
Date: 2017-12-01 20:40:42 +0100 (Fri, 01 Dec 2017)
New Revision: 11615
Modified:
code/branches/AsteroidMining_HS17/src/modules/asteroidmining/AsteroidMinable.cc
code/branches/AsteroidMining_HS17/src/modules/asteroidmining/SpicedAsteroidField.cc
code/branches/AsteroidMining_HS17/src/modules/asteroidmining/SpicedAsteroidField.h
Log:
Gebastel in spawnChildren, hat immer noch Fehler drin.
Modified: code/branches/AsteroidMining_HS17/src/modules/asteroidmining/AsteroidMinable.cc
===================================================================
--- code/branches/AsteroidMining_HS17/src/modules/asteroidmining/AsteroidMinable.cc 2017-12-01 17:38:00 UTC (rev 11614)
+++ code/branches/AsteroidMining_HS17/src/modules/asteroidmining/AsteroidMinable.cc 2017-12-01 19:40:42 UTC (rev 11615)
@@ -42,8 +42,11 @@
Veraenderungstagebuch
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
-KNACKPUNKTE:
+KNACKPUNKTE:
+o Floating point exception
+o math.pi richtig einbinden.
+
OFFEN:
o Add custom pickup 'resources'. Weird template stuff -> Problems setting 'size' and other properties? setNumber of Resources.
--> PickupTemplateName_ in PickupSpawner ist ein string. Wird via getBaseClassIdentifier ausgelesen, daraus wird ein Pickupable fabriziert.
@@ -86,7 +89,10 @@
o Groessenabhaengige Collison shape: Umweg ueber zweiten Konstruktor.
o Absturz beim Asteroidengenerieren: Health war auf 0 gesetzt! Wurde nur bei der xml-Variante definiert.
o Asteroiden fressen Pickups: Argument in Pawn, Test darauf in Tick() von PickupSpawner.
+o Man kann keine Arrays der Groesse 0 initialisieren, aber auch nicht per IF 2x definieren.
+o i++ einfach ganz verhindern, ++i stattdessen.
+
NOTIZEN:
o SUPER entspricht ueberladen, andere Argumente der Methode.
o Warnungsverhinderung anderswo: (void)pickedUp; // To avoid compiler warning.
@@ -109,8 +115,10 @@
#include "core/GameMode.h"
#include "core/XMLPort.h"
#include "core/EventIncludes.h"
-#include "network/NetworkFunction.h"
+#include "network/NetworkFunction.h"
+#include "util/Math.h"
+
// #include "infos/PlayerInfo.h"
// #include "controllers/Controller.h"
// #include "gametypes/Gametype.h"
@@ -133,6 +141,7 @@
+
namespace orxonox
{
RegisterClass(AsteroidMinable);
@@ -327,99 +336,100 @@
}
-void AsteroidMinable::spawnChildren(){
+void AsteroidMinable::spawnChildren(){// Spawn smaller Children
+
if (this->size <=1){return;} // Absicherung trivialer Fall
- // Spawn smaller Children
int massRem = this->size-1; //some mass is lost
- int num = round((massRem-1)*(double)rand() / (double)RAND_MAX)+1; // random number of children, at least one // Tweak towards bigger junks?
+ int num = round(rnd()*(massRem-1)) + 1; // random number of children, at least one
if(num > 10){num = 10;} // no max function in C!
+ int masses[num] = {1}; // Masses of the asteroids, at least one.
+ massRem = massRem-num;
- // num = 1; // zum Testen mal nur einen generieren.
+ orxout() << "SpawnChildren(): passed basic stuff. num = " << num << endl;
- // // TODO: Check this draft for edge cases etc.
- // // 'Triangular', discrete probability density with max at massRem/num
- // // Max at a, value 1, subintervals a+b = c
- // int c = massRem-num;
- // float probDensity = [c]
- // int a = round(massRem/num);
- // int b = c-a;
- // for(int z = 0; z<=a; z++){probDensity[z] = m*z/a; } // rising part
- // for(z = a+1; z<c; z++){probDensity[z] = m - m*(z-a)/b;} // falling part
+ // Randomnised spawning points for the new asteroids
+ float phi[num] = {0.0}; // assuming that it gets initialised to 0. Add (= {0.0})?
+ float theta[num] = {0.0};
+ float pi = 3.14159;//math.pi;
- // double rand = (double)rand() / (double)RAND_MAX; // between 0 and 1
- // double probSum = 0;
- // int result = 0;
- // while(rand>probSum){
- // probSum = probSum+probDensity[result];
- // result++:
- // }
+ float d_p = 2*pi/num;
+ float d_t = pi/num;
+ float p = d_p/2;
+ float t = d_t/2;
+ // float phiOffset = rnd()*2*pi; // Added everywhere to become independent of the coordinate system
+ // float thetaOffset = rnd()*pi;
+ float rScaling = tan(t); // scale radius to prevent asteroids from touching. (distance=AsteroidRadius/tan(sector/2))
+ int pos;
+ for(int it = 0; it<num; ++it){
+ orxout() << "SpawnChildren(): Entering For. " << endl;
- massRem = massRem-num;
+ pos = mod((int)(rnd()*num),num);
+ orxout() << "SpawnChildren(): Trying position: " << pos << endl;
- int extra = 0;
+ while(phi[pos] != 0.0){// find empty spot in array
+ pos = (int)mod(++pos, num);
+ orxout() << "SpawnChildren(): Inside, testing position: " << pos << endl;
+ }
+ phi[pos] = p + it*d_p;// set angle there
- //orxout() << "Number of Children: " << num << endl;
+ pos = mod((int)(rnd()*num),num);
+ while(theta[pos] != 0.0){
+ pos = (int)mod(++pos, num);
+ }
+ theta[pos] = t + it*d_t;
+ }
+ orxout() << "SpawnChildren(): passed angle stuff. " << endl;
- for(int fisch=num; fisch>=1; --fisch){
- // to distribute remaining mass
+ // 'Triangular', discrete probability density with max at the expected value massRem/num at a. a+b = c
+ if(massRem>0){ // Required to avoid array of size 0 or access problems
+ int c = massRem;
+ float probDensity[c] = {0.0};
- //orxout() << "AsteroidMining::spawnChildren(): Fisch-Variable: " << fisch << endl;
+ int a = round(massRem/num);
+ int b = c-a;
+ int m = 2/c; // Peak value, is reached at the average size.
+ int z = 0;
+ for(z = 0; z<=a; ++z){probDensity[z] = m*z/a; } // rising part
+ for(z = a+1; z<c; ++z){probDensity[z] = m - m*(z-a)/b;} // falling part
+
+ // Distributing the mass
+ for(int trav = 0; trav<num && massRem>0; ++trav){
- if(fisch==1){
- extra = massRem;
- }else{
- extra = round(massRem*(double)rand() / (double)RAND_MAX);
- massRem = massRem-extra;
+ int result = 0;
+ float rVal = rnd();// between 0 and 1
+ float probSum = probDensity[0];
+ while(rVal>probSum){
+ probSum = probSum+probDensity[result+1];
+ ++result;
+ }
+ if(result>massRem){result = massRem;}
+ massRem = massRem-result;
+ masses[trav] = masses[trav]+result;
+
}
+ }
+
+ orxout() << "SpawnChildren(): passed Mass stuff. " << endl;
- //orxout() << "Mass chosen: " << extra+1 << endl;
+ for(int fisch = 0; fisch<num; ++fisch){// create the children
- //orxout() << "AsteroidMining::spawnChildren(): Inside for-loop." << endl;
+ // Position offset:
+ float r = masses[fisch]/rScaling;
+ Vector3* pos = new Vector3(r*sin(theta[fisch])*cos(phi[fisch]), r*sin(theta[fisch])*sin(phi[fisch]), r*cos(theta[fisch]));
- //Spawn this child Game crashes!
- //AsteroidMinable* child = new AsteroidMinable(this->context);
- int newMass = extra+1;
- AsteroidMinable* child = new AsteroidMinable(this->context, newMass, this->getPosition() + Vector3(fisch*newMass*2.5, 0, 0));
- // if(!(child == nullptr)){//Errorgebastel
+ AsteroidMinable* child = new AsteroidMinable(this->context, masses[fisch], this->getPosition() + *pos);
- // Position zu spaet gesetzt? Tick nicht atomar -> falsche Groesse evtl?
-
- // child->setSize(extra + 1);
-
- // //OFFEN:Kollision der Kinder verhindern
- // //Relativ zu Elternteil automatisch?
- // //Typ position:rand()*Vektoriwas?
- // //pawn->getWorldPosition() + Vector3(30,0,-30);
- // child->setPosition(this->getPosition() + Vector3(num*5, 0, 0));
- // //child->setPosition(Vector3(0,0,0));
-
if(child == nullptr){
orxout(internal_error, context::pickups) << "Weird, can't create new AsteroidMinable." << endl;
}
-
-
- //orxout() << "Done: Creating new Asteroid" << endl;
-
- // }
-
-
- // Pawn* pawn = this->carrierToPawnHelper();
- // if(pawn == nullptr) // If the PickupCarrier is no Pawn, then this pickup is useless and therefore is destroyed.
- // this->Pickupable::destroy();
-
- // //Attach to pawn
- // Drone* drone = new Drone(pawn->getContext()); // this is neccessary because the projectiles fired need a valid creator for the particlespawner (when colliding against something)
- // drone->addTemplate(this->getDroneTemplate());
-
-
}
- // orxout() << "Leaving spawnChildren() method. " << endl;
+ orxout() << "Leaving spawnChildren() method. " << endl;
}
Modified: code/branches/AsteroidMining_HS17/src/modules/asteroidmining/SpicedAsteroidField.cc
===================================================================
--- code/branches/AsteroidMining_HS17/src/modules/asteroidmining/SpicedAsteroidField.cc 2017-12-01 17:38:00 UTC (rev 11614)
+++ code/branches/AsteroidMining_HS17/src/modules/asteroidmining/SpicedAsteroidField.cc 2017-12-01 19:40:42 UTC (rev 11615)
@@ -41,6 +41,7 @@
#include "../../orxonox/worldentities/WorldEntity.h"
#include "SpicedAsteroidField.h"
+#include "AsteroidMinable.h"
#include <algorithm>
@@ -49,6 +50,7 @@
#include "core/XMLPort.h"
#include "core/EventIncludes.h"
#include "network/NetworkFunction.h"
+#include "util/Math.h"
// #include "infos/PlayerInfo.h"
// #include "controllers/Controller.h"
@@ -60,9 +62,7 @@
// #include "core/object/ObjectListIterator.h"
// #include "controllers/FormationController.h"
-#include "../pickup/items/HealthPickup.h"
-#include "../pickup/PickupSpawner.h"
-#include "../pickup/Pickup.h"
+
//#include "../pickup/pickup ..... pickupable
#include "../objects/collisionshapes/SphereCollisionShape.h"
#include "../../orxonox/graphics/Model.h"
@@ -109,10 +109,20 @@
{
SUPER(SpicedAsteroidField, XMLPort, xmlelement, mode);
// XMLPortParam(PickupSpawner, "pickup", setPickupTemplateName, getPickupTemplateName, xmlelement, mode);
- XMLPortParam(SpicedAsteroidField, "size", setSize, getSize, xmlelement, mode);
+ XMLPortParam(SpicedAsteroidField, "count", setCount, getCount, xmlelement, mode);
+ XMLPortParam(SpicedAsteroidField, "mDensity", setMineralDensity, getMineralDensity, xmlelement, mode);
+ XMLPortParam(SpicedAsteroidField, "position", setPosition, getPosition, xmlelement, mode);
+ XMLPortParam(SpicedAsteroidField, "maxSize", setMaxSize, getMaxSize, xmlelement, mode);
+ XMLPortParam(SpicedAsteroidField, "minSize", setMinSize, getMinSize, xmlelement, mode);
+ XMLPortParam(SpicedAsteroidField, "radius", setRadius, getRadius, xmlelement, mode);
+ XMLPortParam(SpicedAsteroidField, "foggy", setFog, isFoggy, xmlelement, mode);
+
}
+
+
+
void SpicedAsteroidField::XMLEventPort(Element& xmlelement, XMLPort::Mode mode)
{
SUPER(SpicedAsteroidField, XMLEventPort, xmlelement, mode);
@@ -150,13 +160,7 @@
}
- void SpicedAsteroidField::setSize(float s){
- this->size = s;
- }
- float SpicedAsteroidField::getSize(){
- return this->size;
- }
Modified: code/branches/AsteroidMining_HS17/src/modules/asteroidmining/SpicedAsteroidField.h
===================================================================
--- code/branches/AsteroidMining_HS17/src/modules/asteroidmining/SpicedAsteroidField.h 2017-12-01 17:38:00 UTC (rev 11614)
+++ code/branches/AsteroidMining_HS17/src/modules/asteroidmining/SpicedAsteroidField.h 2017-12-01 19:40:42 UTC (rev 11615)
@@ -57,21 +57,43 @@
virtual void tick(float dt) override;
+ inline void setCount(float s){this->count = s;}
+ inline float getCount(){return this->count;}
- virtual void setSize(float f);
- virtual float getSize();
+ inline void setMineralDensity(float d){this->mDensity = d;}
+ inline float getMineralDensity(){return this->mDensity;}
+ inline void setPosition(Vector3 v){this->position = v;}
+ inline Vector3 getPosition(){returrn this->position;}
+ inline void setMaxSize(int i){this->maxSize = i;}
+ inline int getMaxSize(){return this->maxSize;}
+
+ inline void setMinSize(int i){this->minSize = i;}
+ inline int getMinSize(){return this->minSize;}
+
+ inline void setRadius(float r){this->radius = r;}
+ inline int getRadius(){return this->radius;}
+
+ inline void setFog(bool f){this->foggy = f;}
+ inline bool isFoggy(){return this->foggy;}
+
protected:
// Da neue Argumente reinstellen
//float asteroidVersion; // Bodenstrich-Konvention?,
// Wert zwischen 1 und 6 (Spezialdinger?), die Mesh-Form
- float size;
- bool generateSmaller;
+ float count;
+ float mDensity; // Mineral density, between 0 and 1;
+
+ Vector3 position;
bool initialised;
-
Context* context;
+ int maxSize;
+ int minSize;
+ float radius;
+ bool foggy;
+
virtual void create();
More information about the Orxonox-commit
mailing list