- Timestamp:
- Feb 14, 2009, 10:17:35 PM (16 years ago)
- Location:
- code/trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk
- Property svn:mergeinfo changed
-
code/trunk/src/orxonox/objects/worldentities/pawns/Spectator.cc
r2171 r2662 30 30 #include "Spectator.h" 31 31 32 #include <OgreBillboardSet.h> 33 32 34 #include "core/CoreIncludes.h" 35 #include "core/ConfigValueIncludes.h" 33 36 #include "core/Core.h" 34 37 #include "objects/worldentities/Model.h" … … 49 52 RegisterObject(Spectator); 50 53 51 this->speed_ = 100; 52 this->rotationSpeed_ = 3; 54 this->speed_ = 200; 53 55 54 56 this->yaw_ = 0; 55 57 this->pitch_ = 0; 56 58 this->roll_ = 0; 59 this->localVelocity_ = Vector3::ZERO; 57 60 this->setHudTemplate("spectatorhud"); 58 this-> hudmode_ = 0;61 this->greetingFlare_ = 0; 59 62 60 63 this->setDestroyWhenPlayerLeft(true); 61 64 62 this->greetingFlare_ = new BillboardSet(); 63 this->greetingFlare_->setBillboardSet(this->getScene()->getSceneManager(), "Examples/Flare", ColourValue(1.0, 1.0, 0.8), Vector3(0, 20, 0), 1); 64 if (this->greetingFlare_->getBillboardSet()) 65 this->getNode()->attachObject(this->greetingFlare_->getBillboardSet()); 66 this->greetingFlare_->setVisible(false); 65 if (Core::showsGraphics()) 66 { 67 this->greetingFlare_ = new BillboardSet(); 68 this->greetingFlare_->setBillboardSet(this->getScene()->getSceneManager(), "Examples/Flare", ColourValue(1.0, 1.0, 0.8), Vector3(0, 20, 0), 1); 69 if (this->greetingFlare_->getBillboardSet()) 70 this->attachOgreObject(this->greetingFlare_->getBillboardSet()); 71 this->greetingFlare_->setVisible(false); 72 } 73 67 74 this->bGreetingFlareVisible_ = false; 68 75 this->bGreeting_ = false; 69 76 77 this->setConfigValues(); 70 78 this->registerVariables(); 71 79 } … … 78 86 { 79 87 if (this->greetingFlare_->getBillboardSet()) 80 this->getNode()->detachObject(this->greetingFlare_->getBillboardSet()); 88 this->detachOgreObject(this->greetingFlare_->getBillboardSet()); 89 81 90 delete this->greetingFlare_; 82 91 } … … 84 93 } 85 94 95 void Spectator::setConfigValues() 96 { 97 SetConfigValue(speed_, 200.0f); 98 } 99 86 100 void Spectator::registerVariables() 87 101 { 88 REGISTERDATA(this->bGreetingFlareVisible_, direction::toclient, new NetworkCallback<Spectator>(this, &Spectator::changedFlareVisibility)); 89 REGISTERDATA(this->bGreeting_, direction::toserver, new NetworkCallback<Spectator>(this, &Spectator::changedGreeting)); 90 REGISTERDATA(this->hudmode_, direction::toclient); 102 registerVariable(this->bGreetingFlareVisible_, variableDirection::toclient, new NetworkCallback<Spectator>(this, &Spectator::changedFlareVisibility)); 103 registerVariable(this->bGreeting_, variableDirection::toserver, new NetworkCallback<Spectator>(this, &Spectator::changedGreeting)); 91 104 } 92 105 … … 99 112 void Spectator::changedFlareVisibility() 100 113 { 101 this->greetingFlare_->setVisible(this->bGreetingFlareVisible_); 114 if ( this->greetingFlare_ ) 115 this->greetingFlare_->setVisible(this->bGreetingFlareVisible_); 102 116 } 103 117 104 118 void Spectator::tick(float dt) 105 119 { 106 this->updateHUD(); 107 108 if (this->isLocallyControlled()) 109 { 110 Vector3 velocity = this->getVelocity(); 111 velocity.normalise(); 112 this->setVelocity(velocity * this->speed_); 113 114 this->yaw(Radian(this->yaw_ * this->rotationSpeed_)); 115 this->pitch(Radian(this->pitch_ * this->rotationSpeed_)); 116 this->roll(Radian(this->roll_ * this->rotationSpeed_)); 120 if (this->hasLocalController()) 121 { 122 float localSpeedSquared = this->localVelocity_.squaredLength(); 123 float localSpeed; 124 if (localSpeedSquared > 1.0) 125 localSpeed = this->speed_ / sqrtf(localSpeedSquared); 126 else 127 localSpeed = this->speed_; 128 129 this->localVelocity_.x *= localSpeed; 130 this->localVelocity_.y *= localSpeed; 131 this->localVelocity_.z *= localSpeed; 132 this->setVelocity(this->getOrientation() * this->localVelocity_); 133 this->localVelocity_.x = 0; 134 this->localVelocity_.y = 0; 135 this->localVelocity_.z = 0; 136 137 if (!this->isInMouseLook()) 138 { 139 this->yaw(Radian(this->yaw_ * this->getMouseLookSpeed())); 140 this->pitch(Radian(this->pitch_ * this->getMouseLookSpeed())); 141 this->roll(Radian(this->roll_ * this->getMouseLookSpeed())); 142 } 117 143 118 144 this->yaw_ = this->pitch_ = this->roll_ = 0; … … 120 146 121 147 SUPER(Spectator, tick, dt); 122 123 if (this->isLocallyControlled())124 {125 this->setVelocity(Vector3::ZERO);126 }127 148 } 128 149 … … 131 152 ControllableEntity::setPlayer(player); 132 153 133 // this->setObjectMode(direction::toclient); 134 } 135 136 void Spectator::startLocalControl() 137 { 138 ControllableEntity::startLocalControl(); 139 // if (this->isLocallyControlled()) 140 // this->testmesh_->setVisible(false); 154 // this->setObjectMode(objectDirection::toclient); 155 } 156 157 void Spectator::startLocalHumanControl() 158 { 159 ControllableEntity::startLocalHumanControl(); 141 160 } 142 161 143 162 void Spectator::moveFrontBack(const Vector2& value) 144 163 { 145 this-> setVelocity(this->getVelocity() + value.y * this->speed_ * WorldEntity::FRONT);164 this->localVelocity_.z -= value.x; 146 165 } 147 166 148 167 void Spectator::moveRightLeft(const Vector2& value) 149 168 { 150 this-> setVelocity(this->getVelocity() + value.y * this->speed_ * WorldEntity::RIGHT);169 this->localVelocity_.x += value.x; 151 170 } 152 171 153 172 void Spectator::moveUpDown(const Vector2& value) 154 173 { 155 this-> setVelocity(this->getVelocity() + value.y * this->speed_ * WorldEntity::UP);174 this->localVelocity_.y += value.x; 156 175 } 157 176 158 177 void Spectator::rotateYaw(const Vector2& value) 159 178 { 160 this->yaw_ = value.y; 179 this->yaw_ -= value.y; 180 181 ControllableEntity::rotateYaw(value); 161 182 } 162 183 163 184 void Spectator::rotatePitch(const Vector2& value) 164 185 { 165 this->pitch_ = value.y; 186 this->pitch_ += value.y; 187 188 ControllableEntity::rotatePitch(value); 166 189 } 167 190 168 191 void Spectator::rotateRoll(const Vector2& value) 169 192 { 170 this->roll_ = value.y; 171 } 172 173 void Spectator::fire() 193 this->roll_ += value.y; 194 195 ControllableEntity::rotateRoll(value); 196 } 197 198 void Spectator::fire(WeaponMode::Enum fireMode) 174 199 { 175 200 if (this->getPlayer()) … … 187 212 } 188 213 } 189 190 void Spectator::updateHUD()191 {192 // <hack>193 if (Core::isMaster())194 {195 if (this->getPlayer() && this->getGametype())196 {197 if (!this->getGametype()->hasStarted() && !this->getGametype()->isStartCountdownRunning())198 {199 if (!this->getPlayer()->isReadyToSpawn())200 this->hudmode_ = 0;201 else202 this->hudmode_ = 1;203 }204 else if (!this->getGametype()->hasEnded())205 {206 if (this->getGametype()->isStartCountdownRunning())207 this->hudmode_ = 2 + 10*(int)ceil(this->getGametype()->getStartCountdown());208 else209 this->hudmode_ = 3;210 }211 else212 this->hudmode_ = 4;213 }214 else215 return;216 }217 218 if (this->getHUD())219 {220 std::string text;221 int hudmode = this->hudmode_ % 10;222 223 switch (hudmode)224 {225 case 0:226 text = "Press [Fire] to start the match";227 break;228 case 1:229 text = "Waiting for other players";230 break;231 case 2:232 text = convertToString((this->hudmode_ - 2) / 10);233 break;234 case 3:235 text = "Press [Fire] to respawn";236 break;237 case 4:238 text = "Game has ended";239 break;240 default:;241 }242 243 std::map<std::string, OrxonoxOverlay*>::const_iterator it = this->getHUD()->getOverlays().begin();244 for (; it != this->getHUD()->getOverlays().end(); ++it)245 {246 if (it->second->isA(Class(OverlayText)) && it->second->getName() == "state")247 {248 OverlayText* overlay = dynamic_cast<OverlayText*>(it->second);249 if (overlay)250 overlay->setCaption(text);251 break;252 }253 }254 }255 // </hack>256 }257 214 }
Note: See TracChangeset
for help on using the changeset viewer.