- Timestamp:
- Nov 24, 2008, 1:50:47 AM (16 years ago)
- Location:
- code/branches/objecthierarchy2/src/orxonox/objects/worldentities
- Files:
-
- 2 added
- 13 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/objecthierarchy2/src/orxonox/objects/worldentities/Backlight.cc
r2212 r2254 43 43 CreateFactory(Backlight); 44 44 45 Backlight::Backlight(BaseObject* creator) : Billboard(creator)45 Backlight::Backlight(BaseObject* creator) : FadingBillboard(creator) 46 46 { 47 47 RegisterObject(Backlight); … … 53 53 this->length_ = 1.0f; 54 54 this->lifetime_ = 0.001f; 55 this->turnofftime_ = 0.5f;56 this->bTurningOff_ = false;57 55 this->maxelements_ = 1; 58 56 … … 102 100 XMLPortParam(Backlight, "elements", setMaxElements, getMaxElements, xmlelement, mode).defaultValues(10); 103 101 XMLPortParam(Backlight, "lifetime", setLifetime, getLifetime, xmlelement, mode).defaultValues(1.0f); 104 XMLPortParam(Backlight, "turnofftime", setTurnOffTime, getTurnOffTime, xmlelement, mode).defaultValues(0.5f);105 102 XMLPortParam(Backlight, "trailmaterial", setTrailMaterial, getTrailMaterial, xmlelement, mode); 106 103 } … … 117 114 void Backlight::changedColour() 118 115 { 119 Billboard::changedColour();120 121 if (this->ribbonTrail_ && this-> isActive() && this->tickcount_ >= 2)122 this->ribbonTrail_->setInitialColour(0, this->get Colour());116 FadingBillboard::changedColour(); 117 118 if (this->ribbonTrail_ && this->tickcount_ >= 2) 119 this->ribbonTrail_->setInitialColour(0, this->getFadedColour()); 123 120 } 124 121 … … 165 162 } 166 163 167 void Backlight::changedActivity() 168 { 169 SUPER(Backlight, changedActivity); 164 void Backlight::startturnonoff() 165 { 166 FadingBillboard::startturnonoff(); 167 168 if (this->ribbonTrail_ && this->isActive() && this->isVisible()) 169 this->ribbonTrail_->setVisible(true); 170 } 171 172 void Backlight::stopturnonoff() 173 { 174 this->postprocessingtime_ = max(0.0f, this->lifetime_ - this->turnofftime_); 175 176 FadingBillboard::stopturnonoff(); 170 177 171 178 if (this->ribbonTrail_) 172 {173 if (this->isActive())174 this->ribbonTrail_->setInitialColour(0, this->getColour()); 175 else176 177 this->bTurningOff_ = true;178 this->turnofftimer_.setTimer(this->turnofftime_, false, this, createExecutor(createFunctor(&Backlight::stopturnoff))); 179 }180 }179 this->ribbonTrail_->setInitialColour(0, this->getFadedColour()); 180 } 181 182 void Backlight::poststopturnonoff() 183 { 184 FadingBillboard::poststopturnonoff(); 185 186 if (this->ribbonTrail_) 187 this->ribbonTrail_->setVisible(false); 181 188 } 182 189 … … 187 194 this->update_width(); 188 195 this->update_length(); 189 }190 191 void Backlight::stopturnoff()192 {193 this->bTurningOff_ = false;194 196 } 195 197 … … 212 214 } 213 215 214 if (this->bTurningOff_ && this->ribbonTrail_) 215 { 216 this->ribbonTrail_->setInitialColour(0, this->ribbonTrail_->getInitialColour(0) - this->getColour() / this->turnofftime_ * dt); 216 SUPER(Backlight, tick, dt); 217 218 if (this->ribbonTrail_ && this->changedirection_ != 0) 219 { 220 // we use alpha_blend, only adjust alpha 221 const ColourValue& colour = this->getColour(); 222 this->ribbonTrail_->setInitialColour(0, colour.r, colour.g, colour.b, this->getFadedColour().a); 217 223 } 218 224 } -
code/branches/objecthierarchy2/src/orxonox/objects/worldentities/Backlight.h
r2212 r2254 31 31 32 32 #include "OrxonoxPrereqs.h" 33 #include "Billboard.h" 34 #include "objects/Tickable.h" 35 #include "tools/Timer.h" 33 #include "FadingBillboard.h" 36 34 37 35 namespace orxonox 38 36 { 39 class _OrxonoxExport Backlight : public Billboard, public Tickable37 class _OrxonoxExport Backlight : public FadingBillboard 40 38 { 41 39 public: … … 47 45 48 46 virtual void tick(float dt); 49 virtual void changedActivity();50 47 virtual void changedVisibility(); 51 48 … … 59 56 inline float getLifetime() const 60 57 { return this->lifetime_; } 61 62 inline void setTurnOffTime(float turnofftime)63 { this->turnofftime_ = turnofftime; }64 inline float getTurnOffTime() const65 { return this->turnofftime_; }66 58 67 59 inline void setLength(float length) … … 83 75 84 76 private: 85 void stopturnoff(); 77 virtual void startturnonoff(); 78 virtual void stopturnonoff(); 79 virtual void poststopturnonoff(); 86 80 virtual void changedColour(); 87 81 void update_width(); … … 96 90 float length_; 97 91 float lifetime_; 98 float turnofftime_;99 bool bTurningOff_;100 92 size_t maxelements_; 101 93 std::string trailmaterial_; 102 94 char tickcount_; 103 Timer<Backlight> turnofftimer_;104 95 }; 105 96 } -
code/branches/objecthierarchy2/src/orxonox/objects/worldentities/Billboard.cc
r2212 r2254 94 94 if (!this->billboard_.getBillboardSet()) 95 95 { 96 /* 96 97 if (this->getScene() && this->getScene()->getSceneManager() && (this->material_ != "")) 97 98 { … … 101 102 this->billboard_.setVisible(this->isVisible()); 102 103 } 104 */ 103 105 } 104 106 else -
code/branches/objecthierarchy2/src/orxonox/objects/worldentities/Billboard.h
r2182 r2254 62 62 63 63 protected: 64 inline BillboardSet& getBillboardSet() 65 { return this->billboard_; } 66 64 67 virtual void changedColour(); 65 68 -
code/branches/objecthierarchy2/src/orxonox/objects/worldentities/CMakeLists.txt
r2182 r2254 8 8 Billboard.cc 9 9 BlinkingBillboard.cc 10 FadingBillboard.cc 10 11 Light.cc 11 12 Camera.cc -
code/branches/objecthierarchy2/src/orxonox/objects/worldentities/ControllableEntity.cc
r2171 r2254 48 48 RegisterObject(ControllableEntity); 49 49 50 this->bControlled_ = false; 50 this->bHasLocalController_ = false; 51 this->bHasHumanController_ = false; 52 51 53 this->server_overwrite_ = 0; 52 54 this->client_overwrite_ = 0; … … 74 76 if (this->isInitialized()) 75 77 { 76 if (this->b Controlled_)77 this->stopLocal Control();78 if (this->bHasLocalController_) 79 this->stopLocalHumanControl(); 78 80 79 81 if (this->hud_) … … 156 158 this->player_ = player; 157 159 this->playerID_ = player->getObjectID(); 158 this->bControlled_ = (player->isLocalPlayer() && player->isHumanPlayer()); 159 if (this->bControlled_) 160 { 161 this->startLocalControl(); 160 this->bHasLocalController_ = player->isLocalPlayer(); 161 this->bHasHumanController_ = player->isHumanPlayer(); 162 163 if (this->bHasLocalController_ && this->bHasHumanController_) 164 { 165 this->startLocalHumanControl(); 162 166 163 167 if (!Core::isMaster()) … … 172 176 void ControllableEntity::removePlayer() 173 177 { 174 if (this->b Controlled_)175 this->stopLocal Control();178 if (this->bHasLocalController_ && this->bHasHumanController_) 179 this->stopLocalHumanControl(); 176 180 177 181 this->player_ = 0; 178 182 this->playerID_ = OBJECTID_UNKNOWN; 179 this->bControlled_ = false; 183 this->bHasLocalController_ = false; 184 this->bHasHumanController_ = false; 180 185 this->setObjectMode(direction::toclient); 181 186 … … 195 200 } 196 201 197 void ControllableEntity::startLocal Control()202 void ControllableEntity::startLocalHumanControl() 198 203 { 199 204 // std::cout << this->getObjectID() << " ###### start local control" << std::endl; … … 214 219 } 215 220 216 void ControllableEntity::stopLocal Control()221 void ControllableEntity::stopLocalHumanControl() 217 222 { 218 223 // std::cout << "###### stop local control" << std::endl; … … 237 242 this->server_position_ = this->node_->getPosition(); 238 243 } 239 else if (this->b Controlled_)244 else if (this->bHasLocalController_) 240 245 { 241 246 // COUT(2) << "setting client position" << endl; … … 251 256 252 257 REGISTERDATA(this->client_overwrite_, direction::toserver); 253 258 254 259 REGISTERDATA(this->server_position_, direction::toclient, new NetworkCallback<ControllableEntity>(this, &ControllableEntity::processServerPosition)); 255 260 REGISTERDATA(this->server_velocity_, direction::toclient, new NetworkCallback<ControllableEntity>(this, &ControllableEntity::processServerVelocity)); … … 267 272 void ControllableEntity::processServerPosition() 268 273 { 269 if (!this->b Controlled_)274 if (!this->bHasLocalController_) 270 275 this->node_->setPosition(this->server_position_); 271 276 } … … 273 278 void ControllableEntity::processServerVelocity() 274 279 { 275 if (!this->b Controlled_)280 if (!this->bHasLocalController_) 276 281 this->velocity_ = this->server_velocity_; 277 282 } … … 279 284 void ControllableEntity::processServerOrientation() 280 285 { 281 if (!this->b Controlled_)286 if (!this->bHasLocalController_) 282 287 this->node_->setOrientation(this->server_orientation_); 283 288 } … … 285 290 void ControllableEntity::processOverwrite() 286 291 { 287 if (this->b Controlled_)292 if (this->bHasLocalController_) 288 293 { 289 294 this->setPosition(this->server_position_); … … 334 339 ++this->server_overwrite_; 335 340 } 336 else if (this->b Controlled_)341 else if (this->bHasLocalController_) 337 342 { 338 343 this->node_->setPosition(position); … … 349 354 ++this->server_overwrite_; 350 355 } 351 else if (this->b Controlled_)356 else if (this->bHasLocalController_) 352 357 { 353 358 this->velocity_ = velocity; … … 364 369 ++this->server_overwrite_; 365 370 } 366 else if (this->b Controlled_)371 else if (this->bHasLocalController_) 367 372 { 368 373 this->node_->translate(distance, relativeTo); … … 379 384 ++this->server_overwrite_; 380 385 } 381 else if (this->b Controlled_)386 else if (this->bHasLocalController_) 382 387 { 383 388 this->node_->setOrientation(orientation); … … 394 399 ++this->server_overwrite_; 395 400 } 396 else if (this->b Controlled_)401 else if (this->bHasLocalController_) 397 402 { 398 403 this->node_->rotate(rotation, relativeTo); … … 409 414 ++this->server_overwrite_; 410 415 } 411 else if (this->b Controlled_)416 else if (this->bHasLocalController_) 412 417 { 413 418 this->node_->yaw(angle, relativeTo); … … 424 429 ++this->server_overwrite_; 425 430 } 426 else if (this->b Controlled_)431 else if (this->bHasLocalController_) 427 432 { 428 433 this->node_->pitch(angle, relativeTo); … … 439 444 ++this->server_overwrite_; 440 445 } 441 else if (this->b Controlled_)446 else if (this->bHasLocalController_) 442 447 { 443 448 this->node_->roll(angle, relativeTo); … … 454 459 ++this->server_overwrite_; 455 460 } 456 else if (this->b Controlled_)461 else if (this->bHasLocalController_) 457 462 { 458 463 this->node_->lookAt(target, relativeTo, localDirectionVector); … … 469 474 ++this->server_overwrite_; 470 475 } 471 else if (this->b Controlled_)476 else if (this->bHasLocalController_) 472 477 { 473 478 this->node_->setDirection(direction, relativeTo, localDirectionVector); -
code/branches/objecthierarchy2/src/orxonox/objects/worldentities/ControllableEntity.h
r2087 r2254 68 68 virtual void altFire() {} 69 69 70 virtual void boost() {} 70 71 virtual void greet() {} 71 72 virtual void use() {} … … 123 124 { return this->cameraPositionTemplate_; } 124 125 126 inline bool hasLocalController() const 127 { return this->bHasLocalController_; } 128 inline bool hasHumanController() const 129 { return this->bHasHumanController_; } 130 125 131 protected: 126 virtual void startLocal Control();127 virtual void stopLocal Control();132 virtual void startLocalHumanControl(); 133 virtual void stopLocalHumanControl(); 128 134 129 135 inline void setHudTemplate(const std::string& name) 130 136 { this->hudtemplate_ = name; } 131 132 inline bool isLocallyControlled() const133 { return this->bControlled_; }134 137 135 138 Vector3 acceleration_; … … 154 157 Vector3 velocity_; 155 158 156 bool bControlled_; 159 bool bHasLocalController_; 160 bool bHasHumanController_; 161 157 162 Vector3 server_position_; 158 163 Vector3 client_position_; -
code/branches/objecthierarchy2/src/orxonox/objects/worldentities/Light.cc
r2171 r2254 163 163 void Light::changedType() 164 164 { 165 this->light_->setType(this->type_); 165 if (this->light_) 166 this->light_->setType(this->type_); 166 167 } 167 168 … … 170 171 SUPER(Light, changedVisibility); 171 172 172 this->light_->setVisible(this->isVisible()); 173 if (this->light_) 174 this->light_->setVisible(this->isVisible()); 173 175 } 174 176 } -
code/branches/objecthierarchy2/src/orxonox/objects/worldentities/WorldEntity.cc
r2213 r2254 76 76 delete (*it); 77 77 78 if (this->parent_) 79 this->detachFromParent(); 80 78 81 if (this->getScene()->getSceneManager()) 79 82 this->getScene()->getSceneManager()->destroySceneNode(this->node_->getName()); … … 100 103 void WorldEntity::registerVariables() 101 104 { 105 REGISTERSTRING(this->mainStateName_, direction::toclient, new NetworkCallback<WorldEntity>(this, &WorldEntity::changedMainState)); 106 102 107 REGISTERDATA(this->bActive_, direction::toclient, new NetworkCallback<WorldEntity>(this, &WorldEntity::changedActivity)); 103 108 REGISTERDATA(this->bVisible_, direction::toclient, new NetworkCallback<WorldEntity>(this, &WorldEntity::changedVisibility)); … … 122 127 void WorldEntity::attach(WorldEntity* object) 123 128 { 129 if (object == this) 130 { 131 COUT(2) << "Warning: Can't attach a WorldEntity to itself." << std::endl; 132 return; 133 } 134 124 135 if (object->getParent()) 125 136 object->detachFromParent(); -
code/branches/objecthierarchy2/src/orxonox/objects/worldentities/pawns/SpaceShip.cc
r2171 r2254 32 32 #include "core/CoreIncludes.h" 33 33 #include "core/ConfigValueIncludes.h" 34 #include "core/Template.h" 34 35 #include "core/XMLPort.h" 35 36 #include "util/Math.h" 37 #include "objects/items/Engine.h" 36 38 37 39 namespace orxonox … … 45 47 this->zeroDegree_ = 0; 46 48 47 this->maxSpeed_ = 0; 48 this->maxSecondarySpeed_ = 0; 49 this->bBoost_ = false; 50 this->steering_ = Vector3::ZERO; 51 this->engine_ = 0; 52 49 53 this->maxRotation_ = 0; 50 this->translationAcceleration_ = 0;51 54 this->rotationAcceleration_ = 0; 52 55 this->translationDamping_ = 0; … … 66 69 SpaceShip::~SpaceShip() 67 70 { 71 if (this->isInitialized() && this->engine_) 72 delete this->engine_; 68 73 } 69 74 … … 72 77 SUPER(SpaceShip, XMLPort, xmlelement, mode); 73 78 74 XMLPortParam(SpaceShip, "maxspeed", setMaxSpeed, getMaxSpeed, xmlelement, mode); 75 XMLPortParam(SpaceShip, "maxsecondaryspeed", setMaxSecondarySpeed, getMaxSecondarySpeed, xmlelement, mode); 79 XMLPortParam(SpaceShip, "engine", setEngineTemplate, getEngineTemplate, xmlelement, mode); 76 80 XMLPortParam(SpaceShip, "maxrotation", setMaxRotation, getMaxRotation, xmlelement, mode); 77 XMLPortParam(SpaceShip, "transacc", setTransAcc, getTransAcc, xmlelement, mode);78 81 XMLPortParam(SpaceShip, "rotacc", setRotAcc, getRotAcc, xmlelement, mode); 79 82 XMLPortParam(SpaceShip, "transdamp", setTransDamp, getTransDamp, xmlelement, mode); … … 82 85 void SpaceShip::registerVariables() 83 86 { 84 REGISTERDATA(this->maxSpeed_, direction::toclient);85 REGISTERDATA(this->maxSecondarySpeed_, direction::toclient);86 87 REGISTERDATA(this->maxRotation_, direction::toclient); 87 REGISTERDATA(this->translationAcceleration_, direction::toclient);88 88 REGISTERDATA(this->rotationAcceleration_, direction::toclient); 89 89 REGISTERDATA(this->translationDamping_, direction::toclient); … … 97 97 void SpaceShip::tick(float dt) 98 98 { 99 if (this-> isLocallyControlled())99 if (this->hasLocalController()) 100 100 { 101 101 // ##################################### … … 104 104 105 105 Vector3 velocity = this->getVelocity(); 106 if (velocity.x > this->maxSecondarySpeed_)107 velocity.x = this->maxSecondarySpeed_;108 if (velocity.x < -this->maxSecondarySpeed_)109 velocity.x = -this->maxSecondarySpeed_;110 if (velocity.y > this->maxSecondarySpeed_)111 velocity.y = this->maxSecondarySpeed_;112 if (velocity.y < -this->maxSecondarySpeed_)113 velocity.y = -this->maxSecondarySpeed_;114 if (velocity.z > this->maxSecondarySpeed_)115 velocity.z = this->maxSecondarySpeed_;116 if (velocity.z < -this->maxSpeed_)117 velocity.z = -this->maxSpeed_;118 106 119 107 // normalize velocity and acceleration … … 144 132 145 133 146 if (this-> isLocallyControlled())134 if (this->hasLocalController()) 147 135 { 148 136 this->yaw(this->yawRotation_ * dt); … … 153 141 this->roll(this->rollRotation_ * dt); 154 142 155 this->acceleration_.x = 0;156 this->acceleration_.y = 0;157 this->acceleration_.z = 0;158 159 143 this->yawRotation_ = this->zeroDegree_; 160 144 this->pitchRotation_ = this->zeroDegree_; … … 165 149 void SpaceShip::moveFrontBack(const Vector2& value) 166 150 { 167 this-> acceleration_.z = -this->translationAcceleration_ *value.x;151 this->steering_.z = -value.x; 168 152 } 169 153 170 154 void SpaceShip::moveRightLeft(const Vector2& value) 171 155 { 172 this-> acceleration_.x = this->translationAcceleration_ *value.x;156 this->steering_.x = value.x; 173 157 } 174 158 175 159 void SpaceShip::moveUpDown(const Vector2& value) 176 160 { 177 this-> acceleration_.y = this->translationAcceleration_ *value.x;161 this->steering_.y = value.x; 178 162 } 179 163 … … 211 195 { 212 196 } 197 198 void SpaceShip::boost() 199 { 200 this->bBoost_ = true; 201 } 202 203 void SpaceShip::loadEngineTemplate() 204 { 205 if (this->enginetemplate_ != "") 206 { 207 Template* temp = Template::getTemplate(this->enginetemplate_); 208 209 if (temp) 210 { 211 Identifier* identifier = temp->getBaseclassIdentifier(); 212 213 if (identifier) 214 { 215 BaseObject* object = identifier->fabricate(this); 216 this->engine_ = dynamic_cast<Engine*>(object); 217 218 if (this->engine_) 219 { 220 this->engine_->addTemplate(temp); 221 this->engine_->addToSpaceShip(this); 222 } 223 else 224 { 225 delete object; 226 } 227 } 228 } 229 } 230 } 213 231 } -
code/branches/objecthierarchy2/src/orxonox/objects/worldentities/pawns/SpaceShip.h
r2087 r2254 56 56 57 57 virtual void fire(); 58 virtual void boost(); 58 59 59 void setMaxSpeed(float value)60 { this->maxSpeed_ = value; }61 void setMaxSecondarySpeed(float value)62 { this->maxSecondarySpeed_ = value; }63 60 void setMaxRotation(const Degree& value) 64 61 { this->maxRotation_ = value; } 65 void setTransAcc(float value)66 { this->translationAcceleration_ = value; }67 62 void setRotAcc(const Degree& value) 68 63 { this->rotationAcceleration_ = value; } … … 70 65 { this->translationDamping_ = value; } 71 66 72 inline float getMaxSpeed() const73 { return this->maxSpeed_; }74 inline float getMaxSecondarySpeed() const75 { return this->maxSecondarySpeed_; }76 67 inline float getMaxRotation() const 77 68 { return this->maxRotation_.valueDegrees(); } 78 inline float getTransAcc() const79 { return this->translationAcceleration_; }80 69 inline float getRotAcc() const 81 70 { return this->rotationAcceleration_.valueDegrees(); } … … 83 72 { return this->translationDamping_; } 84 73 74 inline void setSteeringDirection(const Vector3& direction) 75 { this->steering_ = direction; } 76 inline const Vector3& getSteeringDirection() const 77 { return this->steering_; } 78 79 inline void setBoost(bool bBoost) 80 { this->bBoost_ = bBoost; } 81 inline bool getBoost() const 82 { return this->bBoost_; } 83 84 inline void setEngineTemplate(const std::string& temp) 85 { this->enginetemplate_ = temp; this->loadEngineTemplate(); } 86 inline const std::string& getEngineTemplate() const 87 { return this->enginetemplate_; } 88 85 89 protected: 86 90 bool bInvertYAxis_; 87 91 88 float maxSpeed_; 89 float maxSecondarySpeed_; 90 float translationAcceleration_; 92 bool bBoost_; 93 Vector3 steering_; 91 94 float translationDamping_; 92 95 … … 98 101 Degree yawRotation_; 99 102 Degree rollRotation_; 103 104 private: 105 void loadEngineTemplate(); 106 107 std::string enginetemplate_; 108 Engine* engine_; 100 109 }; 101 110 } -
code/branches/objecthierarchy2/src/orxonox/objects/worldentities/pawns/Spectator.cc
r2171 r2254 106 106 this->updateHUD(); 107 107 108 if (this-> isLocallyControlled())108 if (this->hasLocalController()) 109 109 { 110 110 Vector3 velocity = this->getVelocity(); … … 121 121 SUPER(Spectator, tick, dt); 122 122 123 if (this-> isLocallyControlled())123 if (this->hasLocalController()) 124 124 { 125 125 this->setVelocity(Vector3::ZERO); … … 134 134 } 135 135 136 void Spectator::startLocal Control()137 { 138 ControllableEntity::startLocal Control();139 // if (this-> isLocallyControlled())136 void Spectator::startLocalHumanControl() 137 { 138 ControllableEntity::startLocalHumanControl(); 139 // if (this->hasLocalController()) 140 140 // this->testmesh_->setVisible(false); 141 141 } -
code/branches/objecthierarchy2/src/orxonox/objects/worldentities/pawns/Spectator.h
r2087 r2254 46 46 47 47 virtual void setPlayer(PlayerInfo* player); 48 virtual void startLocal Control();48 virtual void startLocalHumanControl(); 49 49 50 50 virtual void moveFrontBack(const Vector2& value);
Note: See TracChangeset
for help on using the changeset viewer.