Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

third reactionMode added

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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   
Note: See TracChangeset for help on using the changeset viewer.