Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
May 23, 2011, 11:37:17 PM (13 years ago)
Author:
dafrick
Message:

Some additional cleanup.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/pickup/src/modules/pickup/items/ShrinkPickup.cc

    r8554 r8555  
    6060
    6161        this->initialize();
    62         this->shrinkFactor_ = 5.0;
    63         this->shrinkSpeed_ = 5.0;
    64         this->duration_ = 5.0;
    65         isActive_ = false;
    66         isTerminating_ = false;
     62        this->shrinkFactor_ = 5.0f;
     63        this->shrinkSpeed_ = 5.0f;
     64        this->duration_ = 5.0f;
     65        this->isActive_ = false;
     66        this->isTerminating_ = false;
     67
     68        this->size_ = 0;
     69        this->defaultCameraPos_ = 0.0f;
     70        this->defaultScale_ = Vector3::UNIT_SCALE;
     71        this->actualScale_ = Vector3::UNIT_SCALE;
     72        this->smallScale_ = Vector3::UNIT_SCALE;
     73        this->defaultMass_ = 1.0f;
     74        this->actualMass_ = 1.0f;
     75        this->smallMass_ = 1.0f;
     76        this->pawn_ = NULL;
    6777    }
    6878
     
    157167        {
    158168            this->pawn_ = this->carrierToPawnHelper();
    159             if(pawn_ == NULL) // If the PickupCarrier is no Pawn, then this pickup is useless and therefore is destroyed.
     169            if(this->pawn_ == NULL) // If the PickupCarrier is no Pawn, then this pickup is useless and therefore is destroyed.
    160170                this->Pickupable::destroy();
    161171
    162172            //Collect scaling information.
    163             defaultScale_ = this->pawn_->getScale3D();
    164             defaultMass_ = this->pawn_->getMass();
    165 
    166             smallScale_ = defaultScale_ / shrinkFactor_;
    167             smallMass_ = defaultMass_ / shrinkFactor_;
    168 
    169             actualScale_ = defaultScale_;
    170             actualMass_ = defaultMass_;
    171 
    172             cameraPositions_ = this->pawn_->getCameraPositions();
    173             size_ = cameraPositions_.size();
    174             isActive_ = true;    //start shrinking now.
    175             durationTimer_.setTimer(duration_, false, createExecutor(createFunctor(&ShrinkPickup::terminate, this)));    //Set timer for termination.
     173            this->defaultScale_ = this->pawn_->getScale3D();
     174            this->defaultMass_ = this->pawn_->getMass();
     175
     176            this->smallScale_ = this->defaultScale_ / this->shrinkFactor_;
     177            this->smallMass_ = this->defaultMass_ / this->shrinkFactor_;
     178
     179            this->actualScale_ = this->defaultScale_;
     180            this->actualMass_ = this->defaultMass_;
     181
     182            this->cameraPositions_ = this->pawn_->getCameraPositions();
     183            this->size_ = this->cameraPositions_.size();
     184            this->isActive_ = true;    //start shrinking now.
     185            this->durationTimer_.setTimer(this->duration_, false, createExecutor(createFunctor(&ShrinkPickup::terminate, this)));    //Set timer for termination.
    176186        }
    177187    }
     
    185195    void ShrinkPickup::tick(float dt)
    186196    {
    187         if(isActive_ == true && actualScale_ > smallScale_)    //if the ship has not reached the target scale, continue shrinking
     197        if(this->isActive_ == true && this->actualScale_ > this->smallScale_)    //if the ship has not reached the target scale, continue shrinking
    188198        {
    189             float factor_ = 1 + dt*shrinkSpeed_;
    190 
    191             actualScale_ /= factor_;
    192             actualMass_ /= factor_;
    193 
    194             this->pawn_->setScale3D(actualScale_);
    195             this->pawn_->setMass(actualMass_);
    196 
    197             for(int index = 0; index < size_; index++)
     199            float factor = 1 + dt*this->shrinkSpeed_;
     200
     201            this->actualScale_ /= factor;
     202            this->actualMass_ /= factor;
     203
     204            this->pawn_->setScale3D(this->actualScale_);
     205            this->pawn_->setMass(this->actualMass_);
     206
     207            for(int index = 0; index < this->size_; index++)
    198208            {
    199                 CameraPosition* cameraPos_ = this->pawn_->getCameraPosition(index);
    200                 if(cameraPos_ == NULL)
     209                CameraPosition* cameraPos = this->pawn_->getCameraPosition(index);
     210                if(cameraPos == NULL)
    201211                continue;
    202                 cameraPos_->setPosition(cameraPos_->getPosition()*factor_);
     212                cameraPos->setPosition(cameraPos->getPosition()*factor);
    203213            }
    204214        }
    205         else isActive_ = false;
    206 
    207         if(isTerminating_ == true && actualScale_ < defaultScale_)    //grow until the ship reaches its default scale.
     215        else this->isActive_ = false;
     216
     217        if(this->isTerminating_ == true && this->actualScale_ < this->defaultScale_)    //grow until the ship reaches its default scale.
    208218        {
    209             float factor_ = 1 + dt*shrinkSpeed_;
    210 
    211             actualScale_ *= factor_;
    212             actualMass_ *= factor_;
    213 
    214             this->pawn_->setScale3D(actualScale_);
    215             this->pawn_->setMass(actualMass_);
    216 
    217             for(int index = 0; index < size_; index++)
     219            float factor = 1 + dt*this->shrinkSpeed_;
     220
     221            this->actualScale_ *= factor;
     222            this->actualMass_ *= factor;
     223
     224            this->pawn_->setScale3D(this->actualScale_);
     225            this->pawn_->setMass(this->actualMass_);
     226
     227            for(int index = 0; index < this->size_; index++)
    218228            {
    219                 CameraPosition* cameraPos_ = this->pawn_->getCameraPosition(index);
    220                 if(cameraPos_ == NULL)
     229                CameraPosition* cameraPos = this->pawn_->getCameraPosition(index);
     230                if(cameraPos == NULL)
    221231                continue;
    222                 cameraPos_->setPosition(cameraPos_->getPosition()/factor_);
     232                cameraPos->setPosition(cameraPos->getPosition()/factor);
    223233            }
    224234        }
    225         else if(isTerminating_ == true)
     235        else if(this->isTerminating_ == true)
    226236            this->Pickupable::destroy();
    227237
     
    234244    void ShrinkPickup::terminate(void)
    235245    {
    236         isActive_ = false;
    237         isTerminating_ = true;
     246        this->isActive_ = false;
     247        this->isTerminating_ = true;
    238248        setUsed(false);
    239249    }
Note: See TracChangeset for help on using the changeset viewer.