Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 1201


Ignore:
Timestamp:
Apr 29, 2008, 5:15:44 PM (17 years ago)
Author:
bknecht
Message:

CameraHandler and Camera work now

Location:
code/branches
Files:
1 deleted
7 edited

Legend:

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

    r1102 r1201  
    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/camera/src/core/Script.h

    r1102 r1201  
    5757    public:
    5858      inline static Script* getInstance() { if (!Script::singletonRef) Script::singletonRef = new Script(); return Script::singletonRef; } // tolua_export
    59       inline ~Script() { Script::singletonRef = NULL; };
     59      inline ~Script() { Script::singletonRef = NULL; }
    6060
    6161    void loadFile(std::string filename, bool luaTags);
  • code/branches/camera/src/orxonox/CMakeLists.txt

    r1070 r1201  
    1212  objects/Ambient.cc
    1313  objects/Camera.cc
     14  objects/CameraHandler.cc
    1415  objects/Explosion.cc
    1516#  objects/Fighter.cc
  • code/branches/camera/src/orxonox/objects/Camera.cc

    r1067 r1201  
    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/camera/src/orxonox/objects/Camera.h

    r1056 r1201  
    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/camera/src/orxonox/objects/SpaceShip.cc

    r1064 r1201  
    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"
     
    282283    void SpaceShip::setCamera(const std::string& camera)
    283284    {
    284         Ogre::Camera *cam = GraphicsEngine::getSingleton().getSceneManager()->createCamera("ShipCam");
    285285        this->camNode_ = this->getNode()->createChildSceneNode("CamNode");
     286        camNode_->setPosition(this->getNode()->getPosition() + Vector3(-50,0,10));
    286287/*
    287288//        node->setInheritOrientation(false);
     
    290291        cam->roll(Degree(0));
    291292*/
    292 
    293         cam->setPosition(Vector3(-200,0,35));
     293        cam_ = new Camera(this->camNode_);
     294        cam_->setTargetNode(this->getNode());
     295        CameraHandler::getInstance()->requestFocus(cam_);
    294296//        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);
     297        //cam->roll(Degree(-90));
     298
     299        //this->camNode_->attachObject(cam);
    300300    }
    301301
  • code/branches/camera/src/orxonox/objects/SpaceShip.h

    r1056 r1201  
    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
     
    8082
    8183            Ogre::SceneNode* camNode_;
     84            Camera* cam_;
    8285
    8386            ParticleInterface* tt_;
Note: See TracChangeset for help on using the changeset viewer.