Changeset 8555 for code/branches/pickup/src
- Timestamp:
- May 23, 2011, 11:37:17 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/pickup/src/modules/pickup/items/ShrinkPickup.cc
r8554 r8555 60 60 61 61 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; 67 77 } 68 78 … … 157 167 { 158 168 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. 160 170 this->Pickupable::destroy(); 161 171 162 172 //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. 176 186 } 177 187 } … … 185 195 void ShrinkPickup::tick(float dt) 186 196 { 187 if( isActive_ == true && actualScale_ >smallScale_) //if the ship has not reached the target scale, continue shrinking197 if(this->isActive_ == true && this->actualScale_ > this->smallScale_) //if the ship has not reached the target scale, continue shrinking 188 198 { 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++) 198 208 { 199 CameraPosition* cameraPos _= this->pawn_->getCameraPosition(index);200 if(cameraPos _== NULL)209 CameraPosition* cameraPos = this->pawn_->getCameraPosition(index); 210 if(cameraPos == NULL) 201 211 continue; 202 cameraPos _->setPosition(cameraPos_->getPosition()*factor_);212 cameraPos->setPosition(cameraPos->getPosition()*factor); 203 213 } 204 214 } 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. 208 218 { 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++) 218 228 { 219 CameraPosition* cameraPos _= this->pawn_->getCameraPosition(index);220 if(cameraPos _== NULL)229 CameraPosition* cameraPos = this->pawn_->getCameraPosition(index); 230 if(cameraPos == NULL) 221 231 continue; 222 cameraPos _->setPosition(cameraPos_->getPosition()/factor_);232 cameraPos->setPosition(cameraPos->getPosition()/factor); 223 233 } 224 234 } 225 else if( isTerminating_ == true)235 else if(this->isTerminating_ == true) 226 236 this->Pickupable::destroy(); 227 237 … … 234 244 void ShrinkPickup::terminate(void) 235 245 { 236 isActive_ = false;237 isTerminating_ = true;246 this->isActive_ = false; 247 this->isTerminating_ = true; 238 248 setUsed(false); 239 249 }
Note: See TracChangeset
for help on using the changeset viewer.