[Orxonox-commit 3837] r8513 - in code/branches/spaceboundaries2: data/levels src/orxonox/worldentities
kmaurus at orxonox.net
kmaurus at orxonox.net
Thu May 19 16:16:55 CEST 2011
Author: kmaurus
Date: 2011-05-19 16:16:55 +0200 (Thu, 19 May 2011)
New Revision: 8513
Modified:
code/branches/spaceboundaries2/data/levels/myTestLevel.oxw
code/branches/spaceboundaries2/src/orxonox/worldentities/SpaceBoundaries.cc
code/branches/spaceboundaries2/src/orxonox/worldentities/SpaceBoundaries.h
Log:
third reactionMode added
Modified: code/branches/spaceboundaries2/data/levels/myTestLevel.oxw
===================================================================
--- code/branches/spaceboundaries2/data/levels/myTestLevel.oxw 2011-05-19 14:13:10 UTC (rev 8512)
+++ code/branches/spaceboundaries2/data/levels/myTestLevel.oxw 2011-05-19 14:16:55 UTC (rev 8513)
@@ -31,8 +31,10 @@
<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="2,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="100" reactionMode="2" healthDecrease="0.9" position="0,0,0"/>
+ <Billboard position="0,0,0" colour="1.0,1.0,1.0" material="Flares/backlightflare" scale=1 />
+
</Scene>
</Level>
Modified: code/branches/spaceboundaries2/src/orxonox/worldentities/SpaceBoundaries.cc
===================================================================
--- code/branches/spaceboundaries2/src/orxonox/worldentities/SpaceBoundaries.cc 2011-05-19 14:13:10 UTC (rev 8512)
+++ code/branches/spaceboundaries2/src/orxonox/worldentities/SpaceBoundaries.cc 2011-05-19 14:16:55 UTC (rev 8513)
@@ -86,6 +86,12 @@
{
pawnsIn_.push_back(currentPawn);
}
+ } else if (this->reaction_ == 2) {
+ float distance = this->computeDistance(currentPawn);
+ if(distance >= this->maxDistance_)
+ {
+ pawnsIn_.push_back(currentPawn);
+ }
} else {
pawnsIn_.push_back(currentPawn);
}
@@ -121,7 +127,7 @@
{
if(billy != NULL)
{
- billy->setMaterial("Shield");
+ billy->setMaterial("Grid");
billy->setVisible(true);
}
}
@@ -215,7 +221,7 @@
this->displayWarning("Attention! You are close to the boundary!");
}
}
- if( humanItem && (this->maxDistance_ - distance) < this->showDistance_ )
+ if(/* humanItem &&*/ abs(this->maxDistance_ - distance) < this->showDistance_ )
{
this->displayBoundaries(currentPawn); // Zeige Grenze an!
}
@@ -232,6 +238,10 @@
{
this->conditionalBounceBack(currentPawn, distance, dt);
}
+ if( this->reaction_ == 2 && (distance - 100 < this->maxDistance_) )
+ {
+ this->conditionalBounceBack(currentPawn, distance, dt);
+ }
}
}
}
@@ -272,22 +282,31 @@
/* Checke, ob das Pawn innerhalb des nächsten Ticks, das erlaubte Gebiet verlassen würde.
Falls ja: Spicke es zurück. */
- if( currentDistance + normalSpeed * dt > this->maxDistance_ - 20 ) // -20: "security measure"
+ if( this->reaction_ == 0 && currentDistance + normalSpeed * dt > this->maxDistance_ - 10 ) // -10: "security measure"
{
- float dampingFactor = 0.5;
- velocity = velocity.reflect(normal);
- Vector3 acceleration = item->getAcceleration();
- acceleration = acceleration.reflect(normal);
-
- item->lookAt( velocity + this->getPosition() );
-
- item->setAcceleration(acceleration * dampingFactor);
- item->setVelocity(velocity * dampingFactor);
-
- item->setPosition( item->getPosition() - normal * 10 );
+ bounceBack(item, &normal, &velocity);
+ } else if (this->reaction_ == 2 && currentDistance - normalSpeed * dt < this->maxDistance_ + 10 ) // 10: "security measure"
+ {
+ normal = normal * (-1);
+ bounceBack(item, &normal, &velocity);
}
}
+ void SpaceBoundaries::bounceBack(Pawn *item, Vector3 *normal, Vector3 *velocity)
+ {
+ float dampingFactor = 0.5;
+ *velocity = velocity->reflect(*normal);
+ Vector3 acceleration = item->getAcceleration();
+ acceleration = acceleration.reflect(*normal);
+
+ item->lookAt( *velocity + this->getPosition() );
+
+ item->setAcceleration(acceleration * dampingFactor);
+ item->setVelocity(*velocity * dampingFactor);
+
+ item->setPosition( item->getPosition() - *normal * 10 ); // Setze das SpaceShip noch etwas von der Grenze weg.
+ }
+
bool SpaceBoundaries::isHumanPlayer(Pawn *item)
{
if(item != NULL)
Modified: code/branches/spaceboundaries2/src/orxonox/worldentities/SpaceBoundaries.h
===================================================================
--- code/branches/spaceboundaries2/src/orxonox/worldentities/SpaceBoundaries.h 2011-05-19 14:13:10 UTC (rev 8512)
+++ code/branches/spaceboundaries2/src/orxonox/worldentities/SpaceBoundaries.h 2011-05-19 14:16:55 UTC (rev 8513)
@@ -26,7 +26,9 @@
*
*/
- /* TODO: - Textmessages und Billboards sollen teils nur bei einem humanPlayer angezeigt werden, nicht bei allen (vgl. Netzwerk-Spiel mit mehreren humanPlayers)
+ /* TODO: - Bei Reaction_ == 2 ist die Reflexion noch nicht ganz so top!! Vielleicht auch so belassen, ist ja nicht unbedingt schlecht.
+
+ - Textmessages und Billboards sollen teils nur bei einem humanPlayer angezeigt werden, nicht bei allen (vgl. Netzwerk-Spiel mit mehreren humanPlayers)
beachte hierzu folgende statische Funktion: 'static unsigned int Host::getPlayerID()'
(file:///home/kmaurus/orxonox/spaceBoundaries/build/doc/api/html/classorxonox_1_1_host.html#9c1e3b39e3b42e467dfbf42902911ce2)
@@ -66,6 +68,7 @@
- 'reactionMode' : Integer-Value. Defines what effect appears if a space ship has crossed the boundaries.
0: Reflect the space ship (default).
1: Decrease Health of the space ship after having left the allowed area.
+ 2: Inverted Version of 0. Prohibit to fly INTO a defined area.
- 'healthDecrease' : a measure to define how fast the health of a pawn should decrease after leaving the allowed area (unnecessary if 'reactionMode' == 0).
Recommended values: 0.1 (slow health decrease) to 5 (very fast health decrease)
@@ -88,12 +91,6 @@
SpaceBoundaries(BaseObject* creator);
~SpaceBoundaries();
- void checkWhoIsIn(); //!< Update the list 'pawnsIn_'.
-
- void positionBillboard(const Vector3 position); //!< 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.
-
void setMaxDistance(float r);
float getMaxDistance();
@@ -116,11 +113,15 @@
private:
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_;
- int reaction_; //!< Werte: 0, 1. 0: Reflektion an Boundaries (Standard). 1: Health-Abzug-Modus.
+ int reaction_; //!< Werte: 0, 1, 2.
+ //!< 0: Reflektion an Boundaries (Standard).
+ //!< 1: Health-Abzug-Modus.
+ //!< 2: Invertierte Version von 0. Verbiete es, in ein Gebiet hinein zu fliegen.
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.
@@ -128,14 +129,24 @@
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)
+
RadarViewable* centerRadar_; //!< Repraesentation von SpaceBoundaries auf dem Radar.
+
+ // Funktionen::
float computeDistance(WorldEntity *item); //!< Auf den Mittelpunkt 'this->getPosition()' bezogen.
void displayWarning(const std::string warnText);
void displayBoundaries(Pawn *item);
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 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