Changeset 2254 for code/branches/objecthierarchy2/src/orxonox/objects/worldentities/pawns/SpaceShip.cc
- Timestamp:
- Nov 24, 2008, 1:50:47 AM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/objecthierarchy2/src/orxonox/objects/worldentities/pawns/SpaceShip.cc
r2171 r2254 32 32 #include "core/CoreIncludes.h" 33 33 #include "core/ConfigValueIncludes.h" 34 #include "core/Template.h" 34 35 #include "core/XMLPort.h" 35 36 #include "util/Math.h" 37 #include "objects/items/Engine.h" 36 38 37 39 namespace orxonox … … 45 47 this->zeroDegree_ = 0; 46 48 47 this->maxSpeed_ = 0; 48 this->maxSecondarySpeed_ = 0; 49 this->bBoost_ = false; 50 this->steering_ = Vector3::ZERO; 51 this->engine_ = 0; 52 49 53 this->maxRotation_ = 0; 50 this->translationAcceleration_ = 0;51 54 this->rotationAcceleration_ = 0; 52 55 this->translationDamping_ = 0; … … 66 69 SpaceShip::~SpaceShip() 67 70 { 71 if (this->isInitialized() && this->engine_) 72 delete this->engine_; 68 73 } 69 74 … … 72 77 SUPER(SpaceShip, XMLPort, xmlelement, mode); 73 78 74 XMLPortParam(SpaceShip, "maxspeed", setMaxSpeed, getMaxSpeed, xmlelement, mode); 75 XMLPortParam(SpaceShip, "maxsecondaryspeed", setMaxSecondarySpeed, getMaxSecondarySpeed, xmlelement, mode); 79 XMLPortParam(SpaceShip, "engine", setEngineTemplate, getEngineTemplate, xmlelement, mode); 76 80 XMLPortParam(SpaceShip, "maxrotation", setMaxRotation, getMaxRotation, xmlelement, mode); 77 XMLPortParam(SpaceShip, "transacc", setTransAcc, getTransAcc, xmlelement, mode);78 81 XMLPortParam(SpaceShip, "rotacc", setRotAcc, getRotAcc, xmlelement, mode); 79 82 XMLPortParam(SpaceShip, "transdamp", setTransDamp, getTransDamp, xmlelement, mode); … … 82 85 void SpaceShip::registerVariables() 83 86 { 84 REGISTERDATA(this->maxSpeed_, direction::toclient);85 REGISTERDATA(this->maxSecondarySpeed_, direction::toclient);86 87 REGISTERDATA(this->maxRotation_, direction::toclient); 87 REGISTERDATA(this->translationAcceleration_, direction::toclient);88 88 REGISTERDATA(this->rotationAcceleration_, direction::toclient); 89 89 REGISTERDATA(this->translationDamping_, direction::toclient); … … 97 97 void SpaceShip::tick(float dt) 98 98 { 99 if (this-> isLocallyControlled())99 if (this->hasLocalController()) 100 100 { 101 101 // ##################################### … … 104 104 105 105 Vector3 velocity = this->getVelocity(); 106 if (velocity.x > this->maxSecondarySpeed_)107 velocity.x = this->maxSecondarySpeed_;108 if (velocity.x < -this->maxSecondarySpeed_)109 velocity.x = -this->maxSecondarySpeed_;110 if (velocity.y > this->maxSecondarySpeed_)111 velocity.y = this->maxSecondarySpeed_;112 if (velocity.y < -this->maxSecondarySpeed_)113 velocity.y = -this->maxSecondarySpeed_;114 if (velocity.z > this->maxSecondarySpeed_)115 velocity.z = this->maxSecondarySpeed_;116 if (velocity.z < -this->maxSpeed_)117 velocity.z = -this->maxSpeed_;118 106 119 107 // normalize velocity and acceleration … … 144 132 145 133 146 if (this-> isLocallyControlled())134 if (this->hasLocalController()) 147 135 { 148 136 this->yaw(this->yawRotation_ * dt); … … 153 141 this->roll(this->rollRotation_ * dt); 154 142 155 this->acceleration_.x = 0;156 this->acceleration_.y = 0;157 this->acceleration_.z = 0;158 159 143 this->yawRotation_ = this->zeroDegree_; 160 144 this->pitchRotation_ = this->zeroDegree_; … … 165 149 void SpaceShip::moveFrontBack(const Vector2& value) 166 150 { 167 this-> acceleration_.z = -this->translationAcceleration_ *value.x;151 this->steering_.z = -value.x; 168 152 } 169 153 170 154 void SpaceShip::moveRightLeft(const Vector2& value) 171 155 { 172 this-> acceleration_.x = this->translationAcceleration_ *value.x;156 this->steering_.x = value.x; 173 157 } 174 158 175 159 void SpaceShip::moveUpDown(const Vector2& value) 176 160 { 177 this-> acceleration_.y = this->translationAcceleration_ *value.x;161 this->steering_.y = value.x; 178 162 } 179 163 … … 211 195 { 212 196 } 197 198 void SpaceShip::boost() 199 { 200 this->bBoost_ = true; 201 } 202 203 void SpaceShip::loadEngineTemplate() 204 { 205 if (this->enginetemplate_ != "") 206 { 207 Template* temp = Template::getTemplate(this->enginetemplate_); 208 209 if (temp) 210 { 211 Identifier* identifier = temp->getBaseclassIdentifier(); 212 213 if (identifier) 214 { 215 BaseObject* object = identifier->fabricate(this); 216 this->engine_ = dynamic_cast<Engine*>(object); 217 218 if (this->engine_) 219 { 220 this->engine_->addTemplate(temp); 221 this->engine_->addToSpaceShip(this); 222 } 223 else 224 { 225 delete object; 226 } 227 } 228 } 229 } 230 } 213 231 }
Note: See TracChangeset
for help on using the changeset viewer.