Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 1289


Ignore:
Timestamp:
May 15, 2008, 4:43:20 PM (17 years ago)
Author:
scheusso
Message:

merged camera change into merger branch

Location:
code/branches/merge/src/orxonox/objects
Files:
4 edited

Legend:

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

    r1264 r1289  
    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
    5151  Camera::Camera(Ogre::SceneNode* node)
    5252  {
    53     //RegisterObject(Camera);
    5453    this->bHasFocus_ = false;
     54    this->cameraNode_ = GraphicsEngine::getSingleton().getSceneManager()->getRootSceneNode()->createChildSceneNode(node->getName() + "Camera");
    5555    if( node != NULL )
    56       this->setCameraNode(node);
    57 
     56      this->setPositionNode(node);
    5857  }
    5958
    6059  Camera::~Camera()
    6160  {
     61    CameraHandler::getInstance()->releaseFocus(this);
    6262  }
    6363
    64   /*void Camera::loadParams(TiXmlElement* xmlElem)
    65   {
    66     Ogre::SceneManager* mgr = GraphicsEngine::getSingleton().getSceneManager();
    67 
    68     if (xmlElem->Attribute("name") && xmlElem->Attribute("pos") && xmlElem->Attribute("lookat") && xmlElem->Attribute("node"))
    69     {
    70       //    <Camera name="Camera" pos="0,0,-250" lookat="0,0,0" />
    71 
    72       std::string name = xmlElem->Attribute("name");
    73       std::string pos = xmlElem->Attribute("pos");
    74       std::string lookat = xmlElem->Attribute("lookat");
    75 
    76       this->cam_ = mgr->createCamera(name);
    77 
    78       float x, y, z;
    79       SubString posVec(xmlElem->Attribute("pos"), ',');
    80       convertValue<std::string, float>(&x, posVec[0]);
    81       convertValue<std::string, float>(&y, posVec[1]);
    82       convertValue<std::string, float>(&z, posVec[2]);
    83 
    84       setPosition(Vector3(x,y,z));
    85 
    86       //std::string target = xmlElem->Attribute("lookat");
    87       posVec.split(xmlElem->Attribute("lookat"), ',');
    88       convertValue<std::string, float>(&x, posVec[0]);
    89       convertValue<std::string, float>(&y, posVec[1]);
    90       convertValue<std::string, float>(&z, posVec[2]);
    91 
    92       cam_->lookAt(Vector3(x,y,z));
    93 
    94       /*std::string node = xmlElem->Attribute("node");
    95 
    96       Ogre::SceneNode* sceneNode = (Ogre::SceneNode*)mgr->getRootSceneNode()->createChildSceneNode(node); //getChild(node);
    97       sceneNode->attachObject((Ogre::MovableObject*)cam_);
    98       */
    99 
    100       // FIXME: unused var
    101       //Ogre::Viewport* vp =
    102       //GraphicsEngine::getSingleton().getRenderWindow()->addViewport(cam_);
    103     /*
    104 
    105       COUT(4) << "Loader: Created camera "<< name  << std::endl << std::endl;
    106     }
    107   }*/
    108 
    109   void Camera::setCameraNode(Ogre::SceneNode* node)
     64  void Camera::setPositionNode(Ogre::SceneNode* node)
    11065  {
    11166    this->positionNode_ = node;
     
    11873  }
    11974
     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
    12086  /**
    12187    don't move anything before here! here the Ogre camera is set to values of this camera
     
    12490  void Camera::update()
    12591  {
    126     COUT(0) << "p " << this->positionNode_->getPosition() << std::endl;
    127     COUT(0) << "t " << this->targetNode_->getPosition() << std::endl;
    12892    if(this->positionNode_ != NULL)
    129       this->cam_->setPosition(this->positionNode_->getPosition());
    130     if(this->targetNode_ != NULL)
    131       this->cam_->lookAt(this->targetNode_->getPosition());
     93    {
     94      this->cameraNode_->setPosition(this->positionNode_->getWorldPosition());
     95      this->cameraNode_->setOrientation(this->positionNode_->getWorldOrientation());
     96    }
    13297  }
    13398
     
    139104  {
    140105    this->bHasFocus_ = false;
    141     this->positionNode_->detachObject(cam_);
     106    this->cameraNode_->detachObject(this->cam_);
    142107  }
    143108
     
    146111    this->bHasFocus_ = true;
    147112    this->cam_ = ogreCam;
    148     this->positionNode_->attachObject(cam_);
     113    this->cam_->setOrientation(this->cameraNode_->getWorldOrientation());
     114    this->cameraNode_->attachObject(this->cam_);
    149115  }
    150116}
  • code/branches/merge/src/orxonox/objects/Camera.h

    r1264 r1289  
    2323 *      Fabian 'x3n' Landau
    2424 *   Co-authors:
    25  *      ...
     25 *      Benjamin Knecht
    2626 *
    2727 */
     
    4545        virtual ~Camera();
    4646
    47         //inline void setPosition(Ogre::Vector3 pos) { position_->setPosition(pos); cam_->setPosition(pos); }
    48         void setCameraNode(Ogre::SceneNode* node);
     47        void setPositionNode(Ogre::SceneNode* node);
    4948        inline Ogre::SceneNode* getCameraNode() { return this->positionNode_; }
    5049        // maybe also BaseObject
    5150        void setTargetNode(Ogre::SceneNode* obj);
    5251
    53 
     52        void tick(float dt);
    5453        void update();
    5554        inline bool hasFocus() { return this->bHasFocus_; }
     
    6261        Ogre::SceneNode* targetNode_;
    6362        Ogre::SceneNode* positionNode_;
     63        Ogre::SceneNode* cameraNode_;
     64        Ogre::Vector3 oldPos;
    6465        Ogre::Camera* cam_;
    6566        bool bHasFocus_;
  • code/branches/merge/src/orxonox/objects/CameraHandler.cc

    r1264 r1289  
    7373    focusList_.remove(cam);
    7474    // set new focus if necessary
    75     if(!(focusList_.back()->hasFocus()))
     75    if(focusList_.size() > 0 && !(focusList_.back()->hasFocus()))
    7676      focusList_.back()->setFocus(this->cam_);
    7777  }
  • code/branches/merge/src/orxonox/objects/SpaceShip.cc

    r1284 r1289  
    106106        this->setConfigValues();
    107107
     108
    108109        this->setRotationAxis(1, 0, 0);
    109110        this->setStatic(false);
     
    118119        if(setMouseEventCallback_)
    119120          InputManager::removeMouseHandler("SpaceShip");
     121        if (this->cam_)
     122          delete this->cam_;
    120123    }
    121124
     
    286289      this->camNode_ = this->getNode()->createChildSceneNode(camName_);
    287290      COUT(4) << "position: (this)" << this->getNode()->getPosition() << std::endl;
    288       this->camNode_->setPosition(/*this->getNode()->getPosition() +*/ Vector3(-50,0,10));
     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);
    289295      COUT(4) << "position: (cam)" << this->camNode_->getPosition() << std::endl;
    290 /*
    291 //        node->setInheritOrientation(false);
    292         cam->setPosition(Vector3(0,50,-150));
    293         cam->lookAt(Vector3(0,20,0));
    294         cam->roll(Degree(0));
    295       *//*COUT(4) << "creating new camera" << std::endl;*/
    296296      cam_ = new Camera(this->camNode_);
    297297
     
    436436    void SpaceShip::tick(float dt)
    437437    {
     438        if (this->cam_)
     439            this->cam_->tick(dt);
     440
    438441        if (this->redNode_ && this->greenNode_)
    439442        {
Note: See TracChangeset for help on using the changeset viewer.