[Orxonox-commit 3478] r8164 - code/branches/spaceboundaries/src/orxonox/worldentities
kmaurus at orxonox.net
kmaurus at orxonox.net
Thu Mar 31 16:12:02 CEST 2011
Author: kmaurus
Date: 2011-03-31 16:12:02 +0200 (Thu, 31 Mar 2011)
New Revision: 8164
Modified:
code/branches/spaceboundaries/src/orxonox/worldentities/SpaceBoundaries.cc
code/branches/spaceboundaries/src/orxonox/worldentities/SpaceBoundaries.h
Log:
Es wird nun erkannt, wenn das Spaceship sich zu weit entfernt. Meldung wird noch nicht angezeigt.
Modified: code/branches/spaceboundaries/src/orxonox/worldentities/SpaceBoundaries.cc
===================================================================
--- code/branches/spaceboundaries/src/orxonox/worldentities/SpaceBoundaries.cc 2011-03-31 13:35:59 UTC (rev 8163)
+++ code/branches/spaceboundaries/src/orxonox/worldentities/SpaceBoundaries.cc 2011-03-31 14:12:02 UTC (rev 8164)
@@ -36,8 +36,15 @@
/* Eigene, spezifische include-Statements*/
#include "worldentities/MobileEntity.h"
+#include "worldentities/ControllableEntity.h"
#include "core/ObjectListIterator.h"
+#include <worldentities/pawns/Pawn.h>
+#include <infos/PlayerInfo.h>
+#include <OgreTextAreaOverlayElement.h>
+#include <OgreOverlayManager.h>
+#include <overlays/OverlayText.h>
+
namespace orxonox
{
CreateFactory(SpaceBoundaries);
@@ -45,12 +52,13 @@
SpaceBoundaries::SpaceBoundaries(BaseObject* creator) : StaticEntity(creator)
{
RegisterObject(SpaceBoundaries);
-
+ COUT(0) << "Test ob Konstruktor aufgerufen wird." << std::endl; //!< message for debugging
// Show Boundaries on the radar.
+ m_pColoredTextAreaOverlayElementFactory = new ColoredTextAreaOverlayElementFactory();
}
SpaceBoundaries::~SpaceBoundaries()
{
-
+ delete pColoredTextAreaOverlayElementFactory;
}
void SpaceBoundaries::setCenter(Vector3 r)
@@ -93,14 +101,35 @@
{
for(ObjectListIterator<MobileEntity> item = ObjectList<MobileEntity>::begin(); item != ObjectList<MobileEntity>::end(); ++item)
{
- float distance = computeDistance((WorldEntity *)&item); // fuer casts gibt's scheinbar andere, neuere Variante --> vgl. Coding-Guide und andere Files
- if(distance > this->warnDistance && distance < this->maxDistance)
+ MobileEntity* myMobileEntity = *item;
+ Pawn* myItem = dynamic_cast<Pawn*>(myMobileEntity);
+ //COUT(0) << "Die for-Schleife wird erreicht!!!" << std::endl; //!< message for debugging
+ if(myItem != NULL)
{
- COUT(0) << "You are leaving the area" << std::endl; //!< message for debugging
- // Display Warning on Screen if the humanPlayer (infos/PlayerInfo.h) is leaving the area
- } else if(distance > maxDistance)
- {
- // Decrease Health
+ float distance = computeDistance((WorldEntity*) myItem);
+ bool humanItem = this->isHumanPlayer(myItem);
+ COUT(0) << "Pawn wird erkannt!!!" << std::endl; //!< message for debugging
+ COUT(0) << "Distanz:" << distance << std::endl; //!< message for debugging
+ if(distance > this->warnDistance /*&& distance < this->maxDistance*/)
+ {
+ COUT(0) << "You are leaving the area" << std::endl; //!< message for debugging
+ if(humanItem)
+ {
+ COUT(0) << "humanItem ist true" << std::endl;
+ this->displayWarning("Attention! You are leaving the area!");
+ } else {
+
+ }
+ } else if(distance > maxDistance)
+ {
+ // Decrease Health
+ if(humanItem)
+ {
+
+ } else {
+
+ }
+ }
}
}
}
@@ -108,11 +137,45 @@
float SpaceBoundaries::computeDistance(WorldEntity *item)
{
Vector3 itemPosition = item->getPosition();
- return (itemPosition.distance(center));
+ return (itemPosition.distance(this->center));
}
+ 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");
+
+
+ }
+ bool SpaceBoundaries::isHumanPlayer(Pawn *item)
+ {
+ if(item != NULL)
+ {
+ return item->getPlayer()->isHumanPlayer();
+ } else {
+ return false;
+ }
+ }
@@ -135,4 +198,5 @@
+
}
Modified: code/branches/spaceboundaries/src/orxonox/worldentities/SpaceBoundaries.h
===================================================================
--- code/branches/spaceboundaries/src/orxonox/worldentities/SpaceBoundaries.h 2011-03-31 13:35:59 UTC (rev 8163)
+++ code/branches/spaceboundaries/src/orxonox/worldentities/SpaceBoundaries.h 2011-03-31 14:12:02 UTC (rev 8164)
@@ -31,7 +31,6 @@
/* Folgender Block ist Copy-Paste und somit teilweise wohl unnoetig */
#include "OrxonoxPrereqs.h"
-#include <string>
#include "core/SubclassIdentifier.h"
/* Einige, spezifische include-Statements */
@@ -40,7 +39,11 @@
#include "worldentities/StaticEntity.h"
#include "worldentities/WorldEntity.h"
+#include <ColoredTextAreaOverlayElementFactory.h>
+#include <string>
+
+
namespace orxonox
{
class _OrxonoxExport SpaceBoundaries : public StaticEntity, public Tickable
@@ -68,6 +71,9 @@
float warnDistance;
float computeDistance(WorldEntity *item); //!< Auf den Mittelpunkt 'center' bezogen.
+ void displayWarning(const std::string warnText);
+ bool isHumanPlayer(Pawn *item);
+ ColoredTextAreaOverlayElementFactory* pColoredTextAreaOverlayElementFactory;
};
}
More information about the Orxonox-commit
mailing list