Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
May 1, 2008, 6:09:54 PM (17 years ago)
Author:
scheusso
Message:

merged camera branch changes from 1101 to 1202 into network branch (we have now a camera manager)

File:
1 edited

Legend:

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

    r1067 r1212  
    4747namespace orxonox
    4848{
    49     CreateFactory(Camera);
     49  //CreateFactory(Camera);
    5050
    51     Camera::Camera()
     51  Camera::Camera(Ogre::SceneNode* node)
     52  {
     53    //RegisterObject(Camera);
     54    this->bHasFocus_ = false;
     55    if( node != NULL )
     56      this->setCameraNode(node);
     57
     58  }
     59
     60  Camera::~Camera()
     61  {
     62  }
     63
     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"))
    5269    {
    53         RegisterObject(Camera);
     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;
    54106    }
     107  }*/
    55108
    56     Camera::~Camera()
    57     {
    58     }
     109  void Camera::setCameraNode(Ogre::SceneNode* node)
     110  {
     111    this->positionNode_ = node;
     112    // set camera to node values according to camera mode
     113  }
    59114
    60     void Camera::loadParams(TiXmlElement* xmlElem)
    61     {
    62       Ogre::SceneManager* mgr = GraphicsEngine::getSingleton().getSceneManager();
     115  void Camera::setTargetNode(Ogre::SceneNode* obj)
     116  {
     117    this->targetNode_ = obj;
     118  }
    63119
    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" />
     120  /**
     121    don't move anything before here! here the Ogre camera is set to values of this camera
     122    always call update after changes
     123  */
     124  void Camera::update()
     125  {
     126    COUT(0) << "p " << this->positionNode_->getPosition() << std::endl;
     127    COUT(0) << "t " << this->targetNode_->getPosition() << std::endl;
     128    if(this->positionNode_ != NULL)
     129      //this->cam_->setPosition(this->positionNode_->getPosition());
     130    if(this->targetNode_ != NULL)
     131      this->cam_->lookAt(this->targetNode_->getPosition());
     132  }
    67133
    68         std::string name = xmlElem->Attribute("name");
    69         std::string pos = xmlElem->Attribute("pos");
    70         std::string lookat = xmlElem->Attribute("lookat");
     134  /**
     135    what to do when camera loses focus (do not request focus in this function!!)
     136    this is called by the CameraHandler singleton class to notify the camera
     137  */
     138  void Camera::removeFocus()
     139  {
     140    this->bHasFocus_ = false;
     141  }
    71142
    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    }
     143  void Camera::setFocus(Ogre::Camera* ogreCam)
     144  {
     145    this->bHasFocus_ = true;
     146    this->cam_ = ogreCam;
     147    this->positionNode_->attachObject(cam_);
     148  }
    102149}
Note: See TracChangeset for help on using the changeset viewer.