- Timestamp:
- Oct 29, 2008, 3:26:55 AM (16 years ago)
- Location:
- code/branches/objecthierarchy/src/orxonox/objects/worldentities
- Files:
-
- 2 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/objecthierarchy/src/orxonox/objects/worldentities/ControllableEntity.cc
r2041 r2042 37 37 #include "objects/infos/PlayerInfo.h" 38 38 #include "objects/worldentities/Camera.h" 39 #include "objects/worldentities/CameraPosition.h" 39 40 #include "overlays/OverlayGroup.h" 40 41 … … 92 93 93 94 XMLPortParam(ControllableEntity, "hudtemplate", setHudTemplate, getHudTemplate, xmlelement, mode); 95 XMLPortParam(ControllableEntity, "camerapositiontemplate", setCameraPositionTemplate, getCameraPositionTemkplate, xmlelement, mode); 96 97 XMLPortObject(ControllableEntity, WorldEntity, "camerapositions", addCameraPosition, getCameraPosition, xmlelement, mode); 98 } 99 100 void ControllableEntity::addCameraPosition(CameraPosition* position) 101 { 102 this->attach(position); 103 this->cameraPositions_.push_back(position); 104 } 105 106 CameraPosition* ControllableEntity::getCameraPosition(unsigned int index) const 107 { 108 unsigned int i = 0; 109 for (std::list<CameraPosition*>::const_iterator it = this->cameraPositions_.begin(); it != this->cameraPositions_.end(); ++it) 110 { 111 if (i == index) 112 return (*it); 113 ++i; 114 } 115 return 0; 116 } 117 118 void ControllableEntity::switchCamera() 119 { 120 if (this->camera_) 121 { 122 if (this->camera_->getParent() == this && this->cameraPositions_.size() > 0) 123 { 124 this->cameraPositions_.front()->attachCamera(this->camera_); 125 } 126 else if (this->cameraPositions_.size() > 0) 127 { 128 for (std::list<CameraPosition*>::const_iterator it = this->cameraPositions_.begin(); it != this->cameraPositions_.end(); ++it) 129 { 130 if ((*it) == this->camera_->getParent()) 131 { 132 ++it; 133 if (it != this->cameraPositions_.end()) 134 (*it)->attachCamera(this->camera_); 135 else 136 (*this->cameraPositions_.begin())->attachCamera(this->camera_); 137 break; 138 } 139 } 140 } 141 else 142 { 143 this->attach(this->camera_); 144 } 145 } 94 146 } 95 147 … … 105 157 this->playerID_ = player->getObjectID(); 106 158 this->bControlled_ = (player->isLocalPlayer() && player->isHumanPlayer()); 107 108 159 if (this->bControlled_) 109 160 { … … 111 162 112 163 if (!Core::isMaster()) 164 { 165 COUT(0) << "CE: bidirectional synchronization" << std::endl; 113 166 this->setObjectMode(network::direction::bidirectional); 167 } 114 168 } 115 169 } … … 145 199 this->camera_ = new Camera(this); 146 200 this->camera_->requestFocus(); 147 this->attach(this->camera_); 201 if (this->cameraPositionTemplate_ != "") 202 this->addTemplate(this->cameraPositionTemplate_); 203 if (this->cameraPositions_.size() > 0) 204 this->cameraPositions_.front()->attachCamera(this->camera_); 205 else 206 this->attach(this->camera_); 148 207 149 208 if (this->hudtemplate_ != "") … … 157 216 { 158 217 std::cout << "###### stop local control" << std::endl; 159 this-> detach(this->camera_);218 this->camera_->detachFromParent(); 160 219 delete this->camera_; 161 220 this->camera_ = 0; … … 187 246 void ControllableEntity::registerVariables() 188 247 { 248 REGISTERSTRING(this->cameraPositionTemplate_, network::direction::toclient); 249 189 250 REGISTERDATA(this->server_position_, network::direction::toclient, new network::NetworkCallback<ControllableEntity>(this, &ControllableEntity::processServerPosition)); 190 251 REGISTERDATA(this->server_velocity_, network::direction::toclient, new network::NetworkCallback<ControllableEntity>(this, &ControllableEntity::processServerVelocity)); -
code/branches/objecthierarchy/src/orxonox/objects/worldentities/ControllableEntity.h
r2040 r2042 70 70 virtual void greet() {} 71 71 virtual void use() {} 72 virtual void switchCamera() {}72 virtual void switchCamera(); 73 73 74 74 inline const Vector3& getVelocity() const … … 112 112 inline OverlayGroup* getHUD() const 113 113 { return this->hud_; } 114 115 void addCameraPosition(CameraPosition* position); 116 CameraPosition* getCameraPosition(unsigned int index) const; 117 inline const std::list<CameraPosition*>& getCameraPositions() const 118 { return this->cameraPositions_; } 119 120 inline void setCameraPositionTemplate(const std::string& name) 121 { this->cameraPositionTemplate_ = name; } 122 inline const std::string& getCameraPositionTemkplate() const 123 { return this->cameraPositionTemplate_; } 114 124 115 125 protected: … … 158 168 Camera* camera_; 159 169 bool bDestroyWhenPlayerLeft_; 170 171 std::list<CameraPosition*> cameraPositions_; 172 std::string cameraPositionTemplate_; 160 173 }; 161 174 } -
code/branches/objecthierarchy/src/orxonox/objects/worldentities/WorldEntity.cc
r2040 r2042 136 136 object->parentID_ = (unsigned int)-1; 137 137 138 this->getScene()->getRootSceneNode()->addChild(object->node_);138 // this->getScene()->getRootSceneNode()->addChild(object->node_); 139 139 } 140 140
Note: See TracChangeset
for help on using the changeset viewer.