- Timestamp:
- May 5, 2011, 4:14:07 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/spaceboundaries/src/orxonox/worldentities/SpaceBoundaries.cc
r8301 r8404 50 50 this->setShowDistance(2500); 51 51 this->setHealthDecrease(1); 52 this->setReaction(0); 52 53 53 54 RegisterObject(SpaceBoundaries); … … 62 63 delete this->centerRadar_; 63 64 64 if(this->boundary_ != NULL)65 {66 delete this->boundary_;67 }68 69 65 this->pawnsIn_.clear(); 70 66 … … 106 102 { 107 103 Billboard *tmp = new Billboard(this); 108 setBillboardOptions( tmp );104 this->setBillboardOptions( tmp ); 109 105 tmp->setPosition(position); 110 106 billboardAdministration tmp2 = { true, tmp }; … … 171 167 return this->healthDecrease_; 172 168 } 169 170 void SpaceBoundaries::setReaction(int mode) 171 { 172 this->reaction_ = mode; 173 } 174 int SpaceBoundaries::getReaction() 175 { 176 return this->reaction_; 177 } 173 178 174 179 void SpaceBoundaries::XMLPort(Element& xmlelement, XMLPort::Mode mode) … … 179 184 XMLPortParam(SpaceBoundaries, "warnDistance", setWarnDistance, getWarnDistance, xmlelement, mode); 180 185 XMLPortParam(SpaceBoundaries, "healthDecrease", setHealthDecrease, getHealthDecrease, xmlelement, mode); 186 XMLPortParam(SpaceBoundaries, "reactionMode", setReaction, getReaction, xmlelement, mode); 181 187 } 182 188 183 189 void SpaceBoundaries::tick(float dt) 184 190 { 191 this->checkWhoIsIn(); 185 192 this->removeAllBillboards(); 186 193 COUT(0) << "Groesse der Liste: " << (int) pawnsIn_.size() << std::endl; … … 188 195 float distance; 189 196 bool humanItem; 190 for( std::list<Pawn*>::iterator current = pawnsIn_.begin(); current != pawnsIn_.end(); current++ ) 191 { 192 Pawn* currentPawn = *current; 193 distance = this->computeDistance(currentPawn); 194 humanItem = this->isHumanPlayer(currentPawn); 195 COUT(0) << "Distanz:" << distance << std::endl; // message for debugging 196 if(distance > this->warnDistance_ && distance < this->maxDistance_) // Zeige Warnung an! 197 { 198 COUT(0) << "You are leaving the area" << std::endl; // message for debugging 199 if(humanItem) 200 { 201 COUT(0) << "humanItem ist true" << std::endl; 202 this->displayWarning("Attention! You are leaving the area!"); 203 } else { 204 205 } 206 } 207 if( (this->maxDistance_ - distance) < this->showDistance_) 208 { 209 // Zeige Grenze an! 210 this->displayBoundaries(currentPawn); 211 } 212 if(distance > this->maxDistance_) 213 { 214 if(humanItem) 215 { 216 COUT(0) << "Health should be decreasing!" << std::endl; 217 this->displayWarning("You are out of the area now!"); 218 currentPawn->removeHealth( (distance - maxDistance_) * this->healthDecrease_); 219 } else { 220 221 } 222 223 this->bounceBack(currentPawn); 224 } 225 } 226 this->checkWhoIsIn(); 197 for( std::list<WeakPtr<Pawn> >::iterator current = pawnsIn_.begin(); current != pawnsIn_.end(); current++ ) 198 { 199 Pawn* currentPawn = current->get(); 200 if( currentPawn && currentPawn->getNode() ) 201 { 202 distance = this->computeDistance(currentPawn); 203 humanItem = this->isHumanPlayer(currentPawn); 204 COUT(0) << "Distanz:" << distance << std::endl; // message for debugging 205 if(distance > this->warnDistance_ && distance < this->maxDistance_) // Zeige Warnung an! 206 { 207 COUT(0) << "You are near by the boundaries!" << std::endl; // message for debugging 208 if(humanItem) 209 { 210 COUT(0) << "humanItem ist true" << std::endl; 211 this->displayWarning("Attention! You are near by the boundaries!"); 212 } 213 } 214 if( (this->maxDistance_ - distance) < this->showDistance_ ) 215 { 216 this->displayBoundaries(currentPawn); // Zeige Grenze an! 217 } 218 if(distance > this->maxDistance_ && (this->reaction_ == 1) ) 219 { 220 if( humanItem ) 221 { 222 COUT(0) << "Health should be decreasing!" << std::endl; 223 this->displayWarning("You are out of the area now!"); 224 } 225 currentPawn->removeHealth( (distance - this->maxDistance_) * this->healthDecrease_); 226 } 227 if( (this->reaction_ == 0) && (distance + 100 > this->maxDistance_)) // Annahme: Ein Pawn kann von einem Tick bis zum nächsten nicht mehr als 100 Distanzeinheiten zurücklegen. 228 { 229 this->conditionalBounceBack(currentPawn, distance, dt); 230 } 231 } 232 } 227 233 } 228 234 … … 254 260 } 255 261 256 void SpaceBoundaries:: bounceBack(Pawn *item)262 void SpaceBoundaries::conditionalBounceBack(Pawn *item, float currentDistance, float dt) 257 263 { 258 264 Vector3 normal = item->getPosition() - this->getPosition(); 259 if( item->getVelocity().dotProduct(normal) > 0 ) // Greife nur ein, falls sich das Pawn nach Aussen bewegt. 265 normal.normalise(); 266 Vector3 velocity = item->getVelocity(); 267 float normalSpeed = item->getVelocity().dotProduct(normal); 268 269 /* Checke, ob das Pawn innerhalb des nächsten Ticks, das erlaubte Gebiet verlassen würde. 270 Falls ja: Spicke es zurück. */ 271 if( currentDistance + normalSpeed * dt > this->maxDistance_ ) 260 272 { 261 273 float dampingFactor = 0.5; 262 263 normal.normalise();264 Vector3 velocity = item->getVelocity();265 274 velocity = velocity.reflect(normal); 266 275 Vector3 acceleration = item->getAcceleration();
Note: See TracChangeset
for help on using the changeset viewer.