Changeset 1287 for code/branches/camera/src/orxonox/objects/Camera.cc
- Timestamp:
- May 15, 2008, 3:54:30 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/camera/src/orxonox/objects/Camera.cc
r1231 r1287 23 23 * Fabian 'x3n' Landau 24 24 * Co-authors: 25 * ...25 * Benjamin Knecht 26 26 * 27 27 */ … … 29 29 #include "OrxonoxStableHeaders.h" 30 30 #include "Camera.h" 31 #include "CameraHandler.h" 31 32 32 33 #include <string> … … 47 48 namespace orxonox 48 49 { 49 //CreateFactory(Camera);50 50 51 51 Camera::Camera(Ogre::SceneNode* node) 52 52 { 53 //RegisterObject(Camera);54 53 this->bHasFocus_ = false; 54 this->cameraNode_ = GraphicsEngine::getSingleton().getSceneManager()->getRootSceneNode()->createChildSceneNode(node->getName() + "Camera"); 55 55 if( node != NULL ) 56 this->setCameraNode(node); 57 56 this->setPositionNode(node); 58 57 } 59 58 60 59 Camera::~Camera() 61 60 { 61 CameraHandler::getInstance()->releaseFocus(this); 62 62 } 63 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")) 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) 110 65 { 111 66 this->positionNode_ = node; … … 118 73 } 119 74 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 120 86 /** 121 87 don't move anything before here! here the Ogre camera is set to values of this camera … … 124 90 void Camera::update() 125 91 { 126 COUT(0) << "p " << this->positionNode_->getPosition() << std::endl;127 COUT(0) << "t " << this->targetNode_->getPosition() << std::endl;128 92 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 } 132 97 } 133 98 … … 138 103 void Camera::removeFocus() 139 104 { 140 this->positionNode_->detachObject(cam_);141 105 this->bHasFocus_ = false; 106 this->cameraNode_->detachObject(this->cam_); 142 107 } 143 108 … … 146 111 this->bHasFocus_ = true; 147 112 this->cam_ = ogreCam; 148 this->positionNode_->attachObject(cam_); 113 this->cam_->setOrientation(this->cameraNode_->getWorldOrientation()); 114 this->cameraNode_->attachObject(this->cam_); 149 115 } 150 116 }
Note: See TracChangeset
for help on using the changeset viewer.