Changeset 8244 for code/branches/spaceboundaries/src
- Timestamp:
- Apr 14, 2011, 4:53:27 PM (14 years ago)
- Location:
- code/branches/spaceboundaries/src/orxonox/worldentities
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/spaceboundaries/src/orxonox/worldentities/SpaceBoundaries.cc
r8201 r8244 36 36 #include "infos/PlayerInfo.h" 37 37 #include "interfaces/RadarViewable.h" 38 #include "graphics/Billboard.h" 38 39 39 40 … … 52 53 this->setMaxDistance(3000); 53 54 this->setWarnDistance(2000); 55 this->setShowDistance(2500); 54 56 this->setHealthDecrease(1); 55 57 … … 66 68 { 67 69 delete this->centerRadar_; 70 71 if(this->boundary_ != NULL) 72 { 73 delete this->boundary_; 74 } 75 68 76 // delete pColoredTextAreaOverlayElementFactory; 69 77 } … … 85 93 { 86 94 return this->warnDistance_; 95 } 96 97 void SpaceBoundaries::setShowDistance(float r) 98 { 99 this->showDistance_ = r; 100 } 101 float SpaceBoundaries::getShowDistance() 102 { 103 return this->showDistance_; 87 104 } 88 105 … … 110 127 { 111 128 MobileEntity* myMobileEntity = *item; 112 Pawn* myItem= dynamic_cast<Pawn*>(myMobileEntity);113 if( myItem!= NULL)129 Pawn* currentPawn = dynamic_cast<Pawn*>(myMobileEntity); 130 if(currentPawn != NULL) 114 131 { 115 float distance = computeDistance((WorldEntity*) myItem);116 bool humanItem = this->isHumanPlayer( myItem);132 float distance = this->computeDistance(currentPawn); 133 bool humanItem = this->isHumanPlayer(currentPawn); 117 134 COUT(0) << "Distanz:" << distance << std::endl; //!< message for debugging 118 if(distance > this->warnDistance_ && distance < this->maxDistance_) 135 if(distance > this->warnDistance_ && distance < this->maxDistance_) // Zeige Warnung an! 119 136 { 120 137 COUT(0) << "You are leaving the area" << std::endl; //!< message for debugging … … 127 144 } 128 145 } 129 if(distance > maxDistance_) 146 if( (this->maxDistance_ - distance) < this->showDistance_) 147 { 148 // Zeige Grenze an! 149 this->displayBoundaries(currentPawn); 150 } 151 if(distance > this->maxDistance_) 130 152 { 131 153 if(humanItem) … … 133 155 COUT(0) << "Health should be decreasing!" << std::endl; 134 156 this->displayWarning("You are out of the area now!"); 135 myItem->removeHealth( (distance - maxDistance_) * this->healthDecrease_);157 currentPawn->removeHealth( (distance - maxDistance_) * this->healthDecrease_); 136 158 } else { 137 159 138 160 } 161 162 this->bounceBack(currentPawn); 139 163 } 140 164 } … … 175 199 } 176 200 201 void SpaceBoundaries::displayBoundaries(Pawn *item) 202 { 203 204 Vector3 direction = item->getPosition() - this->getPosition(); 205 direction.normalise(); 206 207 Vector3 boundaryPosition = this->getPosition() + direction * this->maxDistance_; 208 209 if(this->boundary_ == NULL) 210 { 211 this->boundary_ = new Billboard(this); 212 this->boundary_->setMaterial("Examples/Flare"); 213 this->boundary_->setVisible(true); 214 } 215 216 this->boundary_->setPosition(boundaryPosition); 217 } 218 219 void SpaceBoundaries::bounceBack(Pawn *item) 220 { 221 Vector3 normal = item->getPosition() - this->getPosition(); 222 if( item->getVelocity().dotProduct(normal) > 0 ) // greife nur ein, falls 223 { 224 normal.normalise(); 225 Vector3 velocity = item->getVelocity(); 226 velocity = velocity.reflect(normal); 227 Vector3 acceleration = item->getAcceleration(); 228 acceleration = acceleration.reflect(normal); 229 /* 230 Vector3 rotationAxis = velocity.crossProduct(normal); 231 Ogre::Radian angle = velocity.angleBetween(normal); 232 item->setOrientation(Ogre::Quaternion::Quaternion(angle, rotationAxis)); 233 */ 234 item->setAcceleration(acceleration); 235 item->setVelocity(velocity); 236 } 237 } 238 177 239 bool SpaceBoundaries::isHumanPlayer(Pawn *item) 178 240 { -
code/branches/spaceboundaries/src/orxonox/worldentities/SpaceBoundaries.h
r8237 r8244 27 27 */ 28 28 29 /* TODO: - Markiere SpaceBoundaries-Position mit einem schoenen Objekt 30 - Kugel-Model mal hinzufuegen, das nur sichtbar ist, wenn man genuegend nah an maxDistance dran ist 31 - Reflexion an obiger Kugel beim Versuch durchzudringen 29 /* TODO: - Markiere SpaceBoundaries-Position mit einem schoenen Objekt 30 - Reflexion an Grenze mit Quaternionen machen (--> vgl. Funktion bounceBack() ) 32 31 */ 33 32 … … 49 48 @brief SpaceBoundaries gives level creators the possibility to bar Pawns from leaving a defined area. 50 49 51 F ourattributes can/should be defined in the XML-File:52 - 'position' : absolute position of the SpaceBoundaries class. ' *Distance' refersto this 'position'.50 Five attributes can/should be defined in the XML-File: 51 - 'position' : absolute position of the SpaceBoundaries class. 'warnDistance' and 'maxDistance' refer to this 'position'. 53 52 - 'warnDistance' : If the distance between the pawn of the human player and 'position' is bigger than 'warnDistance', a message is displayed to 54 53 inform the player that he'll soon be leaving the allowed area. 55 54 - 'maxDistance' : defines the area, where a pawn is allowed to be (radius of a ball). 55 - 'showDistance' : If the distance between the pawn and the boundary of the allowed area is smaller than 'showDistance', the boundary is shown. 56 56 - 'healthDecrease' : a measure to define how fast the health of a pawn should decrease after leaving the allowed area. 57 57 Empfohlene Werte: 0.1 (langsame Health-Verminderung) bis 5 (sehr schnelle Health-Verminderung) … … 66 66 ~SpaceBoundaries(); 67 67 68 void se 68 void setMaxDistance(float r); 69 69 float getMaxDistance(); 70 70 71 71 void setWarnDistance(float r); 72 72 float getWarnDistance(); 73 74 void setShowDistance(float r); 75 float getShowDistance(); 73 76 74 77 void setHealthDecrease(float amount); … … 82 85 float maxDistance_; //!< maximal zulaessige Entfernung von 'this->getPosition()'. 83 86 float warnDistance_; //!< Entfernung von 'this->getPosition()', ab der eine Warnung angezeigt wird, dass man bald das zulaessige Areal verlaesst. 87 float showDistance_; //!< Definiert, wann die Grenzen visualisiert werden sollen. 84 88 85 89 float healthDecrease_; //!< Mass fuer die Anzahl Health-Points, die nach ueberschreiten der Entfernung 'maxDistance_' von 'this->getPosition()' abgezogen werden. 86 90 //!< Empfohlene Werte: 0.1 (langsame Health-Verminderung) bis 5 (sehr schnelle Health-Verminderung) 91 92 Billboard *boundary_; 87 93 88 94 RadarViewable* centerRadar_; //!< Repraesentation von SpaceBoundaries auf dem Radar. … … 90 96 float computeDistance(WorldEntity *item); //!< Auf den Mittelpunkt 'this->getPosition()' bezogen. 91 97 void displayWarning(const std::string warnText); 98 void displayBoundaries(Pawn *item); 99 void bounceBack(Pawn *item); 92 100 bool isHumanPlayer(Pawn *item); 93 101
Note: See TracChangeset
for help on using the changeset viewer.