[5979] | 1 | /* |
---|
| 2 | * ORXONOX - the hottest 3D action shooter ever to exist |
---|
| 3 | * > www.orxonox.net < |
---|
| 4 | * |
---|
| 5 | * |
---|
| 6 | * License notice: |
---|
| 7 | * |
---|
| 8 | * This program is free software; you can redistribute it and/or |
---|
| 9 | * modify it under the terms of the GNU General Public License |
---|
| 10 | * as published by the Free Software Foundation; either version 2 |
---|
| 11 | * of the License, or (at your option) any later version. |
---|
| 12 | * |
---|
| 13 | * This program is distributed in the hope that it will be useful, |
---|
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 16 | * GNU General Public License for more details. |
---|
| 17 | * |
---|
| 18 | * You should have received a copy of the GNU General Public License |
---|
| 19 | * along with this program; if not, write to the Free Software |
---|
| 20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
---|
| 21 | * |
---|
| 22 | * Author: |
---|
[5981] | 23 | * Michael Wirth |
---|
[5979] | 24 | * Co-authors: |
---|
| 25 | * ... |
---|
| 26 | * |
---|
| 27 | */ |
---|
| 28 | |
---|
| 29 | #include "NewHumanController.h" |
---|
| 30 | |
---|
[6256] | 31 | #include <cmath> |
---|
[6033] | 32 | #include <OgreRay.h> |
---|
| 33 | #include <OgreSceneQuery.h> |
---|
| 34 | #include <OgreCamera.h> |
---|
| 35 | #include <OgreSceneManager.h> |
---|
[5981] | 36 | |
---|
[5979] | 37 | #include "core/CoreIncludes.h" |
---|
| 38 | #include "core/ConsoleCommand.h" |
---|
| 39 | #include "worldentities/ControllableEntity.h" |
---|
[6111] | 40 | #include "worldentities/pawns/Pawn.h" |
---|
[5979] | 41 | #include "infos/PlayerInfo.h" |
---|
[6055] | 42 | #include "overlays/OrxonoxOverlay.h" |
---|
[5979] | 43 | #include "graphics/Camera.h" |
---|
| 44 | #include "sound/SoundManager.h" |
---|
| 45 | #include "Scene.h" |
---|
[6295] | 46 | #include "tools/BulletConversions.h" |
---|
| 47 | #include "bullet/BulletCollision/NarrowPhaseCollision/btManifoldPoint.h" |
---|
[5979] | 48 | |
---|
| 49 | namespace orxonox |
---|
| 50 | { |
---|
[6091] | 51 | SetConsoleCommand(NewHumanController, changeMode, false).keybindMode(KeybindMode::OnPress); |
---|
[6149] | 52 | SetConsoleCommand(NewHumanController, accelerate, false).keybindMode(KeybindMode::OnPress); |
---|
| 53 | SetConsoleCommand(NewHumanController, decelerate, false).keybindMode(KeybindMode::OnPress); |
---|
[6210] | 54 | SetConsoleCommand(NewHumanController, unfire, true).keybindMode(KeybindMode::OnRelease); |
---|
[6091] | 55 | |
---|
[5979] | 56 | CreateUnloadableFactory(NewHumanController); |
---|
| 57 | |
---|
[6091] | 58 | NewHumanController* NewHumanController::localController_s = 0; |
---|
| 59 | |
---|
[6122] | 60 | NewHumanController::NewHumanController(BaseObject* creator) |
---|
| 61 | : HumanController(creator) |
---|
| 62 | , crossHairOverlay_(NULL) |
---|
[6195] | 63 | , centerOverlay_(NULL) |
---|
[6320] | 64 | , damageOverlayTop_(NULL) |
---|
| 65 | , damageOverlayRight_(NULL) |
---|
| 66 | , damageOverlayBottom_(NULL) |
---|
| 67 | , damageOverlayLeft_(NULL) |
---|
| 68 | , damageOverlayTT_(0) |
---|
[6328] | 69 | , arrowsOverlay1_(NULL) |
---|
| 70 | , arrowsOverlay2_(NULL) |
---|
| 71 | , arrowsOverlay3_(NULL) |
---|
| 72 | , arrowsOverlay4_(NULL) |
---|
[5979] | 73 | { |
---|
| 74 | RegisterObject(NewHumanController); |
---|
[6001] | 75 | |
---|
[6055] | 76 | overlaySize_ = 0.08; |
---|
[6210] | 77 | arrowsSize_ = 0.4; |
---|
[6310] | 78 | |
---|
| 79 | damageOverlayTime_ = 0.6; |
---|
| 80 | |
---|
[6055] | 81 | controlMode_ = 0; |
---|
[6149] | 82 | acceleration_ = 0; |
---|
[6236] | 83 | accelerating_ = false; |
---|
[6210] | 84 | firemode_ = -1; |
---|
[6310] | 85 | |
---|
[6210] | 86 | showArrows_ = true; |
---|
[6236] | 87 | showOverlays_ = false; |
---|
[6310] | 88 | showDamageOverlay_ = true; |
---|
[6033] | 89 | |
---|
[6149] | 90 | //currentPitch_ = 1; |
---|
| 91 | //currentYaw_ = 1; |
---|
| 92 | |
---|
[6122] | 93 | if (GameMode::showsGraphics()) |
---|
| 94 | { |
---|
| 95 | crossHairOverlay_ = new OrxonoxOverlay(this); |
---|
| 96 | crossHairOverlay_->setBackgroundMaterial("Orxonox/Crosshair3"); |
---|
| 97 | crossHairOverlay_->setSize(Vector2(overlaySize_, overlaySize_)); |
---|
[6195] | 98 | crossHairOverlay_->hide(); |
---|
[6210] | 99 | //crossHairOverlay_->setAspectCorrection(true); not working |
---|
[6195] | 100 | |
---|
| 101 | centerOverlay_ = new OrxonoxOverlay(this); |
---|
| 102 | centerOverlay_->setBackgroundMaterial("Orxonox/CenterOverlay"); |
---|
| 103 | centerOverlay_->setSize(Vector2(overlaySize_ * 2.5, overlaySize_ * 2.5)); |
---|
| 104 | centerOverlay_->setPosition(Vector2(0.5 - overlaySize_*2.5/2.0, 0.5 - overlaySize_*2.5/2.0));\ |
---|
| 105 | centerOverlay_->hide(); |
---|
[6210] | 106 | |
---|
[6310] | 107 | if ( showDamageOverlay_ ) |
---|
[6210] | 108 | { |
---|
[6310] | 109 | damageOverlayTop_ = new OrxonoxOverlay(this); |
---|
| 110 | damageOverlayTop_->setBackgroundMaterial("Orxonox/DamageOverlayTop"); |
---|
| 111 | damageOverlayTop_->setSize(Vector2(overlaySize_ * 2.5, overlaySize_ * 2.5)); |
---|
| 112 | damageOverlayTop_->setPosition(Vector2(0.5 - overlaySize_*2.5/2.0, 0.5 - overlaySize_*2.5/2.0));\ |
---|
| 113 | damageOverlayTop_->hide(); |
---|
| 114 | |
---|
| 115 | damageOverlayRight_ = new OrxonoxOverlay(this); |
---|
| 116 | damageOverlayRight_->setBackgroundMaterial("Orxonox/DamageOverlayRight"); |
---|
| 117 | damageOverlayRight_->setSize(Vector2(overlaySize_ * 2.5, overlaySize_ * 2.5)); |
---|
| 118 | damageOverlayRight_->setPosition(Vector2(0.5 - overlaySize_*2.5/2.0, 0.5 - overlaySize_*2.5/2.0));\ |
---|
| 119 | damageOverlayRight_->hide(); |
---|
| 120 | |
---|
| 121 | damageOverlayBottom_ = new OrxonoxOverlay(this); |
---|
| 122 | damageOverlayBottom_->setBackgroundMaterial("Orxonox/DamageOverlayBottom"); |
---|
| 123 | damageOverlayBottom_->setSize(Vector2(overlaySize_ * 2.5, overlaySize_ * 2.5)); |
---|
| 124 | damageOverlayBottom_->setPosition(Vector2(0.5 - overlaySize_*2.5/2.0, 0.5 - overlaySize_*2.5/2.0));\ |
---|
| 125 | damageOverlayBottom_->hide(); |
---|
| 126 | |
---|
| 127 | damageOverlayLeft_ = new OrxonoxOverlay(this); |
---|
| 128 | damageOverlayLeft_->setBackgroundMaterial("Orxonox/DamageOverlayLeft"); |
---|
| 129 | damageOverlayLeft_->setSize(Vector2(overlaySize_ * 2.5, overlaySize_ * 2.5)); |
---|
| 130 | damageOverlayLeft_->setPosition(Vector2(0.5 - overlaySize_*2.5/2.0, 0.5 - overlaySize_*2.5/2.0));\ |
---|
| 131 | damageOverlayLeft_->hide(); |
---|
| 132 | } |
---|
| 133 | |
---|
| 134 | if ( showArrows_ ) |
---|
| 135 | { |
---|
[6210] | 136 | arrowsOverlay1_ = new OrxonoxOverlay(this); |
---|
[6289] | 137 | arrowsOverlay1_->setBackgroundMaterial("Orxonox/DirectionArrows1"); |
---|
[6210] | 138 | arrowsOverlay1_->setSize(Vector2(0.02727, 0.36 * arrowsSize_)); |
---|
| 139 | arrowsOverlay1_->setPickPoint(Vector2(0.5, 0.5)); |
---|
| 140 | arrowsOverlay1_->setPosition(Vector2(0.5, 0.5)); |
---|
| 141 | arrowsOverlay1_->hide(); |
---|
| 142 | |
---|
| 143 | arrowsOverlay2_ = new OrxonoxOverlay(this); |
---|
[6289] | 144 | arrowsOverlay2_->setBackgroundMaterial("Orxonox/DirectionArrows2"); |
---|
[6210] | 145 | arrowsOverlay2_->setSize(Vector2(0.02727, 0.59 * arrowsSize_)); |
---|
| 146 | arrowsOverlay2_->setPickPoint(Vector2(0.5, 0.5)); |
---|
| 147 | arrowsOverlay2_->setPosition(Vector2(0.5, 0.5)); |
---|
| 148 | arrowsOverlay2_->hide(); |
---|
| 149 | |
---|
| 150 | arrowsOverlay3_ = new OrxonoxOverlay(this); |
---|
[6289] | 151 | arrowsOverlay3_->setBackgroundMaterial("Orxonox/DirectionArrows3"); |
---|
[6210] | 152 | arrowsOverlay3_->setSize(Vector2(0.02727, 0.77 * arrowsSize_)); |
---|
| 153 | arrowsOverlay3_->setPickPoint(Vector2(0.5, 0.5)); |
---|
| 154 | arrowsOverlay3_->setPosition(Vector2(0.5, 0.5)); |
---|
| 155 | arrowsOverlay3_->hide(); |
---|
| 156 | |
---|
| 157 | arrowsOverlay4_ = new OrxonoxOverlay(this); |
---|
[6289] | 158 | arrowsOverlay4_->setBackgroundMaterial("Orxonox/DirectionArrows4"); |
---|
[6210] | 159 | arrowsOverlay4_->setSize(Vector2(0.02727, arrowsSize_)); |
---|
| 160 | arrowsOverlay4_->setPickPoint(Vector2(0.5, 0.5)); |
---|
| 161 | arrowsOverlay4_->setPosition(Vector2(0.5, 0.5)); |
---|
| 162 | arrowsOverlay4_->hide(); |
---|
| 163 | } |
---|
[6122] | 164 | } |
---|
[6045] | 165 | |
---|
[6058] | 166 | // HACK: Define which objects are targetable when considering the creator of an orxonox::Model |
---|
[6055] | 167 | this->targetMask_.exclude(ClassByString("BaseObject")); |
---|
| 168 | this->targetMask_.include(ClassByString("WorldEntity")); |
---|
| 169 | this->targetMask_.exclude(ClassByString("Projectile")); |
---|
[6091] | 170 | |
---|
| 171 | NewHumanController::localController_s = this; |
---|
[6195] | 172 | |
---|
[6236] | 173 | controlPaused_ = false; |
---|
[6210] | 174 | |
---|
[6195] | 175 | //HumanController::localController_s->getControllableEntity()->getCamera()->setDrag(true); |
---|
[5979] | 176 | } |
---|
| 177 | |
---|
| 178 | NewHumanController::~NewHumanController() |
---|
| 179 | { |
---|
[6055] | 180 | if (this->isInitialized()) |
---|
[5981] | 181 | { |
---|
[6122] | 182 | if (this->crossHairOverlay_) |
---|
| 183 | this->crossHairOverlay_->destroy(); |
---|
[6210] | 184 | if (this->centerOverlay_) |
---|
| 185 | this->centerOverlay_->destroy(); |
---|
| 186 | |
---|
| 187 | if (showArrows_) |
---|
| 188 | { |
---|
| 189 | if (this->arrowsOverlay1_) |
---|
| 190 | this->arrowsOverlay1_->destroy(); |
---|
| 191 | if (this->arrowsOverlay2_) |
---|
| 192 | this->arrowsOverlay2_->destroy(); |
---|
| 193 | if (this->arrowsOverlay3_) |
---|
| 194 | this->arrowsOverlay3_->destroy(); |
---|
| 195 | if (this->arrowsOverlay4_) |
---|
| 196 | this->arrowsOverlay4_->destroy(); |
---|
| 197 | } |
---|
[5981] | 198 | } |
---|
[5979] | 199 | } |
---|
| 200 | |
---|
[6055] | 201 | void NewHumanController::tick(float dt) |
---|
| 202 | { |
---|
[6122] | 203 | if (GameMode::showsGraphics()) |
---|
[6111] | 204 | { |
---|
[6210] | 205 | |
---|
[6122] | 206 | if( this->controllableEntity_ && !this->controllableEntity_->isInMouseLook() ) |
---|
| 207 | { |
---|
[6157] | 208 | this->updateTarget(); |
---|
[6289] | 209 | |
---|
[6195] | 210 | if ( !controlPaused_ ) { |
---|
[6310] | 211 | if (this->getControllableEntity() && (this->getControllableEntity()->getIdentifier()->getName() == "SpaceShip" || this->getControllableEntity()->getIdentifier()->getName() == "Rocket")) |
---|
[6289] | 212 | this->showOverlays(); |
---|
| 213 | |
---|
[6195] | 214 | this->crossHairOverlay_->setPosition(Vector2(static_cast<float>(this->currentYaw_)/2*-1+.5-overlaySize_/2, static_cast<float>(this->currentPitch_)/2*-1+.5-overlaySize_/2)); |
---|
[6210] | 215 | |
---|
| 216 | if ( this->controlMode_ == 0 || ( this->controlMode_ == 1 && this->firemode_ == 1 ) ) |
---|
[6236] | 217 | { |
---|
[6289] | 218 | if ( this->showOverlays_ && this->showArrows_) |
---|
[6236] | 219 | alignArrows(); |
---|
| 220 | } |
---|
[6210] | 221 | else |
---|
| 222 | hideArrows(); |
---|
[6310] | 223 | |
---|
| 224 | if ( this->showDamageOverlay_ && ( this->damageOverlayTT_ > 0 || this->damageOverlayTR_ > 0 || this->damageOverlayTB_ > 0 || this->damageOverlayTL_ > 0 ) ) { |
---|
| 225 | this->damageOverlayTT_ -= dt; |
---|
| 226 | this->damageOverlayTR_ -= dt; |
---|
| 227 | this->damageOverlayTB_ -= dt; |
---|
| 228 | this->damageOverlayTL_ -= dt; |
---|
| 229 | if ( this->damageOverlayTT_ <= 0 ) |
---|
| 230 | this->damageOverlayTop_->hide(); |
---|
| 231 | if ( this->damageOverlayTR_ <= 0 ) |
---|
| 232 | this->damageOverlayRight_->hide(); |
---|
| 233 | if ( this->damageOverlayTB_ <= 0 ) |
---|
| 234 | this->damageOverlayBottom_->hide(); |
---|
| 235 | if ( this->damageOverlayTL_ <= 0 ) |
---|
| 236 | this->damageOverlayLeft_->hide(); |
---|
| 237 | } |
---|
[6195] | 238 | } |
---|
[6122] | 239 | } |
---|
[6279] | 240 | else |
---|
| 241 | this->hideOverlays(); |
---|
[6210] | 242 | |
---|
[6149] | 243 | if ( this->acceleration_ > 0 ) |
---|
[6173] | 244 | { |
---|
| 245 | /* |
---|
| 246 | if (this->controllableEntity_ && this->controllableEntity_->getEngine()) { |
---|
| 247 | std::cout << this->controllableEntity_->getEngine()->getAccelerationFront() << endl; |
---|
| 248 | } |
---|
| 249 | */ |
---|
| 250 | if ( this->accelerating_ ) |
---|
| 251 | HumanController::moveFrontBack(Vector2(1, 0)); |
---|
| 252 | else |
---|
| 253 | HumanController::moveFrontBack(Vector2(this->acceleration_, 0)); |
---|
| 254 | this->accelerating_ = false; |
---|
| 255 | //HumanController::moveFrontBack(Vector2(clamp(this->acceleration_ + this->currentAcceleration_, 0.0f, 1.0f), 0)); |
---|
| 256 | } |
---|
[6111] | 257 | } |
---|
[6001] | 258 | |
---|
[6360] | 259 | // Reset pitch and yaw rates |
---|
| 260 | this->currentPitch_ = 0; |
---|
| 261 | this->currentYaw_ = 0; |
---|
| 262 | |
---|
[6001] | 263 | HumanController::tick(dt); |
---|
| 264 | } |
---|
| 265 | |
---|
[5993] | 266 | /*void NewHumanController::tick(float dt) |
---|
[5979] | 267 | { |
---|
| 268 | if (GameMode::playsSound() && NewHumanController::localController_s && NewHumanController::localController_s->controllableEntity_) |
---|
| 269 | { |
---|
| 270 | // Update sound listener |
---|
| 271 | Camera* camera = NewHumanController::localController_s->controllableEntity_->getCamera(); |
---|
| 272 | if (camera) |
---|
| 273 | { |
---|
| 274 | SoundManager::getInstance().setListenerPosition(camera->getWorldPosition()); |
---|
| 275 | SoundManager::getInstance().setListenerOrientation(camera->getWorldOrientation()); |
---|
| 276 | } |
---|
| 277 | else |
---|
| 278 | COUT(3) << "NewHumanController, Warning: Using a ControllableEntity without Camera" << std::endl; |
---|
| 279 | } |
---|
[5993] | 280 | }*/ |
---|
| 281 | |
---|
[6033] | 282 | void NewHumanController::doFire(unsigned int firemode) |
---|
| 283 | { |
---|
[6316] | 284 | if ( !this->controllableEntity_ ) |
---|
| 285 | return; |
---|
[6033] | 286 | //if (HumanController::localController_s && HumanController::localController_s->controllableEntity_) { |
---|
| 287 | |
---|
| 288 | /* |
---|
[6055] | 289 | // Get results, create a node/entity on the position |
---|
| 290 | for ( itr = result.begin(); itr != result.end(); itr++ ) |
---|
| 291 | { |
---|
| 292 | if (itr->movable && itr->movable->getName() == "Head") |
---|
| 293 | { |
---|
| 294 | soundMgr->StopSound( &jaguarSoundChannel ); |
---|
| 295 | soundMgr->PlaySound( jaguarSound, headNode, &jaguarSoundChannel ); |
---|
| 296 | break; |
---|
| 297 | } // if |
---|
| 298 | } |
---|
[6033] | 299 | */ |
---|
| 300 | |
---|
[6210] | 301 | this->firemode_ = firemode; |
---|
| 302 | |
---|
[6157] | 303 | if (firemode == 1 && this->controlMode_ == 1) |
---|
| 304 | { |
---|
[6143] | 305 | //unlocked steering, steer on right mouse click |
---|
[6144] | 306 | HumanController::yaw(Vector2(this->currentYaw_, 0)); |
---|
| 307 | HumanController::pitch(Vector2(this->currentPitch_, 0)); |
---|
[6143] | 308 | } |
---|
[6157] | 309 | else |
---|
[6143] | 310 | HumanController::localController_s->getControllableEntity()->fire(firemode); |
---|
| 311 | |
---|
[6045] | 312 | } |
---|
| 313 | |
---|
[6295] | 314 | void NewHumanController::hit(Pawn* originator, btManifoldPoint& contactpoint, float damage) { |
---|
[6312] | 315 | if ( this->showDamageOverlay_ && !this->controlPaused_ && this->controllableEntity_ && !this->controllableEntity_->isInMouseLook() ) { |
---|
[6310] | 316 | Vector3 posA; |
---|
| 317 | if ( originator ) |
---|
| 318 | posA = originator->getWorldPosition(); |
---|
| 319 | else |
---|
| 320 | posA = multi_cast<Vector3>(contactpoint.getPositionWorldOnA()); |
---|
| 321 | //Vector3 posB = multi_cast<Vector3>(contactpoint.getPositionWorldOnB()); |
---|
| 322 | //posA and posB are almost identical |
---|
[6295] | 323 | |
---|
[6310] | 324 | Vector3 relativeHit = this->getControllableEntity()->getWorldOrientation().UnitInverse() * (this->getControllableEntity()->getWorldPosition() - posA); |
---|
[6295] | 325 | |
---|
[6310] | 326 | //back is z positive |
---|
| 327 | //x is left positive |
---|
| 328 | //y is down positive |
---|
| 329 | relativeHit.normalise(); |
---|
| 330 | COUT(0) << relativeHit << endl; |
---|
| 331 | |
---|
| 332 | float threshold = 0.3; |
---|
| 333 | // && abs(relativeHit.y) < 0.5 |
---|
| 334 | if ( relativeHit.x > threshold) // Left |
---|
| 335 | { |
---|
| 336 | this->damageOverlayLeft_->show(); |
---|
| 337 | this->damageOverlayTL_ = this->damageOverlayTime_; |
---|
| 338 | //this->damageOverlayLeft_->setBackgroundAlpha(0.3); |
---|
| 339 | } |
---|
| 340 | if ( relativeHit.x < -threshold) //Right |
---|
| 341 | { |
---|
| 342 | this->damageOverlayRight_->show(); |
---|
| 343 | this->damageOverlayTR_ = this->damageOverlayTime_; |
---|
| 344 | //this->damageOverlayRight_->setBackgroundAlpha(0.3); |
---|
| 345 | } |
---|
| 346 | if ( relativeHit.y > threshold) //Top |
---|
| 347 | { |
---|
[6312] | 348 | this->damageOverlayBottom_->show(); |
---|
| 349 | this->damageOverlayTB_ = this->damageOverlayTime_; |
---|
[6310] | 350 | //this->damageOverlayTop_->setBackgroundAlpha(0.3); |
---|
| 351 | } |
---|
| 352 | if ( relativeHit.y < -threshold) //Bottom |
---|
| 353 | { |
---|
[6312] | 354 | this->damageOverlayTop_->show(); |
---|
| 355 | this->damageOverlayTT_ = this->damageOverlayTime_; |
---|
[6310] | 356 | //this->damageOverlayBottom_->setBackgroundAlpha(0.3); |
---|
| 357 | } |
---|
| 358 | |
---|
| 359 | } |
---|
[6295] | 360 | } |
---|
| 361 | |
---|
[6210] | 362 | void NewHumanController::unfire() |
---|
| 363 | { |
---|
| 364 | if (NewHumanController::localController_s) |
---|
| 365 | NewHumanController::localController_s->doUnfire(); |
---|
| 366 | } |
---|
| 367 | |
---|
| 368 | void NewHumanController::doUnfire() |
---|
| 369 | { |
---|
| 370 | this->firemode_ = -1; |
---|
| 371 | hideArrows(); |
---|
| 372 | } |
---|
| 373 | |
---|
[6111] | 374 | void NewHumanController::updateTarget() |
---|
[6055] | 375 | { |
---|
| 376 | Ogre::RaySceneQuery * rsq = HumanController::localController_s->getControllableEntity()->getScene()->getSceneManager()->createRayQuery(Ogre::Ray()); |
---|
[6033] | 377 | |
---|
[6058] | 378 | Ogre::Ray mouseRay = HumanController::localController_s->getControllableEntity()->getCamera()->getOgreCamera()->getCameraToViewportRay(static_cast<float>(this->currentYaw_)/2*-1+.5, static_cast<float>(this->currentPitch_)/2*-1+.5); |
---|
[6033] | 379 | |
---|
[6055] | 380 | rsq->setRay(mouseRay); |
---|
| 381 | rsq->setSortByDistance(true); |
---|
[6033] | 382 | |
---|
[6055] | 383 | /* |
---|
| 384 | Distance of objects: |
---|
| 385 | ignore everything under 200 maybe even take 1000 as min distance to shoot at |
---|
[6033] | 386 | |
---|
[6055] | 387 | shots are regularly traced and are entities!!!!!!!!! this is the biggest problem |
---|
| 388 | they vanish only after a distance of 10'000 |
---|
| 389 | */ |
---|
[6045] | 390 | |
---|
| 391 | |
---|
[6055] | 392 | Ogre::RaySceneQueryResult& result = rsq->execute(); |
---|
[6111] | 393 | Pawn* pawn = orxonox_cast<Pawn*>(this->getControllableEntity()); |
---|
[6033] | 394 | |
---|
[6055] | 395 | Ogre::RaySceneQueryResult::iterator itr; |
---|
| 396 | for (itr = result.begin(); itr != result.end(); ++itr) |
---|
| 397 | { |
---|
| 398 | if (itr->movable->isInScene() && itr->movable->getMovableType() == "Entity" && itr->distance > 500) |
---|
[6045] | 399 | { |
---|
[6055] | 400 | // Try to cast the user pointer |
---|
| 401 | WorldEntity* wePtr = dynamic_cast<WorldEntity*>(itr->movable->getUserObject()); |
---|
| 402 | if (wePtr) |
---|
| 403 | { |
---|
[6114] | 404 | // go through all parents of object and look wheter they are Sightable or not |
---|
| 405 | bool isSightable = false; |
---|
| 406 | WorldEntity* parent = wePtr->getParent(); |
---|
| 407 | while( parent ) |
---|
| 408 | { |
---|
| 409 | if (this->targetMask_.isExcluded(parent->getIdentifier())) |
---|
| 410 | { |
---|
| 411 | parent = parent->getParent(); |
---|
| 412 | continue; |
---|
| 413 | } |
---|
| 414 | else |
---|
| 415 | { |
---|
| 416 | isSightable = true; |
---|
| 417 | break; |
---|
| 418 | } |
---|
| 419 | } |
---|
| 420 | if ( !isSightable ) |
---|
[6055] | 421 | continue; |
---|
[6045] | 422 | } |
---|
[6143] | 423 | |
---|
| 424 | if ( this->getControllableEntity() && this->getControllableEntity()->getTarget() != wePtr ) |
---|
| 425 | { |
---|
[6116] | 426 | this->getControllableEntity()->setTarget(wePtr); |
---|
[6143] | 427 | } |
---|
[6091] | 428 | |
---|
[6143] | 429 | if( pawn ) |
---|
| 430 | { |
---|
| 431 | pawn->setAimPosition( mouseRay.getOrigin() + mouseRay.getDirection() * itr->distance ); |
---|
| 432 | } |
---|
| 433 | |
---|
[6195] | 434 | //itr->movable->getParentSceneNode()->showBoundingBox(true); |
---|
[6091] | 435 | //std::cout << itr->movable->getParentSceneNode()->_getDerivedPosition() << endl; |
---|
[6111] | 436 | //return mouseRay.getOrigin() + mouseRay.getDirection() * itr->distance; //or itr->movable->getParentSceneNode()->_getDerivedPosition() |
---|
| 437 | return; |
---|
[6045] | 438 | } |
---|
[6091] | 439 | |
---|
[6055] | 440 | } |
---|
[6111] | 441 | if ( pawn ) |
---|
| 442 | { |
---|
| 443 | pawn->setAimPosition( mouseRay.getOrigin() + mouseRay.getDirection() * 1200 ); |
---|
| 444 | } |
---|
[6143] | 445 | |
---|
| 446 | if( this->getControllableEntity() && this->getControllableEntity()->getTarget() != 0 ) |
---|
| 447 | this->getControllableEntity()->setTarget( 0 ); |
---|
[6111] | 448 | |
---|
[6033] | 449 | |
---|
[6091] | 450 | //return this->controllableEntity_->getWorldPosition() + (this->controllableEntity_->getWorldOrientation() * Vector3::NEGATIVE_UNIT_Z * 2000); |
---|
[6058] | 451 | //return this->controllableEntity_->getWorldPosition() + (this->controllableEntity_->getCamera()->getOgreCamera()->getOrientation() * Vector3::NEGATIVE_UNIT_Z); |
---|
[6033] | 452 | } |
---|
| 453 | |
---|
[6149] | 454 | void NewHumanController::frontback(const Vector2& value) |
---|
| 455 | { |
---|
[6173] | 456 | this->accelerating_ = true; |
---|
[6149] | 457 | |
---|
[6173] | 458 | //if (this->acceleration_ == 0) |
---|
[6149] | 459 | HumanController::frontback(value); |
---|
| 460 | } |
---|
| 461 | |
---|
[5993] | 462 | void NewHumanController::yaw(const Vector2& value) |
---|
| 463 | { |
---|
| 464 | // SUPER(NewHumanController, yaw, value); |
---|
[6210] | 465 | if (this->controlMode_ == 0 || ( this->controllableEntity_ && this->controllableEntity_->isInMouseLook() ) ) |
---|
[6091] | 466 | HumanController::yaw(value); |
---|
[6143] | 467 | |
---|
[5993] | 468 | this->currentYaw_ = value.x; |
---|
[5979] | 469 | } |
---|
[6055] | 470 | |
---|
[5993] | 471 | void NewHumanController::pitch(const Vector2& value) |
---|
[5981] | 472 | { |
---|
[5993] | 473 | // SUPER(NewHumanController, pitch, value); |
---|
[6210] | 474 | if (this->controlMode_ == 0 || ( this->controllableEntity_ && this->controllableEntity_->isInMouseLook() ) ) |
---|
[6091] | 475 | HumanController::pitch(value); |
---|
| 476 | |
---|
[5993] | 477 | this->currentPitch_ = value.x; |
---|
[5981] | 478 | } |
---|
[6091] | 479 | |
---|
[6149] | 480 | void NewHumanController::changeMode() |
---|
| 481 | { |
---|
[6111] | 482 | if (NewHumanController::localController_s && NewHumanController::localController_s->controlMode_ == 0) |
---|
| 483 | { |
---|
| 484 | NewHumanController::localController_s->controlMode_ = 1; |
---|
[6210] | 485 | NewHumanController::localController_s->hideArrows(); |
---|
[6111] | 486 | } |
---|
[6091] | 487 | else |
---|
| 488 | NewHumanController::localController_s->controlMode_ = 0; |
---|
| 489 | } |
---|
[6143] | 490 | |
---|
[6115] | 491 | void NewHumanController::changedControllableEntity() |
---|
| 492 | { |
---|
[6316] | 493 | if( this->getControllableEntity() ) |
---|
| 494 | CCOUT(0) << "changed controllable entity to: " << this->getControllableEntity()->getIdentifier()->getName() << endl; |
---|
| 495 | else |
---|
| 496 | CCOUT(0) << "changed controllable entity to: " << this->getControllableEntity() << endl; |
---|
[6115] | 497 | this->controlMode_ = 0; |
---|
| 498 | this->currentYaw_ = 0; |
---|
| 499 | this->currentPitch_ = 0; |
---|
[6316] | 500 | if (this->getControllableEntity() && ( this->getControllableEntity()->getIdentifier()->getName() == "SpaceShip" || this->getControllableEntity()->getIdentifier()->getName() == "Rocket" )) |
---|
[6236] | 501 | { |
---|
| 502 | this->showOverlays_ = true; |
---|
| 503 | if( !this->controlPaused_ ) |
---|
| 504 | { |
---|
| 505 | this->showOverlays(); |
---|
| 506 | this->alignArrows(); |
---|
| 507 | } |
---|
| 508 | } |
---|
| 509 | else |
---|
| 510 | { |
---|
| 511 | this->showOverlays_ = false; |
---|
| 512 | this->hideOverlays(); |
---|
| 513 | } |
---|
[6115] | 514 | } |
---|
[6149] | 515 | |
---|
| 516 | void NewHumanController::accelerate() |
---|
| 517 | { |
---|
[6157] | 518 | if ( NewHumanController::localController_s ) |
---|
| 519 | { |
---|
[6173] | 520 | NewHumanController::localController_s->acceleration_ = clamp(NewHumanController::localController_s->acceleration_ + 0.2f, 0.00f, 1.0f); |
---|
[6149] | 521 | } |
---|
| 522 | } |
---|
| 523 | |
---|
| 524 | void NewHumanController::decelerate() |
---|
| 525 | { |
---|
[6157] | 526 | if ( NewHumanController::localController_s ) |
---|
| 527 | { |
---|
[6173] | 528 | NewHumanController::localController_s->acceleration_ = clamp(NewHumanController::localController_s->acceleration_ - 0.1f, 0.0f, 1.0f); |
---|
[6149] | 529 | } |
---|
| 530 | } |
---|
[6195] | 531 | |
---|
| 532 | void NewHumanController::doResumeControl() { |
---|
| 533 | this->controlPaused_ = false; |
---|
[6236] | 534 | if( this->showOverlays_ ) { |
---|
| 535 | this->showOverlays(); |
---|
| 536 | } |
---|
[6195] | 537 | } |
---|
| 538 | |
---|
| 539 | void NewHumanController::doPauseControl() { |
---|
| 540 | this->controlPaused_ = true; |
---|
[6316] | 541 | COUT(0) << "pause control" << endl; |
---|
[6236] | 542 | this->hideOverlays(); |
---|
[6195] | 543 | } |
---|
[6210] | 544 | |
---|
| 545 | void NewHumanController::alignArrows() { |
---|
| 546 | if (showArrows_) { |
---|
| 547 | hideArrows(); |
---|
| 548 | |
---|
| 549 | float distance = sqrt(pow(static_cast<float>(this->currentYaw_)/2*-1,2) + pow(static_cast<float>(this->currentPitch_)/2*-1,2)); |
---|
| 550 | |
---|
| 551 | if ( distance > 0.04 && distance <= 0.59 * arrowsSize_ / 2.0 ) { |
---|
| 552 | this->arrowsOverlay1_->setRotation(Degree(-90 + -1.0 * atan2(static_cast<float>(this->currentPitch_)/2*-1, static_cast<float>(this->currentYaw_)/2*-1) / (2.0f * Ogre::Math::PI) * 360.0f)); |
---|
| 553 | |
---|
| 554 | this->arrowsOverlay1_->show(); |
---|
| 555 | } |
---|
| 556 | else if ( distance > 0.59 * arrowsSize_ / 2.0 && distance <= 0.77 * arrowsSize_ / 2.0 ) { |
---|
| 557 | this->arrowsOverlay2_->setRotation(Degree(-90 + -1.0 * atan2(static_cast<float>(this->currentPitch_)/2*-1, static_cast<float>(this->currentYaw_)/2*-1) / (2.0f * Ogre::Math::PI) * 360.0f)); |
---|
| 558 | |
---|
| 559 | this->arrowsOverlay2_->show(); |
---|
| 560 | } |
---|
| 561 | else if ( distance > 0.77 * arrowsSize_ / 2.0 && distance <= arrowsSize_ / 2.0 ) { |
---|
| 562 | this->arrowsOverlay3_->setRotation(Degree(-90 + -1.0 * atan2(static_cast<float>(this->currentPitch_)/2*-1, static_cast<float>(this->currentYaw_)/2*-1) / (2.0f * Ogre::Math::PI) * 360.0f)); |
---|
| 563 | |
---|
| 564 | this->arrowsOverlay3_->show(); |
---|
| 565 | } |
---|
| 566 | else if ( distance > arrowsSize_ / 2.0 ) { |
---|
| 567 | this->arrowsOverlay4_->setRotation(Degree(-90 + -1.0 * atan2(static_cast<float>(this->currentPitch_)/2*-1, static_cast<float>(this->currentYaw_)/2*-1) / (2.0f * Ogre::Math::PI) * 360.0f)); |
---|
| 568 | |
---|
| 569 | this->arrowsOverlay4_->show(); |
---|
| 570 | } |
---|
| 571 | } |
---|
| 572 | } |
---|
| 573 | |
---|
[6236] | 574 | void NewHumanController::showOverlays() { |
---|
[6320] | 575 | if( !GameMode::showsGraphics() ) |
---|
| 576 | return; |
---|
[6236] | 577 | this->crossHairOverlay_->show(); |
---|
| 578 | this->centerOverlay_->show(); |
---|
[6289] | 579 | |
---|
[6236] | 580 | if (showArrows_) { |
---|
| 581 | this->arrowsOverlay1_->show(); |
---|
| 582 | this->arrowsOverlay2_->show(); |
---|
| 583 | this->arrowsOverlay3_->show(); |
---|
| 584 | this->arrowsOverlay4_->show(); |
---|
| 585 | } |
---|
| 586 | } |
---|
| 587 | |
---|
| 588 | void NewHumanController::hideOverlays() { |
---|
[6320] | 589 | if( !GameMode::showsGraphics() ) |
---|
| 590 | return; |
---|
[6236] | 591 | this->crossHairOverlay_->hide(); |
---|
| 592 | this->centerOverlay_->hide(); |
---|
[6289] | 593 | |
---|
[6310] | 594 | if ( showDamageOverlay_ ) { |
---|
| 595 | this->damageOverlayTop_->hide(); |
---|
| 596 | this->damageOverlayRight_->hide(); |
---|
| 597 | this->damageOverlayBottom_->hide(); |
---|
| 598 | this->damageOverlayLeft_->hide(); |
---|
| 599 | } |
---|
| 600 | |
---|
[6236] | 601 | this->hideArrows(); |
---|
| 602 | } |
---|
| 603 | |
---|
[6210] | 604 | void NewHumanController::hideArrows() { |
---|
[6320] | 605 | if( !GameMode::showsGraphics() ) |
---|
| 606 | return; |
---|
[6210] | 607 | if (showArrows_) { |
---|
| 608 | this->arrowsOverlay1_->hide(); |
---|
| 609 | this->arrowsOverlay2_->hide(); |
---|
| 610 | this->arrowsOverlay3_->hide(); |
---|
| 611 | this->arrowsOverlay4_->hide(); |
---|
| 612 | } |
---|
| 613 | } |
---|
[5979] | 614 | } |
---|