Changeset 8301
- Timestamp:
- Apr 22, 2011, 6:42:42 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
r8281 r8301 38 38 #include "graphics/Billboard.h" 39 39 40 41 //#include <OgreTextAreaOverlayElement.h>42 #include <OgreOverlayManager.h>43 //#include <overlays/OverlayText.h>44 45 40 namespace orxonox 46 41 { … … 62 57 this->centerRadar_->setRadarObjectShape(RadarViewable::Dot); 63 58 this->centerRadar_->setRadarVisibility(false); 64 65 // m_pColoredTextAreaOverlayElementFactory = new ColoredTextAreaOverlayElementFactory();66 59 } 67 60 SpaceBoundaries::~SpaceBoundaries() … … 76 69 this->pawnsIn_.clear(); 77 70 78 // delete pColoredTextAreaOverlayElementFactory; 71 for( std::vector<billboardAdministration>::iterator current = this->billboards_.begin(); current != this->billboards_.end(); current++) 72 { 73 if( current->billy != NULL) 74 { 75 delete current->billy; 76 } 77 } 78 this->billboards_.clear(); 79 79 } 80 80 … … 93 93 } 94 94 95 void SpaceBoundaries::positionBillboard(const Vector3 position) 96 { 97 std::vector<billboardAdministration>::iterator current; 98 for( current = this->billboards_.begin(); current != this->billboards_.end(); current++) 99 { 100 if(!current->usedYet) 101 { 102 break; 103 } 104 } 105 if( current == this->billboards_.end() ) 106 { 107 Billboard *tmp = new Billboard(this); 108 setBillboardOptions( tmp ); 109 tmp->setPosition(position); 110 billboardAdministration tmp2 = { true, tmp }; 111 this->billboards_.push_back( tmp2 ); 112 113 } else { 114 current->billy->setPosition(position); 115 current->billy->setVisible(true); 116 current->usedYet = true; 117 } 118 } 119 120 void SpaceBoundaries::setBillboardOptions(Billboard *billy) 121 { 122 if(billy != NULL) 123 { 124 billy->setMaterial("Shield"); 125 billy->setVisible(true); 126 } 127 } 128 129 void SpaceBoundaries::removeAllBillboards() 130 { 131 for( std::vector<billboardAdministration>::iterator current = this->billboards_.begin(); current != this->billboards_.end(); current++ ) 132 { 133 current->usedYet = false; 134 current->billy->setVisible(false); 135 } 136 } 137 95 138 void SpaceBoundaries::setMaxDistance(float r) 96 139 { … … 140 183 void SpaceBoundaries::tick(float dt) 141 184 { 142 185 this->removeAllBillboards(); 143 186 COUT(0) << "Groesse der Liste: " << (int) pawnsIn_.size() << std::endl; 144 187 145 //for(ObjectListIterator<Pawn> current = ObjectList<Pawn>::begin(); current != ObjectList<Pawn>::end(); ++current) 188 float distance; 189 bool humanItem; 146 190 for( std::list<Pawn*>::iterator current = pawnsIn_.begin(); current != pawnsIn_.end(); current++ ) 147 191 { 148 192 Pawn* currentPawn = *current; 149 floatdistance = this->computeDistance(currentPawn);150 boolhumanItem = this->isHumanPlayer(currentPawn);151 COUT(0) << "Distanz:" << distance << std::endl; // !<message for debugging193 distance = this->computeDistance(currentPawn); 194 humanItem = this->isHumanPlayer(currentPawn); 195 COUT(0) << "Distanz:" << distance << std::endl; // message for debugging 152 196 if(distance > this->warnDistance_ && distance < this->maxDistance_) // Zeige Warnung an! 153 197 { 154 COUT(0) << "You are leaving the area" << std::endl; // !<message for debugging198 COUT(0) << "You are leaving the area" << std::endl; // message for debugging 155 199 if(humanItem) 156 200 { … … 185 229 float SpaceBoundaries::computeDistance(WorldEntity *item) 186 230 { 187 Vector3 itemPosition = item->getPosition(); 188 return (itemPosition.distance(this->getPosition())); 231 if(item != NULL) 232 { 233 Vector3 itemPosition = item->getPosition(); 234 return (itemPosition.distance(this->getPosition())); 235 } else { 236 return -1; 237 } 189 238 } 190 239 191 240 void SpaceBoundaries::displayWarning(const std::string warnText) 192 { /* 193 Ogre::TextAreaOverlayElement *pTextArea; 194 Ogre::OverlayManager manager = Ogre::OverlayManager(); 195 Ogre::OverlayElement temp = manager.createOverlayElement("TextArea", "MyTextArea"); 196 //pTextArea = (Ogre::TextAreaOverlayElement *) 197 // pTextArea->setCaption("Some plain text"); 198 199 Ogre::TextAreaOverlayElement warning(warnText); 200 warning.initialise(); 201 //warning.setPosition(0.2, 0.2); 202 203 204 COUT(0) << "Breite des Warntextes: " << warning.getWidth() << std::endl; 205 COUT(0) << "Hoehe des Warntextes: " << warning.getHeight() << std::endl; 206 207 warning.show();*/ 208 // Register the overlay element 209 /* OverlayManager::getSingleton().addOverlayElementFactory(pColoredTextAreaOverlayElementFactory); 210 211 Ogre::TextAreaOverlayElement *pTextArea = 212 (Ogre::TextAreaOverlayElement*)Ogre::OverlayManager.createOverlayElement("TextArea", "MyTextArea"); 213 pTextArea->setCaption("Some plain text"); 214 */ 241 { 215 242 216 243 } … … 224 251 Vector3 boundaryPosition = this->getPosition() + direction * this->maxDistance_; 225 252 226 if(this->boundary_ == NULL) 227 { 228 this->boundary_ = new Billboard(this); 229 this->boundary_->setMaterial("Examples/Flare"); 230 this->boundary_->setVisible(true); 231 } 232 233 this->boundary_->setPosition(boundaryPosition); 253 this->positionBillboard(boundaryPosition); 234 254 } 235 255 … … 237 257 { 238 258 Vector3 normal = item->getPosition() - this->getPosition(); 239 if( item->getVelocity().dotProduct(normal) > 0 ) // greife nur ein, falls259 if( item->getVelocity().dotProduct(normal) > 0 ) // Greife nur ein, falls sich das Pawn nach Aussen bewegt. 240 260 { 241 261 float dampingFactor = 0.5; … … 246 266 Vector3 acceleration = item->getAcceleration(); 247 267 acceleration = acceleration.reflect(normal); 248 /*249 Vector3 rotationAxis = velocity.crossProduct(normal);250 Ogre::Radian angle = 2 * velocity.angleBetween(normal);251 item->setOrientation(Ogre::Quaternion::Quaternion(angle, rotationAxis));252 */253 /*254 Ogre::Quaternion orientation = item->getOrientation();255 orientation = -1.0 * orientation;256 item->setOrientation(orientation);257 */258 //item->setOrientation(item->getOrientation().UnitInverse() );259 268 260 269 item->lookAt( velocity + this->getPosition() ); -
code/branches/spaceboundaries/src/orxonox/worldentities/SpaceBoundaries.h
r8281 r8301 27 27 */ 28 28 29 /* TODO: - Mehrere SpaceBoundaries-Instanzen pro Level ermoeglichen 30 - Pro Pawn ein Billboard verwenden 29 /* TODO: - Sobald Bots im Spiel sind, stürzt das Programm relativ bald ab!!! 31 30 */ 32 31 … … 52 51 #include "worldentities/WorldEntity.h" 53 52 54 //#include <ColoredTextAreaOverlayElementFactory.h>55 56 53 #include <string> 57 54 #include <list> 55 #include <map> 56 #include <vector> 58 57 59 58 /** … … 78 77 ~SpaceBoundaries(); 79 78 80 void checkWhoIsIn(); 79 void checkWhoIsIn(); //!< Update the list 'pawnsIn_'. 80 81 void positionBillboard(const Vector3 position); 82 void setBillboardOptions(Billboard *billy); 83 void removeAllBillboards(); 81 84 82 85 void setMaxDistance(float r); … … 97 100 98 101 private: 99 std::list<Pawn*> pawnsIn_; 102 struct billboardAdministration{ bool usedYet; Billboard* billy; }; 103 104 std::list<Pawn*> pawnsIn_; //!< List of the pawns that this instance of SpaceBoundaries has to handle. 105 106 std::vector<billboardAdministration> billboards_; 100 107 101 108 float maxDistance_; //!< maximal zulaessige Entfernung von 'this->getPosition()'. … … 116 123 bool isHumanPlayer(Pawn *item); 117 124 118 // ColoredTextAreaOverlayElementFactory* pColoredTextAreaOverlayElementFactory;119 125 }; 120 126 }
Note: See TracChangeset
for help on using the changeset viewer.