Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 1287


Ignore:
Timestamp:
May 15, 2008, 3:54:30 PM (16 years ago)
Author:
bknecht
Message:

camera stuff works now, but maybe need some adjustments, please test this while playing

Location:
code/branches/camera
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • code/branches/camera/bin/ogre.cfg-init

    r790 r1287  
    44FSAA=0
    55Full Screen=No
    6 RTT Preferred Mode=PBuffer
     6RTT Preferred Mode=FBO
    77Video Mode=1024 x 768
  • code/branches/camera/src/orxonox/objects/Camera.cc

    r1231 r1287  
    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
     
    138103  void Camera::removeFocus()
    139104  {
    140     this->positionNode_->detachObject(cam_);
    141105    this->bHasFocus_ = false;
     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/camera/src/orxonox/objects/Camera.h

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

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

    r1235 r1287  
    7979
    8080        this->camNode_ = 0;
     81        this->cam_ = NULL;
    8182
    8283        this->tt_ = 0;
     
    148149        if (this->tt_)
    149150            delete this->tt_;
     151        if (this->cam_)
     152          delete this->cam_;
    150153    }
    151154
     
    284287    {
    285288        this->camNode_ = this->getNode()->createChildSceneNode("CamNode");
    286         camNode_->setPosition(Vector3(-50,0,10));
     289        camNode_->setPosition(Vector3(-30,0,10));
     290        Quaternion q1 = Quaternion(Radian(Degree(90)),Vector3(0,-1,0));
     291        Quaternion q2 = Quaternion(Radian(Degree(90)),Vector3(0,0,-1));
     292        camNode_->setOrientation(q1*q2);
     293        //this->camNode_->showBoundingBox(true);
     294
    287295/*
    288296//        node->setInheritOrientation(false);
     
    292300*/
    293301        cam_ = new Camera(this->camNode_);
    294         cam_->setTargetNode(this->getNode());
     302        cam_->setTargetNode(this->chFarNode_);
    295303        CameraHandler::getInstance()->requestFocus(cam_);
    296304//        cam->setPosition(Vector3(0,-350,0));
     
    427435
    428436    void SpaceShip::tick(float dt)
    429     {
     437    {/*
     438      if (this->cam_)
     439        this->cam_->update();
     440      */
     441      if (this->cam_)
     442        this->cam_->tick(dt);
     443
    430444      if (InputManager::getSingleton().getMouse()->getEventCallback() != this)
    431445        {
Note: See TracChangeset for help on using the changeset viewer.