Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 1212


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

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

Location:
code/branches/network3
Files:
6 edited
2 copied

Legend:

Unmodified
Added
Removed
  • code/branches/network3/bin/levels/sample.oxw

    r1190 r1212  
    1111<!--Ambient colourvalue="1,1,1" /-->
    1212<Skybox src="Orxonox/StarSkyBox" />
    13 
    1413<SpaceShip camera="true" position="0,0,0" scale="10" yawpitchroll="-90,-90,0" mesh="assf3.mesh" maxSpeed="500" maxSideAndBackSpeed="50" maxRotation="1.0" transAcc="200" rotAcc="3.0" transDamp="75" rotDamp="1.0" />
    1514
  • code/branches/network3/src/orxonox/CMakeLists.txt

    r1153 r1212  
    1212  objects/Ambient.cc
    1313  objects/Camera.cc
     14  objects/CameraHandler.cc
    1415  objects/Explosion.cc
    1516#  objects/Fighter.cc
  • 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}
  • code/branches/network3/src/orxonox/objects/Camera.h

    r1056 r1212  
    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();
     46
     47        //inline void setPosition(Ogre::Vector3 pos) { position_->setPosition(pos); cam_->setPosition(pos); }
     48        void setCameraNode(Ogre::SceneNode* node);
     49        inline Ogre::SceneNode* getCameraNode() { return this->positionNode_; }
     50        // maybe also BaseObject
     51        void setTargetNode(Ogre::SceneNode* obj);
    4352
    4453
    45             void loadParams(TiXmlElement* xmlElem);
     54        void update();
     55        inline bool hasFocus() { return this->bHasFocus_; }
    4656
    47         private:
     57      private:
     58        void removeFocus();
     59        void setFocus(Ogre::Camera* ogreCam);
    4860
    49 
     61      private:
     62        Ogre::SceneNode* targetNode_;
     63        Ogre::SceneNode* positionNode_;
     64        Ogre::Camera* cam_;
     65        bool bHasFocus_;
    5066    };
    5167}
  • code/branches/network3/src/orxonox/objects/SpaceShip.cc

    r1184 r1212  
    2323 *      Fabian 'x3n' Landau
    2424 *   Co-authors:
    25  *      ...
     25 *      Benjamin Knecht
    2626 *
    2727 */
     
    3838#include <OgreSceneNode.h>
    3939
     40#include "CameraHandler.h"
    4041#include "util/tinyxml/tinyxml.h"
    4142#include "util/Convert.h"
     
    287288   
    288289    void SpaceShip::createCamera(){
    289       Ogre::Camera *cam = GraphicsEngine::getSingleton().getSceneManager()->createCamera("ShipCam");
    290290      this->camNode_ = this->getNode()->createChildSceneNode("CamNode");
     291      camNode_->setPosition(this->getNode()->getPosition() + Vector3(-50,0,10));
    291292/*
    292293//        node->setInheritOrientation(false);
     
    295296      cam->roll(Degree(0));
    296297*/
    297 
    298       cam->setPosition(Vector3(-200,0,35));
     298      cam_ = new Camera(this->camNode_);
     299      cam_->setTargetNode(this->getNode());
     300      CameraHandler::getInstance()->requestFocus(cam_);
    299301//        cam->setPosition(Vector3(0,-350,0));
    300       cam->lookAt(Vector3(0,0,35));
    301       cam->roll(Degree(-90));
    302 
    303       this->camNode_->attachObject(cam);
    304       GraphicsEngine::getSingleton().getRenderWindow()->addViewport(cam);
     302      //cam->roll(Degree(-90));
     303
     304      //this->camNode_->attachObject(cam);
    305305     
    306306    }
  • code/branches/network3/src/orxonox/objects/SpaceShip.h

    r1184 r1212  
    2323 *      Fabian 'x3n' Landau
    2424 *   Co-authors:
    25  *      ...
     25 *      Benjamin Knecht
    2626 *
    2727 */
     
    3535#include <OIS/OISMouse.h>
    3636
     37#include "Camera.h"
    3738#include "Model.h"
    3839#include "../tools/BillboardSet.h"
     40
    3941
    4042namespace orxonox
     
    8183
    8284            Ogre::SceneNode* camNode_;
     85            Camera* cam_;
    8386
    8487            ParticleInterface* tt_;
Note: See TracChangeset for help on using the changeset viewer.