Changeset 8433 for code/branches/pickup/src
- Timestamp:
- May 9, 2011, 3:58:48 PM (14 years ago)
- Location:
- code/branches/pickup/src/modules/pickup/items
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/pickup/src/modules/pickup/items/ShrinkPickup.cc
r8381 r8433 15 15 CreateFactory(ShrinkPickup); 16 16 17 17 ShrinkPickup::ShrinkPickup(BaseObject* creator) : Pickup(creator) 18 18 { 19 19 RegisterObject(ShrinkPickup); 20 20 21 21 this->initialize(); 22 shrinkFactor_ = 5.0; 23 duration_ = 5.0; 24 shrinkDelay_ = 1.0; 25 isActive_ = false; 22 26 } 23 27 … … 34 38 void ShrinkPickup::changedUsed(void) 35 39 { 40 int i; 41 36 42 SUPER(ShrinkPickup, changedUsed); 37 43 … … 45 51 //this->pawn->setScale3D(this->pawn->getScale3D() / 2.0); 46 52 std::set<WorldEntity*> set = this->pawn->getAttachedObjects(); 53 54 i = 0; 47 55 for(std::set<WorldEntity*>::iterator it = set.begin(); it != set.end(); it++) 48 56 { 49 (*it)->setScale((*it)->getScale() / 5.0); 50 (*it)->setPosition((*it)->getPosition() / 5.0); 57 defaultScales_.push_back((*it)->getScale()); 58 actualScales_.push_back((*it)->getScale()); 59 defaultPositions_.push_back((*it)->getPosition()); 60 actualPositions_.push_back((*it)->getPosition()); 61 //(*it)->setScale((*it)->getScale() / 5.0); 62 //(*it)->setPosition((*it)->getPosition() / 5.0); 51 63 } 52 64 size_ = defaultScales_.size(); 65 for(i = 0; i < size_; i++) 66 { 67 smallScales_.push_back(defaultScales_.at(i) / shrinkFactor_); 68 } 69 isActive_ = true; 53 70 durationTimer.setTimer(10, false, createExecutor(createFunctor(&ShrinkPickup::terminate, this))); 54 71 } … … 57 74 this->Pickupable::destroy(); 58 75 } 76 } 77 78 void ShrinkPickup::tick(float dt) 79 { 80 double temp; 81 int i; 82 double k = dt / shrinkDelay_; 83 if(isActive_) 84 { 85 for(i = 0; i < size_; i++) 86 { 87 temp = actualScales_.at(i); 88 if(temp > smallScales_.at(i)) 89 { 90 actualScales_.erase(i) 91 actualScales_.insert(i, temp - (temp - smallScales_.at(i)) * k); 92 } 93 /*temp = actual; 94 if(temp > smallScales[i]) 95 { 96 actualScales[i] -= (actualScales[i] - smallScales[i]) * k; 97 }*/ 98 99 } 100 101 i = 0; 102 103 std::set<WorldEntity*> set = this->pawn->getAttachedObjects(); 104 for(std::set<WorldEntity*>::iterator it = set.begin(); it != set.end(); it++) 105 { 106 //defaultScales.push_back((*it)->getScale()); 107 //actualScales.push_back((*it)->getScale()); 108 //defaultPositions.push_back((*it)->getPosition()); 109 //actualPositions.push_back((*it)->getPosition()); 110 //(*it)->setScale((*it)->getScale() *0.99); 111 (*it)->setScale(actualScales_.at(i)); 112 //(*it)->setPosition((*it)->getPosition() / 5.0); 113 } 114 } 59 115 } 60 116 -
code/branches/pickup/src/modules/pickup/items/ShrinkPickup.h
r8381 r8433 25 25 virtual void changedUsed(void); //!< Is called when the pickup has transited from used to unused or the other way around. 26 26 virtual void clone(OrxonoxClass*& item); //!< Creates a duplicate of the input OrxonoxClass. 27 void tick(float dt); 27 28 28 29 private: 29 30 void initialize(void); 30 const float duration; //determines how long the pickup will be active 31 const float shrinkFactor; //shrink factor of the space ship 32 const float shrinkDelay; //how long it takes to shrink to the final size 33 double factorPerCall; 34 bool isTerminating; 35 vector<float> defaultScales; 36 vector<float> smallScales; 37 vector<float> actualScales; 38 vector<float> defaultPositions; 39 vector<float> smallPositions; 40 vector<float> actualPositions; 31 32 float duration_; //!< determines how long the pickup will be active 33 float shrinkFactor_; //shrink factor of the space ship 34 float shrinkDelay_; //how long it takes to shrink to the final size 35 bool isActive_; 36 bool isTerminating_; 37 int size_; 38 std::vector<float> defaultScales_; 39 std::vector<float> smallScales_; 40 std::vector<float> actualScales_; 41 std::vector<Vector3> defaultPositions_; 42 std::vector<Vector3> smallPositions_; 43 std::vector<Vector3> actualPositions_; 41 44 Pawn* carrierToPawnHelper(void); 42 45 Pawn* pawn; … … 44 47 void terminate(void); 45 48 46 47 49 }; 48 50 }
Note: See TracChangeset
for help on using the changeset viewer.