- Timestamp:
- Oct 27, 2008, 4:08:51 AM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/objecthierarchy/src/orxonox/objects/Camera.cc
r2006 r2019 32 32 33 33 #include <string> 34 #include <cassert> 34 35 35 36 #include <OgreSceneManager.h> … … 41 42 #include "util/SubString.h" 42 43 #include "util/Math.h" 44 #include "util/String.h" 43 45 #include "util/Debug.h" 44 46 #include "core/CoreIncludes.h" 47 #include "core/ConfigValueIncludes.h" 45 48 #include "GraphicsEngine.h" 49 #include "objects/Scene.h" 46 50 47 51 namespace orxonox 48 52 { 49 CreateUnloadableFactory(Camera);53 CreateFactory(Camera); 50 54 51 Camera::Camera()52 {53 RegisterObject(Camera);55 Camera::Camera(BaseObject* creator) : PositionableEntity(creator) 56 { 57 RegisterObject(Camera); 54 58 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()); 60 61 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() 64 78 { 65 CameraHandler::getInstance()->releaseFocus(this); 66 GraphicsEngine::getInstance().getLevelSceneManager()->getRootSceneNode()->removeAndDestroyChild(this->cameraNode_->getName()); 79 if (this->isInitialized()) 80 { 81 this->releaseFocus(); 82 } 67 83 } 68 }69 84 70 void Camera::tick(float dt)71 {72 // this stuff here may need some adjustments73 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 } 74 89 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 } 77 94 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); 80 100 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); 90 103 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 } 100 107 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 } 108 112 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 } 113 132 }
Note: See TracChangeset
for help on using the changeset viewer.