Changeset 8489
- Timestamp:
- May 16, 2011, 3:49:59 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
r8486 r8489 1 /* 2 * ORXONOX - the hottest 3D action shooter ever to exist 3 * > www.orxonox.net < 4 * 5 * 6 * License notice: 7 * 8 * This program is free software; you can redistribute it and/or 9 * modify it under the terms of the GNU General Public License 10 * as published by the Free Software Foundation; either version 2 11 * of the License, or (at your option) any later version. 12 * 13 * This program is distributed in the hope that it will be useful, 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 * GNU General Public License for more details. 17 * 18 * You should have received a copy of the GNU General Public License 19 * along with this program; if not, write to the Free Software 20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 21 * 22 * Author: 23 * Damian 'Mozork' Frick 24 * Co-authors: 25 * ... 26 * 27 */ 28 29 30 /** 31 @file ShrinkPickup.cc 32 @brief Implementation of the HealthPickup class. 33 */ 34 35 1 36 #include "ShrinkPickup.h" 2 37 … … 10 45 #include "weaponsystem/WeaponSlot.h" 11 46 #include "weaponsystem/Weapon.h" 47 #include "worldentities/CameraPosition.h" 12 48 13 49 namespace orxonox … … 15 51 CreateFactory(ShrinkPickup); 16 52 17 53 ShrinkPickup::ShrinkPickup(BaseObject* creator) : Pickup(creator) 18 54 { 19 55 RegisterObject(ShrinkPickup); 20 56 21 57 this->initialize(); 22 shrinkFactor_ = 5.0; 23 duration_ = 5.0; 24 shrinkDelay_ = 1.0; 25 isActive_ = false; 58 shrinkFactor_ = 5.0; 59 duration_ = 5.0; 60 shrinkSpeed_ = 5.0; 61 isActive_ = false; 62 isTerminating_ = false; 26 63 } 27 64 … … 31 68 } 32 69 33 34 35 36 70 void ShrinkPickup::initialize(void) 71 { 72 this->addTarget(ClassIdentifier<Pawn>::getIdentifier()); 73 } 37 74 38 75 void ShrinkPickup::changedUsed(void) 39 { 40 int i; 41 42 SUPER(ShrinkPickup, changedUsed); 76 { 77 SUPER(ShrinkPickup, changedUsed); 43 78 44 79 if(this->isUsed()) … … 47 82 if(pawn == NULL) // If the PickupCarrier is no Pawn, then this pickup is useless and therefore is destroyed. 48 83 this->Pickupable::destroy(); 49 50 COUT(0) << "shrinking..." << endl;51 //this->pawn->setScale3D(this->pawn->getScale3D() / 2.0);52 std::set<WorldEntity*> set = this->pawn->getAttachedObjects();53 54 /*this->pawn->setScale3D(this->pawn->getScale3D() / 5.0);55 this->pawn->setMass(this->pawn->getMass() / 5.0);56 84 57 const std::list<SmartPtr<CameraPosition> > cameraPositions = this->pawn->getCameraPositions(); 58 unsigned int size = cameraPositions.size(); 59 for(unsigned int index = 0; index < size; index++) 85 defaultScale_ = this->pawn->getScale3D(); 86 defaultMass_ = this->pawn->getMass(); 87 88 smallScale_ = defaultScale_ / shrinkFactor_; 89 smallMass_ = defaultMass_ / shrinkFactor_; 90 91 actualScale_ = defaultScale_; 92 actualMass_ = defaultMass_; 93 94 cameraPositions_ = this->pawn->getCameraPositions(); 95 size_ = cameraPositions_.size(); 96 isActive_ = true; 97 durationTimer.setTimer(duration_, false, createExecutor(createFunctor(&ShrinkPickup::terminate, this))); 98 } 99 else 100 { 101 this->Pickupable::destroy(); 102 } 103 } 104 105 void ShrinkPickup::tick(float dt) 106 { 107 if(isActive_ == true && actualScale_ > smallScale_) 108 { 109 float factor_ = 1 + dt*shrinkSpeed_; 110 111 actualScale_ /= factor_; 112 actualMass_ /= factor_; 113 114 this->pawn->setScale3D(actualScale_); 115 this->pawn->setMass(actualMass_); 116 117 for(int index = 0; index < size_; index++) 60 118 { 61 CameraPosition* cameraPos = this->pawn->getCameraPosition(index); 62 if(cameraPos == NULL) 63 continue; 64 cameraPos->setPosition(cameraPos->getPosition()*5.0); 65 }*/ 66 67 i = 0; 68 for(std::set<WorldEntity*>::iterator it = set.begin(); it != set.end(); it++) 69 { 70 defaultScales_.push_back((*it)->getScale()); 71 actualScales_.push_back((*it)->getScale()); 72 defaultPositions_.push_back((*it)->getPosition()); 73 actualPositions_.push_back((*it)->getPosition()); 74 //(*it)->setScale((*it)->getScale() / 5.0); 75 //(*it)->setPosition((*it)->getPosition() / 5.0); 76 } 77 size_ = defaultScales_.size(); 78 for(i = 0; i < size_; i++) 79 { 80 smallScales_.push_back(defaultScales_.at(i) / shrinkFactor_); 81 } 82 isActive_ = true; 83 durationTimer.setTimer(10, false, createExecutor(createFunctor(&ShrinkPickup::terminate, this))); 119 CameraPosition* cameraPos_ = this->pawn->getCameraPosition(index); 120 if(cameraPos_ == NULL) 121 continue; 122 cameraPos_->setPosition(cameraPos_->getPosition()*factor_); 123 } 84 124 } 85 else 125 else isActive_ = false; 126 127 if(isTerminating_ == true && actualScale_ < defaultScale_) 86 128 { 87 this->Pickupable::destroy(); 129 float factor_ = 1 + dt*shrinkSpeed_; 130 131 actualScale_ *= factor_; 132 actualMass_ *= factor_; 133 134 this->pawn->setScale3D(actualScale_); 135 this->pawn->setMass(actualMass_); 136 137 for(int index = 0; index < size_; index++) 138 { 139 CameraPosition* cameraPos_ = this->pawn->getCameraPosition(index); 140 if(cameraPos_ == NULL) 141 continue; 142 cameraPos_->setPosition(cameraPos_->getPosition()/factor_); 143 } 88 144 } 89 } 145 else if(isTerminating_ == true) 146 setUsed(false); 147 } 90 148 91 void ShrinkPickup::tick(float dt) 92 { 93 double temp; 94 int i; 95 double k = dt / shrinkDelay_; 96 if(isActive_) 97 { 98 for(i = 0; i < size_; i++) 99 { 100 temp = actualScales_.at(i); 101 if(temp > smallScales_.at(i)) 102 { 103 actualScales_.erase(i) 104 actualScales_.insert(i, temp - (temp - smallScales_.at(i)) * k); 105 } 106 /*temp = actual; 107 if(temp > smallScales[i]) 108 { 109 actualScales[i] -= (actualScales[i] - smallScales[i]) * k; 110 }*/ 111 112 } 113 114 i = 0; 115 116 std::set<WorldEntity*> set = this->pawn->getAttachedObjects(); 117 for(std::set<WorldEntity*>::iterator it = set.begin(); it != set.end(); it++) 118 { 119 //defaultScales.push_back((*it)->getScale()); 120 //actualScales.push_back((*it)->getScale()); 121 //defaultPositions.push_back((*it)->getPosition()); 122 //actualPositions.push_back((*it)->getPosition()); 123 //(*it)->setScale((*it)->getScale() *0.99); 124 (*it)->setScale(actualScales_.at(i)); 125 //(*it)->setPosition((*it)->getPosition() / 5.0); 126 } 127 } 128 } 129 130 void ShrinkPickup::terminate(void) 131 { 132 //this->pawn->setScale3D(this->pawn->getScale3D() * 5.0); 133 134 std::set<WorldEntity*> set = this->pawn->getAttachedObjects(); 135 for(std::set<WorldEntity*>::iterator it = set.begin(); it != set.end(); it++) 136 { 137 (*it)->setScale((*it)->getScale() * 5.0); 138 } 139 setUsed(false); 140 } 149 void ShrinkPickup::terminate(void) 150 { 151 isActive_ = false; 152 isTerminating_ = true; 153 } 141 154 142 155 Pawn* ShrinkPickup::carrierToPawnHelper(void) … … 144 157 PickupCarrier* carrier = this->getCarrier(); 145 158 Pawn* pawn = dynamic_cast<Pawn*>(carrier); 146 147 if(pawn == NULL)148 {149 COUT(1) << "Invalid PickupCarrier in ShrinkPickup." << std::endl;150 }151 159 152 160 return pawn; -
code/branches/pickup/src/modules/pickup/items/ShrinkPickup.h
r8433 r8489 1 /* 2 * ORXONOX - the hottest 3D action shooter ever to exist 3 * > www.orxonox.net < 4 * 5 * 6 * License notice: 7 * 8 * This program is free software; you can redistribute it and/or 9 * modify it under the terms of the GNU General Public License 10 * as published by the Free Software Foundation; either version 2 11 * of the License, or (at your option) any later version. 12 * 13 * This program is distributed in the hope that it will be useful, 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 * GNU General Public License for more details. 17 * 18 * You should have received a copy of the GNU General Public License 19 * along with this program; if not, write to the Free Software 20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 21 * 22 * Author: 23 * Damian 'Mozork' Frick 24 * Co-authors: 25 * ... 26 * 27 */ 28 29 /** 30 @file ShrinkPickup.h 31 @brief Declaration of the ShrinkPickup class. 32 @ingroup PickupItems 33 */ 34 35 1 36 #ifndef _ShrinkPickup_H__ 2 37 #define _ShrinkPickup_H__ … … 32 67 float duration_; //!< determines how long the pickup will be active 33 68 float shrinkFactor_; //shrink factor of the space ship 34 float shrink Delay_; //how long it takes to shrink to the final size69 float shrinkSpeed_; 35 70 bool isActive_; 36 71 bool isTerminating_; 37 72 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_; 73 std::list<SmartPtr<CameraPosition> > cameraPositions_; 74 float defaultCameraPos_; 75 Ogre::Vector3 defaultScale_; 76 Ogre::Vector3 actualScale_; 77 Ogre::Vector3 smallScale_; 78 float defaultMass_; 79 float actualMass_; 80 float smallMass_; 44 81 Pawn* carrierToPawnHelper(void); 45 82 Pawn* pawn;
Note: See TracChangeset
for help on using the changeset viewer.