Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
May 13, 2008, 5:01:10 PM (16 years ago)
Author:
scheusso
Message:

merge network3 and camera branch into merge branch

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/merge/src/orxonox/objects/SpaceShip.cc

    r1263 r1264  
    2323 *      Fabian 'x3n' Landau
    2424 *   Co-authors:
    25  *      ...
     25 *      Benjamin Knecht
    2626 *
    2727 */
     
    3737#include <OgreSceneNode.h>
    3838
     39#include "CameraHandler.h"
    3940#include "tinyxml/tinyxml.h"
    4041#include "ois/OIS.h"
     
    5051#include "core/XMLPort.h"
    5152#include "core/ConsoleCommand.h"
     53#include "network/Client.h"
    5254
    5355namespace orxonox
     
    6466    SpaceShip::SpaceShip()
    6567    {
     68        RegisterObject(SpaceShip);
     69        this->registerAllVariables();
     70
    6671        SpaceShip::instance_s = this;
     72
     73        this->setConfigValues();
    6774
    6875        this->setMouseEventCallback_ = false;
     
    7380
    7481        this->camNode_ = 0;
     82        this->camName_ = "camNode";
    7583
    7684        this->tt_ = 0;
     
    96104        this->setRotationAxis(1, 0, 0);
    97105        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
    139109
    140110        COUT(3) << "Info: SpaceShip was loaded" << std::endl;
     
    156126
    157127    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);
    161138
    162139    }
     
    164141    void SpaceShip::init()
    165142    {
    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                }
    171151
    172152        // START CREATING THRUSTER
     
    222202        this->chFarNode_->setScale(0.4, 0.4, 0.4);
    223203
     204        createCamera();
    224205        // END of testing crosshair
    225206    }
     
    236217        Model::loadParams(xmlElem);
    237218        this->create();
     219        this->getFocus();
    238220/*
    239221        if (xmlElem->Attribute("forward") && xmlElem->Attribute("rotateupdown") && xmlElem->Attribute("rotaterightleft") && xmlElem->Attribute("looprightleft"))
     
    286268    void SpaceShip::setCamera(const std::string& camera)
    287269    {
    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;
    290287/*
    291288//        node->setInheritOrientation(false);
     
    293290        cam->lookAt(Vector3(0,20,0));
    294291        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());
    298296//        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
    304302    }
    305303
     
    337335        XMLPortParamLoadOnly(SpaceShip, "transDamp", setTransDamp, xmlelement, mode);
    338336        XMLPortParamLoadOnly(SpaceShip, "rotDamp", setRotDamp, xmlelement, mode);
     337        server_=true; // TODO: this is only a hack
     338        SpaceShip::create();
     339        getFocus();
    339340    }
    340341
     
    448449        if (this->bLMousePressed_ && this->timeToReload_ <= 0)
    449450        {
    450             new Projectile(this);
     451            Projectile *p = new Projectile(this);
     452            p->setBacksync(true);
    451453            this->timeToReload_ = this->reloadTime_;
    452454        }
     
    520522        }
    521523
    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))
    523527            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))
    525529            this->acceleration_.x = -this->translationAcceleration_;
    526         else
     530          else
    527531            this->acceleration_.x = 0;
    528532
    529         if (mKeyboard->isKeyDown(OIS::KC_RIGHT) || mKeyboard->isKeyDown(OIS::KC_D))
     533          if (mKeyboard->isKeyDown(OIS::KC_RIGHT) || mKeyboard->isKeyDown(OIS::KC_D))
    530534            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))
    532536            this->acceleration_.y = this->translationAcceleration_;
    533         else
     537          else
    534538            this->acceleration_.y = 0;
    535539
    536         if (mKeyboard->isKeyDown(OIS::KC_DELETE) || mKeyboard->isKeyDown(OIS::KC_Q))
     540          if (mKeyboard->isKeyDown(OIS::KC_DELETE) || mKeyboard->isKeyDown(OIS::KC_Q))
    537541            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))
    539543            this->momentum_ = Radian(this->rotationAccelerationRadian_);
    540         else
     544          else
    541545            this->momentum_ = 0;
     546        }/*else
     547          COUT(4) << "not steering ship: " << objectID << " our ship: " << network::Client::getSingleton()->getShipID() << std::endl;*/
    542548
    543549        WorldEntity::tick(dt);
Note: See TracChangeset for help on using the changeset viewer.