Changeset 2042 for code/branches/objecthierarchy/src/orxonox/objects/worldentities/ControllableEntity.cc
- Timestamp:
- Oct 29, 2008, 3:26:55 AM (16 years ago)
- File:
-
- 1 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));
Note: See TracChangeset
for help on using the changeset viewer.