Changeset 1502 for code/trunk/src/orxonox/objects/SpaceShip.cc
- Timestamp:
- Jun 1, 2008, 3:54:20 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk/src/orxonox/objects/SpaceShip.cc
r1407 r1502 45 45 #include "particle/ParticleInterface.h" 46 46 #include "Projectile.h" 47 #include "RotatingProjectile.h" 47 48 #include "core/XMLPort.h" 48 49 #include "core/ConsoleCommand.h" 49 50 #include "network/Client.h" 51 #include "hud/HUD.h" 50 52 51 53 namespace orxonox 52 54 { 53 ConsoleCommand(SpaceShip, setMaxSpeedTest, AccessLevel::Debug, false); 54 ConsoleCommand(SpaceShip, whereAmI, AccessLevel::User, true); 55 ConsoleCommandGeneric(test1, SpaceShip, createExecutor(createFunctor(&SpaceShip::setMaxSpeedTest), "setMaxSpeed", AccessLevel::Debug), false); 56 ConsoleCommandGeneric(test2, SpaceShip, createExecutor(createFunctor(&SpaceShip::setMaxSpeedTest), "setMaxBlubber", AccessLevel::Debug), false); 57 ConsoleCommandGeneric(test3, SpaceShip, createExecutor(createFunctor(&SpaceShip::setMaxSpeedTest), "setRofl", AccessLevel::Debug), false); 55 SetConsoleCommand(SpaceShip, setMaxSpeedTest, false).setAccessLevel(AccessLevel::Debug); 56 SetConsoleCommand(SpaceShip, whereAmI, true).setAccessLevel(AccessLevel::User); 57 SetConsoleCommand(SpaceShip, moveLongitudinal, true).setAccessLevel(AccessLevel::User).setDefaultValue(0, 1.0f).setAxisParamIndex(0).setKeybindMode(KeybindMode::OnHold); 58 SetConsoleCommand(SpaceShip, moveLateral, true).setAccessLevel(AccessLevel::User).setDefaultValue(0, 1.0f).setAxisParamIndex(0).setKeybindMode(KeybindMode::OnHold); 59 SetConsoleCommand(SpaceShip, moveYaw, true).setAccessLevel(AccessLevel::User).setDefaultValue(0, 1.0f).setAxisParamIndex(0).setKeybindMode(KeybindMode::OnHold); 60 SetConsoleCommand(SpaceShip, movePitch, true).setAccessLevel(AccessLevel::User).setDefaultValue(0, 1.0f).setAxisParamIndex(0).setKeybindMode(KeybindMode::OnHold); 61 SetConsoleCommand(SpaceShip, moveRoll, true).setAccessLevel(AccessLevel::User).setDefaultValue(0, 1.0f).setAxisParamIndex(0).setKeybindMode(KeybindMode::OnHold); 62 SetConsoleCommand(SpaceShip, fire, true).setAccessLevel(AccessLevel::User).setKeybindMode(KeybindMode::OnHold); 63 SetConsoleCommandGeneric(test1, SpaceShip, createConsoleCommand(createFunctor(&SpaceShip::setMaxSpeedTest), "setMaxSpeed"), false).setAccessLevel(AccessLevel::Debug); 64 SetConsoleCommandGeneric(test2, SpaceShip, createConsoleCommand(createFunctor(&SpaceShip::setMaxSpeedTest), "setMaxBlubber"), false).setAccessLevel(AccessLevel::Debug); 65 SetConsoleCommandGeneric(test3, SpaceShip, createConsoleCommand(createFunctor(&SpaceShip::setMaxSpeedTest), "setRofl"), false).setAccessLevel(AccessLevel::Debug); 58 66 59 67 CreateFactory(SpaceShip); … … 64 72 Iterator<SpaceShip> it; 65 73 for(it = ObjectList<SpaceShip>::start(); it; ++it){ 66 if( (it)->server_ || ( network::Client::getSingleton() && network::Client::getSingleton()->getShipID()==it->objectID ))74 if( (it)->myShip_ ) 67 75 return *it; 68 76 } 69 77 return NULL; 70 78 } 71 79 72 80 SpaceShip::SpaceShip() : 73 81 //testvector_(0,0,0), … … 103 111 mouseY_(0.0f), 104 112 emitterRate_(0.0f), 105 server_(false) 113 myShip_(false), 114 teamNr_(0), 115 health_(100) 106 116 { 107 117 RegisterObject(SpaceShip); … … 112 122 this->setConfigValues(); 113 123 124 initialDir_ = Vector3(1.0, 0.0, 0.0); 125 currentDir_ = initialDir_; 126 initialOrth_ = Vector3(0.0, 0.0, 1.0); 127 currentOrth_ = initialOrth_; 128 129 this->camName_ = this->getName() + "CamNode"; 114 130 115 131 this->setRotationAxis(1, 0, 0); … … 127 143 if (this->cam_) 128 144 delete this->cam_; 145 if (!Identifier::isCreatingHierarchy() && !myShip_ && &HUD::getSingleton()!=NULL) 146 //remove the radar object 147 HUD::getSingleton().removeRadarObject(this->getNode()); 129 148 } 130 149 131 150 bool SpaceShip::create(){ 151 if(!myShip_){ 152 if(network::Client::getSingleton() && objectID == network::Client::getSingleton()->getShipID()) 153 myShip_=true; 154 else 155 HUD::getSingleton().addRadarObject(this->getNode(), 3); 156 } 132 157 if(Model::create()) 133 158 this->init(); … … 153 178 void SpaceShip::init() 154 179 { 155 if ((server_ || ( network::Client::getSingleton() && network::Client::getSingleton()->getShipID()==objectID ) ))156 {157 if (!setMouseEventCallback_)158 {159 InputManager::addMouseHandler(this, "SpaceShip");160 //InputManager::enableMouseHandler("SpaceShip");161 setMouseEventCallback_ = true;162 }163 }164 165 180 // START CREATING THRUSTER 166 181 this->tt_ = new ParticleInterface(GraphicsEngine::getSingleton().getSceneManager(),"twinthruster" + this->getName(),"Orxonox/engineglow"); … … 200 215 // END CREATING BLINKING LIGHTS 201 216 202 // START of testing crosshair 203 this->crosshairNear_.setBillboardSet("Orxonox/Crosshair", ColourValue(1.0, 1.0, 0.0), 1); 204 this->crosshairFar_.setBillboardSet("Orxonox/Crosshair", ColourValue(1.0, 1.0, 0.0), 1); 205 206 this->chNearNode_ = this->getNode()->createChildSceneNode(this->getName() + "near", Vector3(50.0, 0.0, 0.0)); 207 this->chNearNode_->setInheritScale(false); 208 this->chFarNode_ = this->getNode()->createChildSceneNode(this->getName() + "far", Vector3(200.0, 0.0, 0.0)); 209 this->chFarNode_->setInheritScale(false); 210 211 this->chNearNode_->attachObject(this->crosshairNear_.getBillboardSet()); 212 this->chNearNode_->setScale(0.2, 0.2, 0.2); 213 214 this->chFarNode_->attachObject(this->crosshairFar_.getBillboardSet()); 215 this->chFarNode_->setScale(0.4, 0.4, 0.4); 217 if (this->isExactlyA(Class(SpaceShip))) 218 { 219 // START of testing crosshair 220 this->crosshairNear_.setBillboardSet("Orxonox/Crosshair", ColourValue(1.0, 1.0, 0.0), 1); 221 this->crosshairFar_.setBillboardSet("Orxonox/Crosshair", ColourValue(1.0, 1.0, 0.0), 1); 222 223 this->chNearNode_ = this->getNode()->createChildSceneNode(this->getName() + "near", Vector3(50.0, 0.0, 0.0)); 224 this->chNearNode_->setInheritScale(false); 225 this->chFarNode_ = this->getNode()->createChildSceneNode(this->getName() + "far", Vector3(200.0, 0.0, 0.0)); 226 this->chFarNode_->setInheritScale(false); 227 228 this->chNearNode_->attachObject(this->crosshairNear_.getBillboardSet()); 229 this->chNearNode_->setScale(0.2, 0.2, 0.2); 230 231 this->chFarNode_->attachObject(this->crosshairFar_.getBillboardSet()); 232 this->chFarNode_->setScale(0.4, 0.4, 0.4); 233 } 216 234 217 235 createCamera(); … … 237 255 CameraHandler::getInstance()->requestFocus(cam_); 238 256 257 } 258 259 Camera* SpaceShip::getCamera(){ 260 return cam_; 239 261 } 240 262 … … 295 317 XMLPortParamLoadOnly(SpaceShip, "transDamp", setTransDamp, xmlelement, mode); 296 318 XMLPortParamLoadOnly(SpaceShip, "rotDamp", setRotDamp, xmlelement, mode); 297 server_=true; // TODO: this is only a hack 319 myShip_=true; // TODO: this is only a hack 320 298 321 SpaceShip::create(); 299 getFocus(); 322 if (this->isExactlyA(Class(SpaceShip))) 323 getFocus(); 300 324 } 301 325 … … 308 332 } 309 333 310 void SpaceShip::mouseMoved(IntVector2 abs, IntVector2 rel, IntVector2 clippingSize)311 {312 /*313 this->mouseX += e.state.X.rel;314 if (this->bInvertMouse_)315 this->mouseY += e.state.Y.rel;316 else317 this->mouseY -= e.state.Y.rel;318 319 // if(mouseX>maxMouseX) maxMouseX = mouseX;320 // if(mouseX<minMouseX) minMouseX = mouseX;321 // cout << "mouseX: " << mouseX << "\tmouseY: " << mouseY << endl;322 323 this->moved = true;324 */325 if (this->bRMousePressed_)326 {327 this->camNode_->roll(Degree(-rel.x * 0.10));328 this->camNode_->yaw(Degree(rel.y * 0.10));329 }330 else331 {332 float minDimension = clippingSize.y;333 if (clippingSize.x < minDimension)334 minDimension = clippingSize.x;335 336 this->mouseX_ += rel.x;337 if (this->mouseX_ < -minDimension)338 this->mouseX_ = -minDimension;339 if (this->mouseX_ > minDimension)340 this->mouseX_ = minDimension;341 342 this->mouseY_ += rel.y;343 if (this->mouseY_ < -minDimension)344 this->mouseY_ = -minDimension;345 if (this->mouseY_ > minDimension)346 this->mouseY_ = minDimension;347 348 float xRotation = this->mouseX_ / minDimension;349 xRotation = xRotation*xRotation * sgn(xRotation);350 xRotation *= -this->rotationAcceleration_;351 if (xRotation > this->maxRotation_)352 xRotation = this->maxRotation_;353 if (xRotation < -this->maxRotation_)354 xRotation = -this->maxRotation_;355 this->mouseXRotation_ = Radian(xRotation);356 357 float yRotation = this->mouseY_ / minDimension;358 yRotation = yRotation*yRotation * sgn(yRotation);359 yRotation *= this->rotationAcceleration_;360 if (yRotation > this->maxRotation_)361 yRotation = this->maxRotation_;362 if (yRotation < -this->maxRotation_)363 yRotation = -this->maxRotation_;364 this->mouseYRotation_ = Radian(yRotation);365 }366 }367 368 void SpaceShip::mouseButtonPressed(MouseButton::Enum id)369 {370 if (id == MouseButton::Left)371 this->bLMousePressed_ = true;372 else if (id == MouseButton::Right)373 this->bRMousePressed_ = true;374 }375 376 void SpaceShip::mouseButtonReleased(MouseButton::Enum id)377 {378 if (id == MouseButton::Left)379 this->bLMousePressed_ = false;380 else if (id == MouseButton::Right)381 {382 this->bRMousePressed_ = false;383 this->camNode_->resetOrientation();384 }385 }386 387 334 std::string SpaceShip::whereAmI() { 388 335 return getConvertedValue<float, std::string>(SpaceShip::getLocalShip()->getPosition().x) … … 391 338 } 392 339 393 Vector3 SpaceShip::get SPosition() {394 return SpaceShip::getLocalShip()->getPosition();395 } 396 397 Quaternion SpaceShip::getSOrientation(){398 return SpaceShip::getLocalShip()->getOrientation();340 Vector3 SpaceShip::getDir() { 341 return currentDir_; 342 } 343 344 Vector3 SpaceShip::getOrth(){ 345 return currentOrth_; 399 346 } 400 347 … … 403 350 void SpaceShip::tick(float dt) 404 351 { 352 currentDir_ = getOrientation()*initialDir_; 353 currentOrth_ = getOrientation()*initialOrth_; 354 405 355 if (this->cam_) 406 356 this->cam_->tick(dt); … … 422 372 if (this->bLMousePressed_ && this->timeToReload_ <= 0) 423 373 { 424 425 Projectile *p = new Projectile(this); 426 374 375 Projectile *p; 376 if (this->isExactlyA(Class(SpaceShip))) 377 p = new RotatingProjectile(this); 378 else 379 p = new Projectile(this); 380 p->setColour(this->getProjectileColour()); 381 p->create(); 382 if(p->classID==0) 383 COUT(3) << "generated projectile with classid 0" << std::endl; // TODO: remove this output 384 427 385 p->setBacksync(true); 428 386 this->timeToReload_ = this->reloadTime_; … … 495 453 } 496 454 497 if( (network::Client::getSingleton() && network::Client::getSingleton()->getShipID() == objectID) || server_ )498 {499 COUT(4) << "steering our ship: " << objectID << std::endl;500 if (InputManager::isKeyDown(KeyCode::Up) || InputManager::isKeyDown(KeyCode::W))501 this->acceleration_.x = this->translationAcceleration_;502 else if(InputManager::isKeyDown(KeyCode::Down) || InputManager::isKeyDown(KeyCode::S))503 this->acceleration_.x = -this->translationAcceleration_;504 else505 this->acceleration_.x = 0;506 507 if (InputManager::isKeyDown(KeyCode::Right) || InputManager::isKeyDown(KeyCode::D))508 this->acceleration_.y = -this->translationAcceleration_;509 else if (InputManager::isKeyDown(KeyCode::Left) || InputManager::isKeyDown(KeyCode::A))510 this->acceleration_.y = this->translationAcceleration_;511 else512 this->acceleration_.y = 0;513 514 if (InputManager::isKeyDown(KeyCode::Delete) || InputManager::isKeyDown(KeyCode::Q))515 this->momentum_ = Radian(-this->rotationAccelerationRadian_);516 else if (InputManager::isKeyDown(KeyCode::PageDown) || InputManager::isKeyDown(KeyCode::E))517 this->momentum_ = Radian(this->rotationAccelerationRadian_);518 else519 this->momentum_ = 0;520 }/*else521 COUT(4) << "not steering ship: " << objectID << " our ship: " << network::Client::getSingleton()->getShipID() << std::endl;*/522 455 523 456 WorldEntity::tick(dt); … … 533 466 else 534 467 this->tt_->setRate(0); 535 } 536 468 469 if( myShip_ ) 470 { 471 COUT(4) << "steering our ship: " << objectID << std::endl; 472 this->acceleration_.x = 0; 473 this->acceleration_.y = 0; 474 this->momentum_ = 0; 475 this->mouseXRotation_ = Radian(0); 476 this->mouseYRotation_ = Radian(0); 477 this->bLMousePressed_ = false; 478 }/*else 479 COUT(4) << "not steering ship: " << objectID << " our ship: " << network::Client::getSingleton()->getShipID() << std::endl;*/ 480 } 481 482 void SpaceShip::movePitch(float val) 483 { getLocalShip()->setMovePitch(val); } 484 void SpaceShip::moveYaw(float val) 485 { getLocalShip()->setMoveYaw(val); } 486 void SpaceShip::moveRoll(float val) 487 { getLocalShip()->setMoveRoll(val); } 488 void SpaceShip::moveLongitudinal(float val) 489 { getLocalShip()->setMoveLongitudinal(val); } 490 void SpaceShip::moveLateral(float val) 491 { getLocalShip()->setMoveLateral(val); } 492 void SpaceShip::fire() 493 { getLocalShip()->doFire(); } 494 495 void SpaceShip::setMovePitch(float val) 496 { 497 val = -val * val * sgn(val) * this->rotationAcceleration_; 498 if (val > this->maxRotation_) 499 val = this->maxRotation_; 500 if (val < -this->maxRotation_) 501 val = -this->maxRotation_; 502 this->mouseYRotation_ = Radian(val); 503 } 504 505 void SpaceShip::setMoveYaw(float val) 506 { 507 val = -val * val * sgn(val) * this->rotationAcceleration_; 508 if (val > this->maxRotation_) 509 val = this->maxRotation_; 510 if (val < -this->maxRotation_) 511 val = -this->maxRotation_; 512 this->mouseXRotation_ = Radian(val); 513 } 514 515 void SpaceShip::setMoveRoll(float val) 516 { 517 this->momentum_ = Radian(-this->rotationAccelerationRadian_ * val); 518 //COUT(3) << "rotating val: " << val << " acceleration: " << this->rotationAccelerationRadian_.valueDegrees() << std::endl; 519 } 520 521 void SpaceShip::setMoveLongitudinal(float val) 522 { 523 this->acceleration_.x = this->translationAcceleration_ * val; 524 } 525 526 void SpaceShip::setMoveLateral(float val) 527 { 528 this->acceleration_.y = -this->translationAcceleration_ * val; 529 } 530 531 void SpaceShip::doFire() 532 { 533 this->bLMousePressed_ = true; 534 } 537 535 }
Note: See TracChangeset
for help on using the changeset viewer.