[Orxonox-commit 4042] r8713 - in code/trunk: data/levels/includes src/modules/pickup src/modules/pickup/items
dafrick at orxonox.net
dafrick at orxonox.net
Mon Jun 27 10:45:15 CEST 2011
Author: dafrick
Date: 2011-06-27 10:45:15 +0200 (Mon, 27 Jun 2011)
New Revision: 8713
Modified:
code/trunk/data/levels/includes/pickups.oxi
code/trunk/src/modules/pickup/PickupRepresentation.cc
code/trunk/src/modules/pickup/items/ShrinkPickup.cc
code/trunk/src/modules/pickup/items/ShrinkPickup.h
Log:
Cleaning up ShrinkPickup.
Modified: code/trunk/data/levels/includes/pickups.oxi
===================================================================
--- code/trunk/data/levels/includes/pickups.oxi 2011-06-27 08:44:37 UTC (rev 8712)
+++ code/trunk/data/levels/includes/pickups.oxi 2011-06-27 08:45:15 UTC (rev 8713)
@@ -215,6 +215,7 @@
pickupName = "Small Shrink"
pickupDescription = "Shrinks the Ship by a bit"
spawnerTemplate = "smallshrinkpickupRepresentation"
+ inventoryRepresentation = "SmallShrink"
>
<pickup>
<ShrinkPickup template=smallshrinkpickup />
@@ -225,6 +226,7 @@
pickupName = "Medium Shrink"
pickupDescription = "Shrinks the Ship"
spawnerTemplate = "mediumshrinkpickupRepresentation"
+ inventoryRepresentation = "MediumShrink"
>
<pickup>
<ShrinkPickup template=mediumshrinkpickup />
@@ -235,6 +237,7 @@
pickupName = "Huge Shrink"
pickupDescription = "Shrinks the Ship considerably"
spawnerTemplate = "hugeshrinkpickupRepresentation"
+ inventoryRepresentation = "HugeShrink"
>
<pickup>
<ShrinkPickup template=hugeshrinkpickup />
Modified: code/trunk/src/modules/pickup/PickupRepresentation.cc
===================================================================
--- code/trunk/src/modules/pickup/PickupRepresentation.cc 2011-06-27 08:44:37 UTC (rev 8712)
+++ code/trunk/src/modules/pickup/PickupRepresentation.cc 2011-06-27 08:45:15 UTC (rev 8713)
@@ -192,7 +192,7 @@
sphere->setScale(0.1f);
Billboard* icon = new Billboard(spawner);
icon->setColour(ColourValue(0.89f, 0.79f, 0.08f));
- icon->setMaterial("Asterix");
+ icon->setMaterial("asterisk");
icon->setScale(0.5);
sphere->attach(icon);
representation->attach(sphere);
Modified: code/trunk/src/modules/pickup/items/ShrinkPickup.cc
===================================================================
--- code/trunk/src/modules/pickup/items/ShrinkPickup.cc 2011-06-27 08:44:37 UTC (rev 8712)
+++ code/trunk/src/modules/pickup/items/ShrinkPickup.cc 2011-06-27 08:45:15 UTC (rev 8713)
@@ -20,7 +20,7 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Author:
- * Damian 'Mozork' Frick
+ * Sandro Sgier
* Co-authors:
* ...
*
@@ -42,15 +42,13 @@
#include "pickup/PickupIdentifier.h"
#include "worldentities/pawns/Pawn.h"
-#include "weaponsystem/WeaponSlot.h"
-#include "weaponsystem/Weapon.h"
#include "worldentities/CameraPosition.h"
namespace orxonox
{
CreateFactory(ShrinkPickup);
- /**
+ /**
@brief
Constructor: Initializes the Pickup.
*/
@@ -59,28 +57,29 @@
RegisterObject(ShrinkPickup);
this->initialize();
+ }
+
+ ShrinkPickup::~ShrinkPickup()
+ {
+
+ }
+
+ void ShrinkPickup::initialize(void)
+ {
+ this->addTarget(ClassIdentifier<Pawn>::getIdentifier());
+
this->shrinkFactor_ = 5.0f;
- this->shrinkSpeed_ = 5.0f;
+ this->shrinkDuration_ = 5.0f;
this->duration_ = 5.0f;
+
this->isActive_ = false;
+ this->isShrinking_ = false;
this->isTerminating_ = false;
- this->size_ = 0;
- this->defaultCameraPos_ = 0.0f;
- this->defaultScale_ = Vector3::UNIT_SCALE;
- this->actualScale_ = Vector3::UNIT_SCALE;
- this->smallScale_ = Vector3::UNIT_SCALE;
- this->defaultMass_ = 1.0f;
- this->actualMass_ = 1.0f;
- this->smallMass_ = 1.0f;
- this->pawn_ = NULL;
+ this->timeRemainig_ = 0.0f;
+ this->currentFactor_ = 1.0f;
}
- ShrinkPickup::~ShrinkPickup()
- {
-
- }
-
void ShrinkPickup::initializeIdentifier(void)
{
std::stringstream stream;
@@ -96,15 +95,15 @@
this->pickupIdentifier_->addParameter(type2, val2);
stream.clear();
- stream << this->getShrinkSpeed();
+ stream << this->getShrinkDuration();
std::string val3 = stream.str();
- std::string type3 = "shrinkSpeed";
+ std::string type3 = "shrinkDuration";
this->pickupIdentifier_->addParameter(type3, val3);
}
/**
@brief
- Method for creating a ShrinkhPickup object through XML.
+ Method for creating a ShrinkPickup object through XML.
*/
void ShrinkPickup::XMLPort(Element& xmlelement, orxonox::XMLPort::Mode mode)
{
@@ -112,77 +111,97 @@
XMLPortParam(ShrinkPickup, "shrinkFactor", setShrinkFactor, getShrinkFactor, xmlelement, mode);
XMLPortParam(ShrinkPickup, "duration", setDuration, getDuration, xmlelement, mode);
- XMLPortParam(ShrinkPickup, "shrinkSpeed", setShrinkSpeed, getShrinkSpeed, xmlelement, mode);
+ XMLPortParam(ShrinkPickup, "shrinkDuration", setShrinkDuration, getShrinkDuration, xmlelement, mode);
this->initializeIdentifier();
}
/**
@brief
- Sets the shrinking factor.
- @param factor
- The factor.
+ Prepares for shrinking.
*/
- void ShrinkPickup::setShrinkFactor(float factor)
+ void ShrinkPickup::changedUsed(void)
{
- this->shrinkFactor_ = factor;
- }
+ SUPER(ShrinkPickup, changedUsed);
- /**
- @brief
- Sets the duration.
- @param duration
- The duration.
- */
- void ShrinkPickup::setDuration(float duration)
- {
- this->duration_ = duration;
- }
+ if(this->isUsed())
+ {
+ Pawn* pawn = this->carrierToPawnHelper();
+ if(pawn == NULL) // If the PickupCarrier is no Pawn, then this pickup is useless and therefore is destroyed.
+ {
+ this->Pickupable::destroy();
+ return;
+ }
- /**
- @brief
- Sets the shrinking speed.
- @param speed
- The speed.
- */
- void ShrinkPickup::setShrinkSpeed(float speed)
- {
- this->shrinkSpeed_ = speed;
- }
+ this->currentFactor_ = 1.0f;
+ this->timeRemainig_ = this->shrinkDuration_;
- void ShrinkPickup::initialize(void)
- {
- this->addTarget(ClassIdentifier<Pawn>::getIdentifier());
+ this->isActive_ = true; // Start shrinking now.
+ this->isShrinking_ = true;
+ this->durationTimer_.setTimer(this->duration_, false, createExecutor(createFunctor(&ShrinkPickup::terminate, this))); //Set timer for termination.
+ }
+ if(!this->isUsed() && this->isActive_)
+ this->isTerminating_ = true;
}
- /**
- @brief
- Prepares for shrinking (collecting several informations).
- */
- void ShrinkPickup::changedUsed(void)
+ void ShrinkPickup::changedPickedUp(void)
{
- SUPER(ShrinkPickup, changedUsed);
-
- if(this->isUsed())
+ SUPER(ShrinkPickup, changedPickedUp);
+
+ if(!this->isPickedUp() && this->isActive_)
{
- this->pawn_ = this->carrierToPawnHelper();
- if(this->pawn_ == NULL) // If the PickupCarrier is no Pawn, then this pickup is useless and therefore is destroyed.
- this->Pickupable::destroy();
+ if(this->isShrinking_ || this->isTerminating_)
+ {
+ //TODO: Deploy particle effect.
+ Pawn* pawn = this->carrierToPawnHelper();
+ if(pawn == NULL) // If the PickupCarrier is no Pawn, then this pickup is useless and therefore is destroyed.
+ return;
- //Collect scaling information.
- this->defaultScale_ = this->pawn_->getScale3D();
- this->defaultMass_ = this->pawn_->getMass();
+ float factor = 1.0f/this->currentFactor_;
- this->smallScale_ = this->defaultScale_ / this->shrinkFactor_;
- this->smallMass_ = this->defaultMass_ / this->shrinkFactor_;
+ pawn->setScale3D(pawn->getScale3D()*factor);
+ pawn->setMass(pawn->getMass()*factor);
- this->actualScale_ = this->defaultScale_;
- this->actualMass_ = this->defaultMass_;
+ // Iterate over all camera positions and inversely move the camera to create a shrinking sensation.
+ const std::list< SmartPtr<CameraPosition> >& cameraPositions = pawn->getCameraPositions();
+ int size = cameraPositions.size();
+ for(int index = 0; index < size; index++)
+ {
+ CameraPosition* cameraPos = pawn->getCameraPosition(index);
+ if(cameraPos == NULL)
+ continue;
+ cameraPos->setPosition(cameraPos->getPosition()/factor);
+ }
+ this->currentFactor_ = 1.0f;
+ this->timeRemainig_ = this->shrinkDuration_;
+ this->isActive_ = false;
+ this->isShrinking_ = false;
+ this->isTerminating_ = false;
+ }
+ else
+ {
+ //TODO: Deploy particle effect.
+ Pawn* pawn = this->carrierToPawnHelper();
+ if(pawn == NULL) // If the PickupCarrier is no Pawn, then this pickup is useless and therefore is destroyed.
+ return;
- this->cameraPositions_ = this->pawn_->getCameraPositions();
- this->size_ = this->cameraPositions_.size();
- this->isActive_ = true; //start shrinking now.
- this->durationTimer_.setTimer(this->duration_, false, createExecutor(createFunctor(&ShrinkPickup::terminate, this))); //Set timer for termination.
+ pawn->setScale3D(pawn->getScale3D()*this->shrinkFactor_);
+ pawn->setMass(pawn->getMass()*this->shrinkFactor_);
+
+ // Iterate over all camera positions and inversely move the camera to create a shrinking sensation.
+ const std::list< SmartPtr<CameraPosition> >& cameraPositions = pawn->getCameraPositions();
+ int size = cameraPositions.size();
+ for(int index = 0; index < size; index++)
+ {
+ CameraPosition* cameraPos = pawn->getCameraPosition(index);
+ if(cameraPos == NULL)
+ continue;
+ cameraPos->setPosition(cameraPos->getPosition()/this->shrinkFactor_);
+ }
+ this->currentFactor_ = 1.0f;
+ this->timeRemainig_ = this->shrinkDuration_;
+ this->isActive_ = false;
+ }
}
}
@@ -194,47 +213,92 @@
*/
void ShrinkPickup::tick(float dt)
{
- if(this->isActive_ == true && this->actualScale_ > this->smallScale_) //if the ship has not reached the target scale, continue shrinking
+ if(this->isActive_)
{
- float factor = 1 + dt*this->shrinkSpeed_;
+ if(this->isShrinking_) // If the ship has not reached the target scale, continue shrinking
+ {
+ Pawn* pawn = this->carrierToPawnHelper();
+ if(pawn == NULL) // If the PickupCarrier is no Pawn, then this pickup is useless and therefore is destroyed.
+ {
+ this->Pickupable::destroy();
+ return;
+ }
- this->actualScale_ /= factor;
- this->actualMass_ /= factor;
+ this->timeRemainig_ -= dt;
- this->pawn_->setScale3D(this->actualScale_);
- this->pawn_->setMass(this->actualMass_);
+ // Calculate the scaling factor by which the initial size would have to be scaled to have the current scale.
+ float currentFactor = std::max(1 - (1-std::max(this->timeRemainig_, 0.0f)/this->shrinkDuration_)*(1-1/this->shrinkFactor_), 1/this->shrinkFactor_);
+ // Calculate the factor by which the previous size has to be scaled to be the current scale.
+ float factor = currentFactor/this->currentFactor_;
+ this->currentFactor_ = currentFactor;
- for(int index = 0; index < this->size_; index++)
+ // Stop shrinking if the desired size is reached.
+ if(this->timeRemainig_ <= 0.0f)
+ {
+ this->timeRemainig_ = this->shrinkDuration_; // Reset the time remaining for when we start to grow the ship again.
+ this->currentFactor_ = 1/this->shrinkFactor_;
+ this->isShrinking_ = false;
+ }
+
+ pawn->setScale3D(pawn->getScale3D()*factor);
+ pawn->setMass(pawn->getMass()*factor);
+
+ // Iterate over all camera positions and inversely move the camera to create a shrinking sensation.
+ const std::list< SmartPtr<CameraPosition> >& cameraPositions = pawn->getCameraPositions();
+ int size = cameraPositions.size();
+ for(int index = 0; index < size; index++)
+ {
+ CameraPosition* cameraPos = pawn->getCameraPosition(index);
+ if(cameraPos == NULL)
+ continue;
+ cameraPos->setPosition(cameraPos->getPosition()/factor);
+ }
+
+ }
+ else if(this->isTerminating_) // Grow until the ship reaches its default scale.
{
- CameraPosition* cameraPos = this->pawn_->getCameraPosition(index);
- if(cameraPos == NULL)
- continue;
- cameraPos->setPosition(cameraPos->getPosition()*factor);
- }
- }
- else this->isActive_ = false;
+ Pawn* pawn = this->carrierToPawnHelper();
+ if(pawn == NULL) // If the PickupCarrier is no Pawn, then this pickup is useless and therefore is destroyed.
+ this->Pickupable::destroy();
- if(this->isTerminating_ == true && this->actualScale_ < this->defaultScale_) //grow until the ship reaches its default scale.
- {
- float factor = 1 + dt*this->shrinkSpeed_;
+ this->timeRemainig_ -= dt;
- this->actualScale_ *= factor;
- this->actualMass_ *= factor;
+ // Calculate the scaling factor by which the initial size would have to be scaled to have the current scale.
+ float currentFactor = std::min(1/this->shrinkFactor_ + (1-std::max(this->timeRemainig_, 0.0f)/this->shrinkDuration_)*(1-1/this->shrinkFactor_), 1.0f);
+ // Calculate the factor by which the previous size has to be scaled to be the current scale.
+ float factor = currentFactor/this->currentFactor_;
+ this->currentFactor_ = currentFactor;
- this->pawn_->setScale3D(this->actualScale_);
- this->pawn_->setMass(this->actualMass_);
+ bool destroy = false;
+
+ // Stop shrinking if the desired size is reached.
+ if(this->timeRemainig_ <= 0.0f)
+ {
+ this->timeRemainig_ = shrinkDuration_; // Reset the time remaining for when we start to grow the ship again.
+ this->currentFactor_ = 1.0f;
+ this->isTerminating_ = false;
+ this->isActive_ = false;
+ destroy = true;
+ }
- for(int index = 0; index < this->size_; index++)
- {
- CameraPosition* cameraPos = this->pawn_->getCameraPosition(index);
- if(cameraPos == NULL)
- continue;
- cameraPos->setPosition(cameraPos->getPosition()/factor);
+ pawn->setScale3D(pawn->getScale3D()*factor);
+ pawn->setMass(pawn->getMass()*factor);
+
+ // Iterate over all camera positions and inversely move the camera to create a shrinking sensation.
+ const std::list< SmartPtr<CameraPosition> >& cameraPositions = pawn->getCameraPositions();
+ int size = cameraPositions.size();
+ for(int index = 0; index < size; index++)
+ {
+ CameraPosition* cameraPos = pawn->getCameraPosition(index);
+ if(cameraPos == NULL)
+ continue;
+ cameraPos->setPosition(cameraPos->getPosition()/factor);
+ }
+
+ if(destroy)
+ this->Pickupable::destroy();
}
}
- else if(this->isTerminating_ == true)
- this->Pickupable::destroy();
-
}
/**
@@ -243,9 +307,7 @@
*/
void ShrinkPickup::terminate(void)
{
- this->isActive_ = false;
- this->isTerminating_ = true;
- setUsed(false);
+ this->setUsed(false);
}
Pawn* ShrinkPickup::carrierToPawnHelper(void)
@@ -271,7 +333,7 @@
ShrinkPickup* pickup = dynamic_cast<ShrinkPickup*>(item);
pickup->setShrinkFactor(this->getShrinkFactor());
pickup->setDuration(this->getDuration());
- pickup->setShrinkSpeed(this->getShrinkSpeed());
+ pickup->setShrinkDuration(this->getShrinkDuration());
pickup->initializeIdentifier();
}
Modified: code/trunk/src/modules/pickup/items/ShrinkPickup.h
===================================================================
--- code/trunk/src/modules/pickup/items/ShrinkPickup.h 2011-06-27 08:44:37 UTC (rev 8712)
+++ code/trunk/src/modules/pickup/items/ShrinkPickup.h 2011-06-27 08:45:15 UTC (rev 8713)
@@ -20,7 +20,7 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Author:
- * Damian 'Mozork' Frick
+ * Sandro Sgier
* Co-authors:
* ...
*
@@ -47,23 +47,15 @@
namespace orxonox {
/**
- @author
- Sandro Sgier
-
- @ingroup PickupItems
- */
-
- /**
@brief
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:
- 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).
- - The @b duration Specifies how long the ship will keep small.
- - The @b shrinkSpeed Defines how fast the ship shrinks and grows.
+ - The @b duration Specifies how long the ship will stay small.
+ - The @b shrinkDuration Defines how fast the ship shrinks and grows in seconds.
-
- An example of a XML implementation of a HealthPickup would be:
+ An example of a XML implementation of a ShrinkPickup would be:
@code
- <HealthPickup
+ <ShrinkPickup
shrinkFactor = "5.0"
duration = "5.0"
shrinkSpeed = "5.0"
@@ -79,43 +71,71 @@
class _PickupExport ShrinkPickup : public Pickup, public Tickable
{
public:
- ShrinkPickup(BaseObject* creator); //!< Constructor.
- virtual ~ShrinkPickup(); //!< Destructor.
- virtual void changedUsed(void); //!< Is called when the pickup has transited from used to unused or the other way around.
- virtual void clone(OrxonoxClass*& item); //!< Creates a duplicate of the input OrxonoxClass.
+ ShrinkPickup(BaseObject* creator); // Constructor.
+ virtual ~ShrinkPickup(); // Destructor.
+
virtual void XMLPort(Element& xmlelement, orxonox::XMLPort::Mode mode);
+ virtual void tick(float dt);
+
+ virtual void changedUsed(void); // Is called when the pickup has transited from used to unused or the other way around.
+ virtual void changedPickedUp(void);
+ virtual void clone(OrxonoxClass*& item); // Creates a duplicate of the input OrxonoxClass.
+
+ /**
+ @brief Get the shrinking factor.
+ @return Returns the shrinking factor,
+ */
inline float getShrinkFactor(void) const
{ return this->shrinkFactor_; }
+ /**
+ @brief Sets the shrinking factor.
+ @param factor The factor, needs to greater than 1.
+ */
+ inline void setShrinkFactor(float factor)
+ { if(factor <= 1.0f) { COUT(2) << "Invalid shrinking factor in ShrinkPickup. Ignoring.." << endl; return; } this->shrinkFactor_ = factor; }
+ /**
+ @brief Get the duration for which the ship remains shrunken.
+ @return Returns the duration.
+ */
inline float getDuration(void) const
{ return this->duration_; }
- inline float getShrinkSpeed(void) const
- { return this->shrinkSpeed_; }
- void setShrinkFactor(float factor);
- void setDuration(float duration);
- void setShrinkSpeed(float speed);
- void tick(float dt);
+ /**
+ @brief Set the duration for which the ship remains shrunken.
+ @param duration The duration, needs to be non-negative.
+ */
+ inline void setDuration(float duration)
+ { if(duration < 0.0f) { COUT(2) << "Invalid duration in ShrinkPickup. Ignoring.." << endl; return; } this->duration_ = duration; }
+ /**
+ @brief Get the shrink speed.
+ @return Returns the shrink speed.
+ */
+ inline float getShrinkDuration(void) const
+ { return this->shrinkDuration_; }
+ /**
+ @brief Set the shrink duration.
+ @param speed The shrink duration, needs to be positive.
+ */
+ inline void setShrinkDuration(float speed)
+ { if(speed <= 0.0f) { COUT(2) << "Invalid shrink duration in ShrinkPickup. Ignoring.." << endl; return; } this->shrinkDuration_ = speed; }
protected:
void initializeIdentifier(void);
private:
void initialize(void);
- float duration_; //!< determines how long the pickup will be active
- float shrinkFactor_; //shrink factor of the space ship
- float shrinkSpeed_; //speed of shrinking
- bool isActive_; //true if ship is shrinking or small
- bool isTerminating_; //true if ship is growing
- int size_; //number of camera positions
- std::list<SmartPtr<CameraPosition> > cameraPositions_;
- float defaultCameraPos_; //all default, actual and small values...
- Ogre::Vector3 defaultScale_;
- Ogre::Vector3 actualScale_;
- Ogre::Vector3 smallScale_;
- float defaultMass_;
- float actualMass_;
- float smallMass_;
+
+ float duration_; //!< Determines how long the pickup will be active
+ float shrinkFactor_; //!< Shrink factor of the space ship
+ float shrinkDuration_; //!< Duration of shrinking
+
+ bool isActive_; //!< True if ship is shrinking, small, or growing back.
+ bool isShrinking_; //!< True if ship is shrinking
+ bool isTerminating_; //!< True if ship is growing back to the original size
+
+ float currentFactor_; //!< The shrink factor that is currently applied.
+ float timeRemainig_; //!< The remaining shrink time.
+
Pawn* carrierToPawnHelper(void);
- Pawn* pawn_;
Timer durationTimer_;
void terminate(void);
};
More information about the Orxonox-commit
mailing list