Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 8513


Ignore:
Timestamp:
May 19, 2011, 4:16:55 PM (13 years ago)
Author:
kmaurus
Message:

third reactionMode added

Location:
code/branches/spaceboundaries2
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • code/branches/spaceboundaries2/data/levels/myTestLevel.oxw

    r8468 r8513  
    3232    <SpawnPoint team=0 position="0,0,0" lookat="2,0,0" spawnclass=SpaceShip pawndesign=spaceshipassff />
    3333   
    34     <SpaceBoundaries warnDistance="1" maxDistance="200" showDistance="100" reactionMode="0" healthDecrease="0.9" position="0,0,0"/>
     34    <SpaceBoundaries warnDistance="1" maxDistance="200" showDistance="100" reactionMode="2" healthDecrease="0.9" position="0,0,0"/>
     35   
     36    <Billboard position="0,0,0" colour="1.0,1.0,1.0" material="Flares/backlightflare" scale=1 />
    3537   
    3638  </Scene>
  • code/branches/spaceboundaries2/src/orxonox/worldentities/SpaceBoundaries.cc

    r8506 r8513  
    8484                float distance = this->computeDistance(currentPawn);
    8585                if(distance <= this->maxDistance_)
     86                {
     87                    pawnsIn_.push_back(currentPawn);
     88                }
     89            } else if (this->reaction_ == 2) {
     90                float distance = this->computeDistance(currentPawn);
     91                if(distance >= this->maxDistance_)
    8692                {
    8793                    pawnsIn_.push_back(currentPawn);
     
    122128        if(billy != NULL)
    123129        {
    124             billy->setMaterial("Shield");
     130            billy->setMaterial("Grid");
    125131            billy->setVisible(true);
    126132        }
     
    216222                    }
    217223                }
    218                 if( humanItem && (this->maxDistance_ - distance) < this->showDistance_ )
     224                if(/* humanItem &&*/ abs(this->maxDistance_ - distance) < this->showDistance_ )
    219225                {
    220226                    this->displayBoundaries(currentPawn); // Zeige Grenze an!
     
    233239                    this->conditionalBounceBack(currentPawn, distance, dt);
    234240                }
     241                if( this->reaction_ == 2 && (distance - 100 < this->maxDistance_) )
     242                {
     243                    this->conditionalBounceBack(currentPawn, distance, dt);
     244                }
    235245            }
    236246        }
     
    273283        /* Checke, ob das Pawn innerhalb des nächsten Ticks, das erlaubte Gebiet verlassen würde.
    274284           Falls ja: Spicke es zurück. */
    275         if( currentDistance + normalSpeed * dt > this->maxDistance_ - 20 ) // -20: "security measure"
    276         {
    277             float dampingFactor = 0.5;
    278             velocity = velocity.reflect(normal);
    279             Vector3 acceleration = item->getAcceleration();
    280             acceleration = acceleration.reflect(normal);
    281            
    282             item->lookAt( velocity + this->getPosition() );
    283            
    284             item->setAcceleration(acceleration * dampingFactor);
    285             item->setVelocity(velocity * dampingFactor);
    286            
    287             item->setPosition( item->getPosition() - normal * 10 );
    288         }
     285        if( this->reaction_ == 0 && currentDistance + normalSpeed * dt > this->maxDistance_ - 10 ) // -10: "security measure"
     286        {
     287            bounceBack(item, &normal, &velocity);
     288        } else if (this->reaction_ == 2 && currentDistance - normalSpeed * dt < this->maxDistance_ + 10 ) // 10: "security measure"
     289        {
     290            normal = normal * (-1);
     291            bounceBack(item, &normal, &velocity);
     292        }
     293    }
     294   
     295    void SpaceBoundaries::bounceBack(Pawn *item, Vector3 *normal, Vector3 *velocity)
     296    {
     297        float dampingFactor = 0.5;
     298        *velocity = velocity->reflect(*normal);
     299        Vector3 acceleration = item->getAcceleration();
     300        acceleration = acceleration.reflect(*normal);
     301       
     302        item->lookAt( *velocity + this->getPosition() );
     303       
     304        item->setAcceleration(acceleration * dampingFactor);
     305        item->setVelocity(*velocity * dampingFactor);
     306       
     307        item->setPosition( item->getPosition() - *normal * 10 ); // Setze das SpaceShip noch etwas von der Grenze weg.
    289308    }
    290309   
  • code/branches/spaceboundaries2/src/orxonox/worldentities/SpaceBoundaries.h

    r8506 r8513  
    2727 */
    2828 
    29  /* TODO:   - Textmessages und Billboards sollen teils nur bei einem humanPlayer angezeigt werden, nicht bei allen (vgl. Netzwerk-Spiel mit mehreren humanPlayers)
     29 /* TODO:   - Bei Reaction_ == 2 ist die Reflexion noch nicht ganz so top!! Vielleicht auch so belassen, ist ja nicht unbedingt schlecht.
     30 
     31            - Textmessages und Billboards sollen teils nur bei einem humanPlayer angezeigt werden, nicht bei allen (vgl. Netzwerk-Spiel mit mehreren humanPlayers)
    3032                beachte hierzu folgende statische Funktion: 'static unsigned int  Host::getPlayerID()'
    3133                (file:///home/kmaurus/orxonox/spaceBoundaries/build/doc/api/html/classorxonox_1_1_host.html#9c1e3b39e3b42e467dfbf42902911ce2)
     
    6769                            0: Reflect the space ship (default).
    6870                            1: Decrease Health of the space ship after having left the allowed area.
     71                            2: Inverted Version of 0. Prohibit to fly INTO a defined area.
    6972       - 'healthDecrease' : a measure to define how fast the health of a pawn should decrease after leaving the allowed area (unnecessary if 'reactionMode' == 0).
    7073                            Recommended values: 0.1 (slow health decrease) to 5 (very fast health decrease)
     
    8891            SpaceBoundaries(BaseObject* creator);
    8992            ~SpaceBoundaries();
    90            
    91             void checkWhoIsIn(); //!< Update the list 'pawnsIn_'.
    92            
    93             void positionBillboard(const Vector3 position); //!< Display a Billboard at the position 'position'.
    94             void setBillboardOptions(Billboard *billy);
    95             void removeAllBillboards(); //!< Hide all elements of '*billboard_' and set their attribute 'usedYet' to 0.
    9693           
    9794            void setMaxDistance(float r);
     
    117114            struct billboardAdministration{ bool usedYet; Billboard* billy; };
    118115           
     116            // Variabeln::
    119117            std::list<WeakPtr<Pawn> > pawnsIn_; //!< List of the pawns that this instance of SpaceBoundaries has to handle.
    120118           
    121119            std::vector<billboardAdministration> billboards_;
    122120       
    123             int reaction_; //!< Werte: 0, 1. 0: Reflektion an Boundaries (Standard). 1: Health-Abzug-Modus.
     121            int reaction_; //!< Werte: 0, 1, 2.
     122                           //!< 0: Reflektion an Boundaries (Standard).
     123                           //!< 1: Health-Abzug-Modus.
     124                           //!< 2: Invertierte Version von 0. Verbiete es, in ein Gebiet hinein zu fliegen.
    124125            float maxDistance_; //!< maximal zulaessige Entfernung von 'this->getPosition()'.
    125126            float warnDistance_; //!< Entfernung von 'this->getPosition()', ab der eine Warnung angezeigt wird, dass man bald das zulaessige Areal verlaesst.
     
    129130                                   //!< Empfohlene Werte: 0.1 (langsame Health-Verminderung) bis 5 (sehr schnelle Health-Verminderung)
    130131           
     132           
    131133            RadarViewable* centerRadar_; //!< Repraesentation von SpaceBoundaries auf dem Radar.
    132134       
     135       
     136            // Funktionen::
    133137            float computeDistance(WorldEntity *item); //!< Auf den Mittelpunkt 'this->getPosition()' bezogen.
    134138            void displayWarning(const std::string warnText);
    135139            void displayBoundaries(Pawn *item);
    136140            void conditionalBounceBack(Pawn *item, float currentDistance, float dt);
     141            void bounceBack(Pawn *item, Vector3 *normal, Vector3 *velocity);
    137142            bool isHumanPlayer(Pawn *item);
     143           
     144            void checkWhoIsIn(); //!< Update the list 'pawnsIn_'.
     145           
     146            void positionBillboard(const Vector3 position); //!< Display a Billboard at the position 'position'.
     147            void setBillboardOptions(Billboard *billy);
     148            void removeAllBillboards(); //!< Hide all elements of '*billboard_' and set their attribute 'usedYet' to 0.
    138149           
    139150    };
Note: See TracChangeset for help on using the changeset viewer.