Changeset 8614 for code/branches/presentation
- Timestamp:
- May 26, 2011, 5:40:16 PM (14 years ago)
- Location:
- code/branches/presentation
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/presentation
- Property svn:mergeinfo changed
/code/branches/spaceboundaries2 (added) merged: 8468,8506,8513,8604,8609,8613
- Property svn:mergeinfo changed
-
code/branches/presentation/data/levels/myTestLevel.oxw
r8458 r8614 30 30 31 31 <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"/> 32 <SpawnPoint team=0 position="0,0,0" lookat="2,0,0" spawnclass=SpaceShip pawndesign=spaceshipassff />32 <SpawnPoint team=0 position="0,0,0" direction="1,0,0" spawnclass=SpaceShip pawndesign=spaceshipassff /> 33 33 34 <SpaceBoundaries warnDistance="1" maxDistance="200" showDistance="100" healthDecrease="0.1" position="0,0,0"/> 34 <SpaceBoundaries warnDistance="1" maxDistance="200" showDistance="100" reactionMode="0" healthDecrease="0.9" position="0,0,0"/> 35 36 <Billboard position="0,0,0" colour="1.0,1.0,1.0" material="Flares/backlightflare" scale=1 /> 35 37 36 38 </Scene> -
code/branches/presentation/src/orxonox/graphics/Billboard.cc
r7492 r8614 23 23 * Fabian 'x3n' Landau 24 24 * Co-authors: 25 * Maurus Kaufmann 25 26 * ... 26 27 * … … 30 31 31 32 #include "OgreBillboard.h" 32 #include "OgreBillboardSet.h"33 33 34 34 #include "core/CoreIncludes.h" … … 46 46 47 47 this->colour_ = ColourValue::White; 48 //this->rotation_ = 0;48 this->rotation_ = 0; 49 49 50 50 this->registerVariables(); … … 66 66 XMLPortParam(Billboard, "material", setMaterial, getMaterial, xmlelement, mode); 67 67 XMLPortParam(Billboard, "colour", setColour, getColour, xmlelement, mode).defaultValues(ColourValue::White); 68 //XMLPortParam(Billboard, "rotation", setRotation, getRotation, xmlelement, mode).defaultValues(0);68 XMLPortParam(Billboard, "rotation", setRotation, getRotation, xmlelement, mode).defaultValues(0); 69 69 } 70 70 … … 73 73 registerVariable(this->material_, VariableDirection::ToClient, new NetworkCallback<Billboard>(this, &Billboard::changedMaterial)); 74 74 registerVariable(this->colour_, VariableDirection::ToClient, new NetworkCallback<Billboard>(this, &Billboard::changedColour)); 75 //registerVariable(this->rotation_, VariableDirection::ToClient, new NetworkCallback<Billboard>(this, &Billboard::changedRotation));75 registerVariable(this->rotation_, VariableDirection::ToClient, new NetworkCallback<Billboard>(this, &Billboard::changedRotation)); 76 76 } 77 77 … … 89 89 this->attachOgreObject(this->billboard_.getBillboardSet()); 90 90 this->billboard_.setVisible(this->isVisible()); 91 //this->changedRotation();91 this->changedRotation(); 92 92 } 93 93 } … … 114 114 } 115 115 116 /* 116 117 117 void Billboard::changedRotation() 118 118 { … … 128 128 } 129 129 } 130 */ 130 131 131 132 132 void Billboard::changedVisibility() … … 136 136 this->billboard_.setVisible(this->isVisible()); 137 137 } 138 139 void Billboard::setBillboardType(Ogre::BillboardType bbt) 140 { 141 Ogre::BillboardSet* bSet = this->billboard_.getBillboardSet(); 142 if( bSet != NULL ) 143 { 144 bSet->setBillboardType(bbt); 145 } 146 } 147 148 void Billboard::setCommonDirection(Vector3 vec) 149 { 150 Ogre::BillboardSet* bSet = this->billboard_.getBillboardSet(); 151 if( bSet != NULL ) 152 { 153 bSet->setCommonDirection( vec ); 154 } 155 } 156 157 void Billboard::setCommonUpVector(Vector3 vec) 158 { 159 Ogre::BillboardSet* bSet = this->billboard_.getBillboardSet(); 160 if( bSet != NULL ) 161 { 162 bSet->setCommonUpVector( vec ); 163 } 164 } 165 166 void Billboard::setDefaultDimensions(float width, float height) 167 { 168 Ogre::BillboardSet* bSet = this->billboard_.getBillboardSet(); 169 if( bSet != NULL ) 170 { 171 bSet->setDefaultDimensions(width, height); 172 } 173 } 138 174 } -
code/branches/presentation/src/orxonox/graphics/Billboard.h
r7492 r8614 23 23 * Fabian 'x3n' Landau 24 24 * Co-authors: 25 * Maurus Kaufmann 25 26 * ... 26 27 * … … 31 32 32 33 #include "OrxonoxPrereqs.h" 34 35 #include "OgreBillboardSet.h" 33 36 34 37 #include "util/Math.h" … … 62 65 { return this->colour_; } 63 66 64 /* 67 65 68 inline void setRotation(const Radian& rotation) 66 69 { this->rotation_ = rotation; this->changedRotation(); } 67 70 inline const Radian& getRotation() const 68 71 { return this->rotation_; } 69 */ 72 70 73 71 74 virtual void setTeamColour(const ColourValue& colour) 72 75 { this->setColour(colour); } 76 77 void setBillboardType(Ogre::BillboardType bbt); 78 79 void setCommonDirection(Vector3 vec); //!< normalised Vector vec as argument 80 81 void setCommonUpVector(Vector3 vec); //!< normalised Vector vec as argument 82 83 void setDefaultDimensions(float width, float height); 84 73 85 74 86 protected: … … 81 93 void registerVariables(); 82 94 void changedMaterial(); 83 //void changedRotation();95 void changedRotation(); 84 96 85 97 BillboardSet billboard_; 86 98 std::string material_; 87 99 ColourValue colour_; 88 //Radian rotation_;100 Radian rotation_; 89 101 }; 90 102 } -
code/branches/presentation/src/orxonox/worldentities/SpaceBoundaries.cc
r8470 r8614 37 37 #include "interfaces/RadarViewable.h" 38 38 #include "graphics/Billboard.h" 39 #include <OgreBillboardSet.h> 40 39 41 40 42 namespace orxonox … … 44 46 SpaceBoundaries::SpaceBoundaries(BaseObject* creator) : StaticEntity(creator) 45 47 { 46 /* Standardwerte, die zum Tragen kommen,47 * falls im XML-File keine Werte spezifiziert wurden. */ 48 RegisterObject(SpaceBoundaries); 49 48 50 this->setMaxDistance(3000); 49 this->setWarnDistance(2000); 50 this->setShowDistance(2500); 51 this->setHealthDecrease(1); 51 this->setWarnDistance(this->getMaxDistance()); 52 this->setShowDistance(this->getMaxDistance()); 52 53 this->setReaction(0); 53 54 RegisterObject(SpaceBoundaries);55 56 // Show Boundaries on the radar.57 this->centerRadar_ = new RadarViewable(this, this);58 this->centerRadar_->setRadarObjectShape(RadarViewable::Dot);59 this->centerRadar_->setRadarVisibility(false);60 54 } 61 55 SpaceBoundaries::~SpaceBoundaries() … … 63 57 if (this->isInitialized()) 64 58 { 65 delete this->centerRadar_;66 67 59 this->pawnsIn_.clear(); 68 60 … … 84 76 { 85 77 Pawn* currentPawn = *current; 86 float distance = this->computeDistance(currentPawn); 87 if(distance <= this->maxDistance_) 88 { 78 if( this->reaction_ == 0 ) 79 { 80 float distance = this->computeDistance(currentPawn); 81 if(distance <= this->maxDistance_) 82 { 83 pawnsIn_.push_back(currentPawn); 84 } 85 } else if (this->reaction_ == 2) { 86 float distance = this->computeDistance(currentPawn); 87 if(distance >= this->maxDistance_) 88 { 89 pawnsIn_.push_back(currentPawn); 90 } 91 } else { 89 92 pawnsIn_.push_back(currentPawn); 90 93 } … … 105 108 { 106 109 Billboard *tmp = new Billboard(this); 110 tmp->setPosition(position); 107 111 this->setBillboardOptions( tmp ); 108 tmp->setPosition(position); 112 Vector3 normalisedVec = (position - this->getPosition()).normalisedCopy(); /* Vektor von Kugelmitte nach aussen */ 113 tmp->setCommonDirection ( -1.0 * normalisedVec ); 114 tmp->setCommonUpVector( Vector3::UNIT_Z ); 109 115 billboardAdministration tmp2 = { true, tmp }; 110 116 this->billboards_.push_back( tmp2 ); 111 112 117 } else { 113 118 current->billy->setPosition(position); 114 119 current->billy->setVisible(true); 115 120 current->usedYet = true; 121 Vector3 normalisedVec = (position - this->getPosition()).normalisedCopy(); /* Vektor von Kugelmitte nach aussen */ 122 current->billy->setCommonDirection ( -1.0 * normalisedVec ); 123 current->billy->setCommonUpVector( Vector3::UNIT_Z ); 116 124 } 117 125 } … … 121 129 if(billy != NULL) 122 130 { 123 billy->setMaterial("Shield"); 131 billy->setMaterial("Grid"); 132 billy->setBillboardType(Ogre::BBT_PERPENDICULAR_COMMON); 133 billy->setDefaultDimensions(150, 150); 124 134 billy->setVisible(true); 125 135 } … … 186 196 XMLPortParam(SpaceBoundaries, "maxDistance", setMaxDistance, getMaxDistance, xmlelement, mode); 187 197 XMLPortParam(SpaceBoundaries, "warnDistance", setWarnDistance, getWarnDistance, xmlelement, mode); 198 XMLPortParam(SpaceBoundaries, "showDistance", setShowDistance, getShowDistance, xmlelement, mode); 188 199 XMLPortParam(SpaceBoundaries, "healthDecrease", setHealthDecrease, getHealthDecrease, xmlelement, mode); 189 200 XMLPortParam(SpaceBoundaries, "reactionMode", setReaction, getReaction, xmlelement, mode); … … 194 205 this->checkWhoIsIn(); 195 206 this->removeAllBillboards(); 196 //COUT(0) << "Groesse der Liste: " << (int) pawnsIn_.size() << std::endl;197 207 198 208 float distance; … … 205 215 distance = this->computeDistance(currentPawn); 206 216 humanItem = this->isHumanPlayer(currentPawn); 207 //COUT(0) << "Distanz:" << distance << std::endl; // message for debugging 208 if(distance > this->warnDistance_ && distance < this->maxDistance_) // Zeige Warnung an! 209 { 210 //COUT(0) << "You are near by the boundaries!" << std::endl; // message for debugging 217 COUT(5) << "Distance:" << distance << std::endl; // message for debugging 218 if(distance > this->warnDistance_ && distance < this->maxDistance_) // Display warning 219 { 211 220 if(humanItem) 212 221 { 213 //COUT(0) << "humanItem ist true" << std::endl; 214 this->displayWarning("Attention! You are near by the boundaries!"); 222 this->displayWarning("Attention! You are close to the boundary!"); 215 223 } 216 224 } 217 if( 218 { 219 this->displayBoundaries(currentPawn); // Zeige Grenze an!225 if(/* humanItem &&*/ abs(this->maxDistance_ - distance) < this->showDistance_ ) 226 { 227 this->displayBoundaries(currentPawn); // Show the boundary 220 228 } 221 229 if(distance > this->maxDistance_ && (this->reaction_ == 1) ) … … 223 231 if( humanItem ) 224 232 { 225 //COUT(0) << "Health should be decreasing!" << std::endl;233 COUT(5) << "Health should be decreasing!" << std::endl; 226 234 this->displayWarning("You are out of the area now!"); 227 235 } 228 236 currentPawn->removeHealth( (distance - this->maxDistance_) * this->healthDecrease_); 229 237 } 230 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. 238 if( (this->reaction_ == 0) && (distance + 100 > this->maxDistance_)) // Exception: A Pawn can't move more than 100 units per tick. 239 { 240 this->conditionalBounceBack(currentPawn, distance, dt); 241 } 242 if( this->reaction_ == 2 && (distance - 100 < this->maxDistance_) ) 231 243 { 232 244 this->conditionalBounceBack(currentPawn, distance, dt); … … 249 261 void SpaceBoundaries::displayWarning(const std::string warnText) 250 262 { 251 263 // TODO 252 264 } 253 265 … … 270 282 float normalSpeed = item->getVelocity().dotProduct(normal); 271 283 272 /* Checke, ob das Pawn innerhalb des nächsten Ticks, das erlaubte Gebiet verlassen würde. 273 Falls ja: Spicke es zurück. */ 274 if( currentDistance + normalSpeed * dt > this->maxDistance_ ) 275 { 276 float dampingFactor = 0.5; 277 velocity = velocity.reflect(normal); 278 Vector3 acceleration = item->getAcceleration(); 279 acceleration = acceleration.reflect(normal); 280 281 item->lookAt( velocity + this->getPosition() ); 282 283 item->setAcceleration(acceleration * dampingFactor); 284 item->setVelocity(velocity * dampingFactor); 285 } 284 /* Check, whether the Pawn would leave the boundary in the next tick, if so send it back. */ 285 if( this->reaction_ == 0 && currentDistance + normalSpeed * dt > this->maxDistance_ - 10 ) // -10: "security measure" 286 { 287 bounceBack(item, &normal, &velocity); 288 } else if (this->reaction_ == 2 && currentDistance - normalSpeed * dt < this->maxDistance_ + 10 ) // 10: "security measure" 289 { 290 normal = normal * (-1); 291 bounceBack(item, &normal, &velocity); 292 } 293 } 294 295 void SpaceBoundaries::bounceBack(Pawn *item, Vector3 *normal, Vector3 *velocity) 296 { 297 float dampingFactor = 0.5; 298 *velocity = velocity->reflect(*normal); 299 Vector3 acceleration = item->getAcceleration(); 300 acceleration = acceleration.reflect(*normal); 301 302 item->lookAt( *velocity + this->getPosition() ); 303 304 item->setAcceleration(acceleration * dampingFactor); 305 item->setVelocity(*velocity * dampingFactor); 306 307 item->setPosition( item->getPosition() - *normal * 10 ); // Set the position of the Pawn to be well inside the boundary. 286 308 } 287 309 -
code/branches/presentation/src/orxonox/worldentities/SpaceBoundaries.h
r8458 r8614 26 26 * 27 27 */ 28 29 /* TODO: - Textmessages und Billboards sollen teils nur bei einem humanPlayer angezeigt werden, nicht bei allen (vgl. Netzwerk-Spiel mit mehreren humanPlayers)30 beachte hierzu folgende statische Funktion: 'static unsigned int Host::getPlayerID()'31 (file:///home/kmaurus/orxonox/spaceBoundaries/build/doc/api/html/classorxonox_1_1_host.html#9c1e3b39e3b42e467dfbf42902911ce2)32 33 - Kommentieren (Betrachte als Beispiel/Vorbild 'libraries/core/WeakPtr.h')34 35 - Wiki-SpaceBoundaries-Eintrag aktualisieren36 */37 28 38 29 #ifndef _SpaceBoundaries_H__ … … 49 40 #include <string> 50 41 #include <list> 51 #include <map>52 42 #include <vector> 53 43 … … 58 48 @brief SpaceBoundaries gives level creators the possibility to bar Pawns from leaving a defined area (until now this area is a ball). 59 49 60 Five attributes can/should be defined in the XML-File: 50 Some attributes can/should be defined in the XML-File: 51 - 'position' : absolute position of the object of SpaceBoundaries in the level (usually 0,0,0) 52 - 'maxDistance' : defines the area, where a pawn is allowed to be (radius of a ball). 61 53 - 'warnDistance' : If the distance between the pawn of the human player and 'position' is bigger than 'warnDistance', a message is displayed to 62 inform the player that he'll soon be leaving the allowed area. 63 - 'maxDistance' : defines the area, where a pawn is allowed to be (radius of a ball). 54 inform the player that he'll soon be leaving the allowed area. (not implemented yet!) 64 55 - 'showDistance' : If the distance between the pawn and the boundary of the allowed area is smaller than 'showDistance', the boundary is shown. 65 - 'healthDecrease' : a measure to define how fast the health of a pawn should decrease after leaving the allowed area (unnecessary if 'reactionMode' == 0).66 Recommended values: 0.1 (slow health decrease) to 5 (very fast health decrease)67 56 - 'reactionMode' : Integer-Value. Defines what effect appears if a space ship has crossed the boundaries. 68 57 0: Reflect the space ship (default). 69 58 1: Decrease Health of the space ship after having left the allowed area. 59 2: Inverted Version of 0. Prohibit to fly INTO a defined area. 60 - 'healthDecrease' : a measure to define how fast the health of a pawn should decrease after leaving the allowed area (unnecessary if 'reactionMode' == 0). 61 Recommended values: 0.1 (slow health decrease) to 5 (very fast health decrease) 62 63 Follow http://www.orxonox.net/wiki/SpaceBoundaries to get some further information. 64 65 Examples: 66 Two examples how one could include SpaceBoundaries in the XML-File. The first one uses reflection, the second one health decrease. 67 @code 68 <SpaceBoundaries position="0,0,0" maxDistance="1000" warnDistance="800" showDistance="100" reactionMode="0" /> 69 @endcode 70 71 @code 72 <SpaceBoundaries position="0,0,0" maxDistance="1000" warnDistance="800" showDistance="100" reactionMode="1" healthDecrease="0.2" /> 73 @endcode 70 74 */ 71 75 … … 75 79 SpaceBoundaries(BaseObject* creator); 76 80 ~SpaceBoundaries(); 77 78 void checkWhoIsIn(); //!< Update the list 'pawnsIn_'.79 80 void positionBillboard(const Vector3 position); //!< Display a Billboard at the position 'position'.81 void setBillboardOptions(Billboard *billy);82 void removeAllBillboards(); //!< Hide all all elements of '*billboard_' and set their attribute 'usedYet' to 0.83 81 84 82 void setMaxDistance(float r); … … 104 102 struct billboardAdministration{ bool usedYet; Billboard* billy; }; 105 103 104 // Variabeln:: 106 105 std::list<WeakPtr<Pawn> > pawnsIn_; //!< List of the pawns that this instance of SpaceBoundaries has to handle. 107 106 108 107 std::vector<billboardAdministration> billboards_; 109 108 110 int reaction_; //!< Werte: 0, 1. 0: Reflektion an Boundaries (Standard). 1: Health-Abzug-Modus. 111 float maxDistance_; //!< maximal zulaessige Entfernung von 'this->getPosition()'. 112 float warnDistance_; //!< Entfernung von 'this->getPosition()', ab der eine Warnung angezeigt wird, dass man bald das zulaessige Areal verlaesst. 113 float showDistance_; //!< Definiert, wann die Grenzen visualisiert werden sollen. 109 int reaction_; //!< Values: 0, 1, 2. 110 //!< 0: Reflection on boundary (Standard). 111 //!< 1: Decrease-Health-Mode. 112 //!< 2: Inverted Version of 0. Prohibit to fly INTO a defined area. 113 float maxDistance_; //!< Maximum allowed distance. 114 float warnDistance_; //!< Distance in which a warning is displayed. 115 float showDistance_; //!< Distance at which the boundaries are displayed. 114 116 115 float healthDecrease_; //!< Mass fuer die Anzahl Health-Points, die nach ueberschreiten der Entfernung 'maxDistance_' von 'this->getPosition()' abgezogen werden. 116 //!< Empfohlene Werte: 0.1 (langsame Health-Verminderung) bis 5 (sehr schnelle Health-Verminderung) 117 float healthDecrease_; //!< Rate of health loss. 117 118 118 RadarViewable* centerRadar_; //!< Repraesentation von SpaceBoundaries auf dem Radar.119 //RadarViewable* centerRadar_; //!< Representation of the space boundary in the radar. 119 120 120 float computeDistance(WorldEntity *item); //!< Auf den Mittelpunkt 'this->getPosition()' bezogen. 121 void displayWarning(const std::string warnText); 121 // Funktionen:: 122 float computeDistance(WorldEntity *item); //!< Compute distance to center point. 123 void displayWarning(const std::string warnText); //!< TODO: Implement. 122 124 void displayBoundaries(Pawn *item); 123 125 void conditionalBounceBack(Pawn *item, float currentDistance, float dt); 126 void bounceBack(Pawn *item, Vector3 *normal, Vector3 *velocity); 124 127 bool isHumanPlayer(Pawn *item); 128 129 void checkWhoIsIn(); //!< Update the list 'pawnsIn_'. 130 131 void positionBillboard(const Vector3 position); //!< Display a Billboard at the position 'position'. 132 void setBillboardOptions(Billboard *billy); 133 void removeAllBillboards(); //!< Hide all elements of '*billboard_' and set their attribute 'usedYet' to 0. 125 134 126 135 };
Note: See TracChangeset
for help on using the changeset viewer.