- Timestamp:
- Apr 14, 2011, 4:53:27 PM (13 years ago)
- File:
-
- 1 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 {
Note: See TracChangeset
for help on using the changeset viewer.