Changeset 647
- Timestamp:
- Dec 19, 2007, 8:12:01 AM (17 years ago)
- Location:
- code/branches/FICN/src/orxonox
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/FICN/src/orxonox/objects/SpaceShip.cc
r646 r647 45 45 RegisterObject(SpaceShip); 46 46 47 SetConfigValue(bInvert Mouse_, true);47 SetConfigValue(bInvertYAxis_, false); 48 48 SetConfigValue(reloadTime_, 0.125); 49 49 … … 51 51 this->bLMousePressed_ = false; 52 52 this->bRMousePressed_ = false; 53 this->mouseX_ = 0; 54 this->mouseY_ = 0; 53 55 54 56 this->camNode_ = 0; … … 61 63 this->timeToReload_ = 0; 62 64 65 this->maxSpeed_ = 0; 66 this->maxSideAndBackSpeed_ = 0; 67 this->maxRotation_ = 0; 68 this->translationAcceleration_ = 0; 69 this->rotationAcceleration_ = 0; 70 this->translationDamping_ = 0; 71 this->rotationDamping_ = 0; 72 73 this->maxRotationRadian_ = 0; 74 this->rotationAccelerationRadian_ = 0; 75 this->rotationDampingRadian_ = 0; 76 this->zeroRadian_ = Radian(0); 77 78 this->setRotationAxis(1, 0, 0); 79 this->setStatic(false); 80 /* 63 81 this->moveForward_ = 0; 64 82 this->rotateUp_ = 0; … … 95 113 this->brakeRotate(rotate*10); 96 114 this->brakeLoop(loop); 97 115 */ 98 116 COUT(3) << "Info: SpaceShip was loaded" << std::endl; 99 117 } … … 101 119 SpaceShip::~SpaceShip() 102 120 { 103 if (tt_) 104 delete tt_; 105 } 106 107 void SpaceShip::setMaxSpeedValues(float maxSpeedForward, float maxSpeedRotateUpDown, float maxSpeedRotateRightLeft, float maxSpeedLoopRightLeft) 108 { 109 this->maxSpeedForward_ = maxSpeedForward; 110 this->maxSpeedRotateUpDown_ = maxSpeedRotateUpDown; 111 this->maxSpeedRotateRightLeft_ = maxSpeedRotateRightLeft; 112 this->maxSpeedLoopRightLeft_ = maxSpeedLoopRightLeft; 121 if (this->tt_) 122 delete this->tt_; 113 123 } 114 124 … … 119 129 120 130 // START CREATING THRUSTER 121 t t_ = new particle::ParticleInterface(Orxonox::getSingleton()->getSceneManager(),"twinthruster" + this->getName(),"Orxonox/engineglow");122 t t_->getParticleSystem()->setParameter("local_space","true");123 t t_->newEmitter();124 /* 125 t t_->setDirection(Vector3(0,0,1));126 t t_->setPositionOfEmitter(0, Vector3(20,-1,-15));127 t t_->setPositionOfEmitter(1, Vector3(-20,-1,-15));128 */ 129 t t_->setDirection(Vector3(-1,0,0));130 t t_->setPositionOfEmitter(0, Vector3(-15,20,-1));131 t t_->setPositionOfEmitter(1, Vector3(-15,-20,-1));132 t t_->setVelocity(50);131 this->tt_ = new particle::ParticleInterface(Orxonox::getSingleton()->getSceneManager(),"twinthruster" + this->getName(),"Orxonox/engineglow"); 132 this->tt_->getParticleSystem()->setParameter("local_space","true"); 133 this->tt_->newEmitter(); 134 /* 135 this->tt_->setDirection(Vector3(0,0,1)); 136 this->tt_->setPositionOfEmitter(0, Vector3(20,-1,-15)); 137 this->tt_->setPositionOfEmitter(1, Vector3(-20,-1,-15)); 138 */ 139 this->tt_->setDirection(Vector3(-1,0,0)); 140 this->tt_->setPositionOfEmitter(0, Vector3(-15,20,-1)); 141 this->tt_->setPositionOfEmitter(1, Vector3(-15,-20,-1)); 142 this->tt_->setVelocity(50); 133 143 134 144 emitterRate_ = tt_->getRate(); … … 156 166 157 167 168 /* 158 169 if (xmlElem->Attribute("forward") && xmlElem->Attribute("rotateupdown") && xmlElem->Attribute("rotaterightleft") && xmlElem->Attribute("looprightleft")) 159 170 { … … 170 181 COUT(4) << "Loader: Initialized spaceship steering with values " << maxSpeedForward_ << " " << maxSpeedRotateUpDown_ << " " << maxSpeedRotateRightLeft_ << " " << maxSpeedLoopRightLeft_ << " " << std::endl; 171 182 } 183 */ 184 if (xmlElem->Attribute("maxSpeed") && xmlElem->Attribute("maxSideAndBackSpeed") && xmlElem->Attribute("maxRotation") && xmlElem->Attribute("transAcc") && xmlElem->Attribute("rotAcc") && xmlElem->Attribute("transDamp") && xmlElem->Attribute("rotDamp")) 185 { 186 187 std::string msStr = xmlElem->Attribute("maxSpeed"); 188 std::string msabsStr = xmlElem->Attribute("maxSideAndBackSpeed"); 189 std::string mrStr = xmlElem->Attribute("maxRotation"); 190 std::string taStr = xmlElem->Attribute("transAcc"); 191 std::string raStr = xmlElem->Attribute("rotAcc"); 192 std::string tdStr = xmlElem->Attribute("transDamp"); 193 std::string rdStr = xmlElem->Attribute("rotDamp"); 194 195 String2Number<float>(this->maxSpeed_, msStr); 196 String2Number<float>(this->maxSideAndBackSpeed_, msabsStr); 197 String2Number<float>(this->maxRotation_, mrStr); 198 String2Number<float>(this->translationAcceleration_, taStr); 199 String2Number<float>(this->rotationAcceleration_, raStr); 200 String2Number<float>(this->translationDamping_, tdStr); 201 String2Number<float>(this->rotationDamping_, rdStr); 202 203 this->maxRotationRadian_ = Radian(this->maxRotation_); 204 this->rotationAccelerationRadian_ = Radian(this->rotationAcceleration_); 205 this->rotationDampingRadian_ = Radian(this->rotationDamping_); 206 207 COUT(4) << "Loader: Initialized SpaceShip" << std::endl; 208 } 172 209 173 210 if (xmlElem->Attribute("camera")) … … 192 229 } 193 230 231 int sgn(float x) 232 { 233 if (x >= 0) 234 return 1; 235 else 236 return -1; 237 } 238 194 239 bool SpaceShip::mouseMoved(const OIS::MouseEvent &e) 195 240 { 241 /* 196 242 this->mouseX += e.state.X.rel; 197 243 if (this->bInvertMouse_) … … 205 251 206 252 this->moved = true; 207 253 */ 208 254 if (this->bRMousePressed_) 209 255 { 210 256 this->camNode_->roll(Degree(-e.state.X.rel * 0.10)); 211 257 this->camNode_->yaw(Degree(e.state.Y.rel * 0.10)); 258 } 259 else 260 { 261 float minDimension = e.state.height; 262 if (e.state.width < minDimension) 263 minDimension = e.state.width; 264 265 this->mouseX_ += e.state.X.rel; 266 if (this->mouseX_ < -minDimension) 267 this->mouseX_ = -minDimension; 268 if (this->mouseX_ > minDimension) 269 this->mouseX_ = minDimension; 270 271 this->mouseY_ += e.state.Y.rel; 272 if (this->mouseY_ < -minDimension) 273 this->mouseY_ = -minDimension; 274 if (this->mouseY_ > minDimension) 275 this->mouseY_ = minDimension; 276 277 float xRotation = this->mouseX_ / minDimension; 278 xRotation = xRotation*xRotation * sgn(xRotation); 279 xRotation *= -this->rotationAcceleration_; 280 if (xRotation > this->maxRotation_) 281 xRotation = this->maxRotation_; 282 if (xRotation < -this->maxRotation_) 283 xRotation = -this->maxRotation_; 284 this->mouseXRotation_ = Radian(xRotation); 285 286 float yRotation = this->mouseY_ / minDimension; 287 yRotation = yRotation*yRotation * sgn(yRotation); 288 yRotation *= this->rotationAcceleration_; 289 if (yRotation > this->maxRotation_) 290 yRotation = this->maxRotation_; 291 if (yRotation < -this->maxRotation_) 292 yRotation = -this->maxRotation_; 293 this->mouseYRotation_ = Radian(yRotation); 212 294 } 213 295 … … 249 331 } 250 332 251 WorldEntity::tick(dt);252 253 333 if (this->redNode_ && this->greenNode_) 254 334 { … … 277 357 mMouse->capture(); 278 358 359 360 // ##################################### 361 // ############# STEERING ############## 362 // ##################################### 363 364 if (this->velocity_.x > this->maxSpeed_) 365 this->velocity_.x = this->maxSpeed_; 366 if (this->velocity_.x < -this->maxSideAndBackSpeed_) 367 this->velocity_.x = -this->maxSideAndBackSpeed_; 368 if (this->velocity_.y > this->maxSideAndBackSpeed_) 369 this->velocity_.y = this->maxSideAndBackSpeed_; 370 if (this->velocity_.y < -this->maxSideAndBackSpeed_) 371 this->velocity_.y = -this->maxSideAndBackSpeed_; 372 if (this->rotationRate_ > this->maxRotationRadian_) 373 this->rotationRate_ = this->maxRotationRadian_; 374 if (this->rotationRate_ < -this->maxRotationRadian_) 375 this->rotationRate_ = -this->maxRotationRadian_; 376 377 if (this->acceleration_.x == 0) 378 { 379 if (this->velocity_.x > 0) 380 { 381 this->velocity_.x -= (this->translationDamping_ * dt); 382 if (this->velocity_.x < 0) 383 this->velocity_.x = 0; 384 } 385 else if (this->velocity_.x < 0) 386 { 387 this->velocity_.x += (this->translationDamping_ * dt); 388 if (this->velocity_.x > 0) 389 this->velocity_.x = 0; 390 } 391 } 392 393 if (this->acceleration_.y == 0) 394 { 395 if (this->velocity_.y > 0) 396 { 397 this->velocity_.y -= (this->translationDamping_ * dt); 398 if (this->velocity_.y < 0) 399 this->velocity_.y = 0; 400 } 401 else if (this->velocity_.y < 0) 402 { 403 this->velocity_.y += (this->translationDamping_ * dt); 404 if (this->velocity_.y > 0) 405 this->velocity_.y = 0; 406 } 407 } 408 409 if (this->momentum_ == this->zeroRadian_) 410 { 411 if (this->rotationRate_ > this->zeroRadian_) 412 { 413 this->rotationRate_ -= (this->rotationDampingRadian_ * dt); 414 if (this->rotationRate_ < this->zeroRadian_) 415 this->rotationRate_ = 0; 416 } 417 else if (this->rotationRate_ < this->zeroRadian_) 418 { 419 this->rotationRate_ += (this->rotationDampingRadian_ * dt); 420 if (this->rotationRate_ > this->zeroRadian_) 421 this->rotationRate_ = 0; 422 } 423 } 424 425 if (mKeyboard->isKeyDown(OIS::KC_UP) || mKeyboard->isKeyDown(OIS::KC_W)) 426 this->acceleration_.x = this->translationAcceleration_; 427 else if(mKeyboard->isKeyDown(OIS::KC_DOWN) || mKeyboard->isKeyDown(OIS::KC_S)) 428 this->acceleration_.x = -this->translationAcceleration_; 429 else 430 this->acceleration_.x = 0; 431 432 if (mKeyboard->isKeyDown(OIS::KC_RIGHT) || mKeyboard->isKeyDown(OIS::KC_D)) 433 this->acceleration_.y = -this->translationAcceleration_; 434 else if (mKeyboard->isKeyDown(OIS::KC_LEFT) || mKeyboard->isKeyDown(OIS::KC_A)) 435 this->acceleration_.y = this->translationAcceleration_; 436 else 437 this->acceleration_.y = 0; 438 439 if (mKeyboard->isKeyDown(OIS::KC_DELETE) || mKeyboard->isKeyDown(OIS::KC_Q)) 440 this->momentum_ = Radian(-this->rotationAccelerationRadian_); 441 else if (mKeyboard->isKeyDown(OIS::KC_PGDOWN) || mKeyboard->isKeyDown(OIS::KC_E)) 442 this->momentum_ = Radian(this->rotationAccelerationRadian_); 443 else 444 this->momentum_ = 0; 445 446 WorldEntity::tick(dt); 447 448 this->roll(this->mouseXRotation_ * dt); 449 if (this->bInvertYAxis_) 450 this->yaw(Radian(-this->mouseYRotation_ * dt)); 451 else 452 this->yaw(Radian(this->mouseYRotation_ * dt)); 453 454 if (this->acceleration_.x > 0) 455 this->tt_->setRate(emitterRate_); 456 else 457 this->tt_->setRate(0); 458 459 /* 279 460 if (mKeyboard->isKeyDown(OIS::KC_UP) || mKeyboard->isKeyDown(OIS::KC_W)) 280 461 this->moveForward(speed); … … 311 492 mouseX = 0; 312 493 moved = false; 313 } 314 else494 }*/ 495 /* else 315 496 { 316 497 this->rotateUp(0); … … 318 499 this->rotateRight(0); 319 500 this->rotateLeft(0); 320 } 321 501 }*/ 502 /* 322 503 if(moveForward_ > 0) 323 504 { … … 426 607 427 608 Vector3 transVector = Vector3::ZERO; 609 */ 428 610 /* 429 611 transVector.z = 1; … … 433 615 this->roll(Degree(speedLoopRightLeft_*dt), Ogre::Node::TS_LOCAL); 434 616 */ 435 617 /* 436 618 transVector.x = 1; 437 619 this->translate(transVector*speedForward_*dt, Ogre::Node::TS_LOCAL); … … 439 621 this->roll(Degree(speedRotateRightLeft_*dt), Ogre::Node::TS_LOCAL); 440 622 this->pitch(Degree(speedLoopRightLeft_*dt), Ogre::Node::TS_LOCAL); 441 442 if (accelerationForward_ > 25.0) 443 { 444 this->tt_->setRate(emitterRate_); 445 } 446 else 447 { 448 this->tt_->setRate(0); 449 } 450 451 } 452 623 */ 624 } 625 /* 453 626 void SpaceShip::moveForward(float moveForward) { 454 627 moveForward_ = moveForward; … … 506 679 maxSpeedLoopRightLeft_ = maxSpeedLoopRightLeft; 507 680 } 681 */ 508 682 } -
code/branches/FICN/src/orxonox/objects/SpaceShip.h
r644 r647 19 19 ~SpaceShip(); 20 20 virtual void loadParams(TiXmlElement* xmlElem); 21 void setMaxSpeedValues(float maxSpeedForward, float maxSpeedRotateUpDown, float maxSpeedRotateRightLeft, float maxSpeedLoopRightLeft);22 21 virtual void tick(float dt); 22 /* 23 23 void moveForward(float moveForward); 24 24 void rotateUp(float rotateUp); … … 35 35 void maxSpeedRotateRightLeft(float maxSpeedRotateRightLeft); 36 36 void maxSpeedLoopRightLeft(float maxSpeedLoopRightLeft); 37 */ 37 38 bool mouseMoved(const OIS::MouseEvent &e); 38 39 bool mousePressed(const OIS::MouseEvent &e, OIS::MouseButtonID id); … … 41 42 42 43 private: 43 bool bInvert Mouse_;44 bool bInvertYAxis_; 44 45 bool setMouseEventCallback_; 45 46 bool bLMousePressed_; … … 48 49 Ogre::SceneNode* camNode_; 49 50 50 particle::ParticleInterface *tt_;51 particle::ParticleInterface* tt_; 51 52 52 53 BillboardSet redBillboard_; … … 59 60 float reloadTime_; 60 61 62 float maxSideAndBackSpeed_; 63 float maxSpeed_; 64 float maxRotation_; 65 float translationAcceleration_; 66 float rotationAcceleration_; 67 float translationDamping_; 68 float rotationDamping_; 69 70 Radian maxRotationRadian_; 71 Radian rotationAccelerationRadian_; 72 Radian rotationDampingRadian_; 73 Radian zeroRadian_; 74 Radian mouseXRotation_; 75 Radian mouseYRotation_; 76 77 float mouseX_; 78 float mouseY_; 79 80 /* 61 81 float moveForward_; 62 82 float rotateUp_; … … 93 113 float minMouseX; 94 114 bool moved; 95 115 */ 96 116 int emitterRate_; 97 117 }; -
code/branches/FICN/src/orxonox/objects/WorldEntity.h
r646 r647 133 133 void registerAllVariables(); 134 134 135 private:136 Ogre::SceneNode* node_;137 static unsigned int worldEntityCounter_s;138 139 bool bStatic_;140 135 Vector3 velocity_; 141 136 Vector3 acceleration_; … … 143 138 Radian rotationRate_; 144 139 Radian momentum_; 140 141 private: 142 static unsigned int worldEntityCounter_s; 143 Ogre::SceneNode* node_; 144 bool bStatic_; 145 145 }; 146 146 } -
code/branches/FICN/src/orxonox/particle/ParticleInterface.cc
r646 r647 40 40 ParticleInterface::~ParticleInterface(void) 41 41 { 42 std::cout << "blubiblub_1\n";43 42 sceneManager_->destroyParticleSystem(particleSystem_); 44 std::cout << "blubiblub_2\n";45 46 // delete sceneNode_;47 // delete particleSystem_;48 // delete sceneManager_;49 43 } 50 44
Note: See TracChangeset
for help on using the changeset viewer.