Changeset 1264 for code/branches/merge/src/orxonox/objects/SpaceShip.cc
- Timestamp:
- May 13, 2008, 5:01:10 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/merge/src/orxonox/objects/SpaceShip.cc
r1263 r1264 23 23 * Fabian 'x3n' Landau 24 24 * Co-authors: 25 * ...25 * Benjamin Knecht 26 26 * 27 27 */ … … 37 37 #include <OgreSceneNode.h> 38 38 39 #include "CameraHandler.h" 39 40 #include "tinyxml/tinyxml.h" 40 41 #include "ois/OIS.h" … … 50 51 #include "core/XMLPort.h" 51 52 #include "core/ConsoleCommand.h" 53 #include "network/Client.h" 52 54 53 55 namespace orxonox … … 64 66 SpaceShip::SpaceShip() 65 67 { 68 RegisterObject(SpaceShip); 69 this->registerAllVariables(); 70 66 71 SpaceShip::instance_s = this; 72 73 this->setConfigValues(); 67 74 68 75 this->setMouseEventCallback_ = false; … … 73 80 74 81 this->camNode_ = 0; 82 this->camName_ = "camNode"; 75 83 76 84 this->tt_ = 0; … … 96 104 this->setRotationAxis(1, 0, 0); 97 105 this->setStatic(false); 98 /* 99 this->moveForward_ = 0; 100 this->rotateUp_ = 0; 101 this->rotateDown_ = 0; 102 this->rotateRight_ = 0; 103 this->rotateLeft_ = 0; 104 this->loopRight_ = 0; 105 this->loopLeft_ = 0; 106 this->brakeForward_ = 0; 107 this->brakeRotate_ = 0; 108 this->brakeLoop_ = 0; 109 this->speedForward_ = 0; 110 this->speedRotateUpDown_ = 0; 111 this->speedRotateRightLeft_ = 0; 112 this->speedLoopRightLeft_ = 0; 113 this->maxSpeedForward_ = 0; 114 this->maxSpeedRotateUpDown_ = 0; 115 this->maxSpeedRotateRightLeft_ = 0; 116 this->maxSpeedLoopRightLeft_ = 0; 117 this->accelerationForward_ = 0; 118 this->accelerationRotateUpDown_ = 0; 119 this->accelerationRotateRightLeft_ = 0; 120 this->accelerationLoopRightLeft_ = 0; 121 122 this->speed = 250; 123 this->loop = 100; 124 this->rotate = 10; 125 this->mouseX = 0; 126 this->mouseY = 0; 127 this->maxMouseX = 0; 128 this->minMouseX = 0; 129 this->moved = false; 130 131 this->brakeRotate(rotate*10); 132 this->brakeLoop(loop); 133 */ 134 // this->create(); 135 136 RegisterObject(SpaceShip); 137 this->registerAllVariables(); 138 this->setConfigValues(); 106 107 server_=false; 108 139 109 140 110 COUT(3) << "Info: SpaceShip was loaded" << std::endl; … … 156 126 157 127 void SpaceShip::registerAllVariables(){ 158 Model::registerAllVariables(); 159 160 128 registerVar( &camName_, camName_.length()+1, network::STRING, 0x1); 129 registerVar( &maxSpeed_, sizeof(maxSpeed_), network::DATA, 0x1); 130 registerVar( &maxSideAndBackSpeed_, sizeof(maxSideAndBackSpeed_), network::DATA, 0x1); 131 registerVar( &maxRotation_, sizeof(maxRotation_), network::DATA, 0x1); 132 registerVar( &translationAcceleration_, sizeof(translationAcceleration_), network::DATA, 0x1); 133 registerVar( &rotationAcceleration_, sizeof(rotationAcceleration_), network::DATA, 0x1); 134 registerVar( &rotationAccelerationRadian_, sizeof(rotationAccelerationRadian_), network::DATA, 0x1); 135 registerVar( &translationDamping_, sizeof(translationDamping_), network::DATA, 0x1); 136 registerVar( &rotationDamping_, sizeof(rotationDamping_), network::DATA, 0x1); 137 registerVar( &rotationDampingRadian_, sizeof(rotationDampingRadian_), network::DATA, 0x1); 161 138 162 139 } … … 164 141 void SpaceShip::init() 165 142 { 166 if (!setMouseEventCallback_) 167 { 168 InputManager::addMouseHandler(this, "SpaceShip"); 169 setMouseEventCallback_ = true; 170 } 143 if ((!network::Client::getSingleton() || network::Client::getSingleton()->getShipID()==objectID )) 144 { 145 if (!setMouseEventCallback_) 146 { 147 InputManager::addMouseHandler(this, "SpaceShip"); 148 setMouseEventCallback_ = true; 149 } 150 } 171 151 172 152 // START CREATING THRUSTER … … 222 202 this->chFarNode_->setScale(0.4, 0.4, 0.4); 223 203 204 createCamera(); 224 205 // END of testing crosshair 225 206 } … … 236 217 Model::loadParams(xmlElem); 237 218 this->create(); 219 this->getFocus(); 238 220 /* 239 221 if (xmlElem->Attribute("forward") && xmlElem->Attribute("rotateupdown") && xmlElem->Attribute("rotaterightleft") && xmlElem->Attribute("looprightleft")) … … 286 268 void SpaceShip::setCamera(const std::string& camera) 287 269 { 288 Ogre::Camera *cam = GraphicsEngine::getSingleton().getSceneManager()->createCamera("ShipCam"); 289 this->camNode_ = this->getNode()->createChildSceneNode("CamNode"); 270 camName_=camera; 271 // change camera attributes here, if you want to ;) 272 } 273 274 void SpaceShip::getFocus(){ 275 COUT(4) << "requesting focus" << std::endl; 276 if(network::Client::getSingleton()==0 || network::Client::getSingleton()->getShipID()==objectID) 277 CameraHandler::getInstance()->requestFocus(cam_); 278 279 } 280 281 void SpaceShip::createCamera(){ 282 // COUT(4) << "begin camera creation" << std::endl; 283 this->camNode_ = this->getNode()->createChildSceneNode(camName_); 284 COUT(4) << "position: (this)" << this->getNode()->getPosition() << std::endl; 285 this->camNode_->setPosition(/*this->getNode()->getPosition() +*/ Vector3(-50,0,10)); 286 COUT(4) << "position: (cam)" << this->camNode_->getPosition() << std::endl; 290 287 /* 291 288 // node->setInheritOrientation(false); … … 293 290 cam->lookAt(Vector3(0,20,0)); 294 291 cam->roll(Degree(0)); 295 */ 296 297 cam->setPosition(Vector3(-200,0,35)); 292 *//*COUT(4) << "creating new camera" << std::endl;*/ 293 cam_ = new Camera(this->camNode_); 294 295 cam_->setTargetNode(this->getNode()); 298 296 // cam->setPosition(Vector3(0,-350,0)); 299 cam->lookAt(Vector3(0,0,35));300 cam->roll(Degree(-90));301 302 this->camNode_->attachObject(cam);303 GraphicsEngine::getSingleton().getRenderWindow()->addViewport(cam); 297 if(network::Client::getSingleton()!=0 && network::Client::getSingleton()->getShipID()==objectID){ 298 this->setBacksync(true); 299 CameraHandler::getInstance()->requestFocus(cam_); 300 } 301 304 302 } 305 303 … … 337 335 XMLPortParamLoadOnly(SpaceShip, "transDamp", setTransDamp, xmlelement, mode); 338 336 XMLPortParamLoadOnly(SpaceShip, "rotDamp", setRotDamp, xmlelement, mode); 337 server_=true; // TODO: this is only a hack 338 SpaceShip::create(); 339 getFocus(); 339 340 } 340 341 … … 448 449 if (this->bLMousePressed_ && this->timeToReload_ <= 0) 449 450 { 450 new Projectile(this); 451 Projectile *p = new Projectile(this); 452 p->setBacksync(true); 451 453 this->timeToReload_ = this->reloadTime_; 452 454 } … … 520 522 } 521 523 522 if (mKeyboard->isKeyDown(OIS::KC_UP) || mKeyboard->isKeyDown(OIS::KC_W)) 524 if( (network::Client::getSingleton() && network::Client::getSingleton()->getShipID() == objectID) || server_ ){ 525 COUT(4) << "steering our ship: " << objectID << " mkeyboard: " << mKeyboard << std::endl; 526 if (mKeyboard->isKeyDown(OIS::KC_UP) || mKeyboard->isKeyDown(OIS::KC_W)) 523 527 this->acceleration_.x = this->translationAcceleration_; 524 else if(mKeyboard->isKeyDown(OIS::KC_DOWN) || mKeyboard->isKeyDown(OIS::KC_S))528 else if(mKeyboard->isKeyDown(OIS::KC_DOWN) || mKeyboard->isKeyDown(OIS::KC_S)) 525 529 this->acceleration_.x = -this->translationAcceleration_; 526 else530 else 527 531 this->acceleration_.x = 0; 528 532 529 if (mKeyboard->isKeyDown(OIS::KC_RIGHT) || mKeyboard->isKeyDown(OIS::KC_D))533 if (mKeyboard->isKeyDown(OIS::KC_RIGHT) || mKeyboard->isKeyDown(OIS::KC_D)) 530 534 this->acceleration_.y = -this->translationAcceleration_; 531 else if (mKeyboard->isKeyDown(OIS::KC_LEFT) || mKeyboard->isKeyDown(OIS::KC_A))535 else if (mKeyboard->isKeyDown(OIS::KC_LEFT) || mKeyboard->isKeyDown(OIS::KC_A)) 532 536 this->acceleration_.y = this->translationAcceleration_; 533 else537 else 534 538 this->acceleration_.y = 0; 535 539 536 if (mKeyboard->isKeyDown(OIS::KC_DELETE) || mKeyboard->isKeyDown(OIS::KC_Q))540 if (mKeyboard->isKeyDown(OIS::KC_DELETE) || mKeyboard->isKeyDown(OIS::KC_Q)) 537 541 this->momentum_ = Radian(-this->rotationAccelerationRadian_); 538 else if (mKeyboard->isKeyDown(OIS::KC_PGDOWN) || mKeyboard->isKeyDown(OIS::KC_E))542 else if (mKeyboard->isKeyDown(OIS::KC_PGDOWN) || mKeyboard->isKeyDown(OIS::KC_E)) 539 543 this->momentum_ = Radian(this->rotationAccelerationRadian_); 540 else544 else 541 545 this->momentum_ = 0; 546 }/*else 547 COUT(4) << "not steering ship: " << objectID << " our ship: " << network::Client::getSingleton()->getShipID() << std::endl;*/ 542 548 543 549 WorldEntity::tick(dt);
Note: See TracChangeset
for help on using the changeset viewer.