[Orxonox-commit 7048] r11667 - in code/branches/AsteroidMining_HS17: data/levels src/modules/asteroidmining
remartin at orxonox.net
remartin at orxonox.net
Tue Dec 12 20:29:53 CET 2017
Author: remartin
Date: 2017-12-12 20:29:52 +0100 (Tue, 12 Dec 2017)
New Revision: 11667
Modified:
code/branches/AsteroidMining_HS17/data/levels/AsteroidFarming.oxw
code/branches/AsteroidMining_HS17/src/modules/asteroidmining/AsteroidMinable.cc
code/branches/AsteroidMining_HS17/src/modules/asteroidmining/AsteroidMinable.h
code/branches/AsteroidMining_HS17/src/modules/asteroidmining/SpicedAsteroidBelt.cc
code/branches/AsteroidMining_HS17/src/modules/asteroidmining/SpicedAsteroidBelt.h
code/branches/AsteroidMining_HS17/src/modules/asteroidmining/SpicedAsteroidField.cc
code/branches/AsteroidMining_HS17/src/modules/asteroidmining/SpicedAsteroidField.h
Log:
Added tilting for the spicedAsteroidBelt. Finished commenting, polish up. Done.
Modified: code/branches/AsteroidMining_HS17/data/levels/AsteroidFarming.oxw
===================================================================
--- code/branches/AsteroidMining_HS17/data/levels/AsteroidFarming.oxw 2017-12-12 16:43:22 UTC (rev 11666)
+++ code/branches/AsteroidMining_HS17/data/levels/AsteroidFarming.oxw 2017-12-12 19:29:52 UTC (rev 11667)
@@ -61,7 +61,6 @@
<PickupSpawner pickup=destroycarriermetapickup position="50,75,-125" triggerDistance="10" respawnTime="5" maxSpawnedItems="10" />
<!-- Drone pickup -->
-
<PickupSpawner pickup=dronepickup position="-25,100,-125" triggerDistance="10" respawnTime="30" maxSpawnedItems="10" />
@@ -98,18 +97,19 @@
</Pawn>
- <!-----AsteroidMinable --->
+ <!-- AsteroidMinable -->
<AsteroidMinable size=15 position="0,-500,0" />
<AsteroidMinable size=5 position="100,-500,100" />
<AsteroidMinable size=50 position="500,-500, 500" />
<AsteroidMinable size=30 position="-100, -500, -100" velocity= "0, -30, 0"/>
- <!--- SpicedAsteroidField -->
- <SpicedAsteroidField count=30 mDensity= 0.5 maxSize=40 minSize=1 position="5000, 0, 0" radius=1000 velocity="-100,0,0"/>
+ <!-- SpicedAsteroidField -->
+ <SpicedAsteroidField count=30 mDensity= 0.5 maxSize=40 minSize=1 position="5000, 0, 0" radius=1000 velocity="0,0,0"/>
<!-- Asteroid Belt with a planet -->
- <SpicedAsteroidBelt position="-15000,0,0" mDensity=0.3 yaw=90 pitch=90 roll=90 segments=30 minSize=1 maxSize=50 radius0=7190 radius1 = 7800 count=250/>
+
+ <SpicedAsteroidBelt position="-15000,0,0" mDensity=0.3 segments=50 minSize=1 maxSize=50 radius0=7190 radius1 = 7800 count=250 tiltBy=0.5 tiltAt=0/>
<Planet
position="-15000,0,0"
scale="5000"
@@ -138,6 +138,5 @@
-
</Scene>
</Level>
Modified: code/branches/AsteroidMining_HS17/src/modules/asteroidmining/AsteroidMinable.cc
===================================================================
--- code/branches/AsteroidMining_HS17/src/modules/asteroidmining/AsteroidMinable.cc 2017-12-12 16:43:22 UTC (rev 11666)
+++ code/branches/AsteroidMining_HS17/src/modules/asteroidmining/AsteroidMinable.cc 2017-12-12 19:29:52 UTC (rev 11667)
@@ -28,85 +28,47 @@
/*
- @file AsteroidMinable.cc
+ @file
+ @author remartin
+ @brief An asteroid which can be destroyed. Some smaller asteroids are created and a pickup spawns.
-*
-*
-* An asteroid which can be destroyed. Some smaller asteroids are created and a pickup
-* spawns.
-*
-*
-*
+HANDBUCH:
+o Die Collision Shape kann nur im Konstruktor hinzugefügt werden. Die XML-Argumente werden aber erst nach dem Konstruktor gesetzt.
+ Darum wird hier beim ersten Aufruf der tick()-Methode via putStuff() ein komplett neuer Asteroid generiert und der alte zerstört.
+o im Level-File includes/pickups.oxi importieren.
-*/
-
-/*
-Veraenderungstagebuch
-++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
-
-
-KNACKPUNKTE:
-o Super-XML-Argumente werden nicht richtig geparst (Velocity, Pitch, Yaw etc. )
-
-
-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.
---> MunitionPickup erbt von Pickup erbt von collectiblePickup erbt von Pickupable
-----> im MineralsPickup die isPickedUp()-Methode überschreiben?
---> data_extern/images/effects: PNG's für die Pickups und GUI-Dinger.
+OFFEN/Weiterentwicklung:
+o @TODO Add resource pickups.
+--> data_extern/images/effects: PNG's für die Pickups
--> https://www.orxonox.net/jenkins/view/Management/job/orxonox_doxygen_trunk/javadoc/group___pickup.html
-o Anfangsgeschwindigkeit fuers Asteroidenfeld
o Density doesn't add up to 1...
-o set collisionDamage? Just for static entities?
-
-o Dokumentieren mit @brief?
-o unregister -empty- asteroids from radar. (or turn them green or whatever)
+o Does collision damage work properly
o Add sound effect (crunching etc. ) (No sound in space...)
o Explosion parts
-HANDBUCH:
-o im Level-File includes/pickups.oxi importieren.
-o Bei der XML-Variante wird beim ersten Aufruf der Tick-Methode ein neuer Asteroid generiert,
- damit die Groesse der Collision Shape korrekt initialisiert wird.
-
-FREMDANPASSUNGEN:
+ANDERORTS VERÄNDERTE SACHEN:
Pickup-Zeug:
-o Pickup.h: Zugriffsänderung createSpawner
+o Pickup.h: createSpawner() neu public statt private
o PickupSpawner.h: Zugriffsrechte setPickupTemplateName() und setMaxSpawnedItems()
-o PickupSpawner.h: In Tick() zwei Testbedingungen eingefuegt.
+o PickupSpawner.h: In Tick() zwei Testbedingungen eingefügt.
o Pawn.h: Attribut acceptsPickups_ inklusive get/set.
ERLEGTE FEHLER:
-o Rand() geht bis zu riesigen Nummern!
-o Pickupgenerierung: vgl. Fremdanpassungen.
-o Minimalbegrenzung fuer Masse vergessen.
-o Dynamische Definition -> putStuff-Methode, Werte noch nicht durchgesickert.
-o Error-Nachricht: Einfach Argumente leer lassen.
-o Pickups: setMaxSpawned funktioniert nicht -> Bastelloesung: Auf 2 statt eins setzen, erstes wird wohl direkt zerstoert.
-o setHealth: Wird mit Max verwurstelt, war 0.
-o Position nicht gesetzt -> alles im Ursprung, Kollision -> fliegt davon.
-o nimmt zuviel Schaden. -> wird mit maxHealth verwurstelt -> einfach auch setzen.
-
-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 Grössenabhängige Collision Shape -> putStuff-Methode, Werte noch nicht durchgesickert.
+o setHealth: maxHealth() des pawns setzen!
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.
-o Discusting mixup with array length, accessing element a[len]...
-o unitialised mass value -> obese asteroid, physics bug.
+o Velocity didn-t get passed properly through the 2nd constructor. Used get/set instead.
+o Rand() geht bis zu riesigen Nummern! rnd() ist zwischen 0 und 1
-
NOTIZEN:
-o SUPER entspricht ueberladen, andere Argumente der Methode.
+o SUPER
o Warnungsverhinderung anderswo: (void)pickedUp; // To avoid compiler warning.
+o friend class Pickupable;
-Was ist das? friend class Pickupable;
-
*/
@@ -149,20 +111,17 @@
this->maxHealth_ = this->health_;
this->acceptsPickups_ = false;
- //Noetig, damit nicht sofort zerstoert?
this->setCollisionType(WorldEntity::CollisionType::Dynamic);
this->enableCollisionCallback();
-
// Old from Pawn
this->registerVariables();
this->initialised = false;
-
}
// @brief Use this constructor with care. Mainly used internally, arguments are passed directly.
- AsteroidMinable::AsteroidMinable(Context* c, float size, Vector3 position, Vector3 v, bool dropStuff) : Pawn(c){
+ AsteroidMinable::AsteroidMinable(Context* c, float size, Vector3 position, bool dropStuff) : Pawn(c){
RegisterObject(AsteroidMinable);
@@ -171,7 +130,9 @@
this->setRadarObjectColour(ColourValue(1.0f, 1.0f, 0.0f, 1.0f));
this->setRadarObjectShape(RadarViewable::Shape::Dot);
}else{
- // Somehow remove from radar?
+ // Somehow remove from radar? (all pawns get registered automatically... )
+ this->setRadarObjectColour(ColourValue(0.663f, 0.663f, 0.663f, 1.0f));
+ this->setRadarObjectShape(RadarViewable::Shape::Dot);
}
this->context = c;
@@ -183,13 +144,11 @@
this->dropStuff = dropStuff;
this->setPosition(position);
- this->setVelocity(v);
//this->roll = rand()*5; //etwas Drehung. Richtige Variable?
this->setCollisionType(WorldEntity::CollisionType::Dynamic);
this->enableCollisionCallback();
-
// Add Model, random one of the 6 shapes
Model* hull = new Model(this->context);
char meshThingy[] = "";
@@ -213,12 +172,14 @@
}
- // @brief Helper method. Create a new asteroid to have an appropriate size for the collision shape etc.
+ // @brief Helper method.
void AsteroidMinable::putStuff(){
- // Just create a new asteroid to avoid Collision shape scale problems etc.
- AsteroidMinable* reborn = new AsteroidMinable(this->context, this->size, this->getPosition(), this->getVelocity(), this->dropStuff);
+ AsteroidMinable* reborn = new AsteroidMinable(this->context, this->size, this->getPosition(), this->dropStuff);
+ reborn->setVelocity(this->getVelocity());
+ // reborn->setAngularVelocity(this->getAngularVelocity()); // Add all other stuff, too?
(void)reborn; // avoid compiler warning
+
this->bAlive_ = false;
this->destroyLater();
@@ -257,7 +218,7 @@
}
- void AsteroidMinable::death(){ // ueberschreibt das Zeug in Pawn
+ void AsteroidMinable::death(){ // @brief Überschreibt die Methode in Pawn
// just copied that from somewhere else.
this->bAlive_ = false;
@@ -267,10 +228,10 @@
// this->goWithStyle();
- // Pickups which can be harvested.
+ // Pickups which can be harvested. It's munition at the moment, could be changed/extended.
if(dropStuff){
PickupSpawner* thingy = new PickupSpawner(this->context);
- // OFFEN: more precise size relation in custom resource pickup.
+
char tname[] = ""; // can-t overwrite strings easily in C (strcat etc.)
if(this->size <= 5){
strcat(tname, "smallmunitionpickup");
@@ -290,20 +251,18 @@
}
+// @brief If the option generateSmaller is enabled, individual fragments are added with this method.
+ void AsteroidMinable::spawnChildren(){
-void AsteroidMinable::spawnChildren(){// Spawn smaller Children
-
if (this->size <=1){return;} // Absicherung trivialer Fall
int massRem = this->size-1; //some mass is lost
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]; // Masses of the asteroids, at least one.
-
+ if(num > 10){num = 10;} // no max function in C?
+ int masses[num]; // Masses of the asteroids
// orxout() << "SpawnChildren(): Passed basic stuff. num = " << num << "; massRem(total) = "<< massRem << endl;
+ massRem = massRem-num; // mass must be at least one, add later.
- massRem = massRem-num; // mass is at least one, add again below.
-
// Randomnised spawning points for the new asteroids
float phi[num];
float theta[num];
@@ -347,8 +306,8 @@
//orxout() << "SpawnChildren(): Theta: "; printArrayString(theta);
//orxout() << "SpawnChildren(): Passed angle stuff. " << endl;
- // '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
+ // Triangular, discrete probability "density" with max at the average value massRem/num. 50% chance to be below that.
+ if(massRem>0){
int c = massRem;
float probDensity[c];
@@ -371,21 +330,22 @@
// orxout() << "Sum of densities should b 1, it is: " << sum << endl;
// Distributing the mass to individual asteroids
- int result;
- float rVal;// between 0 and 1
- float probSum;
+ int result;
+ float rVal; // between 0 and 1
+ float probSum; // summing up until rval is reached.
for(int trav = 0; trav<num; ++trav){
- result = 0;// reset
- rVal = rnd();// between 0 and 1
+ result = 0;
+ rVal = rnd();
probSum = probDensity[0];
- while(rVal>probSum && result<massRem){// Not yet found && there-s smth left to distribute (Incrementing once inside!)
+ while(rVal>probSum && result<massRem){// Not yet found && there-s smth left to distribute (Incrementing inside!)
if(result<(massRem-2)){probSum = probSum + probDensity[result+1];} // avoid logical/acess error
++result;
}
+ masses[trav] = 1 +result; // Fragments have mass of at least one.
massRem = massRem-result;
- masses[trav] = 1 +result; // Fragments have mass of at least one.
+
}
}else{
for(int schnaegg = 0; schnaegg<num; ++schnaegg){masses[schnaegg] = 1;}
@@ -403,7 +363,8 @@
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
}
- AsteroidMinable* child = new AsteroidMinable(this->context, masses[fisch], this->getPosition() + *pos, this->getVelocity(), this->dropStuff);
+ AsteroidMinable* child = new AsteroidMinable(this->context, masses[fisch], this->getPosition() + *pos, this->dropStuff);
+ child->setVelocity(this->getVelocity());
if(child == nullptr){
orxout(internal_error, context::pickups) << "Weird, can't create new AsteroidMinable." << endl;
@@ -413,19 +374,14 @@
// orxout() << "Leaving spawnChildren() method. " << endl;
}
-
+// @brief overloading that to prevent asteroids from taking damage from each other (domino effect etc. )
void AsteroidMinable::hit(Pawn* originator, const Vector3& force, const btCollisionShape* cs, float damage, float healthdamage, float shielddamage){
- orxout() << "AsteroidMining::Hit(Variante 1) Dings aufgerufen. " << endl;
-
- // Kollision mit anderem Asteroid oder Pickup verhindern. In diesem Fall einfach nichts tun.
- // Wird staending aufgerufen -> Rechenleistung?
+ // orxout() << "AsteroidMining::Hit(Variante 1) Dings aufgerufen. " << endl;
if(orxonox_cast<AsteroidMinable*>(originator) || orxonox_cast<Pickup*>(originator)){return;}
this->damage(damage, healthdamage, shielddamage, originator, cs);
this->setVelocity(this->getVelocity() + force);
-
-
// if (this->getGametype() && this->getGametype()->allowPawnHit(this, originator))// && (!this->getController() || !this->getController()->getGodMode()) )
// {
// this->damage(damage, healthdamage, shielddamage, originator, cs);
@@ -433,20 +389,13 @@
// }
}
+// @brief overloading that to prevent asteroids from taking damage from each other (domino effect etc. )
void AsteroidMinable::hit(Pawn* originator, btManifoldPoint& contactpoint, const btCollisionShape* cs, float damage, float healthdamage, float shielddamage){
//orxout() << "AsteroidMining::Hit(Variante 2) Dings aufgerufen. " << endl;
- // Kollision mit anderem Asteroid oder Pickup (OFFEN: evtl. Spawner oder irgendwas?) verhindern. In diesem Fall einfach nichts tun.
- // Wird staending aufgerufen -> Rechenleistung?
if(orxonox_cast<AsteroidMinable*>(originator) || orxonox_cast<Pickup*>(originator)){return;}
-
- //orxout() << "Schaden. HP: " << this->health_ << " Dmg: " << damage << " hDmg: " << healthdamage << " sDmg: " << shielddamage << endl;
-
this->damage(damage, healthdamage, shielddamage, originator, cs);
-
-
-
// if (this->getGametype() && this->getGametype()->allowPawnHit(this, originator))// && (!this->getController() || !this->getController()->getGodMode()) )
// {
// this->damage(damage, healthdamage, shielddamage, originator, cs);
Modified: code/branches/AsteroidMining_HS17/src/modules/asteroidmining/AsteroidMinable.h
===================================================================
--- code/branches/AsteroidMining_HS17/src/modules/asteroidmining/AsteroidMinable.h 2017-12-12 16:43:22 UTC (rev 11666)
+++ code/branches/AsteroidMining_HS17/src/modules/asteroidmining/AsteroidMinable.h 2017-12-12 19:29:52 UTC (rev 11667)
@@ -28,9 +28,46 @@
/**
- @file AsteroidMinable.h
+ @file
+ @author remartin
+ @brief An asteroid which can be destroyed. Some smaller asteroids are created and a pickup spawns.
+HANDBUCH:
+o Die Collision Shape kann nur im Konstruktor hinzugefügt werden. Die XML-Argumente werden aber erst nach dem Konstruktor gesetzt.
+ Darum wird hier beim ersten Aufruf der tick()-Methode via putStuff() ein komplett neuer Asteroid generiert und der alte zerstört.
+o im Level-File includes/pickups.oxi importieren.
+
+OFFEN/Weiterentwicklung:
+o @TODO Add resource pickups.
+--> data_extern/images/effects: PNG's für die Pickups
+--> https://www.orxonox.net/jenkins/view/Management/job/orxonox_doxygen_trunk/javadoc/group___pickup.html
+
+o Density doesn't add up to 1...
+o Does collision damage work properly
+o Add sound effect (crunching etc. ) (No sound in space...)
+o Explosion parts
+
+ANDERORTS VERÄNDERTE SACHEN:
+Pickup-Zeug:
+o Pickup.h: createSpawner() neu public statt private
+o PickupSpawner.h: Zugriffsrechte setPickupTemplateName() und setMaxSpawnedItems()
+o PickupSpawner.h: In Tick() zwei Testbedingungen eingefügt.
+o Pawn.h: Attribut acceptsPickups_ inklusive get/set.
+
+ERLEGTE FEHLER:
+o Grössenabhängige Collision Shape -> putStuff-Methode, Werte noch nicht durchgesickert.
+o setHealth: maxHealth() des pawns setzen!
+o Asteroiden fressen Pickups: Argument in Pawn, Test darauf in Tick() von PickupSpawner.
+o i++ einfach ganz verhindern, ++i stattdessen.
+o Velocity didn-t get passed properly through the 2nd constructor. Used get/set instead.
+o Rand() geht bis zu riesigen Nummern! rnd() ist zwischen 0 und 1
+
+NOTIZEN:
+o SUPER
+o Warnungsverhinderung anderswo: (void)pickedUp; // To avoid compiler warning.
+o friend class Pickupable;
+
*/
#ifndef _AsteroidMinable_H__
@@ -47,15 +84,16 @@
#include "../../orxonox/worldentities/pawns/Pawn.h"
-namespace orxonox
-{
+namespace orxonox{
class _OrxonoxExport AsteroidMinable : public Pawn{
public:
- AsteroidMinable(Context* context);// @brief This constructor is for XML access only!
- AsteroidMinable(Context* c, float size, Vector3 position, Vector3 velocity, bool dS);// @brief Call this Constructor from other C-files.
+ // @brief This constructor is for XML access only!
+ AsteroidMinable(Context* context);
+ // @brief Call this Constructor from other C-files.
+ AsteroidMinable(Context* c, float size, Vector3 position, bool dS);
virtual ~AsteroidMinable();
virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
@@ -62,7 +100,7 @@
virtual void XMLEventPort(Element& xmlelement, XMLPort::Mode mode) override;
virtual void tick(float dt) override;
- // @brief Overwrite to prevet 'self-collision' of generated stuff
+ // @brief overloading that to prevent asteroids from taking damage from each other (domino effect etc. )
virtual void hit(Pawn* originator, const Vector3& force, const btCollisionShape* cs, float damage, float healthdamage = 0.0f, float shielddamage = 0.0f);
virtual void hit(Pawn* originator, btManifoldPoint& contactpoint, const btCollisionShape* cs, float damage, float healthdamage = 0.0f, float shielddamage = 0.0f);
@@ -79,30 +117,30 @@
Context* context;
- int size;
- bool generateSmaller;
- bool dropStuff;
+ int size; //!< Implies health and type of dropped pickups
+ bool generateSmaller; //!< Whether this asteroid leaves fragments
+ bool dropStuff; //!< Whether this asteroid yields valuable stuff
- bool initialised;
-
+ // @brief Überschreibt die Methode in Pawn
virtual void death();
+ private:
+ bool initialised; //!< Used in relation to the constructor detour described above
- private:
void registerVariables();
- virtual void spawnChildren();
+
+ // @brief Helper method.
virtual void putStuff();
+ // @brief If the option generateSmaller is enabled, individual fragments are added with this method.
+ virtual void spawnChildren();
+
// @brief Just for testing. Don-t work anyways.
void printArrayString(float thingy[]);
// @brief Just for testing. Don-t work anyways.
- void printArrayString(int thingy[]);// Just for testing
+ void printArrayString(int thingy[]);
-
-
-
-
}; // tolua_export
} // tolua_export
Modified: code/branches/AsteroidMining_HS17/src/modules/asteroidmining/SpicedAsteroidBelt.cc
===================================================================
--- code/branches/AsteroidMining_HS17/src/modules/asteroidmining/SpicedAsteroidBelt.cc 2017-12-12 16:43:22 UTC (rev 11666)
+++ code/branches/AsteroidMining_HS17/src/modules/asteroidmining/SpicedAsteroidBelt.cc 2017-12-12 19:29:52 UTC (rev 11667)
@@ -28,10 +28,19 @@
/**
- @file SpicedAsteroidBelt.cc
+ @file
+ @author remartin
@brief Asteroid belt with lots of parameters. Derived from asteroidField.lua
+ Generates a ring of asteroids by calling SpicedAsteroidField multiple times.
+ It's in the xy-plane at default, orientation can be changed with tiltAt
+ (angle where it gets elevated/lowered the most) and TiltBy (angle at z-axis).
+ This doesn't work very well and could probably implemented differently with
+ relative coordinates (attach etc, stuff in WorldEntity).
+ It is required to wait until all XML-arguments are set. That's why the actual
+ generation happens when tick() gets called for the first time.
+
*/
@@ -63,8 +72,6 @@
// Default Values:
this->count = 250;
this->position = Vector3(0,0,0);
- // this->yaw = 0;
- // this->pitch = 0;
this->segments = 30;
this->minSize = 1;
this->maxSize = 50;
@@ -74,7 +81,9 @@
this->mDensity = 0.3;
this->fogDensity = 0.5;
- // Old from Pawn
+ this->tiltAt = 0.0;
+ this->tiltBy = 0.0;
+
this->registerVariables();
}
@@ -86,17 +95,29 @@
void SpicedAsteroidBelt::create(){
float myPi = 3.1415927410125732421875; //pi; // Math.pi ist statisch oder so.
- float dPhi = (2 * myPi) / segments;
- float width = radius1 - radius0; if(width<0){width = -width;} // predefined abs?
- float radius = (radius1 + radius0) / 2.0;
- int segmentCount = round(count / segments);
+ float width = this->radius1 - this->radius0; if(width<0){width = -width;} // predefined abs?
+ float radius = (this->radius1 + this->radius0) / 2.0;
+ int segmentCount = round(this->count / this->segments);
- SpicedAsteroidField* af[segments];
+ SpicedAsteroidField* af[this->segments];
(void)af[0]; // avoid nasty compiler warning
+ float dPhi = (2 * myPi) / this->segments;
+ float dTheta = 4.0*this->tiltBy/this->segments;
+ float sepp = -this->tiltAt;
+ float globi = (myPi/2.0) + this->tiltBy;
+
for(int s = 0; s<segments; ++s){
- Vector3* pos = new Vector3(radius*cos(s*dPhi), radius*sin(s*dPhi),0);
+ sepp = sepp + dPhi;
+ if(s<segments/2){
+ globi = globi - dTheta;
+ }else{
+ globi = globi + dTheta;
+ }
+
+ Vector3* pos = new Vector3(radius*cos(sepp)*sin(globi), radius*sin(sepp)*sin(globi), radius*cos(globi));
af[s] = new SpicedAsteroidField(this->context, this->position + *pos, this->minSize, this->maxSize, width, segmentCount, this->foggy, this->mDensity, this->fogDensity);
+
}
}
@@ -108,8 +129,6 @@
XMLPortParam(SpicedAsteroidBelt, "count", setCount, getCount, xmlelement, mode);
XMLPortParam(SpicedAsteroidBelt, "mDensity", setMineralDensity, getMineralDensity, xmlelement, mode);
XMLPortParam(SpicedAsteroidBelt, "position", setPosition, getPosition, xmlelement, mode);
- // XMLPortParam(SpicedAsteroidBelt, "yaw", setYaw, getYaw, xmlelement, mode);
- // XMLPortParam(SpicedAsteroidBelt, "pitch", setPitch, getPitch, xmlelement, mode);
XMLPortParam(SpicedAsteroidBelt, "segments", setSegments, getSegments, xmlelement, mode);
XMLPortParam(SpicedAsteroidBelt, "maxSize", setMaxSize, getMaxSize, xmlelement, mode);
@@ -119,6 +138,9 @@
XMLPortParam(SpicedAsteroidBelt, "foggy", setFog, isFoggy, xmlelement, mode);
XMLPortParam(SpicedAsteroidBelt, "fogDensity", setFogDensity, getFogDensity, xmlelement, mode);
+ XMLPortParam(SpicedAsteroidBelt, "tiltAt", setTiltAt, getTiltAt, xmlelement, mode);
+ XMLPortParam(SpicedAsteroidBelt, "tiltBy", setTiltBy, getTiltBy, xmlelement, mode);
+
}
void SpicedAsteroidBelt::XMLEventPort(Element& xmlelement, XMLPort::Mode mode){
@@ -130,8 +152,6 @@
registerVariable(this->count, VariableDirection::ToClient);
registerVariable(this->mDensity, VariableDirection::ToClient);
registerVariable(this->position, VariableDirection::ToClient);
- // registerVariable(this->yaw, VariableDirection::ToClient);
- // registerVariable(this->pitch, VariableDirection::ToClient);
registerVariable(this->segments, VariableDirection::ToClient);
registerVariable(this->maxSize, VariableDirection::ToClient);
@@ -141,6 +161,9 @@
registerVariable(this->foggy, VariableDirection::ToClient);
registerVariable(this->fogDensity, VariableDirection::ToClient);
+ registerVariable(this->tiltAt, VariableDirection::ToClient);
+ registerVariable(this->tiltBy, VariableDirection::ToClient);
+
}
void SpicedAsteroidBelt::tick(float dt){
Modified: code/branches/AsteroidMining_HS17/src/modules/asteroidmining/SpicedAsteroidBelt.h
===================================================================
--- code/branches/AsteroidMining_HS17/src/modules/asteroidmining/SpicedAsteroidBelt.h 2017-12-12 16:43:22 UTC (rev 11666)
+++ code/branches/AsteroidMining_HS17/src/modules/asteroidmining/SpicedAsteroidBelt.h 2017-12-12 19:29:52 UTC (rev 11667)
@@ -22,16 +22,24 @@
* Author:
* Fabian 'x3n' Landau
* Co-authors:
- * ...
*
*/
/**
- @file SpicedAsteroidBelt.h
+ @file
+ @author remartin
@brief Asteroid belt with lots of parameters. Derived from asteroidField.lua
+ Generates a ring of asteroids by calling SpicedAsteroidField multiple times.
+ It's in the xy-plane at default, orientation can be changed with tiltAt
+ (angle where it gets elevated/lowered the most) and TiltBy (angle at z-axis).
+ This doesn't work very well and could probably implemented differently with
+ relative coordinates (attach etc, stuff in WorldEntity).
+ It is required to wait until all XML-arguments are set. That's why the actual
+ generation happens when tick() gets called for the first time.
+
*/
@@ -71,12 +79,6 @@
inline void setPosition(Vector3 v){this->position = v;}
inline Vector3 getPosition(){return this->position;}
- // inline void setYaw(float y){this->yaw = y;}
- // inline float getYaw(){return this->yaw;}
-
- // inline void setPitch(float p){this->pitch = p;}
- // inline float getPitch(){return this->pitch;}
-
inline void setSegments(int s){this->segments = s;}
inline int getSegments(){return this->segments;}
@@ -98,33 +100,39 @@
inline void setFogDensity(float fd){this->fogDensity = fd;}
inline float getFogDensity(){return this->fogDensity;}
+ inline void setTiltAt(float ta){this->tiltAt = ta;}
+ inline void setTiltBy(float tb){this->tiltBy = tb;}
+ inline float getTiltAt(){return this->tiltAt;}
+ inline float getTiltBy(){return this->tiltBy;}
+
protected:
Context* context;
- float count;
- float mDensity; // Mineral density, between 0 and 1;
+ float count; //!< Approximate number of asteroids
+ float mDensity; //!< Approximate commonness of asteroids that yield stuff, value between 0 and 1;
Vector3 position;
- // float yaw;
- // float pitch;
- int segments;
+ int segments; //!< Number of asteroidFields that get generated.
- int maxSize;
- int minSize;
+ int maxSize; //!< Most obese asteroid possible
+ int minSize; //!< Most meagre asteroid possible
- float radius0;
- float radius1;
+ float radius0; //!< Inner radius
+ float radius1; //!< Outer radius
- bool foggy;
+ bool foggy; //!< Whether there's fog arount the asteroids
float fogDensity;
- virtual void create();
+ float tiltAt; //!< Orientation: Angle where it gets elevated/lowered the most
+ float tiltBy; //!< angle at z-axis
private:
void registerVariables();
+
+ virtual void create();
}; // tolua_export
} // tolua_export
Modified: code/branches/AsteroidMining_HS17/src/modules/asteroidmining/SpicedAsteroidField.cc
===================================================================
--- code/branches/AsteroidMining_HS17/src/modules/asteroidmining/SpicedAsteroidField.cc 2017-12-12 16:43:22 UTC (rev 11666)
+++ code/branches/AsteroidMining_HS17/src/modules/asteroidmining/SpicedAsteroidField.cc 2017-12-12 19:29:52 UTC (rev 11667)
@@ -28,10 +28,14 @@
/**
- @file SpicedAsteroidField.cc
+ @file
+ @author remartin
@brief Asteroid field with lots of parameters. Derived from asteroidField.lua
-
+ Generates a bunch of asteroids that may contain some stuff.
+ It is required to wait until all XML-arguments are set. That's why the actual
+ generation happens when tick() gets called for the first time.
+
*/
@@ -104,13 +108,13 @@
Vector3* relPos;
-
for(int gertrud = 0; gertrud<count; ++gertrud){
AsteroidMinable* a = new AsteroidMinable(this->context);
size = round(rnd()*(this->maxSize - this->minSize)) + this->minSize;
- a->setSize(size);
+ a->setSize(size);
+
pX = round(rnd()*2*this->radius) - radius;
pY = round(rnd()*2*this->radius) - radius;
pZ = round(rnd()*2*this->radius) - radius;
@@ -117,13 +121,12 @@
relPos = new Vector3(pX, pY, pZ);
a->setPosition(this->position + *relPos);
- bool spiced = (rnd() < (this->mDensity)); // does drop pickups etc.
+ bool spiced = (rnd() < (this->mDensity)); // Whether the asteroid does drop pickups etc.
a->toggleDropStuff(spiced);
-
- // A problem
- a->setVelocity(this->getVelocity());
- // Fog is iplemented with billboards.
+ a->setVelocity(this->getVelocity());
+
+ // Fog is iplemented with billboards (as in asteroidField.lua, that bloke had the idea)
Billboard* bb;
if(this->foggy && mod(gertrud, 5) == 0){
bb = new Billboard(this->context);
Modified: code/branches/AsteroidMining_HS17/src/modules/asteroidmining/SpicedAsteroidField.h
===================================================================
--- code/branches/AsteroidMining_HS17/src/modules/asteroidmining/SpicedAsteroidField.h 2017-12-12 16:43:22 UTC (rev 11666)
+++ code/branches/AsteroidMining_HS17/src/modules/asteroidmining/SpicedAsteroidField.h 2017-12-12 19:29:52 UTC (rev 11667)
@@ -22,16 +22,19 @@
* Author:
* Fabian 'x3n' Landau
* Co-authors:
- * ...
*
*/
/**
- @file SpicedAsteroidField.h
+ @file
+ @author remartin
@brief Asteroid field with lots of parameters. Derived from asteroidField.lua
-
+ Generates a bunch of asteroids that may contain some stuff.
+ It is required to wait until all XML-arguments are set. That's why the actual
+ generation happens when tick() gets called for the first time.
+
*/
#ifndef _SpicedAsteroidField_H__
@@ -90,25 +93,25 @@
Context* context;
- float count;
- float mDensity; // Mineral density, between 0 and 1;
+ float count; //!< Number of asteroids generated
+ float mDensity; //!< Mineral density, between 0 and 1;
- Vector3 position;
+ Vector3 position; //!< The center
- int maxSize;
- int minSize;
+ int maxSize; //!< Upper bound to asteroid size
+ int minSize; //!< Lower bound to asteroid size
- float radius;
- bool foggy;
+ float radius; //!< Asteroids can appear within a sphere.
+ bool foggy; //!< Whether there's fog
float fogDensity;
- virtual void create();
-
-
private:
void registerVariables();
+ virtual void create();
+
+
}; // tolua_export
} // tolua_export
More information about the Orxonox-commit
mailing list