Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Oct 27, 2008, 4:08:51 AM (16 years ago)
Author:
landauf
Message:

many changes, most important: BaseObject takes now a pointer to it's creator which is needed to build a level hierarchy (with different scenes)

File:
1 edited

Legend:

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

    r2006 r2019  
    3232
    3333#include <string>
     34#include <cassert>
    3435
    3536#include <OgreSceneManager.h>
     
    4142#include "util/SubString.h"
    4243#include "util/Math.h"
     44#include "util/String.h"
    4345#include "util/Debug.h"
    4446#include "core/CoreIncludes.h"
     47#include "core/ConfigValueIncludes.h"
    4548#include "GraphicsEngine.h"
     49#include "objects/Scene.h"
    4650
    4751namespace orxonox
    4852{
    49   CreateUnloadableFactory(Camera);
     53    CreateFactory(Camera);
    5054
    51   Camera::Camera()
    52   {
    53     RegisterObject(Camera);
     55    Camera::Camera(BaseObject* creator) : PositionableEntity(creator)
     56    {
     57        RegisterObject(Camera);
    5458
    55     this->bHasFocus_ = false;
    56     this->bDrag_ = false;
    57     this->cameraNode_ = GraphicsEngine::getInstance().getLevelSceneManager()->getRootSceneNode()->createChildSceneNode();
    58     this->setObjectMode(0x0);
    59   }
     59        assert(this->getScene());
     60        assert(this->getScene()->getSceneManager());
    6061
    61   Camera::~Camera()
    62   {
    63     if (this->isInitialized())
     62        this->camera_ = this->getScene()->getSceneManager()->createCamera(getUniqueNumberString());
     63        this->getNode()->attachObject(this->camera_);
     64
     65        this->bHasFocus_ = false;
     66        this->bDrag_ = false;
     67        this->nearClipDistance_ = 1;
     68
     69        this->setObjectMode(0x0);
     70
     71        this->setConfigValues();
     72        this->configvaluecallback_changedNearClipDistance();
     73
     74        this->requestFocus(); // ! HACK ! REMOVE THIS !
     75    }
     76
     77    Camera::~Camera()
    6478    {
    65       CameraHandler::getInstance()->releaseFocus(this);
    66       GraphicsEngine::getInstance().getLevelSceneManager()->getRootSceneNode()->removeAndDestroyChild(this->cameraNode_->getName());
     79        if (this->isInitialized())
     80        {
     81            this->releaseFocus();
     82        }
    6783    }
    68   }
    6984
    70   void Camera::tick(float dt)
    71   {
    72       // this stuff here may need some adjustments
    73       float coeff = (this->bDrag_) ? min(1.0f, 15.0f * dt) : (1.0f);
     85    void Camera::setConfigValues()
     86    {
     87        SetConfigValue(nearClipDistance_, 1.0f).callback(this, &Camera::configvaluecallback_changedNearClipDistance);
     88    }
    7489
    75       Vector3 offset = this->getNode()->getWorldPosition() - this->cameraNode_->getWorldPosition();
    76       this->cameraNode_->translate(coeff * offset);
     90    void Camera::configvaluecallback_changedNearClipDistance()
     91    {
     92        this->camera_->setNearClipDistance(this->nearClipDistance_);
     93    }
    7794
    78       this->cameraNode_->setOrientation(Quaternion::Slerp(coeff, this->cameraNode_->getWorldOrientation(), this->getWorldOrientation(), false));
    79   }
     95    void Camera::tick(float dt)
     96    {
     97/*
     98        // this stuff here may need some adjustments
     99        float coeff = (this->bDrag_) ? min(1.0f, 15.0f * dt) : (1.0f);
    80100
    81   /**
    82     don't move anything before here! here the Ogre camera is set to values of this camera
    83     always call update after changes
    84   */
    85   void Camera::update()
    86   {
    87       this->cameraNode_->setPosition(this->getWorldPosition());
    88       this->cameraNode_->setOrientation(this->getWorldOrientation());
    89   }
     101        Vector3 offset = this->getNode()->getWorldPosition() - this->cameraNode_->getWorldPosition();
     102        this->cameraNode_->translate(coeff * offset);
    90103
    91   /**
    92     what to do when camera loses focus (do not request focus in this function!!)
    93     this is called by the CameraHandler singleton class to notify the camera
    94   */
    95   void Camera::removeFocus()
    96   {
    97     this->bHasFocus_ = false;
    98     this->cameraNode_->detachObject(this->cam_);
    99   }
     104        this->cameraNode_->setOrientation(Quaternion::Slerp(coeff, this->cameraNode_->getWorldOrientation(), this->getWorldOrientation(), false));
     105*/
     106    }
    100107
    101   void Camera::setFocus(Ogre::Camera* ogreCam)
    102   {
    103     this->bHasFocus_ = true;
    104     this->cam_ = ogreCam;
    105     this->cam_->setOrientation(this->cameraNode_->getWorldOrientation());
    106     this->cameraNode_->attachObject(this->cam_);
    107   }
     108    void Camera::requestFocus()
     109    {
     110        CameraHandler::getInstance().requestFocus(this);
     111    }
    108112
    109   void Camera::requestFocus()
    110   {
    111     CameraHandler::getInstance()->requestFocus(this);
    112   }
     113    void Camera::releaseFocus()
     114    {
     115        CameraHandler::getInstance().releaseFocus(this);
     116    }
     117
     118    /**
     119        what to do when camera loses focus (do not request focus in this function!!)
     120        this is called by the CameraHandler singleton class to notify the camera
     121    */
     122    void Camera::removeFocus()
     123    {
     124        this->bHasFocus_ = false;
     125    }
     126
     127    void Camera::setFocus(Ogre::Viewport* viewport)
     128    {
     129        this->bHasFocus_ = true;
     130        viewport->setCamera(this->camera_);
     131    }
    113132}
Note: See TracChangeset for help on using the changeset viewer.