[Orxonox-commit 7021] r11640 - in code/branches/AsteroidMining_HS17: data/levels src/modules/asteroidmining
remartin at orxonox.net
remartin at orxonox.net
Mon Dec 4 16:38:18 CET 2017
Author: remartin
Date: 2017-12-04 16:38:17 +0100 (Mon, 04 Dec 2017)
New Revision: 11640
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/CMakeLists.txt
code/branches/AsteroidMining_HS17/src/modules/asteroidmining/SpicedAsteroidField.cc
code/branches/AsteroidMining_HS17/src/modules/asteroidmining/SpicedAsteroidField.h
Log:
Das Aufteilen funktioniert nun gut. AsteroidField fertiggestellt und mit dokumentieren begonnen.
Modified: code/branches/AsteroidMining_HS17/data/levels/AsteroidFarming.oxw
===================================================================
--- code/branches/AsteroidMining_HS17/data/levels/AsteroidFarming.oxw 2017-12-04 15:23:58 UTC (rev 11639)
+++ code/branches/AsteroidMining_HS17/data/levels/AsteroidFarming.oxw 2017-12-04 15:38:17 UTC (rev 11640)
@@ -40,7 +40,7 @@
<!-- Asteroid Display: -->
- <Model position="0, 0,40" yaw="90" pitch="-90" roll="0" scale="3" mesh="ast1.mesh" />
+ <Model position="0, 0,40" yaw="90" pitch="-90" roll="0" scale="3" mesh="ast1.mesh" />
<Model position="0, 20,40" yaw="90" pitch="-90" roll="0" scale="3" mesh="ast2.mesh" />
<Model position="0, 40,40" yaw="90" pitch="-90" roll="0" scale="3" mesh="ast3.mesh" />
<Model position="0, 60,40" yaw="90" pitch="-90" roll="0" scale="3" mesh="ast4.mesh" />
@@ -76,6 +76,7 @@
</Pawn>
+ <!----Just a box with different mesh-->
<Pawn team=1 health=50 position="0,1000,0" direction="0,-1,0" collisionType=dynamic mass=100000 name=box RVName = "Globi Asteroid" >
<events>
<visibility>
@@ -93,12 +94,13 @@
<!-----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/>
</Scene>
Modified: code/branches/AsteroidMining_HS17/src/modules/asteroidmining/AsteroidMinable.cc
===================================================================
--- code/branches/AsteroidMining_HS17/src/modules/asteroidmining/AsteroidMinable.cc 2017-12-04 15:23:58 UTC (rev 11639)
+++ code/branches/AsteroidMining_HS17/src/modules/asteroidmining/AsteroidMinable.cc 2017-12-04 15:38:17 UTC (rev 11640)
@@ -42,36 +42,30 @@
Veraenderungstagebuch
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
-FRAGEN:
-* Zeilen-Loeschung beim output
-* orxout()-Problem
-* dokumentieren mit @brief?
-* Warnumg aus Asteroidenzerstoerung
-
KNACKPUNKTE:
-
OFFEN:
-o Mass distribution -> weird for bigger asteroids
---> more testing
-
-o SpicedAsteroidField fertigstellen, Mineraldichten-Parameter
-
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.
+--> https://www.orxonox.net/jenkins/view/Management/job/orxonox_doxygen_trunk/javadoc/group___pickup.html
-o inherit parent velocity
+o Anfangsgeschwindigkeit fuers Asteroidenfeld
+o Density doesn't add up to 1...
o set collisionDamage? Just for static entities?
+o AsteroidBelt?
+
o Dokumentieren mit @brief?
-
+o unregister -empty- asteroids from radar. (or turn them green or whatever)
+o Add sound effect (crunching etc. ) (No sound in space...)
o Explosion parts
o custom HUD
+
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,
@@ -84,7 +78,7 @@
o PickupSpawner.h: In Tick() zwei Testbedingungen eingefuegt.
o Pawn.h: Attribut acceptsPickups_ inklusive get/set.
-ERLEGT:
+ERLEGTE FEHLER:
o Rand() geht bis zu riesigen Nummern!
o Pickupgenerierung: vgl. Fremdanpassungen.
o Minimalbegrenzung fuer Masse vergessen.
@@ -157,15 +151,14 @@
{
RegisterClass(AsteroidMinable);
-
- // This constructor is for XML access only.
+ // @brief Standard constructor
AsteroidMinable::AsteroidMinable(Context* context) : Pawn(context){
- // Da auch noetig? Wegen set in XML-Code?
RegisterObject(AsteroidMinable);
this->context = context;
this->initialised = false;
+ this->dropStuff = true; // Default
//Noetig, damit nicht sofort zerstoert?
this->setCollisionType(WorldEntity::CollisionType::Dynamic);
@@ -177,27 +170,33 @@
}
- // Call this one from other C-files. Takes arguments.
- AsteroidMinable::AsteroidMinable(Context* c, float size, Vector3 position) : Pawn(c){
+ // @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){
RegisterObject(AsteroidMinable);
- // Old stuff from pawn
- this->setRadarObjectColour(ColourValue(1.0f, 1.0f, 0.0f, 1.0f));
- this->setRadarObjectShape(RadarViewable::Shape::Dot);
+ // The radar is able to detect whether an asteroid contains resources....
+ if(dropStuff){
+ this->setRadarObjectColour(ColourValue(1.0f, 1.0f, 0.0f, 1.0f));
+ this->setRadarObjectShape(RadarViewable::Shape::Dot);
+ }else{
+ // Somehow remove from radar?
+ }
+
this->setCollisionType(WorldEntity::CollisionType::Dynamic);
-
this->enableCollisionCallback();
// Default Values
- this->generateSmaller = true;
this->context = c;
this->size = size;
this->health_ = 15*size;
this->maxHealth_ = this->health_;
- this->acceptsPickups_ = false;
+ this->acceptsPickups_ = false;
+ this->generateSmaller = true;
+ this->dropStuff = dropStuff;
this->setPosition(position);
+ this->setVelocity(v); // velocity = v; // The right one?
//this->roll = rand()*5; //etwas Drehung. richtige Variable
@@ -227,13 +226,15 @@
AsteroidMinable::~AsteroidMinable(){
}
-
+ // @brief Helper method. Create a new asteroid to have an appropriate size for the collision shape etc.
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());
+ AsteroidMinable* reborn = new AsteroidMinable(this->context, this->size, this->getPosition(), this->getVelocity(), this->dropStuff);
reborn->toggleShattering(true); // mainly here to avoid 'unused' warning.
- this->~AsteroidMinable(); // seems dangerous, yields warning. Necessary for efficiency?
+ this->bAlive_ = false;
+ this->destroyLater();
+ //this->~AsteroidMinable(); // seems dangerous, yields warning. Necessary for efficiency?
}
@@ -275,19 +276,9 @@
}
- void AsteroidMinable::setSize(float s){
- this->size = s;
- }
- float AsteroidMinable::getSize(){
- return this->size;
- }
- void AsteroidMinable::toggleShattering(bool b){
- this->generateSmaller = b;
- }
-
void AsteroidMinable::death() //ueberschreiben
{
@@ -303,22 +294,23 @@
// this->goWithStyle();
- // Stuff that can be harvested.
- 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");
- }else if(this->size <= 20){
- strcat(tname, "mediummunitionpickup");
- }else{
- strcat(tname, "hugemunitionpickup");
+ // Pickups which can be harvested.
+ 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");
+ }else if(this->size <= 20){
+ strcat(tname, "mediummunitionpickup");
+ }else{
+ strcat(tname, "hugemunitionpickup");
+ }
+ thingy->setPickupTemplateName(tname);
+ thingy->setPosition(this->getPosition());
+ thingy->setMaxSpawnedItems(1); // Would be default anyways
+ thingy->setRespawnTime(0.2f);
}
- thingy->setPickupTemplateName(tname);
- thingy->setPosition(this->getPosition());
- thingy->setMaxSpawnedItems(1); // Would be default anyways
- thingy->setRespawnTime(0.2f);
-
// orxout() << "AsteroidMining::Death(): Passed Pickup stuff!" << endl;
// Smaller Parts = 'Children'
@@ -338,7 +330,7 @@
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.
- orxout() << "SpawnChildren(): Passed basic stuff. num = " << num << "; massRem(total) = "<< massRem << endl;
+ //orxout() << "SpawnChildren(): Passed basic stuff. num = " << num << "; massRem(total) = "<< massRem << endl;
massRem = massRem-num; // mass is at least one, add again below.
@@ -345,7 +337,7 @@
// 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 piG = pi; // ist statisch oder so.
+ float piG = 3.1415927410125732421875; //pi; // Math.pi ist statisch oder so.
float d_p = 2*piG/num;
float d_t = piG/num;
@@ -379,9 +371,9 @@
//orxout() << "SpawnChildren(): Phi: "; printArrayString(phi);
//orxout() << "SpawnChildren(): Theta: "; printArrayString(theta);
- orxout() << "SpawnChildren(): Passed angle stuff. " << endl;
+ //orxout() << "SpawnChildren(): Passed angle stuff. " << endl;
- // 'Triangular', discrete probability density with max at the expected value massRem/num at a. a+b = c
+ // '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};
@@ -396,10 +388,13 @@
float dProbB = 1.0/(b*b +3.0*b + 2.0);
for(z = 0; z<b; ++z){probDensity[c-z] = (z+1)*dProbB;} // falling part
- // Testing
- for(int globi = 0; globi<c; ++globi){
- orxout() << "pDensity at [" << globi << "] is: " << probDensity[globi] << endl;
- }
+ // // Just for testing:
+ // float sum = 0.0;
+ // for(int globi = 0; globi<c; ++globi){
+ // orxout() << "pDensity at [" << globi << "] is: " << probDensity[globi] << endl;
+ // sum = sum+ probDensity[globi];
+ // }
+ // orxout() << "Sum of densities should b 1, it is: " << sum << endl;
// Distributing the mass to individual asteroids
int result;
@@ -408,19 +403,19 @@
for(int trav = 0; trav<num; ++trav){
result = 0;// reset
rVal = rnd();// between 0 and 1
- orxout() << "Random Value picked: " << rVal << endl;
+ // orxout() << "Random Value picked: " << rVal << endl;
probSum = probDensity[0];
//orxout() << "Sum at start: " << probSum << endl;
while(rVal>probSum && result<massRem){// Not yet found && there-s smth to distribute (Incrementing once inside!)
- if(result<(num-2)){probSum = probSum+probDensity[result+1];} // avoid logical/acess error
+ if(result<(massRem-2)){probSum = probSum + probDensity[result+1];} // avoid logical/acess error
++result;
- //orxout() << "Sum so far: " << probSum << endl;
+ // orxout() << "Sum so far: " << probSum << ". Just added " << probDensity[result+1] << endl;
}
massRem = massRem-result;
masses[trav] = 1 +result; // at least one
- orxout() << "Mass chosen for child " << trav << " is: " << masses[trav] << endl;
+ // orxout() << "Mass chosen for child " << trav << " is: " << masses[trav] << endl;
}
}else{// Everyone has mass 1. Initialising the array to 1 doesn-t seem to work. Hideous C language!
@@ -429,8 +424,8 @@
}
}
- //orxout() << "SpawnChildren(): Masses: "; printArrayString(masses);
- orxout() << "SpawnChildren(): Passed mass stuff. " << endl;
+ // orxout() << "SpawnChildren(): Masses: "; printArrayString(masses);
+ // orxout() << "SpawnChildren(): Passed mass stuff. " << endl;
// Creating the 'chlidren':
for(int fisch = 0; fisch<num; ++fisch){
@@ -441,8 +436,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
}
- //orxout() << "Creating asteroid with mass " << masses[fisch] << " at relative postition " << *pos << endl;
- AsteroidMinable* child = new AsteroidMinable(this->context, masses[fisch], this->getPosition() + *pos);
+ // orxout() << "Creating asteroid with mass " << masses[fisch] << " at relative postition " << *pos << endl;
+ AsteroidMinable* child = new AsteroidMinable(this->context, masses[fisch], this->getPosition() + *pos, this->getVelocity(), this->dropStuff);
if(child == nullptr){
orxout(internal_error, context::pickups) << "Weird, can't create new AsteroidMinable." << endl;
@@ -449,7 +444,7 @@
}
}
- orxout() << "Leaving spawnChildren() method. " << endl;
+ // orxout() << "Leaving spawnChildren() method. " << endl;
}
@@ -457,7 +452,7 @@
orxout() << "AsteroidMining::Hit(Variante 1) Dings aufgerufen. " << endl;
- // Kollision mit anderem Asteroid oder Pickup (OFFEN: evtl. Spawner oder irgendwas?) verhindern. In diesem Fall einfach nichts tun.
+ // Kollision mit anderem Asteroid oder Pickup verhindern. In diesem Fall einfach nichts tun.
// Wird staending aufgerufen -> Rechenleistung?
if(orxonox_cast<AsteroidMinable*>(originator) || orxonox_cast<Pickup*>(originator)){return;}
this->damage(damage, healthdamage, shielddamage, originator, cs);
@@ -495,6 +490,7 @@
// }
}
+ // @brief Just for testing. Don-t work anyways.
void AsteroidMinable::printArrayString(float thingy[]){ // Don-t work!
orxout() << "[" ; //<< endl;
@@ -508,6 +504,7 @@
orxout() << frag << endl; // Just print it here! No ugly passing.
}
+ // @brief Just for testing. Don-t work anyways.
void AsteroidMinable::printArrayString(int thingy[]){
orxout() << "[" ; //<< endl;
@@ -523,9 +520,7 @@
orxout() << frag << endl; // Just print it here! No ugly passing.
}
-
// void AsteroidMinable::printArrayString(int thingy[]){
-
// char res[] = "[";
// //strcat(res, "[");
// char frag[] = "";
@@ -546,117 +541,4 @@
// // return result;
// }
-
-
-//Pawn:
- // void Pawn::hit(Pawn* originator, const Vector3& force, const btCollisionShape* cs, float damage, float healthdamage, float shielddamage)
- // {
- // if (this->getGametype() && this->getGametype()->allowPawnHit(this, originator) && (!this->getController() || !this->getController()->getGodMode()) )
- // {
- // this->damage(damage, healthdamage, shielddamage, originator, cs);
- // this->setVelocity(this->getVelocity() + force);
- // }
- // }
-
- // void Pawn::hit(Pawn* originator, btManifoldPoint& contactpoint, const btCollisionShape* cs, float damage, float healthdamage, float shielddamage)
- // {
- // if (this->getGametype() && this->getGametype()->allowPawnHit(this, originator) && (!this->getController() || !this->getController()->getGodMode()) )
- // {
- // this->damage(damage, healthdamage, shielddamage, originator, cs);
-
- // if ( this->getController() )
- // this->getController()->hit(originator, contactpoint, damage); // changed to damage, why shielddamage?
- // }
- // }
-
-
-
-
- // /**
- // @brief
- // Virtual function that gets called when this object collides with another.
- // @param otherObject
- // The object this one has collided into.
- // @param ownCollisionShape
- // The collision shape of the other object
- // @param contactPoint
- // Contact point provided by Bullet. Holds more information and can me modified. See return value.
- // @return
- // Returning false means that no modification to the contactPoint has been made. Return true otherwise!
- // @note
- // Condition is that enableCollisionCallback() was called.
- // */
- // virtual inline bool collidesAgainst(WorldEntity* otherObject, const btCollisionShape* ownCollisionShape, btManifoldPoint& contactPoint)
- // { return false; } /* With false, Bullet assumes no modification to the collision objects. */
-
- // //! Enables the collidesAgainst(.) function. The object doesn't respond to collision otherwise!
- // inline void enableCollisionCallback()
- // { this->bCollisionCallbackActive_ = true; this->collisionCallbackActivityChanged(); }
-
-
-
- // //! Disables the collidesAgainst(.) function. @see enableCollisionCallback()
- // inline void disableCollisionCallback()
- // { this->bCollisionCallbackActive_ = false; this->collisionCallbackActivityChanged(); }
-
-
- // //! Tells whether there could be a collision callback via collidesAgainst(.)
- // inline bool isCollisionCallbackActive() const
- // { return this->bCollisionCallbackActive_; }
-
- // //! Enables or disables collision response (default is of course on)
- // inline void setCollisionResponse(bool value)
- // { this->bCollisionResponseActive_ = value; this->collisionResponseActivityChanged(); }
-
-
- // //! Tells whether there could be a collision response
- // inline bool hasCollisionResponse()
- // { return this->bCollisionResponseActive_; }
-
-
-}
-
-
-
-
-
-/*
- void DronePickup::changedUsed(void)
- {
- SUPER(DronePickup, changedUsed);
-
- // If the pickup has transited to used.
- if(this->isUsed())
- {
-
- 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());
-
- Controller* controller = drone->getController();
- DroneController* droneController = orxonox_cast<DroneController*>(controller);
- if(droneController != nullptr)
- {
- droneController->setOwner(pawn);
- }
-
- Vector3 spawnPosition = pawn->getWorldPosition() + Vector3(30,0,-30);
- drone->setPosition(spawnPosition);
-
- // The pickup has been used up.
- this->setUsed(false);
- }
- else
- {
- // If either the pickup can only be used once or it is continuous and used up, it is destroyed upon setting it to unused.
- if(this->isOnce() || (this->isContinuous() ))
- {
- this->Pickupable::destroy();
- }
- }
- }
-*/
\ No newline at end of file
+}
\ No newline at end of file
Modified: code/branches/AsteroidMining_HS17/src/modules/asteroidmining/AsteroidMinable.h
===================================================================
--- code/branches/AsteroidMining_HS17/src/modules/asteroidmining/AsteroidMinable.h 2017-12-04 15:23:58 UTC (rev 11639)
+++ code/branches/AsteroidMining_HS17/src/modules/asteroidmining/AsteroidMinable.h 2017-12-04 15:38:17 UTC (rev 11640)
@@ -40,17 +40,15 @@
#include "../../orxonox/worldentities/pawns/Pawn.h"
-namespace orxonox // tolua_export
+namespace orxonox
{
- // tolua_export
- class _OrxonoxExport AsteroidMinable : public Pawn
- { // tolua_export
+ class _OrxonoxExport AsteroidMinable : public Pawn{
public:
AsteroidMinable(Context* context);// This constructor is for XML access only!
- AsteroidMinable(Context* c, float size, Vector3 position);// Call this Constructor from other C-files.
+ AsteroidMinable(Context* c, float size, Vector3 position, Vector3 velocity, bool dS);// Call this Constructor from other C-files.
virtual ~AsteroidMinable();
virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
@@ -61,29 +59,23 @@
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);
+ inline void setSize(int s){this->size = s;}
+ inline int getSize(){return this->size;}
+ inline void toggleShattering(bool b){this->generateSmaller = b;}
+ inline void toggleDropStuff(bool b){this->dropStuff = b;}
- virtual void setSize(float f);
- virtual float getSize();
- virtual void toggleShattering(bool b);
+ protected:
+ Context* context;
-
-
-
- protected:
- // Da neue Argumente reinstellen
- //float asteroidVersion; // Bodenstrich-Konvention?,
- // Wert zwischen 1 und 6 (Spezialdinger?), die Mesh-Form
- float size;
+ int size;
bool generateSmaller;
+ bool dropStuff;
bool initialised;
- Context* context;
-
virtual void death();
- virtual void putStuff();
@@ -90,8 +82,11 @@
private:
void registerVariables();
virtual void spawnChildren();
+ virtual void putStuff();
- void printArrayString(float thingy[]);// Just for testing
+ // @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
Modified: code/branches/AsteroidMining_HS17/src/modules/asteroidmining/CMakeLists.txt
===================================================================
--- code/branches/AsteroidMining_HS17/src/modules/asteroidmining/CMakeLists.txt 2017-12-04 15:23:58 UTC (rev 11639)
+++ code/branches/AsteroidMining_HS17/src/modules/asteroidmining/CMakeLists.txt 2017-12-04 15:38:17 UTC (rev 11640)
@@ -1,5 +1,6 @@
SET_SOURCE_FILES(PICKUP_SRC_FILES
AsteroidMinable.cc
+ SpicedAsteroidField.cc
)
ORXONOX_ADD_LIBRARY(asteroidmining
Modified: code/branches/AsteroidMining_HS17/src/modules/asteroidmining/SpicedAsteroidField.cc
===================================================================
--- code/branches/AsteroidMining_HS17/src/modules/asteroidmining/SpicedAsteroidField.cc 2017-12-04 15:23:58 UTC (rev 11639)
+++ code/branches/AsteroidMining_HS17/src/modules/asteroidmining/SpicedAsteroidField.cc 2017-12-04 15:38:17 UTC (rev 11640)
@@ -30,10 +30,17 @@
*
*
-*<OFFEN Describe
+*<OFFEN Describe
+Math from asteroidField.lua used.
*
*
+
+DESCRIPTION
+o Andere: Simpel wie in asteroidField.lua, oder einfach Asteroiden, die nichts abwerfen?
+--> Letzteres scheint passender, simpler.
+
+
*/
@@ -76,22 +83,22 @@
{
RegisterClass(SpicedAsteroidField);
- SpicedAsteroidField::SpicedAsteroidField(Context* context) {
+ SpicedAsteroidField::SpicedAsteroidField(Context* context) : Pawn(context) {
// Da auch noetig? Wegen set in XML-Code?
RegisterObject(SpicedAsteroidField);
this->context = context;
- this->initialised = false;
+ this->foggy = true;
+ this->fogDensity = 0.5;
- //Noetig, damit nicht sofort zerstoert?
- this->setCollisionType(WorldEntity::CollisionType::Dynamic);
-
// Old from Pawn
this->registerVariables();
- orxout() << "AsteroidMining:: Pseudo-Konstruktor passiert!" << endl;
+ // this->create();
+ this->bAlive_ = false;
+ this->destroyLater();
}
SpicedAsteroidField::~SpicedAsteroidField(){
@@ -100,14 +107,59 @@
void SpicedAsteroidField::create(){
+ int size;
+ int pX;
+ int pY;
+ int pZ;
+ 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);
+
+ pX = round(rnd()*2*this->radius) - radius;
+ pY = round(rnd()*2*this->radius) - radius;
+ pZ = round(rnd()*2*this->radius) - radius;
+ relPos = new Vector3(pX, pY, pZ);
+ a->setPosition(this->position + *relPos);
+
+ bool spiced = (rnd() < (this->mDensity)); // does drop pickups etc.
+ a->toggleDropStuff(spiced);
+
+ // @TODO: Fox Fog stuff, error due to billbord
+
+// Billboard* bb;
+// if(this->foggy && mod(gertrud, 5) == 0){
+// bb = new Billboard(this->context);
+// bb->setPosition(this-position + *relPos);
+// bb->setMaterial("Smoke/Smoke");
+// bb->setScale(size); // tricky?
+
+// bb->setColour(ColourValue(this-fogDensity, this->fogDensity, this->fogDensity)); // 4rd argument = transparency?
+
+// // print("<Billboard ")
+// // print("position = \"")
+// // print(posX) print(",")
+// // print(posY) print(",")
+// // print(posZ) print("\" ")
+// // print("colour=\"")
+// // print(brightness) print(",")
+// // print(brightness) print(",")
+// // print(brightness) print("\" ")
+// // print("material=\"Smoke/Smoke\" scale=")
+// // print(size)
+// // print(" />")
+// }
+ }
}
void SpicedAsteroidField::XMLPort(Element& xmlelement, XMLPort::Mode mode)
{
- SUPER(SpicedAsteroidField, XMLPort, xmlelement, mode);
+ // SUPER(SpicedAsteroidField, XMLPort, xmlelement, mode);
// XMLPortParam(PickupSpawner, "pickup", setPickupTemplateName, getPickupTemplateName, xmlelement, mode);
XMLPortParam(SpicedAsteroidField, "count", setCount, getCount, xmlelement, mode);
XMLPortParam(SpicedAsteroidField, "mDensity", setMineralDensity, getMineralDensity, xmlelement, mode);
@@ -116,8 +168,8 @@
XMLPortParam(SpicedAsteroidField, "minSize", setMinSize, getMinSize, xmlelement, mode);
XMLPortParam(SpicedAsteroidField, "radius", setRadius, getRadius, xmlelement, mode);
XMLPortParam(SpicedAsteroidField, "foggy", setFog, isFoggy, xmlelement, mode);
+ XMLPortParam(SpicedAsteroidField, "fogDensity", setFogDensity, getFogDensity, xmlelement, mode);
-
}
@@ -125,7 +177,7 @@
void SpicedAsteroidField::XMLEventPort(Element& xmlelement, XMLPort::Mode mode)
{
- SUPER(SpicedAsteroidField, XMLEventPort, xmlelement, mode);
+ // SUPER(SpicedAsteroidField, XMLEventPort, xmlelement, mode);
XMLPortEventState(SpicedAsteroidField, BaseObject, "vulnerability", setVulnerable, xmlelement, mode);
}
@@ -132,36 +184,130 @@
void SpicedAsteroidField::registerVariables()
{
- // registerVariable(this->bAlive_, VariableDirection::ToClient);
- // registerVariable(this->bVulnerable_, VariableDirection::ToClient);
- // registerVariable(this->health_, VariableDirection::ToClient);
- // registerVariable(this->maxHealth_, VariableDirection::ToClient);
- registerVariable(this->size, VariableDirection::ToClient);
- registerVariable(this->generateSmaller, VariableDirection::ToClient);
+ registerVariable(this->count, VariableDirection::ToClient);
+ registerVariable(this->mDensity, VariableDirection::ToClient);
+ registerVariable(this->position, VariableDirection::ToClient);
+ registerVariable(this->maxSize, VariableDirection::ToClient);
+ registerVariable(this->minSize, VariableDirection::ToClient);
+ registerVariable(this->radius, VariableDirection::ToClient);
+ registerVariable(this->foggy, VariableDirection::ToClient);
+ registerVariable(this->fogDensity, VariableDirection::ToClient);
- registerVariable(this->initialised, VariableDirection::ToClient);
- //registerVariable(this->context, VariableDirection::ToClient); // can't link that since it's a context
+ }
- // float size;
- // bool generateSmaller;
- // bool initialised;
+ void SpicedAsteroidField::tick(float dt){
- // Context* context;
+ this->create();
+ this->bAlive_ = false;
+ this->destroyLater();
}
- void SpicedAsteroidField::tick(float dt)
- {
- this->create();
- this->~SpicedAsteroidField(); // seems dangerous. Necessary for efficiency?
- }
+}
+// --[[ fog generator
+// generates fog
+// posX, posY, posZ - position in space
+// size - size of billboard
+// brightness - [0,1] fog brightness
+// --]]
+// function generateFog(posX, posY, posZ, size, brightness)
+// print("<Billboard ")
+// print("position = \"")
+// print(posX) print(",")
+// print(posY) print(",")
+// print(posZ) print("\" ")
+// print("colour=\"")
+// print(brightness) print(",")
+// print(brightness) print(",")
+// print(brightness) print("\" ")
+// print("material=\"Smoke/Smoke\" scale=")
+// print(size)
+// print(" />")
+// end
+// --[[ asteroid field generator
+// generates asteroid field
+// posX, posY, posZ - position in space
+// minSize, maxSize - size boundaries of each asteroid
+// radius - size of the cube around position in space
+// count - number of asteroids
+// fog - enable fog 0/1
+// --]]
+// function asteroidField(posX, posY, posZ, minSize, maxSize, radius, count, fog)
+// for i = 1, count, 1 do
+// size = (math.random() * (maxSize - minSize)) + minSize
+// pX = (2 * math.random() * radius) - radius + posX
+// pY = (2 * math.random() * radius) - radius + posY
+// pZ = (2 * math.random() * radius) - radius + posZ
+// print("<StaticEntity ")
+// print("position = \"")
+// print(pX) print(",")
+// print(pY) print(",")
+// print(pZ) print("\" ")
-}
+// print("scale = \"") print(size) print("\" ")
+
+// print("collisionType = static linearDamping = 0.8 angularDamping = 1 ")
+// print("collisiondamage = 1000 enablecollisiondamage = true>")
+
+// print("<attached>")
+// print("<Model mass=\"") print(size * 10) print("\" ")
+// print("mesh=\"ast") print(math.mod(i,6) + 1) print(".mesh\" />")
+// print("</attached>")
+
+// print("<collisionShapes> ")
+// print("<SphereCollisionShape radius=\"")
+// print(size * 2.5) print("\" />")
+// print("</collisionShapes>")
+
+// print("</StaticEntity>")
+
+// if fog == 1 and i % 5 == 0 then
+// generateFog(pX, pY, pZ, radius*0.04, 0.2)
+// end
+// end
+// end
+
+
+// --[[ asteroid belt generator
+// generates asteroid belt
+// posX, posY, posZ - position in space
+// yaw, pitch - rotation
+// minSize, maxSize - size boundaries of each asteroid
+// radius0, radius1 - inner/outer radius
+// count - number of asteroids
+// fog - enable fog 0/1
+// --]]
+// function asteroidBelt(centerX, centerY, centerZ, yaw, pitch, segments, minSize, maxSize, radius0, radius1, count, fog)
+// dPhi = (2 * math.pi) / segments
+// width = math.abs(radius1 - radius0)
+// radius = (radius1 + radius0) / 2
+// segmentCount = count / segments
+
+// print("<StaticEntity collisionType=static yaw=") print(yaw)
+// print(" pitch=") print(pitch)
+
+// print(" position = \"")
+// print(centerX) print(",")
+// print(centerY) print(",")
+// print(centerZ) print("\"")
+// print(">")
+
+// print("<attached>")
+
+// for i = 0, segments - 1, 1 do
+// asteroidField((radius * math.cos(i * dPhi)),
+// (radius * math.sin(i * dPhi)),
+// 0, minSize, maxSize, width, segmentCount, fog)
+// end
+
+// print("</attached>")
+// print("</StaticEntity>")
+// end
Modified: code/branches/AsteroidMining_HS17/src/modules/asteroidmining/SpicedAsteroidField.h
===================================================================
--- code/branches/AsteroidMining_HS17/src/modules/asteroidmining/SpicedAsteroidField.h 2017-12-04 15:23:58 UTC (rev 11639)
+++ code/branches/AsteroidMining_HS17/src/modules/asteroidmining/SpicedAsteroidField.h 2017-12-04 15:38:17 UTC (rev 11640)
@@ -45,7 +45,7 @@
// tolua_export
- class _OrxonoxExport SpicedAsteroidField
+ class _OrxonoxExport SpicedAsteroidField : public Pawn // need pawn to get tick for clean argument passing
{ // tolua_export
public:
@@ -64,7 +64,7 @@
inline float getMineralDensity(){return this->mDensity;}
inline void setPosition(Vector3 v){this->position = v;}
- inline Vector3 getPosition(){returrn this->position;}
+ inline Vector3 getPosition(){return this->position;}
inline void setMaxSize(int i){this->maxSize = i;}
inline int getMaxSize(){return this->maxSize;}
@@ -78,6 +78,9 @@
inline void setFog(bool f){this->foggy = f;}
inline bool isFoggy(){return this->foggy;}
+ inline void setFogDensity(float fd){this->fogDensity = fd;}
+ inline float getFogDensity(){return this->fogDensity;}
+
protected:
// Da neue Argumente reinstellen
//float asteroidVersion; // Bodenstrich-Konvention?,
@@ -86,13 +89,14 @@
float mDensity; // Mineral density, between 0 and 1;
Vector3 position;
- bool initialised;
Context* context;
+
int maxSize;
int minSize;
float radius;
bool foggy;
+ float fogDensity;
virtual void create();
More information about the Orxonox-commit
mailing list