Index: /code/branches/spaceboundaries/data/levels/myTestLevel.oxw
===================================================================
--- /code/branches/spaceboundaries/data/levels/myTestLevel.oxw (revision 8243)
+++ /code/branches/spaceboundaries/data/levels/myTestLevel.oxw (revision 8244)
@@ -30,7 +30,7 @@
-
+
-
+
Index: /code/branches/spaceboundaries/src/orxonox/worldentities/SpaceBoundaries.cc
===================================================================
--- /code/branches/spaceboundaries/src/orxonox/worldentities/SpaceBoundaries.cc (revision 8243)
+++ /code/branches/spaceboundaries/src/orxonox/worldentities/SpaceBoundaries.cc (revision 8244)
@@ -36,4 +36,5 @@
#include "infos/PlayerInfo.h"
#include "interfaces/RadarViewable.h"
+#include "graphics/Billboard.h"
@@ -52,4 +53,5 @@
this->setMaxDistance(3000);
this->setWarnDistance(2000);
+ this->setShowDistance(2500);
this->setHealthDecrease(1);
@@ -66,4 +68,10 @@
{
delete this->centerRadar_;
+
+ if(this->boundary_ != NULL)
+ {
+ delete this->boundary_;
+ }
+
// delete pColoredTextAreaOverlayElementFactory;
}
@@ -85,4 +93,13 @@
{
return this->warnDistance_;
+ }
+
+ void SpaceBoundaries::setShowDistance(float r)
+ {
+ this->showDistance_ = r;
+ }
+ float SpaceBoundaries::getShowDistance()
+ {
+ return this->showDistance_;
}
@@ -110,11 +127,11 @@
{
MobileEntity* myMobileEntity = *item;
- Pawn* myItem = dynamic_cast(myMobileEntity);
- if(myItem != NULL)
+ Pawn* currentPawn = dynamic_cast(myMobileEntity);
+ if(currentPawn != NULL)
{
- float distance = computeDistance((WorldEntity*) myItem);
- bool humanItem = this->isHumanPlayer(myItem);
+ float distance = this->computeDistance(currentPawn);
+ bool humanItem = this->isHumanPlayer(currentPawn);
COUT(0) << "Distanz:" << distance << std::endl; //!< message for debugging
- if(distance > this->warnDistance_ && distance < this->maxDistance_)
+ if(distance > this->warnDistance_ && distance < this->maxDistance_) // Zeige Warnung an!
{
COUT(0) << "You are leaving the area" << std::endl; //!< message for debugging
@@ -127,5 +144,10 @@
}
}
- if(distance > maxDistance_)
+ if( (this->maxDistance_ - distance) < this->showDistance_)
+ {
+ // Zeige Grenze an!
+ this->displayBoundaries(currentPawn);
+ }
+ if(distance > this->maxDistance_)
{
if(humanItem)
@@ -133,8 +155,10 @@
COUT(0) << "Health should be decreasing!" << std::endl;
this->displayWarning("You are out of the area now!");
- myItem->removeHealth( (distance - maxDistance_) * this->healthDecrease_);
+ currentPawn->removeHealth( (distance - maxDistance_) * this->healthDecrease_);
} else {
}
+
+ this->bounceBack(currentPawn);
}
}
@@ -175,4 +199,42 @@
}
+ void SpaceBoundaries::displayBoundaries(Pawn *item)
+ {
+
+ Vector3 direction = item->getPosition() - this->getPosition();
+ direction.normalise();
+
+ 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);
+ }
+
+ void SpaceBoundaries::bounceBack(Pawn *item)
+ {
+ Vector3 normal = item->getPosition() - this->getPosition();
+ if( item->getVelocity().dotProduct(normal) > 0 ) // greife nur ein, falls
+ {
+ normal.normalise();
+ Vector3 velocity = item->getVelocity();
+ velocity = velocity.reflect(normal);
+ Vector3 acceleration = item->getAcceleration();
+ acceleration = acceleration.reflect(normal);
+ /*
+ Vector3 rotationAxis = velocity.crossProduct(normal);
+ Ogre::Radian angle = velocity.angleBetween(normal);
+ item->setOrientation(Ogre::Quaternion::Quaternion(angle, rotationAxis));
+ */
+ item->setAcceleration(acceleration);
+ item->setVelocity(velocity);
+ }
+ }
+
bool SpaceBoundaries::isHumanPlayer(Pawn *item)
{
Index: /code/branches/spaceboundaries/src/orxonox/worldentities/SpaceBoundaries.h
===================================================================
--- /code/branches/spaceboundaries/src/orxonox/worldentities/SpaceBoundaries.h (revision 8243)
+++ /code/branches/spaceboundaries/src/orxonox/worldentities/SpaceBoundaries.h (revision 8244)
@@ -27,7 +27,6 @@
*/
- /* TODO: - Markiere SpaceBoundaries-Position mit einem schoenen Objekt
- - Kugel-Model mal hinzufuegen, das nur sichtbar ist, wenn man genuegend nah an maxDistance dran ist
- - Reflexion an obiger Kugel beim Versuch durchzudringen
+ /* TODO: - Markiere SpaceBoundaries-Position mit einem schoenen Objekt
+ - Reflexion an Grenze mit Quaternionen machen (--> vgl. Funktion bounceBack() )
*/
@@ -49,9 +48,10 @@
@brief SpaceBoundaries gives level creators the possibility to bar Pawns from leaving a defined area.
- Four attributes can/should be defined in the XML-File:
- - 'position' : absolute position of the SpaceBoundaries class. '*Distance' refers to this 'position'.
+ Five attributes can/should be defined in the XML-File:
+ - 'position' : absolute position of the SpaceBoundaries class. 'warnDistance' and 'maxDistance' refer to this 'position'.
- 'warnDistance' : If the distance between the pawn of the human player and 'position' is bigger than 'warnDistance', a message is displayed to
inform the player that he'll soon be leaving the allowed area.
- 'maxDistance' : defines the area, where a pawn is allowed to be (radius of a ball).
+ - 'showDistance' : If the distance between the pawn and the boundary of the allowed area is smaller than 'showDistance', the boundary is shown.
- 'healthDecrease' : a measure to define how fast the health of a pawn should decrease after leaving the allowed area.
Empfohlene Werte: 0.1 (langsame Health-Verminderung) bis 5 (sehr schnelle Health-Verminderung)
@@ -66,9 +66,12 @@
~SpaceBoundaries();
- void se tMaxDistance(float r);
+ void setMaxDistance(float r);
float getMaxDistance();
void setWarnDistance(float r);
float getWarnDistance();
+
+ void setShowDistance(float r);
+ float getShowDistance();
void setHealthDecrease(float amount);
@@ -82,7 +85,10 @@
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.
+ float showDistance_; //!< Definiert, wann die Grenzen visualisiert werden sollen.
float healthDecrease_; //!< Mass fuer die Anzahl Health-Points, die nach ueberschreiten der Entfernung 'maxDistance_' von 'this->getPosition()' abgezogen werden.
//!< Empfohlene Werte: 0.1 (langsame Health-Verminderung) bis 5 (sehr schnelle Health-Verminderung)
+
+ Billboard *boundary_;
RadarViewable* centerRadar_; //!< Repraesentation von SpaceBoundaries auf dem Radar.
@@ -90,4 +96,6 @@
float computeDistance(WorldEntity *item); //!< Auf den Mittelpunkt 'this->getPosition()' bezogen.
void displayWarning(const std::string warnText);
+ void displayBoundaries(Pawn *item);
+ void bounceBack(Pawn *item);
bool isHumanPlayer(Pawn *item);