[Orxonox-commit 3558] r8244 - in code/branches/spaceboundaries: data/levels src/orxonox/worldentities
kmaurus at orxonox.net
kmaurus at orxonox.net
Thu Apr 14 16:53:28 CEST 2011
Author: kmaurus
Date: 2011-04-14 16:53:27 +0200 (Thu, 14 Apr 2011)
New Revision: 8244
Modified:
code/branches/spaceboundaries/data/levels/myTestLevel.oxw
code/branches/spaceboundaries/src/orxonox/worldentities/SpaceBoundaries.cc
code/branches/spaceboundaries/src/orxonox/worldentities/SpaceBoundaries.h
Log:
Pawns that want to leave the area are reflected, one billboard is added that represents the boundary
Modified: code/branches/spaceboundaries/data/levels/myTestLevel.oxw
===================================================================
--- code/branches/spaceboundaries/data/levels/myTestLevel.oxw 2011-04-14 14:33:33 UTC (rev 8243)
+++ code/branches/spaceboundaries/data/levels/myTestLevel.oxw 2011-04-14 14:53:27 UTC (rev 8244)
@@ -29,9 +29,9 @@
>
<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" lookat="200,0,0" spawnclass=SpaceShip pawndesign=spaceshipassff />
+ <SpawnPoint team=0 position="0,0,0" lookat="2,0,0" spawnclass=SpaceShip pawndesign=spaceshipassff />
- <SpaceBoundaries warnDistance="-1" maxDistance="200" healthDecrease="0.1" position="200,0,0"/>
+ <SpaceBoundaries warnDistance="1" maxDistance="200" showDistance="100" healthDecrease="0.1" position="0,0,0"/>
</Scene>
</Level>
Modified: code/branches/spaceboundaries/src/orxonox/worldentities/SpaceBoundaries.cc
===================================================================
--- code/branches/spaceboundaries/src/orxonox/worldentities/SpaceBoundaries.cc 2011-04-14 14:33:33 UTC (rev 8243)
+++ code/branches/spaceboundaries/src/orxonox/worldentities/SpaceBoundaries.cc 2011-04-14 14:53:27 UTC (rev 8244)
@@ -35,6 +35,7 @@
#include "worldentities/pawns/Pawn.h"
#include "infos/PlayerInfo.h"
#include "interfaces/RadarViewable.h"
+#include "graphics/Billboard.h"
//#include <OgreTextAreaOverlayElement.h>
@@ -51,6 +52,7 @@
* falls im XML-File keine Werte spezifiziert wurden. */
this->setMaxDistance(3000);
this->setWarnDistance(2000);
+ this->setShowDistance(2500);
this->setHealthDecrease(1);
RegisterObject(SpaceBoundaries);
@@ -65,6 +67,12 @@
SpaceBoundaries::~SpaceBoundaries()
{
delete this->centerRadar_;
+
+ if(this->boundary_ != NULL)
+ {
+ delete this->boundary_;
+ }
+
// delete pColoredTextAreaOverlayElementFactory;
}
@@ -86,6 +94,15 @@
return this->warnDistance_;
}
+ void SpaceBoundaries::setShowDistance(float r)
+ {
+ this->showDistance_ = r;
+ }
+ float SpaceBoundaries::getShowDistance()
+ {
+ return this->showDistance_;
+ }
+
void SpaceBoundaries::setHealthDecrease(float amount)
{
this->healthDecrease_ = amount/1000;
@@ -109,13 +126,13 @@
for(ObjectListIterator<MobileEntity> item = ObjectList<MobileEntity>::begin(); item != ObjectList<MobileEntity>::end(); ++item)
{
MobileEntity* myMobileEntity = *item;
- Pawn* myItem = dynamic_cast<Pawn*>(myMobileEntity);
- if(myItem != NULL)
+ Pawn* currentPawn = dynamic_cast<Pawn*>(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
if(humanItem)
@@ -126,16 +143,23 @@
}
}
- if(distance > maxDistance_)
+ if( (this->maxDistance_ - distance) < this->showDistance_)
{
+ // Zeige Grenze an!
+ this->displayBoundaries(currentPawn);
+ }
+ if(distance > this->maxDistance_)
+ {
if(humanItem)
{
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);
}
}
}
@@ -174,6 +198,44 @@
}
+ 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)
{
if(item != NULL)
Modified: code/branches/spaceboundaries/src/orxonox/worldentities/SpaceBoundaries.h
===================================================================
--- code/branches/spaceboundaries/src/orxonox/worldentities/SpaceBoundaries.h 2011-04-14 14:33:33 UTC (rev 8243)
+++ code/branches/spaceboundaries/src/orxonox/worldentities/SpaceBoundaries.h 2011-04-14 14:53:27 UTC (rev 8244)
@@ -26,9 +26,8 @@
*
*/
- /* 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() )
*/
#ifndef _SpaceBoundaries_H__
@@ -48,11 +47,12 @@
/**
@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)
*/
@@ -65,12 +65,15 @@
SpaceBoundaries(BaseObject* creator);
~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);
float getHealthDecrease();
@@ -81,14 +84,19 @@
private:
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.
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);
// ColoredTextAreaOverlayElementFactory* pColoredTextAreaOverlayElementFactory;
More information about the Orxonox-commit
mailing list