- Timestamp:
- May 25, 2011, 9:22:53 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/presentation/src/orxonox/worldentities/pawns/SpaceShip.cc
r7860 r8578 36 36 #include "core/XMLPort.h" 37 37 #include "items/Engine.h" 38 #include "graphics/Camera.h" 39 #include "CameraManager.h" 40 #include "util/Math.h" 38 41 39 42 namespace orxonox … … 53 56 this->localAngularAcceleration_.setValue(0, 0, 0); 54 57 this->bBoost_ = false; 55 this->bPermanentBoost_ = false;56 58 this->steering_ = Vector3::ZERO; 57 59 this->engine_ = 0; … … 76 78 this->setConfigValues(); 77 79 this->registerVariables(); 80 81 Camera* camera = CameraManager::getInstance().getActiveCamera(); 82 this->cameraOriginalPosition_ = camera->getPosition(); 83 this->cameraOriginalOrientation_ = camera->getOrientation(); 84 85 this->shakeFrequency_ = 15; 86 this->shakeAmplitude_ = 5; 87 this->shakeDt_ = 0; 78 88 } 79 89 … … 96 106 XMLPortParamVariable(SpaceShip, "boostRate", boostRate_, xmlelement, mode); 97 107 XMLPortParamVariable(SpaceShip, "boostCooldownDuration", boostCooldownDuration_, xmlelement, mode); 108 XMLPortParamVariable(SpaceShip, "shakeFrequency", shakeFrequency_, xmlelement, mode); 109 XMLPortParamVariable(SpaceShip, "shakeAmplitude", shakeAmplitude_, xmlelement, mode); 98 110 } 99 111 … … 103 115 registerVariable(this->auxilaryThrust_, VariableDirection::ToClient); 104 116 registerVariable(this->rotationThrust_, VariableDirection::ToClient); 117 // TODO: Synchronization of boost needed? 118 registerVariable(this->boostPower_, VariableDirection::ToClient); 119 registerVariable(this->boostPowerRate_, VariableDirection::ToClient); 120 registerVariable(this->boostRate_, VariableDirection::ToClient); 121 registerVariable(this->boostCooldownDuration_, VariableDirection::ToClient); 122 registerVariable(this->shakeFrequency_, VariableDirection::ToClient); 123 registerVariable(this->shakeAmplitude_, VariableDirection::ToClient); 105 124 } 106 125 … … 128 147 if (this->hasLocalController()) 129 148 { 149 130 150 /* 131 151 this->localLinearAcceleration_.setX(this->localLinearAcceleration_.x() * getMass() * this->auxilaryThrust_); … … 150 170 this->boostPower_ += this->boostPowerRate_*dt; 151 171 } 172 152 173 if(this->bBoost_) 153 174 { … … 155 176 if(this->boostPower_ <= 0.0f) 156 177 { 157 this->b Boost_ = false;178 this->boost(false); 158 179 this->bBoostCooldown_ = true; 159 180 this->timer_.setTimer(this->boostCooldownDuration_, false, createExecutor(createFunctor(&SpaceShip::boostCooledDown, this))); 181 160 182 } 161 } 162 } 163 } 164 165 void SpaceShip::boostCooledDown(void) 166 { 167 this->bBoostCooldown_ = false; 183 184 shakeCamera(dt); 185 } 186 } 168 187 } 169 188 … … 207 226 } 208 227 209 // TODO: something seems to call this function every tick, could probably handled a little more efficiently! 210 void SpaceShip::setBoost(bool bBoost) 211 { 212 if(bBoost == this->bBoost_) 228 void SpaceShip::fire() 229 { 230 } 231 232 /** 233 @brief 234 Starts or stops boosting. 235 @param bBoost 236 Whether to start or stop boosting. 237 */ 238 void SpaceShip::boost(bool bBoost) 239 { 240 if(bBoost && !this->bBoostCooldown_) 241 { 242 //COUT(0) << "Boost startet!\n"; 243 this->bBoost_ = true; 244 } 245 if(!bBoost) 246 { 247 //COUT(0) << "Boost stoppt\n"; 248 this->resetCamera(); 249 this->bBoost_ = false; 250 } 251 } 252 253 void SpaceShip::boostCooledDown(void) 254 { 255 this->bBoostCooldown_ = false; 256 } 257 258 void SpaceShip::shakeCamera(float dt) 259 { 260 //make sure the ship is only shaking if it's moving 261 if (this->getVelocity().squaredLength() > 80) 262 { 263 this->shakeDt_ += dt; 264 265 int frequency = this->shakeFrequency_ * (this->getVelocity().squaredLength()); 266 267 if (this->shakeDt_ >= 1 /(frequency)) 268 { 269 this->shakeDt_ -= 1/(frequency); 270 } 271 272 Degree angle = Degree(sin(this->shakeDt_ * 2* math::pi * frequency) * this->shakeAmplitude_); 273 274 //COUT(0) << "Angle: " << angle << std::endl; 275 Camera* c = this->getCamera(); 276 277 //Shaking Camera effect 278 if (c != 0) 279 { 280 c->setOrientation(Vector3::UNIT_X, angle); 281 } 282 } 283 } 284 285 void SpaceShip::resetCamera() 286 { 287 288 //COUT(0) << "Resetting camera\n"; 289 Camera *c = this->getCamera(); 290 291 if (c == 0) 292 { 293 COUT(2) << "Failed to reset camera!"; 213 294 return; 214 215 if(bBoost) 216 this->boost(); 217 else 218 { 219 this->bBoost_ = false; 220 } 221 } 222 223 void SpaceShip::fire() 224 { 225 } 226 227 void SpaceShip::boost() 228 { 229 if(!this->bBoostCooldown_) 230 this->bBoost_ = true; 295 } 296 297 shakeDt_ = 0; 298 // 299 c->setPosition(this->cameraOriginalPosition_); 300 c->setOrientation(this->cameraOriginalOrientation_); 231 301 } 232 302 … … 273 343 return list; 274 344 } 345 346 275 347 }
Note: See TracChangeset
for help on using the changeset viewer.