Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
May 15, 2008, 5:44:55 PM (16 years ago)
Author:
scheusso
Message:

merged changes from input & camera & network branch into trunk

Location:
code/trunk/src/orxonox/objects
Files:
15 edited
2 copied

Legend:

Unmodified
Added
Removed
  • code/trunk/src/orxonox/objects/Ambient.cc

    r1209 r1293  
    5757        RegisterObject(Ambient);
    5858        Ambient::instance_s = this;
     59        registerAllVariables();
    5960    }
    6061
     
    6364    }
    6465
     66    bool Ambient::create(){
     67      GraphicsEngine::getSingleton().getSceneManager()->setAmbientLight(ambientLight_);
     68      return true;
     69    }
     70   
     71    void Ambient::registerAllVariables(){
     72      registerVar(&ambientLight_, sizeof(ColourValue), network::DATA);
     73     
     74    }
     75   
    6576    void Ambient::loadParams(TiXmlElement* xmlElem)
    6677    {
     
    8394   {
    8495        GraphicsEngine::getSingleton().getSceneManager()->setAmbientLight(colour);
     96      ambientLight_=colour;     
    8597   }
    8698
     
    96108
    97109        XMLPortParamLoadOnly(Ambient, "colourvalue", setAmbientLight, xmlelement, mode);
     110        create();
    98111    }
    99112}
  • code/trunk/src/orxonox/objects/Ambient.h

    r1056 r1293  
    3434#include "util/Math.h"
    3535#include "core/BaseObject.h"
     36#include "network/Synchronisable.h"
    3637
    3738namespace orxonox
    3839{
    39     class _OrxonoxExport Ambient : public BaseObject
     40    class _OrxonoxExport Ambient : public BaseObject, network::Synchronisable
    4041    {
    4142        public:
     
    4647            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
    4748            void setAmbientLight(const ColourValue& colour);
     49            bool create();
     50            void registerAllVariables();
    4851
    4952            static void setAmbientLightTest(const ColourValue& colour)
     
    5255        private:
    5356            static Ambient* instance_s;
     57            ColourValue ambientLight_;
    5458
    5559    };
  • code/trunk/src/orxonox/objects/Camera.cc

    r1209 r1293  
    2323 *      Fabian 'x3n' Landau
    2424 *   Co-authors:
    25  *      ...
     25 *      Benjamin Knecht
    2626 *
    2727 */
     
    2929#include "OrxonoxStableHeaders.h"
    3030#include "Camera.h"
     31#include "CameraHandler.h"
    3132
    3233#include <string>
     
    4748namespace orxonox
    4849{
    49     CreateFactory(Camera);
    5050
    51     Camera::Camera()
     51  Camera::Camera(Ogre::SceneNode* node)
     52  {
     53    this->bHasFocus_ = false;
     54    this->cameraNode_ = GraphicsEngine::getSingleton().getSceneManager()->getRootSceneNode()->createChildSceneNode(node->getName() + "Camera");
     55    if( node != NULL )
     56      this->setPositionNode(node);
     57  }
     58
     59  Camera::~Camera()
     60  {
     61    CameraHandler::getInstance()->releaseFocus(this);
     62  }
     63
     64  void Camera::setPositionNode(Ogre::SceneNode* node)
     65  {
     66    this->positionNode_ = node;
     67    // set camera to node values according to camera mode
     68  }
     69
     70  void Camera::setTargetNode(Ogre::SceneNode* obj)
     71  {
     72    this->targetNode_ = obj;
     73  }
     74
     75  void Camera::tick(float dt)
     76  {
     77    if(this->positionNode_ != NULL) {
     78      // this stuff here may need some adjustments
     79      Vector3 offset = this->positionNode_->getWorldPosition() - this->cameraNode_->getPosition();
     80      this->cameraNode_->translate(15*dt*offset);
     81
     82      this->cameraNode_->setOrientation(Quaternion::Slerp(0.7, this->positionNode_->getWorldOrientation(), this->cameraNode_->getWorldOrientation(), false));
     83    }
     84  }
     85
     86  /**
     87    don't move anything before here! here the Ogre camera is set to values of this camera
     88    always call update after changes
     89  */
     90  void Camera::update()
     91  {
     92    if(this->positionNode_ != NULL)
    5293    {
    53         RegisterObject(Camera);
     94      this->cameraNode_->setPosition(this->positionNode_->getWorldPosition());
     95      this->cameraNode_->setOrientation(this->positionNode_->getWorldOrientation());
    5496    }
     97  }
    5598
    56     Camera::~Camera()
    57     {
    58     }
     99  /**
     100    what to do when camera loses focus (do not request focus in this function!!)
     101    this is called by the CameraHandler singleton class to notify the camera
     102  */
     103  void Camera::removeFocus()
     104  {
     105    this->bHasFocus_ = false;
     106    this->cameraNode_->detachObject(this->cam_);
     107  }
    59108
    60     void Camera::loadParams(TiXmlElement* xmlElem)
    61     {
    62       Ogre::SceneManager* mgr = GraphicsEngine::getSingleton().getSceneManager();
    63 
    64       if (xmlElem->Attribute("name") && xmlElem->Attribute("pos") && xmlElem->Attribute("lookat") && xmlElem->Attribute("node"))
    65       {
    66         //    <Camera name="Camera" pos="0,0,-250" lookat="0,0,0" />
    67 
    68         std::string name = xmlElem->Attribute("name");
    69         std::string pos = xmlElem->Attribute("pos");
    70         std::string lookat = xmlElem->Attribute("lookat");
    71 
    72         Ogre::Camera *cam = mgr->createCamera(name);
    73 
    74         float x, y, z;
    75         SubString posVec(xmlElem->Attribute("pos"), ',');
    76         convertValue<std::string, float>(&x, posVec[0]);
    77         convertValue<std::string, float>(&y, posVec[1]);
    78         convertValue<std::string, float>(&z, posVec[2]);
    79 
    80         cam->setPosition(Vector3(x,y,z));
    81 
    82         posVec = SubString(xmlElem->Attribute("lookat"), ',');
    83         convertValue<std::string, float>(&x, posVec[0]);
    84         convertValue<std::string, float>(&y, posVec[1]);
    85         convertValue<std::string, float>(&z, posVec[2]);
    86 
    87         cam->lookAt(Vector3(x,y,z));
    88 
    89         std::string node = xmlElem->Attribute("node");
    90 
    91         Ogre::SceneNode* sceneNode = (Ogre::SceneNode*)mgr->getRootSceneNode()->createChildSceneNode(node); //getChild(node);
    92         sceneNode->attachObject((Ogre::MovableObject*)cam);
    93 
    94         // FIXME: unused var
    95         //Ogre::Viewport* vp =
    96         GraphicsEngine::getSingleton().getRenderWindow()->addViewport(cam);
    97 
    98 
    99         COUT(4) << "Loader: Created camera "<< name  << std::endl << std::endl;
    100       }
    101    }
     109  void Camera::setFocus(Ogre::Camera* ogreCam)
     110  {
     111    this->bHasFocus_ = true;
     112    this->cam_ = ogreCam;
     113    this->cam_->setOrientation(this->cameraNode_->getWorldOrientation());
     114    this->cameraNode_->attachObject(this->cam_);
     115  }
    102116}
  • code/trunk/src/orxonox/objects/Camera.h

    r1056 r1293  
    2323 *      Fabian 'x3n' Landau
    2424 *   Co-authors:
    25  *      ...
     25 *      Benjamin Knecht
    2626 *
    2727 */
     
    3030#define _Camera_H__
    3131
     32#include <OgrePrerequisites.h>
     33#include <OgreSceneNode.h>
     34#include <OgreCamera.h>
     35
    3236#include "OrxonoxPrereqs.h"
    33 
    34 #include "core/BaseObject.h"
    3537
    3638namespace orxonox
    3739{
    38     class _OrxonoxExport Camera : public BaseObject
     40    class _OrxonoxExport Camera
    3941    {
    40         public:
    41             Camera();
    42             virtual ~Camera();
     42      friend class CameraHandler;
     43      public:
     44        Camera(Ogre::SceneNode* node = NULL);
     45        virtual ~Camera();
    4346
     47        void setPositionNode(Ogre::SceneNode* node);
     48        inline Ogre::SceneNode* getCameraNode() { return this->positionNode_; }
     49        // maybe also BaseObject
     50        void setTargetNode(Ogre::SceneNode* obj);
    4451
    45             void loadParams(TiXmlElement* xmlElem);
     52        void tick(float dt);
     53        void update();
     54        inline bool hasFocus() { return this->bHasFocus_; }
    4655
    47         private:
     56      private:
     57        void removeFocus();
     58        void setFocus(Ogre::Camera* ogreCam);
    4859
    49 
     60      private:
     61        Ogre::SceneNode* targetNode_;
     62        Ogre::SceneNode* positionNode_;
     63        Ogre::SceneNode* cameraNode_;
     64        Ogre::Vector3 oldPos;
     65        Ogre::Camera* cam_;
     66        bool bHasFocus_;
    5067    };
    5168}
  • code/trunk/src/orxonox/objects/Explosion.cc

    r1056 r1293  
    4545    CreateFactory(Explosion);
    4646
    47     Explosion::Explosion(WorldEntity* owner)
     47    Explosion::Explosion(WorldEntity* owner) :
     48      lifetime_(0.4),
     49      particle_(0)
    4850    {
    4951        RegisterObject(Explosion);
    50 
    51         this->particle_ = 0;
    52         this->lifetime_ = 0.4;
    5352
    5453        if (owner)
  • code/trunk/src/orxonox/objects/Model.cc

    r1209 r1293  
    4949    }
    5050
    51     void Model::loadParams(TiXmlElement* xmlElem)
    52     {
    53         WorldEntity::loadParams(xmlElem);
    54 
    55         if (xmlElem->Attribute("mesh"))
    56         {
    57             meshSrc_ = xmlElem->Attribute("mesh");
    58         }
    59         create();
    60     }
    61 
    6251    /**
    6352        @brief XML loading and saving.
     
    7362        XMLPortParamLoadOnly(Model, "mesh", setMesh, xmlelement, mode);
    7463
    75         create();
     64        Model::create();
    7665    }
    7766
     
    8271
    8372    bool Model::create(){
    84       WorldEntity::create();
     73      if(!WorldEntity::create())
     74        return false;
    8575      if ((this->meshSrc_ != "") && (this->meshSrc_.size() > 0))
    8676      {
    8777        this->mesh_.setMesh(meshSrc_);
    8878        this->attachObject(this->mesh_.getEntity());
    89         COUT(4) << "Loader: Created model" << std::endl;
     79        COUT(4) << "Loader (Model.cc): Created model" << std::endl;
    9080      }
    9181      return true;
     
    9383
    9484    void Model::registerAllVariables(){
    95       WorldEntity::registerAllVariables();
     85//       WorldEntity::registerAllVariables();
     86      COUT(5) << "Model.cc:registering new meshsrc with size: " << meshSrc_.length()+1 << " this: " << this << std::endl;
    9687      registerVar(&meshSrc_, meshSrc_.length() + 1, network::STRING);
    9788    }
  • code/trunk/src/orxonox/objects/Model.h

    r1056 r1293  
    4343            Model();
    4444            virtual ~Model();
    45             virtual void loadParams(TiXmlElement* xmlElem);
    4645            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
    4746            void setMesh(const std::string& meshname);
  • code/trunk/src/orxonox/objects/NPC.cc

    r1056 r1293  
    3636  CreateFactory(NPC);
    3737
    38   NPC::NPC()
     38  NPC::NPC() :
     39    movable_(true)
    3940  {
    4041    RegisterObject(NPC);
    41     movable_ = true;
     42    registerAllVariables();
    4243  }
    4344
     
    5960    this->translate(location);
    6061    movable_ = movable;
     62  }
     63 
     64  void NPC::registerAllVariables(){
     65    Model::registerAllVariables();
     66    registerVar(&movable_, sizeof(movable_), network::DATA);
     67  }
     68 
     69  bool NPC::create(){
     70    Model::create();
     71    return true;
    6172  }
    6273
  • code/trunk/src/orxonox/objects/NPC.h

    r1056 r1293  
    5252      void update();
    5353      void setValues(Vector3 location, Vector3 speed, Vector3 acceleration, bool movable);
     54      void registerAllVariables();
     55      bool create();
    5456
    5557    private:
  • code/trunk/src/orxonox/objects/Projectile.cc

    r1056 r1293  
    4242    CreateFactory(Projectile);
    4343
    44     Projectile::Projectile(SpaceShip* owner)
     44    Projectile::Projectile(SpaceShip* owner) :
     45      owner_(owner)
    4546    {
    4647        RegisterObject(Projectile);
    4748
    4849        this->setConfigValues();
    49 
    50         this->owner_ = owner;
    5150
    5251        this->billboard_.setBillboardSet("Examples/Flare", ColourValue(1.0, 1.0, 0.5), 1);
  • code/trunk/src/orxonox/objects/Skybox.cc

    r1209 r1293  
    4747    {
    4848        RegisterObject(Skybox);
     49        registerAllVariables();
    4950    }
    5051
     
    5758        if (xmlElem->Attribute("src"))
    5859        {
    59                 std::string skyboxSrc = xmlElem->Attribute("src");
    60                 this->setSkybox(skyboxSrc);
     60                skyboxSrc_ = xmlElem->Attribute("src");
     61        this->create();
    6162
    62                 COUT(4) << "Loader: Set skybox: "<< skyboxSrc << std::endl << std::endl;
     63                COUT(4) << "Loader: Set skybox: "<< skyboxSrc_ << std::endl << std::endl;
    6364        }
    6465   }
     
    6970   }
    7071
     72   void Skybox::setSkyboxSrc(const std::string& src){
     73     skyboxSrc_ = src;
     74   }
     75   
    7176    /**
    7277        @brief XML loading and saving.
     
    7984        BaseObject::XMLPort(xmlelement, mode);
    8085
    81         XMLPortParamLoadOnly(Skybox, "src", setSkybox, xmlelement, mode);
     86        XMLPortParamLoadOnly(Skybox, "src", setSkyboxSrc, xmlelement, mode);
     87        create();
    8288    }
     89   
     90    bool Skybox::create(){
     91      this->setSkybox(skyboxSrc_);
     92      return true;
     93    }
     94   
     95    void Skybox::registerAllVariables(){
     96      registerVar(&skyboxSrc_, skyboxSrc_.length()+1 ,network::STRING);
     97    }
     98   
    8399}
  • code/trunk/src/orxonox/objects/Skybox.h

    r1056 r1293  
    3333
    3434#include "core/BaseObject.h"
     35#include "network/Synchronisable.h"
    3536
    3637namespace orxonox
    3738{
    38     class _OrxonoxExport Skybox : public BaseObject
     39    class _OrxonoxExport Skybox : public BaseObject, public network::Synchronisable
    3940    {
    4041        public:
     
    4546            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
    4647            void setSkybox(const std::string& skyboxname);
     48           
     49            bool create();
     50            void registerAllVariables();
     51            void setSkyboxSrc(const std::string &src);
    4752
    4853        private:
     54            std::string skyboxSrc_;
    4955
    5056
  • code/trunk/src/orxonox/objects/SpaceShip.cc

    r1219 r1293  
    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
     
    6264    SpaceShip* SpaceShip::instance_s;
    6365
    64     SpaceShip::SpaceShip()
     66    SpaceShip::SpaceShip() :
     67      //testvector_(0,0,0),
     68      //bInvertYAxis_(false),
     69      setMouseEventCallback_(false),
     70      bLMousePressed_(false),
     71      bRMousePressed_(false),
     72      camNode_(0),
     73      cam_(0),
     74      camName_("CamNode"),
     75      tt_(0),
     76      redNode_(0),
     77      greenNode_(0),
     78      blinkTime_(0.0f),
     79      chNearNode_(0),
     80      chFarNode_(0),
     81      timeToReload_(0.0f),
     82      //reloadTime_(0.0f),
     83      maxSideAndBackSpeed_(0.0f),
     84      maxSpeed_(0.0f),
     85      maxRotation_(0.0f),
     86      translationAcceleration_(0.0f),
     87      rotationAcceleration_(0.0f),
     88      translationDamping_(0.0f),
     89      rotationDamping_(0.0f),
     90      maxRotationRadian_(0),
     91      rotationAccelerationRadian_(0),
     92      rotationDampingRadian_(0),
     93      zeroRadian_(0),
     94      mouseXRotation_(0),
     95      mouseYRotation_(0),
     96      mouseX_(0.0f),
     97      mouseY_(0.0f),
     98      emitterRate_(0.0f),
     99      server_(false)
    65100    {
    66101        RegisterObject(SpaceShip);
     
    71106        this->setConfigValues();
    72107
    73         this->setMouseEventCallback_ = false;
    74         this->bLMousePressed_ = false;
    75         this->bRMousePressed_ = false;
    76         this->mouseX_ = 0;
    77         this->mouseY_ = 0;
    78 
    79         this->camNode_ = 0;
    80 
    81         this->tt_ = 0;
    82         this->redNode_ = 0;
    83         this->greenNode_ = 0;
    84         this->blinkTime_ = 0;
    85 
    86         this->timeToReload_ = 0;
    87 
    88         this->maxSpeed_ = 0;
    89         this->maxSideAndBackSpeed_ = 0;
    90         this->maxRotation_ = 0;
    91         this->translationAcceleration_ = 0;
    92         this->rotationAcceleration_ = 0;
    93         this->translationDamping_ = 0;
    94         this->rotationDamping_ = 0;
    95 
    96         this->maxRotationRadian_ = 0;
    97         this->rotationAccelerationRadian_ = 0;
    98         this->rotationDampingRadian_ = 0;
    99         this->zeroRadian_ = Radian(0);
    100108
    101109        this->setRotationAxis(1, 0, 0);
    102110        this->setStatic(false);
    103 /*
    104         this->moveForward_ = 0;
    105         this->rotateUp_ = 0;
    106         this->rotateDown_ = 0;
    107         this->rotateRight_ = 0;
    108         this->rotateLeft_ = 0;
    109         this->loopRight_ = 0;
    110         this->loopLeft_ = 0;
    111         this->brakeForward_ = 0;
    112         this->brakeRotate_ = 0;
    113         this->brakeLoop_ = 0;
    114         this->speedForward_ = 0;
    115         this->speedRotateUpDown_ = 0;
    116         this->speedRotateRightLeft_ = 0;
    117         this->speedLoopRightLeft_ = 0;
    118         this->maxSpeedForward_ = 0;
    119         this->maxSpeedRotateUpDown_ = 0;
    120         this->maxSpeedRotateRightLeft_ = 0;
    121         this->maxSpeedLoopRightLeft_ = 0;
    122         this->accelerationForward_ = 0;
    123         this->accelerationRotateUpDown_ = 0;
    124         this->accelerationRotateRightLeft_ = 0;
    125         this->accelerationLoopRightLeft_ = 0;
    126 
    127         this->speed = 250;
    128         this->loop = 100;
    129         this->rotate = 10;
    130         this->mouseX = 0;
    131         this->mouseY = 0;
    132         this->maxMouseX = 0;
    133         this->minMouseX = 0;
    134         this->moved = false;
    135 
    136         this->brakeRotate(rotate*10);
    137         this->brakeLoop(loop);
    138 */
    139 //         this->create();
    140 
    141111
    142112        COUT(3) << "Info: SpaceShip was loaded" << std::endl;
     
    147117        if (this->tt_)
    148118            delete this->tt_;
     119        if(setMouseEventCallback_)
     120          InputManager::removeMouseHandler("SpaceShip");
     121        if (this->cam_)
     122          delete this->cam_;
    149123    }
    150124
     
    158132
    159133    void SpaceShip::registerAllVariables(){
    160       Model::registerAllVariables();
    161 
    162 
     134      registerVar( &camName_, camName_.length()+1, network::STRING, 0x1);
     135      registerVar( &maxSpeed_, sizeof(maxSpeed_), network::DATA, 0x1);
     136      registerVar( &maxSideAndBackSpeed_, sizeof(maxSideAndBackSpeed_), network::DATA, 0x1);
     137      registerVar( &maxRotation_, sizeof(maxRotation_), network::DATA, 0x1);
     138      registerVar( &translationAcceleration_, sizeof(translationAcceleration_), network::DATA, 0x1);
     139      registerVar( &rotationAcceleration_, sizeof(rotationAcceleration_), network::DATA, 0x1);
     140      registerVar( &rotationAccelerationRadian_, sizeof(rotationAccelerationRadian_), network::DATA, 0x1);
     141      registerVar( &translationDamping_, sizeof(translationDamping_), network::DATA, 0x1);
     142      registerVar( &rotationDamping_, sizeof(rotationDamping_), network::DATA, 0x1);
     143      registerVar( &rotationDampingRadian_, sizeof(rotationDampingRadian_), network::DATA, 0x1);
    163144
    164145    }
     
    166147    void SpaceShip::init()
    167148    {
     149    if ((server_ || ( network::Client::getSingleton() && network::Client::getSingleton()->getShipID()==objectID ) ))
     150    {
     151          if (!setMouseEventCallback_)
     152          {
     153              InputManager::addMouseHandler(this, "SpaceShip");
     154              setMouseEventCallback_ = true;
     155          }
     156    }
     157
    168158        // START CREATING THRUSTER
    169159        this->tt_ = new ParticleInterface(GraphicsEngine::getSingleton().getSceneManager(),"twinthruster" + this->getName(),"Orxonox/engineglow");
     
    191181        this->greenBillboard_.setBillboardSet("Examples/Flare", ColourValue(0.0, 1.0, 0.0), 1);
    192182
    193         this->redNode_ = this->getNode()->createChildSceneNode(this->getName() + "red", Vector3(0.3, 4.7, -0.3));
     183        this->redNode_ = this->getNode()->createChildSceneNode(this->getName() + "red", Vector3(0.3, 4.0, -0.3));
    194184        this->redNode_->setInheritScale(false);
    195         this->greenNode_ = this->getNode()->createChildSceneNode(this->getName() + "green", Vector3(0.3, -4.7, -0.3));
     185        this->greenNode_ = this->getNode()->createChildSceneNode(this->getName() + "green", Vector3(0.3, -4.0, -0.3));
    196186        this->greenNode_->setInheritScale(false);
    197187
     
    218208        this->chFarNode_->setScale(0.4, 0.4, 0.4);
    219209
     210        createCamera();
    220211        // END of testing crosshair
    221212    }
     
    232223        Model::loadParams(xmlElem);
    233224        this->create();
     225        this->getFocus();
    234226/*
    235227        if (xmlElem->Attribute("forward") && xmlElem->Attribute("rotateupdown") && xmlElem->Attribute("rotaterightleft") && xmlElem->Attribute("looprightleft"))
     
    246238
    247239            COUT(4) << "Loader: Initialized spaceship steering with values " << maxSpeedForward_ << " " << maxSpeedRotateUpDown_ << " " << maxSpeedRotateRightLeft_ << " " << maxSpeedLoopRightLeft_ << " " << std::endl;
    248         }
     240      }
    249241*/
    250242        if (xmlElem->Attribute("maxSpeed") && xmlElem->Attribute("maxSideAndBackSpeed") && xmlElem->Attribute("maxRotation") && xmlElem->Attribute("transAcc") && xmlElem->Attribute("rotAcc") && xmlElem->Attribute("transDamp") && xmlElem->Attribute("rotDamp"))
     
    272264
    273265            COUT(4) << "Loader: Initialized SpaceShip" << std::endl;
    274         }
    275 
    276         if (xmlElem->Attribute("camera"))
    277         {
    278             this->setCamera();
    279         }
     266        }
     267
     268        if (xmlElem->Attribute("camera"))
     269        {
     270            this->setCamera();
     271        }
    280272    }
    281273
    282274    void SpaceShip::setCamera(const std::string& camera)
    283275    {
    284         Ogre::Camera *cam = GraphicsEngine::getSingleton().getSceneManager()->createCamera("ShipCam");
    285         this->camNode_ = this->getNode()->createChildSceneNode("CamNode");
    286 /*
    287 //        node->setInheritOrientation(false);
    288         cam->setPosition(Vector3(0,50,-150));
    289         cam->lookAt(Vector3(0,20,0));
    290         cam->roll(Degree(0));
    291 */
    292 
    293         cam->setPosition(Vector3(-200,0,35));
     276      camName_=camera;
     277      // change camera attributes here, if you want to ;)
     278    }
     279   
     280    void SpaceShip::getFocus(){
     281      COUT(4) << "requesting focus" << std::endl;
     282      if(network::Client::getSingleton()==0 || network::Client::getSingleton()->getShipID()==objectID)
     283        CameraHandler::getInstance()->requestFocus(cam_);
     284     
     285    }
     286   
     287    void SpaceShip::createCamera(){
     288//       COUT(4) << "begin camera creation" << std::endl;
     289      this->camNode_ = this->getNode()->createChildSceneNode(camName_);
     290      COUT(4) << "position: (this)" << this->getNode()->getPosition() << std::endl;
     291      this->camNode_->setPosition(Vector3(-50,0,10));
     292      Quaternion q1 = Quaternion(Radian(Degree(90)),Vector3(0,-1,0));
     293      Quaternion q2 = Quaternion(Radian(Degree(90)),Vector3(0,0,-1));
     294      camNode_->setOrientation(q1*q2);
     295      COUT(4) << "position: (cam)" << this->camNode_->getPosition() << std::endl;
     296      cam_ = new Camera(this->camNode_);
     297
     298      cam_->setTargetNode(this->getNode());
    294299//        cam->setPosition(Vector3(0,-350,0));
    295         cam->lookAt(Vector3(0,0,35));
    296         cam->roll(Degree(-90));
    297 
    298         this->camNode_->attachObject(cam);
    299         GraphicsEngine::getSingleton().getRenderWindow()->addViewport(cam);
     300      if(network::Client::getSingleton()!=0 && network::Client::getSingleton()->getShipID()==objectID){
     301        this->setBacksync(true);
     302        CameraHandler::getInstance()->requestFocus(cam_);
     303      }
     304
    300305    }
    301306
     
    333338        XMLPortParamLoadOnly(SpaceShip, "transDamp", setTransDamp, xmlelement, mode);
    334339        XMLPortParamLoadOnly(SpaceShip, "rotDamp", setRotDamp, xmlelement, mode);
     340        server_=true; // TODO: this is only a hack
     341        SpaceShip::create();
     342        getFocus();
    335343    }
    336344
     
    343351    }
    344352
    345     bool SpaceShip::mouseMoved(const OIS::MouseEvent &e)
     353    bool SpaceShip::mouseMoved(const MouseState& state)
    346354    {
    347355/*
     
    360368        if (this->bRMousePressed_)
    361369        {
    362             this->camNode_->roll(Degree(-e.state.X.rel * 0.10));
    363             this->camNode_->yaw(Degree(e.state.Y.rel * 0.10));
    364         }
    365         else
    366         {
    367             float minDimension = e.state.height;
    368             if (e.state.width < minDimension)
    369                 minDimension = e.state.width;
    370 
    371             this->mouseX_ += e.state.X.rel;
     370            this->camNode_->roll(Degree(-state.X.rel * 0.10));
     371            this->camNode_->yaw(Degree(state.Y.rel * 0.10));
     372        }
     373        else
     374        {
     375            float minDimension = state.height;
     376            if (state.width < minDimension)
     377                minDimension = state.width;
     378
     379            this->mouseX_ += state.X.rel;
    372380            if (this->mouseX_ < -minDimension)
    373381                this->mouseX_ = -minDimension;
     
    375383                this->mouseX_ = minDimension;
    376384
    377             this->mouseY_ += e.state.Y.rel;
     385            this->mouseY_ += state.Y.rel;
    378386            if (this->mouseY_ < -minDimension)
    379387                this->mouseY_ = -minDimension;
     
    403411    }
    404412
    405     bool SpaceShip::mousePressed(const OIS::MouseEvent &e, OIS::MouseButtonID id)
    406     {
    407         if (id == OIS::MB_Left)
     413    bool SpaceShip::mouseButtonPressed(const MouseState& state, MouseButton::Enum id)
     414    {
     415        if (id == MouseButton::Left)
    408416            this->bLMousePressed_ = true;
    409         else if (id == OIS::MB_Right)
     417        else if (id == MouseButton::Right)
    410418            this->bRMousePressed_ = true;
    411419
     
    413421    }
    414422
    415     bool SpaceShip::mouseReleased(const OIS::MouseEvent &e, OIS::MouseButtonID id)
    416     {
    417         if (id == OIS::MB_Left)
     423    bool SpaceShip::mouseButtonReleased(const MouseState& state, MouseButton::Enum id)
     424    {
     425        if (id == MouseButton::Left)
    418426            this->bLMousePressed_ = false;
    419         else if (id == OIS::MB_Right)
     427        else if (id == MouseButton::Right)
    420428        {
    421429            this->bRMousePressed_ = false;
     
    428436    void SpaceShip::tick(float dt)
    429437    {
    430         if (!setMouseEventCallback_)
    431         {
    432           InputManager::addMouseHandler(this, "SpaceShip");
    433           setMouseEventCallback_ = true;
    434         }
     438        if (this->cam_)
     439            this->cam_->tick(dt);
    435440
    436441        if (this->redNode_ && this->greenNode_)
     
    450455        if (this->bLMousePressed_ && this->timeToReload_ <= 0)
    451456        {
    452             new Projectile(this);
     457            Projectile *p = new Projectile(this);
     458            p->setBacksync(true);
    453459            this->timeToReload_ = this->reloadTime_;
    454460        }
    455 
    456         OIS::Keyboard* mKeyboard = InputManager::getKeyboard();
    457461
    458462
     
    522526        }
    523527
    524         if (mKeyboard->isKeyDown(OIS::KC_UP) || mKeyboard->isKeyDown(OIS::KC_W))
     528        if( (network::Client::getSingleton() &&  network::Client::getSingleton()->getShipID() == objectID) || server_ )
     529        {
     530          COUT(4) << "steering our ship: " << objectID << std::endl;
     531          if (InputManager::isKeyDown(KeyCode::Up) || InputManager::isKeyDown(KeyCode::W))
    525532            this->acceleration_.x = this->translationAcceleration_;
    526         else if(mKeyboard->isKeyDown(OIS::KC_DOWN) || mKeyboard->isKeyDown(OIS::KC_S))
     533          else if(InputManager::isKeyDown(KeyCode::Down) || InputManager::isKeyDown(KeyCode::S))
    527534            this->acceleration_.x = -this->translationAcceleration_;
    528         else
     535          else
    529536            this->acceleration_.x = 0;
    530537
    531         if (mKeyboard->isKeyDown(OIS::KC_RIGHT) || mKeyboard->isKeyDown(OIS::KC_D))
     538          if (InputManager::isKeyDown(KeyCode::Right) || InputManager::isKeyDown(KeyCode::D))
    532539            this->acceleration_.y = -this->translationAcceleration_;
    533         else if (mKeyboard->isKeyDown(OIS::KC_LEFT) || mKeyboard->isKeyDown(OIS::KC_A))
     540          else if (InputManager::isKeyDown(KeyCode::Left) || InputManager::isKeyDown(KeyCode::A))
    534541            this->acceleration_.y = this->translationAcceleration_;
    535         else
     542          else
    536543            this->acceleration_.y = 0;
    537544
    538         if (mKeyboard->isKeyDown(OIS::KC_DELETE) || mKeyboard->isKeyDown(OIS::KC_Q))
     545          if (InputManager::isKeyDown(KeyCode::Delete) || InputManager::isKeyDown(KeyCode::Q))
    539546            this->momentum_ = Radian(-this->rotationAccelerationRadian_);
    540         else if (mKeyboard->isKeyDown(OIS::KC_PGDOWN) || mKeyboard->isKeyDown(OIS::KC_E))
     547          else if (InputManager::isKeyDown(KeyCode::PageDown) || InputManager::isKeyDown(KeyCode::E))
    541548            this->momentum_ = Radian(this->rotationAccelerationRadian_);
    542         else
     549          else
    543550            this->momentum_ = 0;
     551        }/*else
     552          COUT(4) << "not steering ship: " << objectID << " our ship: " << network::Client::getSingleton()->getShipID() << std::endl;*/
    544553
    545554        WorldEntity::tick(dt);
  • code/trunk/src/orxonox/objects/SpaceShip.h

    r1219 r1293  
    2323 *      Fabian 'x3n' Landau
    2424 *   Co-authors:
    25  *      ...
     25 *      Benjamin Knecht
    2626 *
    2727 */
     
    3434#include <OgrePrerequisites.h>
    3535
    36 #include "core/InputHandler.h"
     36#include "core/InputInterfaces.h"
     37#include "Camera.h"
    3738#include "Model.h"
    3839#include "../tools/BillboardSet.h"
     
    6263            void setRotDamp(float value);
    6364
     65            void getFocus();
     66
    6467            static void setMaxSpeedTest(float value)
    6568                { SpaceShip::instance_s->setMaxSpeed(value); }
    6669
    67             bool mouseMoved(const OIS::MouseEvent &e);
    68             bool mousePressed(const OIS::MouseEvent &e, OIS::MouseButtonID id);
    69             bool mouseReleased(const OIS::MouseEvent &e, OIS::MouseButtonID id);
    70             bool mouseHeld(const OIS::MouseEvent &e, OIS::MouseButtonID id) { return true; }
     70            bool mouseButtonPressed (const MouseState& state, MouseButton::Enum id);
     71            bool mouseButtonReleased(const MouseState& state, MouseButton::Enum id);
     72            bool mouseButtonHeld    (const MouseState& state, MouseButton::Enum id) { return true; }
     73            bool mouseMoved         (const MouseState& state);
     74            bool mouseScrolled      (const MouseState& state) { return true; }
    7175
    7276
    7377        private:
     78            void createCamera();
    7479            static SpaceShip* instance_s;
    7580
     
    8186
    8287            Ogre::SceneNode* camNode_;
     88            Camera* cam_; 
     89            std::string camName_;
     90
    8391
    8492            ParticleInterface* tt_;
     
    117125
    118126            float emitterRate_;
     127            bool server_;
    119128    };
    120129}
  • code/trunk/src/orxonox/objects/WorldEntity.cc

    r1209 r1293  
    4545    unsigned int WorldEntity::worldEntityCounter_s = 0;
    4646
    47     WorldEntity::WorldEntity()
     47    WorldEntity::WorldEntity() :
     48      velocity_    (0, 0, 0),
     49      acceleration_(0, 0, 0),
     50      rotationAxis_(0, 1, 0),
     51      rotationRate_(0),
     52      momentum_    (0),
     53      node_        (0),
     54      bStatic_     (true)
    4855    {
    4956        RegisterObject(WorldEntity);
    50 
    51         //create();
    52 
    53         this->bStatic_ = true;
    54         this->velocity_ = Vector3(0, 0, 0);
    55         this->acceleration_ = Vector3(0, 0, 0);
    56         this->rotationAxis_ = Vector3(0, 1, 0);
    57         this->rotationRate_ = 0;
    58         this->momentum_ = 0;
    5957
    6058        if (GraphicsEngine::getSingleton().getSceneManager())
     
    6765          registerAllVariables();
    6866        }
    69         else
    70         {
    71           this->node_ = 0;
    72         }
    7367    }
     68   
    7469
    7570    WorldEntity::~WorldEntity()
    7671    {
     72      // just to make sure we clean out all scene nodes
     73      if(this->getNode())
     74        this->getNode()->removeAndDestroyAllChildren();
    7775    }
    7876
     
    8179        if (!this->bStatic_)
    8280        {
     81//             COUT(4) << "acceleration: " << this->acceleration_ << " velocity: " << this->velocity_ << std::endl;
    8382            this->velocity_ += (dt * this->acceleration_);
    8483            this->translate(dt * this->velocity_, Ogre::Node::TS_LOCAL);
     
    9493        BaseObject::loadParams(xmlElem);
    9594        create();
    96 /*
    97         if (xmlElem->Attribute("position"))
    98         {
    99             std::vector<std::string> pos = tokenize(xmlElem->Attribute("position"),",");
    100             float x, y, z;
    101             String2Number<float>(x, pos[0]);
    102             String2Number<float>(y, pos[1]);
    103             String2Number<float>(z, pos[2]);
    104             this->setPosition(x, y, z);
    105         }
    106 
    107         if (xmlElem->Attribute("direction"))
    108         {
    109             std::vector<std::string> pos = tokenize(xmlElem->Attribute("direction"),",");
    110             float x, y, z;
    111             String2Number<float>(x, pos[0]);
    112             String2Number<float>(y, pos[1]);
    113             String2Number<float>(z, pos[2]);
    114             this->setDirection(x, y, z);
    115         }
    116 
    117         if (xmlElem->Attribute("yaw") || xmlElem->Attribute("pitch") || xmlElem->Attribute("roll"))
    118         {
    119             float yaw = 0.0, pitch = 0.0, roll = 0.0;
    120             if (xmlElem->Attribute("yaw"))
    121                 String2Number<float>(yaw,xmlElem->Attribute("yaw"));
    122 
    123             if (xmlElem->Attribute("pitch"))
    124                 String2Number<float>(pitch,xmlElem->Attribute("pitch"));
    125 
    126             if (xmlElem->Attribute("roll"))
    127                 String2Number<float>(roll,xmlElem->Attribute("roll"));
    128 
    129             this->yaw(Degree(yaw));
    130             this->pitch(Degree(pitch));
    131             this->roll(Degree(roll));
    132         }
    133 
    134         if (xmlElem->Attribute("scale"))
    135         {
    136             std::string scaleStr = xmlElem->Attribute("scale");
    137             float scale;
    138             String2Number<float>(scale, scaleStr);
    139             this->setScale(scale);
    140         }
    141 
    142         if (xmlElem->Attribute("rotationAxis"))
    143         {
    144             std::vector<std::string> pos = tokenize(xmlElem->Attribute("rotationAxis"),",");
    145             float x, y, z;
    146             String2Number<float>(x, pos[0]);
    147             String2Number<float>(y, pos[1]);
    148             String2Number<float>(z, pos[2]);
    149             this->setRotationAxis(x, y, z);
    150         }
    151 
    152         if (xmlElem->Attribute("rotationRate"))
    153         {
    154             float rotationRate;
    155             String2Number<float>(rotationRate, xmlElem->Attribute("rotationRate"));
    156             this->setRotationRate(Degree(rotationRate));
    157             if (rotationRate != 0)
    158                 this->setStatic(false);
    159         }
    160 
    161         create();
    162 */
    16395    }
     96   
    16497
    16598    void WorldEntity::setYawPitchRoll(const Degree& yaw, const Degree& pitch, const Degree& roll)
     
    188121
    189122        XMLPortObject(WorldEntity, WorldEntity, "attached", attachWorldEntity, getAttachedWorldEntity, xmlelement, mode, false, true);
     123       
     124        WorldEntity::create();
    190125    }
    191126
     
    194129    {
    195130      // register coordinates
    196       registerVar( (void*) &(this->getPosition().x), sizeof(this->getPosition().x), network::DATA);
    197       registerVar( (void*) &(this->getPosition().y), sizeof(this->getPosition().y), network::DATA);
    198       registerVar( (void*) &(this->getPosition().z), sizeof(this->getPosition().z), network::DATA);
     131      registerVar( (void*) &(this->getPosition().x), sizeof(this->getPosition().x), network::DATA, 0x3);
     132      registerVar( (void*) &(this->getPosition().y), sizeof(this->getPosition().y), network::DATA, 0x3);
     133      registerVar( (void*) &(this->getPosition().z), sizeof(this->getPosition().z), network::DATA, 0x3);
    199134      // register orientation
    200       registerVar( (void*) &(this->getOrientation().w), sizeof(this->getOrientation().w), network::DATA);
    201       registerVar( (void*) &(this->getOrientation().x), sizeof(this->getOrientation().x), network::DATA);
    202       registerVar( (void*) &(this->getOrientation().y), sizeof(this->getOrientation().y), network::DATA);
    203       registerVar( (void*) &(this->getOrientation().z), sizeof(this->getOrientation().z), network::DATA);
    204       // not needed at the moment, because we don't have prediction yet
     135      registerVar( (void*) &(this->getOrientation().w), sizeof(this->getOrientation().w), network::DATA, 0x3);
     136      registerVar( (void*) &(this->getOrientation().x), sizeof(this->getOrientation().x), network::DATA, 0x3);
     137      registerVar( (void*) &(this->getOrientation().y), sizeof(this->getOrientation().y), network::DATA, 0x3);
     138      registerVar( (void*) &(this->getOrientation().z), sizeof(this->getOrientation().z), network::DATA, 0x3);
    205139      // register velocity_
    206       registerVar( (void*) &(this->getVelocity().x), sizeof(this->getVelocity().x), network::DATA);
    207       registerVar( (void*) &(this->getVelocity().y), sizeof(this->getVelocity().y), network::DATA);
    208       registerVar( (void*) &(this->getVelocity().z), sizeof(this->getVelocity().z), network::DATA);
    209       // register rotationAxis/rate
    210       registerVar( (void*) &(this->getRotationRate()), sizeof(this->getRotationRate()), network::DATA);
    211       registerVar( (void*) &(this->getRotationAxis().x), sizeof(this->getRotationAxis().x), network::DATA);
    212       registerVar( (void*) &(this->getRotationAxis().y), sizeof(this->getRotationAxis().y), network::DATA);
    213       registerVar( (void*) &(this->getRotationAxis().z), sizeof(this->getRotationAxis().z), network::DATA);
     140//       registerVar( (void*) &(this->getVelocity().x), sizeof(this->getVelocity().x), network::DATA, 0x3);
     141//       registerVar( (void*) &(this->getVelocity().y), sizeof(this->getVelocity().y), network::DATA, 0x3);
     142//       registerVar( (void*) &(this->getVelocity().z), sizeof(this->getVelocity().z), network::DATA, 0x3);
     143//       // register rotationAxis/rate
     144//       registerVar( (void*) &(this->getRotationRate()), sizeof(this->getRotationRate()), network::DATA, 0x3);
     145//       registerVar( (void*) &(this->getRotationAxis().x), sizeof(this->getRotationAxis().x), network::DATA, 0x3);
     146//       registerVar( (void*) &(this->getRotationAxis().y), sizeof(this->getRotationAxis().y), network::DATA, 0x3);
     147//       registerVar( (void*) &(this->getRotationAxis().z), sizeof(this->getRotationAxis().z), network::DATA, 0x3);
     148      // register scale of node
     149      registerVar( (void*) &(this->getScale().x), sizeof(this->getScale().x), network::DATA, 0x3);
     150      registerVar( (void*) &(this->getScale().y), sizeof(this->getScale().y), network::DATA, 0x3);
     151      registerVar( (void*) &(this->getScale().z), sizeof(this->getScale().z), network::DATA, 0x3);
     152      //register staticity
     153      registerVar( (void*) &(this->bStatic_), sizeof(this->bStatic_), network::DATA, 0x3);
     154      //register acceleration
     155      // register velocity_
     156//       registerVar( (void*) &(this->getAcceleration().x), sizeof(this->getAcceleration().x), network::DATA, 0x3);
     157//       registerVar( (void*) &(this->getAcceleration().y), sizeof(this->getAcceleration().y), network::DATA, 0x3);
     158//       registerVar( (void*) &(this->getAcceleration().z), sizeof(this->getAcceleration().z), network::DATA, 0x3);
    214159    }
    215160
Note: See TracChangeset for help on using the changeset viewer.