- Timestamp:
- Dec 16, 2008, 6:01:13 PM (17 years ago)
- Location:
- code/branches/presentation
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/presentation
-
code/branches/presentation/src/orxonox/objects/worldentities/pawns/SpaceShip.cc
r2475 r2485 36 36 #include "core/CoreIncludes.h" 37 37 #include "core/ConfigValueIncludes.h" 38 #include "core/Template.h" 38 39 #include "core/XMLPort.h" 40 #include "objects/items/Engine.h" 39 41 40 42 namespace orxonox … … 53 55 this->localLinearAcceleration_.setValue(0, 0, 0); 54 56 this->localAngularAcceleration_.setValue(0, 0, 0); 57 this->bBoost_ = false; 58 this->steering_ = Vector3::ZERO; 59 this->engine_ = 0; 60 55 61 56 62 this->bInvertYAxis_ = false; … … 70 76 SpaceShip::~SpaceShip() 71 77 { 78 if (this->isInitialized() && this->engine_) 79 delete this->engine_; 72 80 } 73 81 … … 76 84 SUPER(SpaceShip, XMLPort, xmlelement, mode); 77 85 86 XMLPortParam(SpaceShip, "engine", setEngineTemplate, getEngineTemplate, xmlelement, mode); 78 87 XMLPortParamVariable(SpaceShip, "primaryThrust", primaryThrust_, xmlelement, mode); 79 88 XMLPortParamVariable(SpaceShip, "auxilaryThrust", auxilaryThrust_, xmlelement, mode); … … 109 118 SUPER(SpaceShip, tick, dt); 110 119 111 if (this-> isLocallyControlled())120 if (this->hasLocalController()) 112 121 { 113 this->localLinearAcceleration_.setX(this->localLinearAcceleration_.x() * getMass() * this->auxilaryThrust_); 114 this->localLinearAcceleration_.setY(this->localLinearAcceleration_.y() * getMass() * this->auxilaryThrust_); 115 if (this->localLinearAcceleration_.z() > 0) 116 this->localLinearAcceleration_.setZ(this->localLinearAcceleration_.z() * getMass() * this->auxilaryThrust_); 117 else 118 this->localLinearAcceleration_.setZ(this->localLinearAcceleration_.z() * getMass() * this->primaryThrust_); 119 this->physicalBody_->applyCentralForce(physicalBody_->getWorldTransform().getBasis() * this->localLinearAcceleration_); 120 this->localLinearAcceleration_.setValue(0, 0, 0); 122 if (!this->isInMouseLook()) 123 { 124 this->localLinearAcceleration_.setX(this->localLinearAcceleration_.x() * getMass() * this->auxilaryThrust_); 125 this->localLinearAcceleration_.setY(this->localLinearAcceleration_.y() * getMass() * this->auxilaryThrust_); 126 if (this->localLinearAcceleration_.z() > 0) 127 this->localLinearAcceleration_.setZ(this->localLinearAcceleration_.z() * getMass() * this->auxilaryThrust_); 128 else 129 this->localLinearAcceleration_.setZ(this->localLinearAcceleration_.z() * getMass() * this->primaryThrust_); 130 this->physicalBody_->applyCentralForce(physicalBody_->getWorldTransform().getBasis() * this->localLinearAcceleration_); 131 this->localLinearAcceleration_.setValue(0, 0, 0); 132 } 121 133 122 134 this->localAngularAcceleration_ *= this->getLocalInertia() * this->rotationThrust_; … … 129 141 { 130 142 this->localLinearAcceleration_.setZ(this->localLinearAcceleration_.z() - value.x); 143 this->steering_.z = -value.x; 131 144 } 132 145 … … 134 147 { 135 148 this->localLinearAcceleration_.setX(this->localLinearAcceleration_.x() + value.x); 149 this->steering_.x = value.x; 136 150 } 137 151 … … 139 153 { 140 154 this->localLinearAcceleration_.setY(this->localLinearAcceleration_.y() + value.x); 155 this->steering_.y = value.x; 141 156 } 142 157 … … 144 159 { 145 160 this->localAngularAcceleration_.setY(this->localAngularAcceleration_.y() + value.x); 161 162 Pawn::rotateYaw(value); 146 163 } 147 164 … … 149 166 { 150 167 this->localAngularAcceleration_.setX(this->localAngularAcceleration_.x() + value.x); 168 169 Pawn::rotatePitch(value); 151 170 } 152 171 … … 154 173 { 155 174 this->localAngularAcceleration_.setZ(this->localAngularAcceleration_.z() + value.x); 175 176 Pawn::rotateRoll(value); 156 177 } 157 178 … … 159 180 { 160 181 } 182 183 void SpaceShip::boost() 184 { 185 this->bBoost_ = true; 186 } 187 188 void SpaceShip::loadEngineTemplate() 189 { 190 if (this->enginetemplate_ != "") 191 { 192 Template* temp = Template::getTemplate(this->enginetemplate_); 193 194 if (temp) 195 { 196 Identifier* identifier = temp->getBaseclassIdentifier(); 197 198 if (identifier) 199 { 200 BaseObject* object = identifier->fabricate(this); 201 this->engine_ = dynamic_cast<Engine*>(object); 202 203 if (this->engine_) 204 { 205 this->engine_->addTemplate(temp); 206 this->engine_->addToSpaceShip(this); 207 } 208 else 209 { 210 delete object; 211 } 212 } 213 } 214 } 215 } 216 217 void SpaceShip::setEngine(Engine* engine) 218 { 219 this->engine_ = engine; 220 if (engine && engine->getShip() != this) 221 engine->addToSpaceShip(this); 222 } 161 223 }
Note: See TracChangeset
for help on using the changeset viewer.