Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Dec 4, 2017, 4:38:17 PM (7 years ago)
Author:
remartin
Message:

Das Aufteilen funktioniert nun gut. AsteroidField fertiggestellt und mit dokumentieren begonnen.

Location:
code/branches/AsteroidMining_HS17/src/modules/asteroidmining
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • code/branches/AsteroidMining_HS17/src/modules/asteroidmining/AsteroidMinable.cc

    r11618 r11640  
    4343++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    4444
    45 FRAGEN:
    46 * Zeilen-Loeschung beim output
    47 * orxout()-Problem
    48 * dokumentieren mit @brief?
    49 * Warnumg aus Asteroidenzerstoerung
    50 
    5145
    5246KNACKPUNKTE:
    5347
    54 
    5548OFFEN:
    56 
    57 o Mass distribution -> weird for bigger asteroids
    58 --> more testing
    59 
    60 o SpicedAsteroidField fertigstellen, Mineraldichten-Parameter
    6149
    6250o Add custom pickup 'resources'. Weird template stuff -> Problems setting 'size' and other properties? setNumber of Resources.
     
    6553----> im MineralsPickup die isPickedUp()-Methode überschreiben?
    6654--> data_extern/images/effects: PNG's für die Pickups und GUI-Dinger.
    67 
    68 o inherit parent velocity
     55--> https://www.orxonox.net/jenkins/view/Management/job/orxonox_doxygen_trunk/javadoc/group___pickup.html
     56
     57o Anfangsgeschwindigkeit fuers Asteroidenfeld
     58o Density doesn't add up to 1...
    6959o set collisionDamage? Just for static entities?
     60o AsteroidBelt?
     61
    7062o Dokumentieren mit @brief?
    71 
     63o unregister -empty- asteroids from radar. (or turn them green or whatever)
     64o Add sound effect (crunching etc. ) (No sound in space...)
    7265o Explosion parts
    7366o custom HUD
     67
    7468
    7569HANDBUCH:
     
    8579o Pawn.h: Attribut acceptsPickups_ inklusive get/set.
    8680
    87 ERLEGT:
     81ERLEGTE FEHLER:
    8882o Rand() geht bis zu riesigen Nummern!
    8983o Pickupgenerierung: vgl. Fremdanpassungen.
     
    158152    RegisterClass(AsteroidMinable);
    159153
    160 
    161     // This constructor is for XML access only.
     154    // @brief Standard constructor
    162155    AsteroidMinable::AsteroidMinable(Context* context) : Pawn(context){
    163156
    164         // Da auch noetig? Wegen set in XML-Code?
    165157        RegisterObject(AsteroidMinable);
    166158
    167159        this->context = context;
    168160        this->initialised = false;
     161        this->dropStuff = true; // Default
    169162
    170163        //Noetig, damit nicht sofort zerstoert?
     
    178171    }
    179172
    180     // Call this one from other C-files. Takes arguments.
    181     AsteroidMinable::AsteroidMinable(Context* c, float size, Vector3 position) : Pawn(c){
     173    // @brief Use this constructor with care. Mainly used internally, arguments are passed directly.
     174    AsteroidMinable::AsteroidMinable(Context* c, float size, Vector3 position, Vector3 v, bool dropStuff) : Pawn(c){
    182175
    183176        RegisterObject(AsteroidMinable);
    184177
    185         // Old stuff from pawn
    186         this->setRadarObjectColour(ColourValue(1.0f, 1.0f, 0.0f, 1.0f));
    187         this->setRadarObjectShape(RadarViewable::Shape::Dot);
     178        // The radar is able to detect whether an asteroid contains resources....
     179        if(dropStuff){
     180            this->setRadarObjectColour(ColourValue(1.0f, 1.0f, 0.0f, 1.0f));
     181            this->setRadarObjectShape(RadarViewable::Shape::Dot);
     182        }else{
     183            // Somehow remove from radar?
     184        }
     185
    188186        this->setCollisionType(WorldEntity::CollisionType::Dynamic);
    189 
    190187        this->enableCollisionCallback();
    191188
    192189        // Default Values
    193         this->generateSmaller = true;
    194190        this->context = c;
    195191        this->size = size;
    196192        this->health_ = 15*size;
    197193        this->maxHealth_ = this->health_;
    198         this->acceptsPickups_ = false;
     194        this->acceptsPickups_ = false;
     195        this->generateSmaller = true;
     196        this->dropStuff = dropStuff;
    199197
    200198        this->setPosition(position);
     199        this->setVelocity(v); // velocity = v; // The right one?
    201200        //this->roll = rand()*5; //etwas Drehung. richtige Variable
    202201
     
    228227
    229228    }
    230 
     229    // @brief Helper method. Create a new asteroid to have an appropriate size for the collision shape etc.
    231230    void AsteroidMinable::putStuff(){
    232231
    233232        // Just create a new asteroid to avoid Collision shape scale problems etc.
    234         AsteroidMinable* reborn = new AsteroidMinable(this->context, this->size, this->getPosition());
     233        AsteroidMinable* reborn = new AsteroidMinable(this->context, this->size, this->getPosition(), this->getVelocity(), this->dropStuff);
    235234        reborn->toggleShattering(true); // mainly here to avoid 'unused' warning.
    236         this->~AsteroidMinable(); // seems dangerous, yields warning.  Necessary for efficiency?
     235        this->bAlive_ = false;
     236        this->destroyLater();
     237        //this->~AsteroidMinable(); // seems dangerous, yields warning.  Necessary for efficiency?
    237238
    238239    }
     
    276277    }
    277278
    278     void AsteroidMinable::setSize(float s){
    279         this->size = s;
    280     }
    281 
    282     float AsteroidMinable::getSize(){
    283         return this->size;
    284     }
    285 
    286     void AsteroidMinable::toggleShattering(bool b){
    287         this->generateSmaller = b;
    288     }
     279
    289280
    290281
     
    304295
    305296
    306         // Stuff that can be harvested.
    307         PickupSpawner* thingy = new PickupSpawner(this->context);
    308         // OFFEN: more precise size relation in custom resource pickup.
    309         char tname[] = ""; // can-t overwrite strings easily in C (strcat etc.)
    310         if(this->size <= 5){
    311             strcat(tname, "smallmunitionpickup");
    312         }else if(this->size <= 20){
    313             strcat(tname, "mediummunitionpickup");
    314         }else{
    315             strcat(tname, "hugemunitionpickup");
    316         }
    317         thingy->setPickupTemplateName(tname);
    318         thingy->setPosition(this->getPosition());
    319         thingy->setMaxSpawnedItems(1); // Would be default anyways
    320         thingy->setRespawnTime(0.2f);
    321 
     297        // Pickups which can be harvested.
     298        if(dropStuff){
     299            PickupSpawner* thingy = new PickupSpawner(this->context);
     300            // OFFEN: more precise size relation in custom resource pickup.
     301            char tname[] = ""; // can-t overwrite strings easily in C (strcat etc.)
     302            if(this->size <= 5){
     303                strcat(tname, "smallmunitionpickup");
     304            }else if(this->size <= 20){
     305                strcat(tname, "mediummunitionpickup");
     306            }else{
     307                strcat(tname, "hugemunitionpickup");
     308            }
     309            thingy->setPickupTemplateName(tname);
     310            thingy->setPosition(this->getPosition());
     311            thingy->setMaxSpawnedItems(1); // Would be default anyways
     312            thingy->setRespawnTime(0.2f);
     313        }
    322314        // orxout() << "AsteroidMining::Death(): Passed Pickup stuff!" << endl;
    323315
     
    339331    if(num > 10){num = 10;} // no max function in C!
    340332    int masses[num]; // Masses of the asteroids, at least one.
    341     orxout() << "SpawnChildren(): Passed basic stuff. num = " << num << "; massRem(total) = "<< massRem << endl;
     333    //orxout() << "SpawnChildren(): Passed basic stuff. num = " << num << "; massRem(total) = "<< massRem << endl;
    342334
    343335    massRem = massRem-num; // mass is at least one, add again below.
     
    346338    float phi[num] = {0.0}; // assuming that it gets initialised to 0. Add (= {0.0})?
    347339    float theta[num] = {0.0};
    348     float piG = pi; // ist statisch oder so.
     340    float piG = 3.1415927410125732421875; //pi; // Math.pi ist statisch oder so.
    349341
    350342    float d_p = 2*piG/num;
     
    380372    //orxout() << "SpawnChildren(): Phi: "; printArrayString(phi);
    381373    //orxout() << "SpawnChildren(): Theta: "; printArrayString(theta);
    382     orxout() << "SpawnChildren(): Passed angle stuff. " << endl;
    383 
    384     // 'Triangular', discrete probability density with max at the expected value massRem/num at a. a+b = c
     374    //orxout() << "SpawnChildren(): Passed angle stuff. " << endl;
     375
     376    // 'Triangular', discrete probability "density" with max at the expected value massRem/num at a. a+b = c
    385377    if(massRem>0){ // Required to avoid array of size 0 or access problems
    386378        int c = massRem;
     
    397389        for(z = 0; z<b; ++z){probDensity[c-z] = (z+1)*dProbB;} // falling part
    398390   
    399         // Testing
    400         for(int globi = 0; globi<c; ++globi){
    401             orxout() << "pDensity at [" << globi << "] is: " << probDensity[globi] << endl;
    402         }
     391        // // Just for testing:
     392        // float sum = 0.0;
     393        // for(int globi = 0; globi<c; ++globi){
     394        //     orxout() << "pDensity at [" << globi << "] is: " << probDensity[globi] << endl;
     395        //     sum = sum+ probDensity[globi];
     396        // }
     397        // orxout() << "Sum of densities should b 1, it is: " << sum << endl;
    403398
    404399        // Distributing the mass to individual asteroids
     
    409404            result = 0;// reset
    410405            rVal = rnd();// between 0 and 1
    411             orxout() << "Random Value picked: " << rVal << endl;
     406            // orxout() << "Random Value picked: " << rVal << endl;
    412407            probSum = probDensity[0];
    413408            //orxout() << "Sum at start: " << probSum << endl;
    414409
    415410            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
     411                if(result<(massRem-2)){probSum = probSum + probDensity[result+1];} // avoid logical/acess error
    417412                ++result;
    418                 //orxout() << "Sum so far: " << probSum << endl;
     413                // orxout() << "Sum so far: " << probSum << ". Just added " << probDensity[result+1] << endl;
    419414            }
    420415
    421416            massRem = massRem-result;
    422417            masses[trav] = 1 +result; // at least one
    423             orxout() << "Mass chosen for child " << trav << " is: " << masses[trav] << endl;
     418            // orxout() << "Mass chosen for child " << trav << " is: " << masses[trav] << endl;
    424419
    425420        }
     
    430425    }
    431426
    432     //orxout() << "SpawnChildren(): Masses: "; printArrayString(masses);
    433     orxout() << "SpawnChildren(): Passed mass stuff. " << endl;
     427    // orxout() << "SpawnChildren(): Masses: "; printArrayString(masses);
     428    // orxout() << "SpawnChildren(): Passed mass stuff. " << endl;
    434429
    435430    // Creating the 'chlidren':
     
    442437        }
    443438       
    444         //orxout() << "Creating asteroid with mass " << masses[fisch] << " at relative postition " << *pos << endl;
    445         AsteroidMinable* child = new AsteroidMinable(this->context, masses[fisch], this->getPosition() + *pos);
     439        // orxout() << "Creating asteroid with mass " << masses[fisch] << " at relative postition " << *pos << endl;
     440        AsteroidMinable* child = new AsteroidMinable(this->context, masses[fisch], this->getPosition() + *pos, this->getVelocity(), this->dropStuff);
    446441
    447442        if(child == nullptr){
     
    450445
    451446    }
    452     orxout() << "Leaving spawnChildren() method. " << endl;
     447    // orxout() << "Leaving spawnChildren() method. " << endl;
    453448}
    454449
     
    458453        orxout() << "AsteroidMining::Hit(Variante 1) Dings aufgerufen. " << endl;
    459454
    460         // Kollision mit anderem Asteroid oder Pickup (OFFEN: evtl. Spawner oder irgendwas?) verhindern. In diesem Fall einfach nichts tun.
     455        // Kollision mit anderem Asteroid oder Pickup verhindern. In diesem Fall einfach nichts tun.
    461456        // Wird staending aufgerufen -> Rechenleistung?
    462457        if(orxonox_cast<AsteroidMinable*>(originator) || orxonox_cast<Pickup*>(originator)){return;}
     
    496491    }
    497492
     493    // @brief Just for testing. Don-t work anyways.
    498494    void AsteroidMinable::printArrayString(float thingy[]){ // Don-t work!
    499495
     
    509505    }
    510506
     507    // @brief Just for testing. Don-t work anyways.
    511508    void AsteroidMinable::printArrayString(int thingy[]){
    512509
     
    524521    }
    525522
    526 
    527523    // void AsteroidMinable::printArrayString(int thingy[]){
    528 
    529524    //     char res[] = "[";
    530525    //     //strcat(res, "[");
     
    547542    // }
    548543
    549 
    550 
    551 //Pawn:
    552     // void Pawn::hit(Pawn* originator, const Vector3& force, const btCollisionShape* cs, float damage, float healthdamage, float shielddamage)
    553     // {
    554     //     if (this->getGametype() && this->getGametype()->allowPawnHit(this, originator) && (!this->getController() || !this->getController()->getGodMode()) )
    555     //     {
    556     //         this->damage(damage, healthdamage, shielddamage, originator, cs);
    557     //         this->setVelocity(this->getVelocity() + force);
    558     //     }
    559     // }
    560 
    561     // void Pawn::hit(Pawn* originator, btManifoldPoint& contactpoint, const btCollisionShape* cs, float damage, float healthdamage, float shielddamage)
    562     // {
    563     //     if (this->getGametype() && this->getGametype()->allowPawnHit(this, originator) && (!this->getController() || !this->getController()->getGodMode()) )
    564     //     {
    565     //         this->damage(damage, healthdamage, shielddamage, originator, cs);
    566 
    567     //         if ( this->getController() )
    568     //             this->getController()->hit(originator, contactpoint, damage); // changed to damage, why shielddamage?
    569     //     }
    570     // }
    571 
    572 
    573 
    574 
    575             // /**
    576             // @brief
    577             //     Virtual function that gets called when this object collides with another.
    578             // @param otherObject
    579             //     The object this one has collided into.
    580             // @param ownCollisionShape
    581             //     The collision shape of the other object
    582             // @param contactPoint
    583             //     Contact point provided by Bullet. Holds more information and can me modified. See return value.
    584             // @return
    585             //     Returning false means that no modification to the contactPoint has been made. Return true otherwise!
    586             // @note
    587             //     Condition is that enableCollisionCallback() was called.
    588             // */
    589             // virtual inline bool collidesAgainst(WorldEntity* otherObject, const btCollisionShape* ownCollisionShape, btManifoldPoint& contactPoint)
    590             //     { return false; } /* With false, Bullet assumes no modification to the collision objects. */
    591 
    592             // //! Enables the collidesAgainst(.) function. The object doesn't respond to collision otherwise!
    593             // inline void enableCollisionCallback()
    594             //     { this->bCollisionCallbackActive_ = true; this->collisionCallbackActivityChanged(); }
    595 
    596 
    597 
    598             // //! Disables the collidesAgainst(.) function. @see enableCollisionCallback()
    599             // inline void disableCollisionCallback()
    600             //     { this->bCollisionCallbackActive_ = false; this->collisionCallbackActivityChanged(); }
    601 
    602 
    603             // //! Tells whether there could be a collision callback via collidesAgainst(.)
    604             // inline bool isCollisionCallbackActive() const
    605             //     { return this->bCollisionCallbackActive_; }
    606 
    607             // //! Enables or disables collision response (default is of course on)
    608             // inline void setCollisionResponse(bool value)
    609             //     { this->bCollisionResponseActive_ = value; this->collisionResponseActivityChanged(); }
    610 
    611 
    612             // //! Tells whether there could be a collision response
    613             // inline bool hasCollisionResponse()
    614             //     { return this->bCollisionResponseActive_; }
    615 
    616 
    617544}
    618 
    619 
    620 
    621 
    622 
    623 /*
    624     void DronePickup::changedUsed(void)
    625     {
    626         SUPER(DronePickup, changedUsed);
    627 
    628         // If the pickup has transited to used.
    629         if(this->isUsed())
    630         {
    631 
    632                 Pawn* pawn = this->carrierToPawnHelper();
    633                 if(pawn == nullptr) // If the PickupCarrier is no Pawn, then this pickup is useless and therefore is destroyed.
    634                     this->Pickupable::destroy();
    635 
    636                 //Attach to pawn
    637                 Drone* drone = new Drone(pawn->getContext()); // this is neccessary because the projectiles fired need a valid creator for the particlespawner (when colliding against something)
    638                 drone->addTemplate(this->getDroneTemplate());
    639 
    640                 Controller* controller = drone->getController();
    641                 DroneController* droneController = orxonox_cast<DroneController*>(controller);
    642                 if(droneController != nullptr)
    643                 {
    644                     droneController->setOwner(pawn);
    645                 }
    646 
    647                 Vector3 spawnPosition = pawn->getWorldPosition() + Vector3(30,0,-30);
    648                 drone->setPosition(spawnPosition);
    649 
    650                 // The pickup has been used up.
    651                 this->setUsed(false);
    652         }
    653         else
    654         {
    655             // If either the pickup can only be used once or it is continuous and used up, it is destroyed upon setting it to unused.
    656             if(this->isOnce() || (this->isContinuous() ))
    657             {
    658                 this->Pickupable::destroy();
    659             }
    660         }
    661     }
    662 */
  • code/branches/AsteroidMining_HS17/src/modules/asteroidmining/AsteroidMinable.h

    r11618 r11640  
    4141#include "../../orxonox/worldentities/pawns/Pawn.h"
    4242
    43 namespace orxonox // tolua_export
     43namespace orxonox
    4444{
    4545
    4646
    47     // tolua_export
    48     class _OrxonoxExport AsteroidMinable : public Pawn
    49     { // tolua_export
     47    class _OrxonoxExport AsteroidMinable : public Pawn{
    5048
    5149        public:
    5250            AsteroidMinable(Context* context);// This constructor is for XML access only!
    53             AsteroidMinable(Context* c, float size, Vector3 position);// Call this Constructor from other C-files.
     51            AsteroidMinable(Context* c, float size, Vector3 position, Vector3 velocity, bool dS);// Call this Constructor from other C-files.
    5452
    5553            virtual ~AsteroidMinable();
     
    6260            virtual void hit(Pawn* originator, btManifoldPoint& contactpoint, const btCollisionShape* cs, float damage, float healthdamage = 0.0f, float shielddamage = 0.0f);
    6361
     62            inline void setSize(int s){this->size = s;}
     63            inline int getSize(){return this->size;}
    6464
    65 
    66             virtual void setSize(float f);
    67             virtual float getSize();
    68 
    69             virtual void toggleShattering(bool b);
    70 
    71 
    72 
     65            inline void toggleShattering(bool b){this->generateSmaller = b;}
     66            inline void toggleDropStuff(bool b){this->dropStuff = b;}
    7367
    7468
    7569        protected:
    76             // Da neue Argumente reinstellen
    77             //float asteroidVersion; // Bodenstrich-Konvention?,
    78             // Wert zwischen 1 und 6 (Spezialdinger?), die Mesh-Form
    79             float size;
    80             bool generateSmaller;
    81             bool initialised;
    8270
    8371            Context* context;
    8472
     73            int size;
     74            bool generateSmaller;
     75            bool dropStuff;
     76            bool initialised;
     77
    8578            virtual void death();
    86             virtual void putStuff();
    8779
    8880
     
    9183            void registerVariables();
    9284            virtual void spawnChildren();
     85            virtual void putStuff();
    9386
    94             void printArrayString(float thingy[]);// Just for testing
     87            // @brief Just for testing. Don-t work anyways.
     88            void printArrayString(float thingy[]);
     89            // @brief Just for testing. Don-t work anyways.
    9590            void printArrayString(int thingy[]);// Just for testing
    9691
  • code/branches/AsteroidMining_HS17/src/modules/asteroidmining/CMakeLists.txt

    r11547 r11640  
    11SET_SOURCE_FILES(PICKUP_SRC_FILES
    22  AsteroidMinable.cc
     3  SpicedAsteroidField.cc
    34)
    45
  • code/branches/AsteroidMining_HS17/src/modules/asteroidmining/SpicedAsteroidField.cc

    r11615 r11640  
    3131*
    3232*
    33 *<OFFEN Describe
     33*<OFFEN Describe
     34Math from asteroidField.lua used.
    3435*
    3536*
     37
     38
     39DESCRIPTION
     40o Andere: Simpel wie in asteroidField.lua, oder einfach Asteroiden, die nichts abwerfen?
     41--> Letzteres scheint passender, simpler.
     42
    3643
    3744*/
     
    7784    RegisterClass(SpicedAsteroidField);
    7885
    79     SpicedAsteroidField::SpicedAsteroidField(Context* context) {
     86    SpicedAsteroidField::SpicedAsteroidField(Context* context) : Pawn(context) {
    8087
    8188        // Da auch noetig? Wegen set in XML-Code?
     
    8390
    8491        this->context = context;
    85         this->initialised = false;
    86 
    87         //Noetig, damit nicht sofort zerstoert?
    88         this->setCollisionType(WorldEntity::CollisionType::Dynamic);
     92        this->foggy = true;
     93        this->fogDensity = 0.5;
    8994
    9095        // Old from Pawn
    9196        this->registerVariables();
    9297
    93         orxout() << "AsteroidMining:: Pseudo-Konstruktor passiert!" << endl;
    94 
     98
     99        // this->create();
     100        this->bAlive_ = false;
     101        this->destroyLater();
    95102    }
    96103
     
    101108    void SpicedAsteroidField::create(){
    102109
    103 
    104 
    105 
     110        int size;
     111        int pX;
     112        int pY;
     113        int pZ;
     114
     115        Vector3* relPos;
     116
     117        for(int gertrud = 0; gertrud<count; ++gertrud){
     118
     119            AsteroidMinable* a = new AsteroidMinable(this->context);
     120
     121            size = round(rnd()*(this->maxSize - this->minSize)) + this->minSize;
     122            a->setSize(size);
     123
     124            pX = round(rnd()*2*this->radius) - radius;
     125            pY = round(rnd()*2*this->radius) - radius;
     126            pZ = round(rnd()*2*this->radius) - radius;
     127            relPos = new Vector3(pX, pY, pZ);
     128            a->setPosition(this->position + *relPos);
     129
     130            bool spiced = (rnd() < (this->mDensity)); // does drop pickups etc.
     131            a->toggleDropStuff(spiced);
     132
     133            // @TODO: Fox Fog stuff, error due to billbord
     134
     135//             Billboard* bb;
     136//             if(this->foggy && mod(gertrud, 5) == 0){
     137//                 bb = new Billboard(this->context);
     138//                 bb->setPosition(this-position + *relPos);
     139//                 bb->setMaterial("Smoke/Smoke");
     140//                 bb->setScale(size); // tricky?
     141
     142//                 bb->setColour(ColourValue(this-fogDensity, this->fogDensity, this->fogDensity)); // 4rd argument = transparency?
     143               
     144// //     print("<Billboard ")
     145// //         print("position = \"")
     146// //             print(posX) print(",")
     147// //             print(posY) print(",")
     148// //             print(posZ) print("\" ")
     149// //         print("colour=\"")
     150// //             print(brightness) print(",")
     151// //             print(brightness) print(",")
     152// //             print(brightness) print("\" ")
     153// //         print("material=\"Smoke/Smoke\" scale=")
     154// //         print(size)
     155// //     print(" />")
     156//             }
     157        }
    106158    }
    107159
    108160    void SpicedAsteroidField::XMLPort(Element& xmlelement, XMLPort::Mode mode)
    109161    {
    110         SUPER(SpicedAsteroidField, XMLPort, xmlelement, mode);
     162        // SUPER(SpicedAsteroidField, XMLPort, xmlelement, mode);
    111163        //        XMLPortParam(PickupSpawner, "pickup", setPickupTemplateName, getPickupTemplateName, xmlelement, mode);
    112164        XMLPortParam(SpicedAsteroidField, "count", setCount, getCount, xmlelement, mode);
     
    117169        XMLPortParam(SpicedAsteroidField, "radius", setRadius, getRadius, xmlelement, mode);
    118170        XMLPortParam(SpicedAsteroidField, "foggy", setFog, isFoggy, xmlelement, mode);
    119 
     171        XMLPortParam(SpicedAsteroidField, "fogDensity", setFogDensity, getFogDensity, xmlelement, mode);
    120172
    121173    }
     
    126178    void SpicedAsteroidField::XMLEventPort(Element& xmlelement, XMLPort::Mode mode)
    127179    {
    128         SUPER(SpicedAsteroidField, XMLEventPort, xmlelement, mode);
     180        // SUPER(SpicedAsteroidField, XMLEventPort, xmlelement, mode);
    129181
    130182        XMLPortEventState(SpicedAsteroidField, BaseObject, "vulnerability", setVulnerable, xmlelement, mode);
     
    133185    void SpicedAsteroidField::registerVariables()
    134186    {
    135         // registerVariable(this->bAlive_,            VariableDirection::ToClient);
    136         // registerVariable(this->bVulnerable_,       VariableDirection::ToClient);
    137         // registerVariable(this->health_,            VariableDirection::ToClient);
    138         // registerVariable(this->maxHealth_,         VariableDirection::ToClient);
    139 
    140         registerVariable(this->size, VariableDirection::ToClient);
    141         registerVariable(this->generateSmaller, VariableDirection::ToClient);
    142 
    143         registerVariable(this->initialised, VariableDirection::ToClient);
    144         //registerVariable(this->context, VariableDirection::ToClient); // can't link that since it's a context
    145 
    146 
    147             //         float size;
    148             // bool generateSmaller;
    149             // bool initialised;
    150 
    151             // Context* context;
    152     }
    153 
    154     void SpicedAsteroidField::tick(float dt)
    155     {
     187
     188        registerVariable(this->count, VariableDirection::ToClient);
     189        registerVariable(this->mDensity, VariableDirection::ToClient);
     190        registerVariable(this->position, VariableDirection::ToClient);
     191        registerVariable(this->maxSize, VariableDirection::ToClient);
     192        registerVariable(this->minSize, VariableDirection::ToClient);
     193        registerVariable(this->radius, VariableDirection::ToClient);
     194        registerVariable(this->foggy, VariableDirection::ToClient);
     195        registerVariable(this->fogDensity, VariableDirection::ToClient);
     196
     197
     198    }
     199
     200    void SpicedAsteroidField::tick(float dt){
    156201
    157202        this->create();
    158         this->~SpicedAsteroidField(); // seems dangerous. Necessary for efficiency?
    159 
    160 
     203        this->bAlive_ = false;
     204        this->destroyLater();
    161205    }
    162206
     
    166210
    167211}
     212
     213// --[[ fog generator
     214// generates fog
     215//     posX, posY, posZ - position in space
     216//     size - size of billboard
     217//     brightness - [0,1] fog brightness
     218// --]]
     219// function generateFog(posX, posY, posZ, size, brightness)
     220//     print("<Billboard ")
     221//         print("position = \"")
     222//             print(posX) print(",")
     223//             print(posY) print(",")
     224//             print(posZ) print("\" ")
     225//         print("colour=\"")
     226//             print(brightness) print(",")
     227//             print(brightness) print(",")
     228//             print(brightness) print("\" ")
     229//         print("material=\"Smoke/Smoke\" scale=")
     230//         print(size)
     231//     print(" />")
     232// end
     233
     234// --[[ asteroid field generator
     235// generates asteroid field
     236//     posX, posY, posZ - position in space
     237//     minSize, maxSize - size boundaries of each asteroid
     238//     radius - size of the cube around position in space
     239//     count - number of asteroids
     240//     fog - enable fog 0/1
     241// --]]
     242// function asteroidField(posX, posY, posZ, minSize, maxSize, radius, count, fog)
     243//     for i = 1, count, 1 do
     244//         size = (math.random() * (maxSize - minSize)) + minSize
     245//         pX = (2 * math.random() * radius) - radius + posX
     246//         pY = (2 * math.random() * radius) - radius + posY
     247//         pZ = (2 * math.random() * radius) - radius + posZ
     248//         print("<StaticEntity ")
     249
     250//         print("position = \"")
     251//         print(pX) print(",")
     252//         print(pY) print(",")
     253//         print(pZ) print("\" ")
     254
     255//         print("scale = \"") print(size) print("\" ")
     256
     257//         print("collisionType = static linearDamping = 0.8 angularDamping = 1 ")
     258//         print("collisiondamage = 1000 enablecollisiondamage = true>")
     259
     260//         print("<attached>")
     261//             print("<Model mass=\"") print(size * 10) print("\" ")
     262//             print("mesh=\"ast") print(math.mod(i,6) + 1) print(".mesh\" />")
     263//         print("</attached>")
     264
     265//         print("<collisionShapes> ")
     266//             print("<SphereCollisionShape radius=\"")
     267//             print(size * 2.5) print("\" />")
     268//         print("</collisionShapes>")
     269
     270//         print("</StaticEntity>")
     271
     272//         if fog == 1 and i % 5 == 0 then
     273//             generateFog(pX, pY, pZ, radius*0.04, 0.2)
     274//         end
     275//     end
     276// end
     277
     278
     279// --[[ asteroid belt generator
     280// generates asteroid belt
     281//     posX, posY, posZ - position in space
     282//     yaw, pitch - rotation
     283//     minSize, maxSize - size boundaries of each asteroid
     284//     radius0, radius1 - inner/outer radius
     285//     count - number of asteroids
     286//     fog - enable fog 0/1
     287// --]]
     288// function asteroidBelt(centerX, centerY, centerZ, yaw, pitch, segments, minSize, maxSize, radius0, radius1, count, fog)
     289//     dPhi = (2 * math.pi) / segments
     290//     width = math.abs(radius1 - radius0)
     291//     radius = (radius1 + radius0) / 2
     292//     segmentCount = count / segments
     293
     294//     print("<StaticEntity collisionType=static yaw=") print(yaw)
     295//     print(" pitch=") print(pitch)
     296
     297//     print(" position = \"")
     298//         print(centerX) print(",")
     299//         print(centerY) print(",")
     300//         print(centerZ) print("\"")
     301//     print(">")
     302
     303//     print("<attached>")
     304
     305//     for i = 0, segments - 1, 1 do
     306//         asteroidField((radius * math.cos(i * dPhi)),
     307//                     (radius * math.sin(i * dPhi)),
     308//                     0, minSize, maxSize, width, segmentCount, fog)
     309//     end
     310
     311//     print("</attached>")
     312//     print("</StaticEntity>")
     313// end
  • code/branches/AsteroidMining_HS17/src/modules/asteroidmining/SpicedAsteroidField.h

    r11615 r11640  
    4646
    4747    // tolua_export
    48     class _OrxonoxExport SpicedAsteroidField
     48    class _OrxonoxExport SpicedAsteroidField : public Pawn // need pawn to get tick for clean argument passing
    4949    { // tolua_export
    5050
     
    6565
    6666            inline void setPosition(Vector3 v){this->position = v;}
    67             inline Vector3 getPosition(){returrn this->position;}
     67            inline Vector3 getPosition(){return this->position;}
    6868
    6969            inline void setMaxSize(int i){this->maxSize = i;}
     
    7979            inline bool isFoggy(){return this->foggy;}
    8080
     81            inline void setFogDensity(float fd){this->fogDensity = fd;}
     82            inline float getFogDensity(){return this->fogDensity;}
     83
    8184        protected:
    8285            // Da neue Argumente reinstellen
     
    8790
    8891            Vector3 position;
    89             bool initialised;
    9092            Context* context;
     93           
    9194            int maxSize;
    9295            int minSize;
     
    9497            float radius;
    9598            bool foggy;
     99            float fogDensity;
    96100
    97101            virtual void create();
Note: See TracChangeset for help on using the changeset viewer.