[Orxonox-commit 3986] r8660 - in code/branches/presentation: data/levels src/modules/objects
landauf at orxonox.net
landauf at orxonox.net
Sun May 29 16:02:07 CEST 2011
Author: landauf
Date: 2011-05-29 16:02:07 +0200 (Sun, 29 May 2011)
New Revision: 8660
Modified:
code/branches/presentation/data/levels/myTestLevel.oxw
code/branches/presentation/src/modules/objects/SpaceBoundaries.cc
code/branches/presentation/src/modules/objects/SpaceBoundaries.h
Log:
added fade in/out effect for space boundaries (alpha value, based on distance)
Modified: code/branches/presentation/data/levels/myTestLevel.oxw
===================================================================
--- code/branches/presentation/data/levels/myTestLevel.oxw 2011-05-29 13:40:02 UTC (rev 8659)
+++ code/branches/presentation/data/levels/myTestLevel.oxw 2011-05-29 14:02:07 UTC (rev 8660)
@@ -32,7 +32,7 @@
<Light type=directional position="0,0,0" direction="0.253, 0.593, -0.765" diffuse="1.0, 0.9, 0.9, 1.0" specular="1.0, 0.9, 0.9, 1.0"/>
<SpawnPoint team=0 position="0,0,0" direction="1,0,0" spawnclass=SpaceShip pawndesign=spaceshipassff />
- <SpaceBoundaries warnDistance="1" maxDistance="200" showDistance="100" reactionMode="0" healthDecrease="0.9" position="0,0,0"/>
+ <SpaceBoundaries warnDistance="1" maxDistance="200" showDistance="150" reactionMode="0" healthDecrease="0.9" position="0,0,0"/>
<Billboard position="0,0,0" colour="1.0,1.0,1.0" material="Flares/backlightflare" scale=1 />
Modified: code/branches/presentation/src/modules/objects/SpaceBoundaries.cc
===================================================================
--- code/branches/presentation/src/modules/objects/SpaceBoundaries.cc 2011-05-29 13:40:02 UTC (rev 8659)
+++ code/branches/presentation/src/modules/objects/SpaceBoundaries.cc 2011-05-29 14:02:07 UTC (rev 8660)
@@ -58,7 +58,7 @@
{
this->pawnsIn_.clear();
- for( std::vector<billboardAdministration>::iterator current = this->billboards_.begin(); current != this->billboards_.end(); current++)
+ for( std::vector<BillboardAdministration>::iterator current = this->billboards_.begin(); current != this->billboards_.end(); current++)
{
if( current->billy != NULL)
{
@@ -94,38 +94,33 @@
}
}
- void SpaceBoundaries::positionBillboard(const Vector3 position)
+ void SpaceBoundaries::positionBillboard(const Vector3& position, float alpha)
{
- std::vector<billboardAdministration>::iterator current;
- for( current = this->billboards_.begin(); current != this->billboards_.end(); current++)
- {
- if(!current->usedYet)
- {
+ size_t current;
+ for (current = 0; current < this->billboards_.size(); ++current)
+ if (!this->billboards_[current].usedYet)
break;
- }
- }
- if( current == this->billboards_.end() )
+
+ if (current == this->billboards_.size())
{
- Billboard *tmp = new Billboard(this);
- tmp->setPosition(position);
- this->setBillboardOptions( tmp );
- Vector3 normalisedVec = (position - this->getPosition()).normalisedCopy(); /* Vektor von Kugelmitte nach aussen */
- tmp->setCommonDirection ( -1.0 * normalisedVec );
- Vector3 upVector = Vector3(normalisedVec.z, normalisedVec.z, -(normalisedVec.x+normalisedVec.y));
- upVector.normalise();
- tmp->setCommonUpVector( upVector );
- billboardAdministration tmp2 = { true, tmp };
- this->billboards_.push_back( tmp2 );
- } else {
- current->billy->setPosition(position);
- current->billy->setVisible(true);
- current->usedYet = true;
- Vector3 normalisedVec = (position - this->getPosition()).normalisedCopy(); /* Vektor von Kugelmitte nach aussen */
- current->billy->setCommonDirection ( -1.0 * normalisedVec );
- Vector3 upVector = Vector3(normalisedVec.z, normalisedVec.z, -(normalisedVec.x+normalisedVec.y));
- upVector.normalise();
- current->billy->setCommonUpVector( upVector );
+ Billboard* billboard = new Billboard(this);
+ billboard->setPosition(position);
+ this->setBillboardOptions(billboard);
+ BillboardAdministration ba = {true, billboard};
+ this->billboards_.push_back(ba);
}
+
+ this->billboards_[current].billy->setPosition(position);
+ this->billboards_[current].billy->setVisible(true);
+ this->billboards_[current].billy->setColour(ColourValue(1, 1, 1, alpha));
+ this->billboards_[current].usedYet = true;
+
+ Vector3 directionVector = (this->getPosition() - position).normalisedCopy(); // vector from the position of the billboard to the center of the sphere
+ this->billboards_[current].billy->setCommonDirection(directionVector);
+
+ Vector3 upVector = Vector3(directionVector.z, directionVector.z, -(directionVector.x + directionVector.y)); // vector perpendicular to the direction vector
+ upVector.normalise();
+ this->billboards_[current].billy->setCommonUpVector(upVector);
}
void SpaceBoundaries::setBillboardOptions(Billboard *billy)
@@ -141,7 +136,7 @@
void SpaceBoundaries::removeAllBillboards()
{
- for( std::vector<billboardAdministration>::iterator current = this->billboards_.begin(); current != this->billboards_.end(); current++ )
+ for( std::vector<BillboardAdministration>::iterator current = this->billboards_.begin(); current != this->billboards_.end(); current++ )
{
current->usedYet = false;
current->billy->setVisible(false);
@@ -228,7 +223,7 @@
}
if(/* humanItem &&*/ abs(this->maxDistance_ - distance) < this->showDistance_ )
{
- this->displayBoundaries(currentPawn); // Show the boundary
+ this->displayBoundaries(currentPawn, 1.0f - fabs(this->maxDistance_ - distance) / this->showDistance_); // Show the boundary
}
if(distance > this->maxDistance_ && (this->reaction_ == 1) )
{
@@ -267,7 +262,7 @@
// TODO
}
- void SpaceBoundaries::displayBoundaries(Pawn *item)
+ void SpaceBoundaries::displayBoundaries(Pawn *item, float alpha)
{
Vector3 direction = item->getPosition() - this->getPosition();
@@ -275,7 +270,7 @@
Vector3 boundaryPosition = this->getPosition() + direction * this->maxDistance_;
- this->positionBillboard(boundaryPosition);
+ this->positionBillboard(boundaryPosition, alpha);
}
void SpaceBoundaries::conditionalBounceBack(Pawn *item, float currentDistance, float dt)
Modified: code/branches/presentation/src/modules/objects/SpaceBoundaries.h
===================================================================
--- code/branches/presentation/src/modules/objects/SpaceBoundaries.h 2011-05-29 13:40:02 UTC (rev 8659)
+++ code/branches/presentation/src/modules/objects/SpaceBoundaries.h 2011-05-29 14:02:07 UTC (rev 8660)
@@ -99,12 +99,12 @@
void tick(float dt);
private:
- struct billboardAdministration{ bool usedYet; Billboard* billy; };
+ struct BillboardAdministration{ bool usedYet; Billboard* billy; };
// Variabeln::
std::list<WeakPtr<Pawn> > pawnsIn_; //!< List of the pawns that this instance of SpaceBoundaries has to handle.
- std::vector<billboardAdministration> billboards_;
+ std::vector<BillboardAdministration> billboards_;
int reaction_; //!< Values: 0, 1, 2.
//!< 0: Reflection on boundary (Standard).
@@ -121,14 +121,14 @@
// Funktionen::
float computeDistance(WorldEntity *item); //!< Compute distance to center point.
void displayWarning(const std::string warnText); //!< TODO: Implement.
- void displayBoundaries(Pawn *item);
+ void displayBoundaries(Pawn *item, float alpha);
void conditionalBounceBack(Pawn *item, float currentDistance, float dt);
void bounceBack(Pawn *item, Vector3 *normal, Vector3 *velocity);
bool isHumanPlayer(Pawn *item);
void checkWhoIsIn(); //!< Update the list 'pawnsIn_'.
- void positionBillboard(const Vector3 position); //!< Display a Billboard at the position 'position'.
+ void positionBillboard(const Vector3& position, float alpha); //!< Display a Billboard at the position 'position'.
void setBillboardOptions(Billboard *billy);
void removeAllBillboards(); //!< Hide all elements of '*billboard_' and set their attribute 'usedYet' to 0.
More information about the Orxonox-commit
mailing list