[Orxonox-commit 3616] r8301 - code/branches/spaceboundaries/src/orxonox/worldentities
kmaurus at orxonox.net
kmaurus at orxonox.net
Fri Apr 22 18:42:42 CEST 2011
Author: kmaurus
Date: 2011-04-22 18:42:42 +0200 (Fri, 22 Apr 2011)
New Revision: 8301
Modified:
code/branches/spaceboundaries/src/orxonox/worldentities/SpaceBoundaries.cc
code/branches/spaceboundaries/src/orxonox/worldentities/SpaceBoundaries.h
Log:
several billboards that represent the boundary can be displayed now
Modified: code/branches/spaceboundaries/src/orxonox/worldentities/SpaceBoundaries.cc
===================================================================
--- code/branches/spaceboundaries/src/orxonox/worldentities/SpaceBoundaries.cc 2011-04-22 16:32:29 UTC (rev 8300)
+++ code/branches/spaceboundaries/src/orxonox/worldentities/SpaceBoundaries.cc 2011-04-22 16:42:42 UTC (rev 8301)
@@ -37,11 +37,6 @@
#include "interfaces/RadarViewable.h"
#include "graphics/Billboard.h"
-
-//#include <OgreTextAreaOverlayElement.h>
-#include <OgreOverlayManager.h>
-//#include <overlays/OverlayText.h>
-
namespace orxonox
{
CreateFactory(SpaceBoundaries);
@@ -61,8 +56,6 @@
this->centerRadar_ = new RadarViewable(this, this);
this->centerRadar_->setRadarObjectShape(RadarViewable::Dot);
this->centerRadar_->setRadarVisibility(false);
-
-// m_pColoredTextAreaOverlayElementFactory = new ColoredTextAreaOverlayElementFactory();
}
SpaceBoundaries::~SpaceBoundaries()
{
@@ -75,7 +68,14 @@
this->pawnsIn_.clear();
-// delete pColoredTextAreaOverlayElementFactory;
+ for( std::vector<billboardAdministration>::iterator current = this->billboards_.begin(); current != this->billboards_.end(); current++)
+ {
+ if( current->billy != NULL)
+ {
+ delete current->billy;
+ }
+ }
+ this->billboards_.clear();
}
void SpaceBoundaries::checkWhoIsIn()
@@ -92,6 +92,49 @@
}
}
+ void SpaceBoundaries::positionBillboard(const Vector3 position)
+ {
+ std::vector<billboardAdministration>::iterator current;
+ for( current = this->billboards_.begin(); current != this->billboards_.end(); current++)
+ {
+ if(!current->usedYet)
+ {
+ break;
+ }
+ }
+ if( current == this->billboards_.end() )
+ {
+ Billboard *tmp = new Billboard(this);
+ setBillboardOptions( tmp );
+ tmp->setPosition(position);
+ billboardAdministration tmp2 = { true, tmp };
+ this->billboards_.push_back( tmp2 );
+
+ } else {
+ current->billy->setPosition(position);
+ current->billy->setVisible(true);
+ current->usedYet = true;
+ }
+ }
+
+ void SpaceBoundaries::setBillboardOptions(Billboard *billy)
+ {
+ if(billy != NULL)
+ {
+ billy->setMaterial("Shield");
+ billy->setVisible(true);
+ }
+ }
+
+ void SpaceBoundaries::removeAllBillboards()
+ {
+ for( std::vector<billboardAdministration>::iterator current = this->billboards_.begin(); current != this->billboards_.end(); current++ )
+ {
+ current->usedYet = false;
+ current->billy->setVisible(false);
+ }
+ }
+
void SpaceBoundaries::setMaxDistance(float r)
{
this->maxDistance_ = r;
@@ -139,19 +182,20 @@
void SpaceBoundaries::tick(float dt)
{
-
+ this->removeAllBillboards();
COUT(0) << "Groesse der Liste: " << (int) pawnsIn_.size() << std::endl;
- //for(ObjectListIterator<Pawn> current = ObjectList<Pawn>::begin(); current != ObjectList<Pawn>::end(); ++current)
+ float distance;
+ bool humanItem;
for( std::list<Pawn*>::iterator current = pawnsIn_.begin(); current != pawnsIn_.end(); current++ )
{
Pawn* currentPawn = *current;
- float distance = this->computeDistance(currentPawn);
- bool humanItem = this->isHumanPlayer(currentPawn);
- COUT(0) << "Distanz:" << distance << std::endl; //!< message for debugging
+ distance = this->computeDistance(currentPawn);
+ humanItem = this->isHumanPlayer(currentPawn);
+ COUT(0) << "Distanz:" << distance << std::endl; // message for debugging
if(distance > this->warnDistance_ && distance < this->maxDistance_) // Zeige Warnung an!
{
- COUT(0) << "You are leaving the area" << std::endl; //!< message for debugging
+ COUT(0) << "You are leaving the area" << std::endl; // message for debugging
if(humanItem)
{
COUT(0) << "humanItem ist true" << std::endl;
@@ -184,35 +228,18 @@
float SpaceBoundaries::computeDistance(WorldEntity *item)
{
- Vector3 itemPosition = item->getPosition();
- return (itemPosition.distance(this->getPosition()));
+ if(item != NULL)
+ {
+ Vector3 itemPosition = item->getPosition();
+ return (itemPosition.distance(this->getPosition()));
+ } else {
+ return -1;
+ }
}
void SpaceBoundaries::displayWarning(const std::string warnText)
- { /*
- Ogre::TextAreaOverlayElement *pTextArea;
- Ogre::OverlayManager manager = Ogre::OverlayManager();
- Ogre::OverlayElement temp = manager.createOverlayElement("TextArea", "MyTextArea");
- //pTextArea = (Ogre::TextAreaOverlayElement *)
- // pTextArea->setCaption("Some plain text");
-
- Ogre::TextAreaOverlayElement warning(warnText);
- warning.initialise();
- //warning.setPosition(0.2, 0.2);
+ {
-
- COUT(0) << "Breite des Warntextes: " << warning.getWidth() << std::endl;
- COUT(0) << "Hoehe des Warntextes: " << warning.getHeight() << std::endl;
-
- warning.show();*/
- // Register the overlay element
-/* OverlayManager::getSingleton().addOverlayElementFactory(pColoredTextAreaOverlayElementFactory);
-
- Ogre::TextAreaOverlayElement *pTextArea =
- (Ogre::TextAreaOverlayElement*)Ogre::OverlayManager.createOverlayElement("TextArea", "MyTextArea");
- pTextArea->setCaption("Some plain text");
-*/
-
}
void SpaceBoundaries::displayBoundaries(Pawn *item)
@@ -223,20 +250,13 @@
Vector3 boundaryPosition = this->getPosition() + direction * this->maxDistance_;
- if(this->boundary_ == NULL)
- {
- this->boundary_ = new Billboard(this);
- this->boundary_->setMaterial("Examples/Flare");
- this->boundary_->setVisible(true);
- }
-
- this->boundary_->setPosition(boundaryPosition);
+ this->positionBillboard(boundaryPosition);
}
void SpaceBoundaries::bounceBack(Pawn *item)
{
Vector3 normal = item->getPosition() - this->getPosition();
- if( item->getVelocity().dotProduct(normal) > 0 ) // greife nur ein, falls
+ if( item->getVelocity().dotProduct(normal) > 0 ) // Greife nur ein, falls sich das Pawn nach Aussen bewegt.
{
float dampingFactor = 0.5;
@@ -245,17 +265,6 @@
velocity = velocity.reflect(normal);
Vector3 acceleration = item->getAcceleration();
acceleration = acceleration.reflect(normal);
- /*
- Vector3 rotationAxis = velocity.crossProduct(normal);
- Ogre::Radian angle = 2 * velocity.angleBetween(normal);
- item->setOrientation(Ogre::Quaternion::Quaternion(angle, rotationAxis));
- */
- /*
- Ogre::Quaternion orientation = item->getOrientation();
- orientation = -1.0 * orientation;
- item->setOrientation(orientation);
- */
- //item->setOrientation(item->getOrientation().UnitInverse() );
item->lookAt( velocity + this->getPosition() );
Modified: code/branches/spaceboundaries/src/orxonox/worldentities/SpaceBoundaries.h
===================================================================
--- code/branches/spaceboundaries/src/orxonox/worldentities/SpaceBoundaries.h 2011-04-22 16:32:29 UTC (rev 8300)
+++ code/branches/spaceboundaries/src/orxonox/worldentities/SpaceBoundaries.h 2011-04-22 16:42:42 UTC (rev 8301)
@@ -26,8 +26,7 @@
*
*/
- /* TODO: - Mehrere SpaceBoundaries-Instanzen pro Level ermoeglichen
- - Pro Pawn ein Billboard verwenden
+ /* TODO: - Sobald Bots im Spiel sind, stürzt das Programm relativ bald ab!!!
*/
@@ -51,10 +50,10 @@
#include "worldentities/StaticEntity.h"
#include "worldentities/WorldEntity.h"
-//#include <ColoredTextAreaOverlayElementFactory.h>
-
#include <string>
#include <list>
+#include <map>
+#include <vector>
/**
@brief SpaceBoundaries gives level creators the possibility to bar Pawns from leaving a defined area.
@@ -77,8 +76,12 @@
SpaceBoundaries(BaseObject* creator);
~SpaceBoundaries();
- void checkWhoIsIn();
+ void checkWhoIsIn(); //!< Update the list 'pawnsIn_'.
+ void positionBillboard(const Vector3 position);
+ void setBillboardOptions(Billboard *billy);
+ void removeAllBillboards();
+
void setMaxDistance(float r);
float getMaxDistance();
@@ -96,7 +99,11 @@
void tick(float dt);
private:
- std::list<Pawn*> pawnsIn_;
+ struct billboardAdministration{ bool usedYet; Billboard* billy; };
+
+ std::list<Pawn*> pawnsIn_; //!< List of the pawns that this instance of SpaceBoundaries has to handle.
+
+ std::vector<billboardAdministration> billboards_;
float maxDistance_; //!< maximal zulaessige Entfernung von 'this->getPosition()'.
float warnDistance_; //!< Entfernung von 'this->getPosition()', ab der eine Warnung angezeigt wird, dass man bald das zulaessige Areal verlaesst.
@@ -115,7 +122,6 @@
void bounceBack(Pawn *item);
bool isHumanPlayer(Pawn *item);
- // ColoredTextAreaOverlayElementFactory* pColoredTextAreaOverlayElementFactory;
};
}
More information about the Orxonox-commit
mailing list