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