Changeset 8767 for code/trunk/src/modules/objects
- Timestamp:
- Jul 20, 2011, 11:27:45 PM (13 years ago)
- Location:
- code/trunk/src/modules/objects
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk/src/modules/objects/SpaceBoundaries.cc
r8706 r8767 58 58 { 59 59 this->pawnsIn_.clear(); 60 60 61 61 for( std::vector<BillboardAdministration>::iterator current = this->billboards_.begin(); current != this->billboards_.end(); current++) 62 62 { … … 69 69 } 70 70 } 71 71 72 72 void SpaceBoundaries::checkWhoIsIn() 73 73 { … … 94 94 } 95 95 } 96 96 97 97 void SpaceBoundaries::positionBillboard(const Vector3& position, float alpha) 98 98 { … … 124 124 this->billboards_[current].billy->setCommonUpVector(upVector); 125 125 } 126 126 127 127 void SpaceBoundaries::setBillboardOptions(Billboard *billy) 128 128 { … … 135 135 } 136 136 } 137 137 138 138 void SpaceBoundaries::removeAllBillboards() 139 139 { … … 144 144 } 145 145 } 146 146 147 147 void SpaceBoundaries::setMaxDistance(float r) 148 148 { … … 153 153 return this->maxDistance_; 154 154 } 155 155 156 156 void SpaceBoundaries::setWarnDistance(float r) 157 157 { … … 162 162 return this->warnDistance_; 163 163 } 164 164 165 165 void SpaceBoundaries::setShowDistance(float r) 166 166 { … … 171 171 return this->showDistance_; 172 172 } 173 173 174 174 void SpaceBoundaries::setHealthDecrease(float amount) 175 175 { … … 180 180 return this->healthDecrease_; 181 181 } 182 182 183 183 void SpaceBoundaries::setReaction(int mode) 184 184 { … … 200 200 XMLPortParam(SpaceBoundaries, "reactionMode", setReaction, getReaction, xmlelement, mode); 201 201 } 202 202 203 203 void SpaceBoundaries::tick(float dt) 204 204 { 205 205 this->checkWhoIsIn(); 206 206 this->removeAllBillboards(); 207 207 208 208 float distance; 209 209 bool humanItem; … … 247 247 } 248 248 } 249 249 250 250 float SpaceBoundaries::computeDistance(WorldEntity *item) 251 251 { … … 258 258 } 259 259 } 260 260 261 261 void SpaceBoundaries::displayWarning(const std::string warnText) 262 { 262 { 263 263 // TODO 264 264 } 265 265 266 266 void SpaceBoundaries::displayBoundaries(Pawn *item, float alpha) 267 267 { 268 268 269 269 Vector3 direction = item->getPosition() - this->getPosition(); 270 270 direction.normalise(); 271 271 272 272 Vector3 boundaryPosition = this->getPosition() + direction * this->maxDistance_; 273 273 274 274 this->positionBillboard(boundaryPosition, alpha); 275 275 } 276 276 277 277 void SpaceBoundaries::conditionalBounceBack(Pawn *item, float currentDistance, float dt) 278 278 { … … 281 281 Vector3 velocity = item->getVelocity(); 282 282 float normalSpeed = item->getVelocity().dotProduct(normal); 283 283 284 284 /* Check, whether the Pawn would leave the boundary in the next tick, if so send it back. */ 285 285 if( this->reaction_ == 0 && currentDistance + normalSpeed * dt > this->maxDistance_ - 10 ) // -10: "security measure" … … 292 292 } 293 293 } 294 294 295 295 void SpaceBoundaries::bounceBack(Pawn *item, Vector3 *normal, Vector3 *velocity) 296 296 { … … 299 299 Vector3 acceleration = item->getAcceleration(); 300 300 acceleration = acceleration.reflect(*normal); 301 301 302 302 item->lookAt( *velocity + this->getPosition() ); 303 303 304 304 item->setAcceleration(acceleration * dampingFactor); 305 305 item->setVelocity(*velocity * dampingFactor); 306 306 307 307 item->setPosition( item->getPosition() - *normal * 10 ); // Set the position of the Pawn to be well inside the boundary. 308 308 } 309 309 310 310 bool SpaceBoundaries::isHumanPlayer(Pawn *item) 311 311 { … … 319 319 return false; 320 320 } 321 321 322 322 } -
code/trunk/src/modules/objects/SpaceBoundaries.h
r8706 r8767 45 45 { 46 46 47 /**48 @brief SpaceBoundaries gives level creators the possibility to bar Pawns from leaving a defined area (until now this area is a ball).47 /** 48 @brief SpaceBoundaries gives level creators the possibility to bar Pawns from leaving a defined area (until now this area is a ball). 49 49 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).53 - 'warnDistance' : If the distance between the pawn of the human player and 'position' is bigger than 'warnDistance', a message is displayed to54 inform the player that he'll soon be leaving the allowed area. (not implemented yet!)55 - 'showDistance' : If the distance between the pawn and the boundary of the allowed area is smaller than 'showDistance', the boundary is shown.56 - 'reactionMode' : Integer-Value. Defines what effect appears if a space ship has crossed the boundaries.57 0: Reflect the space ship (default).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)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). 53 - 'warnDistance' : If the distance between the pawn of the human player and 'position' is bigger than 'warnDistance', a message is displayed to 54 inform the player that he'll soon be leaving the allowed area. (not implemented yet!) 55 - 'showDistance' : If the distance between the pawn and the boundary of the allowed area is smaller than 'showDistance', the boundary is shown. 56 - 'reactionMode' : Integer-Value. Defines what effect appears if a space ship has crossed the boundaries. 57 0: Reflect the space ship (default). 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 62 63 Follow http://www.orxonox.net/wiki/SpaceBoundaries to get some further information.63 Follow http://www.orxonox.net/wiki/SpaceBoundaries to get some further information. 64 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 @code68 <SpaceBoundaries position="0,0,0" maxDistance="1000" warnDistance="800" showDistance="100" reactionMode="0" />69 @endcode65 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 70 71 @code 72 <SpaceBoundaries position="0,0,0" maxDistance="1000" warnDistance="800" showDistance="100" reactionMode="1" healthDecrease="0.2" /> 73 @endcode 74 */ 75 71 @code 72 <SpaceBoundaries position="0,0,0" maxDistance="1000" warnDistance="800" showDistance="100" reactionMode="1" healthDecrease="0.2" /> 73 @endcode 74 */ 76 75 class _ObjectsExport SpaceBoundaries : public StaticEntity, public Tickable 77 76 { … … 79 78 SpaceBoundaries(BaseObject* creator); 80 79 ~SpaceBoundaries(); 81 80 82 81 void setMaxDistance(float r); 83 82 float getMaxDistance(); 84 83 85 84 void setWarnDistance(float r); 86 85 float getWarnDistance(); 87 86 88 87 void setShowDistance(float r); 89 88 float getShowDistance(); 90 89 91 90 void setHealthDecrease(float amount); 92 91 float getHealthDecrease(); 93 92 94 93 void setReaction(int mode); 95 94 int getReaction(); 96 95 97 96 void XMLPort(Element& xmlelement, XMLPort::Mode mode); 98 97 99 98 void tick(float dt); 100 99 101 100 private: 102 101 struct BillboardAdministration{ bool usedYet; Billboard* billy; }; 103 102 104 103 // Variabeln:: 105 104 std::list<WeakPtr<Pawn> > pawnsIn_; //!< List of the pawns that this instance of SpaceBoundaries has to handle. 106 105 107 106 std::vector<BillboardAdministration> billboards_; 108 107 109 108 int reaction_; //!< Values: 0, 1, 2. 110 109 //!< 0: Reflection on boundary (Standard). … … 114 113 float warnDistance_; //!< Distance in which a warning is displayed. 115 114 float showDistance_; //!< Distance at which the boundaries are displayed. 116 115 117 116 float healthDecrease_; //!< Rate of health loss. 118 117 119 118 //RadarViewable* centerRadar_; //!< Representation of the space boundary in the radar. 120 119 121 120 // Funktionen:: 122 121 float computeDistance(WorldEntity *item); //!< Compute distance to center point. … … 126 125 void bounceBack(Pawn *item, Vector3 *normal, Vector3 *velocity); 127 126 bool isHumanPlayer(Pawn *item); 128 127 129 128 void checkWhoIsIn(); //!< Update the list 'pawnsIn_'. 130 129 131 130 void positionBillboard(const Vector3& position, float alpha); //!< Display a Billboard at the position 'position'. 132 131 void setBillboardOptions(Billboard *billy); 133 132 void removeAllBillboards(); //!< Hide all elements of '*billboard_' and set their attribute 'usedYet' to 0. 134 135 133 }; 136 134 }
Note: See TracChangeset
for help on using the changeset viewer.