Changeset 1289 for code/branches/merge/src/orxonox/objects
- Timestamp:
- May 15, 2008, 4:43:20 PM (17 years ago)
- Location:
- code/branches/merge/src/orxonox/objects
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/merge/src/orxonox/objects/Camera.cc
r1264 r1289 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 … … 139 104 { 140 105 this->bHasFocus_ = false; 141 this-> positionNode_->detachObject(cam_);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 } -
code/branches/merge/src/orxonox/objects/Camera.h
r1264 r1289 23 23 * Fabian 'x3n' Landau 24 24 * Co-authors: 25 * ...25 * Benjamin Knecht 26 26 * 27 27 */ … … 45 45 virtual ~Camera(); 46 46 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); 49 48 inline Ogre::SceneNode* getCameraNode() { return this->positionNode_; } 50 49 // maybe also BaseObject 51 50 void setTargetNode(Ogre::SceneNode* obj); 52 51 53 52 void tick(float dt); 54 53 void update(); 55 54 inline bool hasFocus() { return this->bHasFocus_; } … … 62 61 Ogre::SceneNode* targetNode_; 63 62 Ogre::SceneNode* positionNode_; 63 Ogre::SceneNode* cameraNode_; 64 Ogre::Vector3 oldPos; 64 65 Ogre::Camera* cam_; 65 66 bool bHasFocus_; -
code/branches/merge/src/orxonox/objects/CameraHandler.cc
r1264 r1289 73 73 focusList_.remove(cam); 74 74 // set new focus if necessary 75 if( !(focusList_.back()->hasFocus()))75 if(focusList_.size() > 0 && !(focusList_.back()->hasFocus())) 76 76 focusList_.back()->setFocus(this->cam_); 77 77 } -
code/branches/merge/src/orxonox/objects/SpaceShip.cc
r1284 r1289 106 106 this->setConfigValues(); 107 107 108 108 109 this->setRotationAxis(1, 0, 0); 109 110 this->setStatic(false); … … 118 119 if(setMouseEventCallback_) 119 120 InputManager::removeMouseHandler("SpaceShip"); 121 if (this->cam_) 122 delete this->cam_; 120 123 } 121 124 … … 286 289 this->camNode_ = this->getNode()->createChildSceneNode(camName_); 287 290 COUT(4) << "position: (this)" << this->getNode()->getPosition() << std::endl; 288 this->camNode_->setPosition(/*this->getNode()->getPosition() +*/ Vector3(-50,0,10)); 291 this->camNode_->setPosition(Vector3(-50,0,10)); 292 Quaternion q1 = Quaternion(Radian(Degree(90)),Vector3(0,-1,0)); 293 Quaternion q2 = Quaternion(Radian(Degree(90)),Vector3(0,0,-1)); 294 camNode_->setOrientation(q1*q2); 289 295 COUT(4) << "position: (cam)" << this->camNode_->getPosition() << std::endl; 290 /*291 // node->setInheritOrientation(false);292 cam->setPosition(Vector3(0,50,-150));293 cam->lookAt(Vector3(0,20,0));294 cam->roll(Degree(0));295 *//*COUT(4) << "creating new camera" << std::endl;*/296 296 cam_ = new Camera(this->camNode_); 297 297 … … 436 436 void SpaceShip::tick(float dt) 437 437 { 438 if (this->cam_) 439 this->cam_->tick(dt); 440 438 441 if (this->redNode_ && this->greenNode_) 439 442 {
Note: See TracChangeset
for help on using the changeset viewer.