Changeset 8713 for code/trunk/src/modules/pickup
- Timestamp:
- Jun 27, 2011, 10:45:15 AM (13 years ago)
- Location:
- code/trunk/src/modules/pickup
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk/src/modules/pickup/PickupRepresentation.cc
r8706 r8713 193 193 Billboard* icon = new Billboard(spawner); 194 194 icon->setColour(ColourValue(0.89f, 0.79f, 0.08f)); 195 icon->setMaterial(" Asterix");195 icon->setMaterial("asterisk"); 196 196 icon->setScale(0.5); 197 197 sphere->attach(icon); -
code/trunk/src/modules/pickup/items/ShrinkPickup.cc
r8706 r8713 21 21 * 22 22 * Author: 23 * Damian 'Mozork' Frick23 * Sandro Sgier 24 24 * Co-authors: 25 25 * ... … … 43 43 #include "worldentities/pawns/Pawn.h" 44 44 45 #include "weaponsystem/WeaponSlot.h"46 #include "weaponsystem/Weapon.h"47 45 #include "worldentities/CameraPosition.h" 48 46 … … 51 49 CreateFactory(ShrinkPickup); 52 50 53 51 /** 54 52 @brief 55 53 Constructor: Initializes the Pickup. … … 60 58 61 59 this->initialize(); 60 } 61 62 ShrinkPickup::~ShrinkPickup() 63 { 64 65 } 66 67 void ShrinkPickup::initialize(void) 68 { 69 this->addTarget(ClassIdentifier<Pawn>::getIdentifier()); 70 62 71 this->shrinkFactor_ = 5.0f; 63 this->shrink Speed_ = 5.0f;72 this->shrinkDuration_ = 5.0f; 64 73 this->duration_ = 5.0f; 74 65 75 this->isActive_ = false; 76 this->isShrinking_ = false; 66 77 this->isTerminating_ = false; 67 78 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; 77 } 78 79 ShrinkPickup::~ShrinkPickup() 80 { 81 79 this->timeRemainig_ = 0.0f; 80 this->currentFactor_ = 1.0f; 82 81 } 83 82 … … 97 96 98 97 stream.clear(); 99 stream << this->getShrink Speed();98 stream << this->getShrinkDuration(); 100 99 std::string val3 = stream.str(); 101 std::string type3 = "shrink Speed";100 std::string type3 = "shrinkDuration"; 102 101 this->pickupIdentifier_->addParameter(type3, val3); 103 102 } … … 105 104 /** 106 105 @brief 107 Method for creating a Shrink hPickup object through XML.106 Method for creating a ShrinkPickup object through XML. 108 107 */ 109 108 void ShrinkPickup::XMLPort(Element& xmlelement, orxonox::XMLPort::Mode mode) … … 113 112 XMLPortParam(ShrinkPickup, "shrinkFactor", setShrinkFactor, getShrinkFactor, xmlelement, mode); 114 113 XMLPortParam(ShrinkPickup, "duration", setDuration, getDuration, xmlelement, mode); 115 XMLPortParam(ShrinkPickup, "shrink Speed", setShrinkSpeed, getShrinkSpeed, xmlelement, mode);114 XMLPortParam(ShrinkPickup, "shrinkDuration", setShrinkDuration, getShrinkDuration, xmlelement, mode); 116 115 117 116 this->initializeIdentifier(); … … 120 119 /** 121 120 @brief 122 Sets the shrinking factor. 123 @param factor 124 The factor. 125 */ 126 void ShrinkPickup::setShrinkFactor(float factor) 127 { 128 this->shrinkFactor_ = factor; 129 } 130 131 /** 132 @brief 133 Sets the duration. 134 @param duration 135 The duration. 136 */ 137 void ShrinkPickup::setDuration(float duration) 138 { 139 this->duration_ = duration; 140 } 141 142 /** 143 @brief 144 Sets the shrinking speed. 145 @param speed 146 The speed. 147 */ 148 void ShrinkPickup::setShrinkSpeed(float speed) 149 { 150 this->shrinkSpeed_ = speed; 151 } 152 153 void ShrinkPickup::initialize(void) 154 { 155 this->addTarget(ClassIdentifier<Pawn>::getIdentifier()); 156 } 157 158 /** 159 @brief 160 Prepares for shrinking (collecting several informations). 121 Prepares for shrinking. 161 122 */ 162 123 void ShrinkPickup::changedUsed(void) … … 166 127 if(this->isUsed()) 167 128 { 168 this->pawn_ = this->carrierToPawnHelper(); 169 if(this->pawn_ == NULL) // If the PickupCarrier is no Pawn, then this pickup is useless and therefore is destroyed. 129 Pawn* pawn = this->carrierToPawnHelper(); 130 if(pawn == NULL) // If the PickupCarrier is no Pawn, then this pickup is useless and therefore is destroyed. 131 { 170 132 this->Pickupable::destroy(); 171 172 //Collect scaling information. 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. 133 return; 134 } 135 136 this->currentFactor_ = 1.0f; 137 this->timeRemainig_ = this->shrinkDuration_; 138 139 this->isActive_ = true; // Start shrinking now. 140 this->isShrinking_ = true; 141 this->durationTimer_.setTimer(this->duration_, false, createExecutor(createFunctor(&ShrinkPickup::terminate, this))); //Set timer for termination. 142 } 143 if(!this->isUsed() && this->isActive_) 144 this->isTerminating_ = true; 145 } 146 147 void ShrinkPickup::changedPickedUp(void) 148 { 149 SUPER(ShrinkPickup, changedPickedUp); 150 151 if(!this->isPickedUp() && this->isActive_) 152 { 153 if(this->isShrinking_ || this->isTerminating_) 154 { 155 //TODO: Deploy particle effect. 156 Pawn* pawn = this->carrierToPawnHelper(); 157 if(pawn == NULL) // If the PickupCarrier is no Pawn, then this pickup is useless and therefore is destroyed. 158 return; 159 160 float factor = 1.0f/this->currentFactor_; 161 162 pawn->setScale3D(pawn->getScale3D()*factor); 163 pawn->setMass(pawn->getMass()*factor); 164 165 // Iterate over all camera positions and inversely move the camera to create a shrinking sensation. 166 const std::list< SmartPtr<CameraPosition> >& cameraPositions = pawn->getCameraPositions(); 167 int size = cameraPositions.size(); 168 for(int index = 0; index < size; index++) 169 { 170 CameraPosition* cameraPos = pawn->getCameraPosition(index); 171 if(cameraPos == NULL) 172 continue; 173 cameraPos->setPosition(cameraPos->getPosition()/factor); 174 } 175 this->currentFactor_ = 1.0f; 176 this->timeRemainig_ = this->shrinkDuration_; 177 this->isActive_ = false; 178 this->isShrinking_ = false; 179 this->isTerminating_ = false; 180 } 181 else 182 { 183 //TODO: Deploy particle effect. 184 Pawn* pawn = this->carrierToPawnHelper(); 185 if(pawn == NULL) // If the PickupCarrier is no Pawn, then this pickup is useless and therefore is destroyed. 186 return; 187 188 pawn->setScale3D(pawn->getScale3D()*this->shrinkFactor_); 189 pawn->setMass(pawn->getMass()*this->shrinkFactor_); 190 191 // Iterate over all camera positions and inversely move the camera to create a shrinking sensation. 192 const std::list< SmartPtr<CameraPosition> >& cameraPositions = pawn->getCameraPositions(); 193 int size = cameraPositions.size(); 194 for(int index = 0; index < size; index++) 195 { 196 CameraPosition* cameraPos = pawn->getCameraPosition(index); 197 if(cameraPos == NULL) 198 continue; 199 cameraPos->setPosition(cameraPos->getPosition()/this->shrinkFactor_); 200 } 201 this->currentFactor_ = 1.0f; 202 this->timeRemainig_ = this->shrinkDuration_; 203 this->isActive_ = false; 204 } 186 205 } 187 206 } … … 195 214 void ShrinkPickup::tick(float dt) 196 215 { 197 if(this->isActive_ == true && this->actualScale_ > this->smallScale_) //if the ship has not reached the target scale, continue shrinking216 if(this->isActive_) 198 217 { 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++) 208 { 209 CameraPosition* cameraPos = this->pawn_->getCameraPosition(index); 210 if(cameraPos == NULL) 211 continue; 212 cameraPos->setPosition(cameraPos->getPosition()*factor); 218 if(this->isShrinking_) // If the ship has not reached the target scale, continue shrinking 219 { 220 Pawn* pawn = this->carrierToPawnHelper(); 221 if(pawn == NULL) // If the PickupCarrier is no Pawn, then this pickup is useless and therefore is destroyed. 222 { 223 this->Pickupable::destroy(); 224 return; 225 } 226 227 this->timeRemainig_ -= dt; 228 229 // Calculate the scaling factor by which the initial size would have to be scaled to have the current scale. 230 float currentFactor = std::max(1 - (1-std::max(this->timeRemainig_, 0.0f)/this->shrinkDuration_)*(1-1/this->shrinkFactor_), 1/this->shrinkFactor_); 231 // Calculate the factor by which the previous size has to be scaled to be the current scale. 232 float factor = currentFactor/this->currentFactor_; 233 this->currentFactor_ = currentFactor; 234 235 // Stop shrinking if the desired size is reached. 236 if(this->timeRemainig_ <= 0.0f) 237 { 238 this->timeRemainig_ = this->shrinkDuration_; // Reset the time remaining for when we start to grow the ship again. 239 this->currentFactor_ = 1/this->shrinkFactor_; 240 this->isShrinking_ = false; 241 } 242 243 pawn->setScale3D(pawn->getScale3D()*factor); 244 pawn->setMass(pawn->getMass()*factor); 245 246 // Iterate over all camera positions and inversely move the camera to create a shrinking sensation. 247 const std::list< SmartPtr<CameraPosition> >& cameraPositions = pawn->getCameraPositions(); 248 int size = cameraPositions.size(); 249 for(int index = 0; index < size; index++) 250 { 251 CameraPosition* cameraPos = pawn->getCameraPosition(index); 252 if(cameraPos == NULL) 253 continue; 254 cameraPos->setPosition(cameraPos->getPosition()/factor); 255 } 256 257 } 258 else if(this->isTerminating_) // Grow until the ship reaches its default scale. 259 { 260 Pawn* pawn = this->carrierToPawnHelper(); 261 if(pawn == NULL) // If the PickupCarrier is no Pawn, then this pickup is useless and therefore is destroyed. 262 this->Pickupable::destroy(); 263 264 this->timeRemainig_ -= dt; 265 266 // Calculate the scaling factor by which the initial size would have to be scaled to have the current scale. 267 float currentFactor = std::min(1/this->shrinkFactor_ + (1-std::max(this->timeRemainig_, 0.0f)/this->shrinkDuration_)*(1-1/this->shrinkFactor_), 1.0f); 268 // Calculate the factor by which the previous size has to be scaled to be the current scale. 269 float factor = currentFactor/this->currentFactor_; 270 this->currentFactor_ = currentFactor; 271 272 bool destroy = false; 273 274 // Stop shrinking if the desired size is reached. 275 if(this->timeRemainig_ <= 0.0f) 276 { 277 this->timeRemainig_ = shrinkDuration_; // Reset the time remaining for when we start to grow the ship again. 278 this->currentFactor_ = 1.0f; 279 this->isTerminating_ = false; 280 this->isActive_ = false; 281 destroy = true; 282 } 283 284 pawn->setScale3D(pawn->getScale3D()*factor); 285 pawn->setMass(pawn->getMass()*factor); 286 287 // Iterate over all camera positions and inversely move the camera to create a shrinking sensation. 288 const std::list< SmartPtr<CameraPosition> >& cameraPositions = pawn->getCameraPositions(); 289 int size = cameraPositions.size(); 290 for(int index = 0; index < size; index++) 291 { 292 CameraPosition* cameraPos = pawn->getCameraPosition(index); 293 if(cameraPos == NULL) 294 continue; 295 cameraPos->setPosition(cameraPos->getPosition()/factor); 296 } 297 298 if(destroy) 299 this->Pickupable::destroy(); 213 300 } 214 301 } 215 else this->isActive_ = false;216 217 if(this->isTerminating_ == true && this->actualScale_ < this->defaultScale_) //grow until the ship reaches its default scale.218 {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++)228 {229 CameraPosition* cameraPos = this->pawn_->getCameraPosition(index);230 if(cameraPos == NULL)231 continue;232 cameraPos->setPosition(cameraPos->getPosition()/factor);233 }234 }235 else if(this->isTerminating_ == true)236 this->Pickupable::destroy();237 238 302 } 239 303 … … 244 308 void ShrinkPickup::terminate(void) 245 309 { 246 this->isActive_ = false; 247 this->isTerminating_ = true; 248 setUsed(false); 310 this->setUsed(false); 249 311 } 250 312 … … 272 334 pickup->setShrinkFactor(this->getShrinkFactor()); 273 335 pickup->setDuration(this->getDuration()); 274 pickup->setShrink Speed(this->getShrinkSpeed());336 pickup->setShrinkDuration(this->getShrinkDuration()); 275 337 276 338 pickup->initializeIdentifier(); -
code/trunk/src/modules/pickup/items/ShrinkPickup.h
r8706 r8713 21 21 * 22 22 * Author: 23 * Damian 'Mozork' Frick23 * Sandro Sgier 24 24 * Co-authors: 25 25 * ... … … 48 48 49 49 /** 50 @author51 Sandro Sgier52 53 @ingroup PickupItems54 */55 56 /**57 50 @brief 58 51 The ShrinkPickup is a Pickupable that causes the pawn to shrink to a certain size for a certain time with a certain speed, all of them specified in the following variables: 59 52 - The @b shrinkFactor It determines how much the ship is going to shrink (e.g. the factor 2 would make the ship shrinking to half its size). 60 - The @b duration Specifies how long the ship will keepsmall.61 - The @b shrink Speed Defines how fast the ship shrinks and grows.53 - The @b duration Specifies how long the ship will stay small. 54 - The @b shrinkDuration Defines how fast the ship shrinks and grows in seconds. 62 55 63 64 An example of a XML implementation of a HealthPickup would be: 56 An example of a XML implementation of a ShrinkPickup would be: 65 57 @code 66 < HealthPickup58 <ShrinkPickup 67 59 shrinkFactor = "5.0" 68 60 duration = "5.0" … … 80 72 { 81 73 public: 82 ShrinkPickup(BaseObject* creator); //!< Constructor. 83 virtual ~ShrinkPickup(); //!< Destructor. 84 virtual void changedUsed(void); //!< Is called when the pickup has transited from used to unused or the other way around. 85 virtual void clone(OrxonoxClass*& item); //!< Creates a duplicate of the input OrxonoxClass. 74 ShrinkPickup(BaseObject* creator); // Constructor. 75 virtual ~ShrinkPickup(); // Destructor. 76 86 77 virtual void XMLPort(Element& xmlelement, orxonox::XMLPort::Mode mode); 78 virtual void tick(float dt); 79 80 virtual void changedUsed(void); // Is called when the pickup has transited from used to unused or the other way around. 81 virtual void changedPickedUp(void); 82 virtual void clone(OrxonoxClass*& item); // Creates a duplicate of the input OrxonoxClass. 83 84 /** 85 @brief Get the shrinking factor. 86 @return Returns the shrinking factor, 87 */ 87 88 inline float getShrinkFactor(void) const 88 89 { return this->shrinkFactor_; } 90 /** 91 @brief Sets the shrinking factor. 92 @param factor The factor, needs to greater than 1. 93 */ 94 inline void setShrinkFactor(float factor) 95 { if(factor <= 1.0f) { COUT(2) << "Invalid shrinking factor in ShrinkPickup. Ignoring.." << endl; return; } this->shrinkFactor_ = factor; } 96 /** 97 @brief Get the duration for which the ship remains shrunken. 98 @return Returns the duration. 99 */ 89 100 inline float getDuration(void) const 90 101 { return this->duration_; } 91 inline float getShrinkSpeed(void) const 92 { return this->shrinkSpeed_; } 93 void setShrinkFactor(float factor); 94 void setDuration(float duration); 95 void setShrinkSpeed(float speed); 96 void tick(float dt); 102 /** 103 @brief Set the duration for which the ship remains shrunken. 104 @param duration The duration, needs to be non-negative. 105 */ 106 inline void setDuration(float duration) 107 { if(duration < 0.0f) { COUT(2) << "Invalid duration in ShrinkPickup. Ignoring.." << endl; return; } this->duration_ = duration; } 108 /** 109 @brief Get the shrink speed. 110 @return Returns the shrink speed. 111 */ 112 inline float getShrinkDuration(void) const 113 { return this->shrinkDuration_; } 114 /** 115 @brief Set the shrink duration. 116 @param speed The shrink duration, needs to be positive. 117 */ 118 inline void setShrinkDuration(float speed) 119 { if(speed <= 0.0f) { COUT(2) << "Invalid shrink duration in ShrinkPickup. Ignoring.." << endl; return; } this->shrinkDuration_ = speed; } 97 120 98 121 protected: … … 101 124 private: 102 125 void initialize(void); 103 float duration_; //!< determines how long the pickup will be active 104 float shrinkFactor_; //shrink factor of the space ship 105 float shrinkSpeed_; //speed of shrinking 106 bool isActive_; //true if ship is shrinking or small 107 bool isTerminating_; //true if ship is growing 108 int size_; //number of camera positions 109 std::list<SmartPtr<CameraPosition> > cameraPositions_; 110 float defaultCameraPos_; //all default, actual and small values... 111 Ogre::Vector3 defaultScale_; 112 Ogre::Vector3 actualScale_; 113 Ogre::Vector3 smallScale_; 114 float defaultMass_; 115 float actualMass_; 116 float smallMass_; 126 127 float duration_; //!< Determines how long the pickup will be active 128 float shrinkFactor_; //!< Shrink factor of the space ship 129 float shrinkDuration_; //!< Duration of shrinking 130 131 bool isActive_; //!< True if ship is shrinking, small, or growing back. 132 bool isShrinking_; //!< True if ship is shrinking 133 bool isTerminating_; //!< True if ship is growing back to the original size 134 135 float currentFactor_; //!< The shrink factor that is currently applied. 136 float timeRemainig_; //!< The remaining shrink time. 137 117 138 Pawn* carrierToPawnHelper(void); 118 Pawn* pawn_;119 139 Timer durationTimer_; 120 140 void terminate(void);
Note: See TracChangeset
for help on using the changeset viewer.