[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> |
---|
[6377] | 36 | #include <bullet/BulletCollision/NarrowPhaseCollision/btManifoldPoint.h> |
---|
[5981] | 37 | |
---|
[5979] | 38 | #include "core/CoreIncludes.h" |
---|
[10624] | 39 | #include "core/command/ConsoleCommandIncludes.h" |
---|
[7859] | 40 | #include "core/input/KeyBinder.h" |
---|
| 41 | #include "core/input/KeyBinderManager.h" |
---|
[5979] | 42 | #include "worldentities/ControllableEntity.h" |
---|
[6111] | 43 | #include "worldentities/pawns/Pawn.h" |
---|
[5979] | 44 | #include "infos/PlayerInfo.h" |
---|
[6055] | 45 | #include "overlays/OrxonoxOverlay.h" |
---|
[5979] | 46 | #include "graphics/Camera.h" |
---|
| 47 | #include "sound/SoundManager.h" |
---|
[6377] | 48 | #include "tools/BulletConversions.h" |
---|
[5979] | 49 | #include "Scene.h" |
---|
| 50 | |
---|
| 51 | namespace orxonox |
---|
| 52 | { |
---|
[7284] | 53 | SetConsoleCommand("NewHumanController", "changeMode", &NewHumanController::changeMode).keybindMode(KeybindMode::OnPress); |
---|
| 54 | SetConsoleCommand("NewHumanController", "accelerate", &NewHumanController::accelerate).keybindMode(KeybindMode::OnPress); |
---|
| 55 | SetConsoleCommand("NewHumanController", "decelerate", &NewHumanController::decelerate).keybindMode(KeybindMode::OnPress); |
---|
[11153] | 56 | SetConsoleCommand("NewHumanController", "release", &NewHumanController::release ).keybindMode(KeybindMode::OnRelease).addShortcut(); |
---|
[6091] | 57 | |
---|
[9667] | 58 | RegisterUnloadableClass(NewHumanController); |
---|
[5979] | 59 | |
---|
[11071] | 60 | NewHumanController* NewHumanController::localController_s = nullptr; |
---|
[6091] | 61 | |
---|
[9667] | 62 | NewHumanController::NewHumanController(Context* context) |
---|
| 63 | : HumanController(context) |
---|
[11071] | 64 | , crossHairOverlay_(nullptr) |
---|
| 65 | , centerOverlay_(nullptr) |
---|
| 66 | , damageOverlayTop_(nullptr) |
---|
| 67 | , damageOverlayRight_(nullptr) |
---|
| 68 | , damageOverlayBottom_(nullptr) |
---|
| 69 | , damageOverlayLeft_(nullptr) |
---|
[6320] | 70 | , damageOverlayTT_(0) |
---|
[8436] | 71 | , damageOverlayTR_(0) |
---|
| 72 | , damageOverlayTB_(0) |
---|
| 73 | , damageOverlayTL_(0) |
---|
[11071] | 74 | , arrowsOverlay1_(nullptr) |
---|
| 75 | , arrowsOverlay2_(nullptr) |
---|
| 76 | , arrowsOverlay3_(nullptr) |
---|
| 77 | , arrowsOverlay4_(nullptr) |
---|
[5979] | 78 | { |
---|
| 79 | RegisterObject(NewHumanController); |
---|
[6001] | 80 | |
---|
[6502] | 81 | overlaySize_ = 0.08f; |
---|
| 82 | arrowsSize_ = 0.4f; |
---|
[6310] | 83 | |
---|
[6502] | 84 | damageOverlayTime_ = 0.6f; |
---|
[6310] | 85 | |
---|
[6055] | 86 | controlMode_ = 0; |
---|
[6149] | 87 | acceleration_ = 0; |
---|
[6236] | 88 | accelerating_ = false; |
---|
[6210] | 89 | firemode_ = -1; |
---|
[6310] | 90 | |
---|
[6210] | 91 | showArrows_ = true; |
---|
[6236] | 92 | showOverlays_ = false; |
---|
[6310] | 93 | showDamageOverlay_ = true; |
---|
[6033] | 94 | |
---|
[6149] | 95 | //currentPitch_ = 1; |
---|
| 96 | //currentYaw_ = 1; |
---|
| 97 | |
---|
[6122] | 98 | if (GameMode::showsGraphics()) |
---|
| 99 | { |
---|
[9667] | 100 | crossHairOverlay_ = new OrxonoxOverlay(this->getContext()); |
---|
[6122] | 101 | crossHairOverlay_->setBackgroundMaterial("Orxonox/Crosshair3"); |
---|
| 102 | crossHairOverlay_->setSize(Vector2(overlaySize_, overlaySize_)); |
---|
[6195] | 103 | crossHairOverlay_->hide(); |
---|
[6210] | 104 | //crossHairOverlay_->setAspectCorrection(true); not working |
---|
[6195] | 105 | |
---|
[9667] | 106 | centerOverlay_ = new OrxonoxOverlay(this->getContext()); |
---|
[6195] | 107 | centerOverlay_->setBackgroundMaterial("Orxonox/CenterOverlay"); |
---|
[6502] | 108 | centerOverlay_->setSize(Vector2(overlaySize_ * 2.5f, overlaySize_ * 2.5f)); |
---|
| 109 | centerOverlay_->setPosition(Vector2(0.5f - overlaySize_*2.5f/2.0f, 0.5f - overlaySize_*2.5f/2.0f)); |
---|
[6195] | 110 | centerOverlay_->hide(); |
---|
[6210] | 111 | |
---|
[6377] | 112 | if (showDamageOverlay_) |
---|
[6210] | 113 | { |
---|
[9667] | 114 | damageOverlayTop_ = new OrxonoxOverlay(this->getContext()); |
---|
[6310] | 115 | damageOverlayTop_->setBackgroundMaterial("Orxonox/DamageOverlayTop"); |
---|
[6502] | 116 | damageOverlayTop_->setSize(Vector2(overlaySize_ * 2.5f, overlaySize_ * 2.5f)); |
---|
| 117 | damageOverlayTop_->setPosition(Vector2(0.5f - overlaySize_*2.5f/2.0f, 0.5f - overlaySize_*2.5f/2.0f)); |
---|
[6310] | 118 | damageOverlayTop_->hide(); |
---|
| 119 | |
---|
[9667] | 120 | damageOverlayRight_ = new OrxonoxOverlay(this->getContext()); |
---|
[6310] | 121 | damageOverlayRight_->setBackgroundMaterial("Orxonox/DamageOverlayRight"); |
---|
[6502] | 122 | damageOverlayRight_->setSize(Vector2(overlaySize_ * 2.5f, overlaySize_ * 2.5f)); |
---|
| 123 | damageOverlayRight_->setPosition(Vector2(0.5f - overlaySize_*2.5f/2.0f, 0.5f - overlaySize_*2.5f/2.0f)); |
---|
[6310] | 124 | damageOverlayRight_->hide(); |
---|
| 125 | |
---|
[9667] | 126 | damageOverlayBottom_ = new OrxonoxOverlay(this->getContext()); |
---|
[6310] | 127 | damageOverlayBottom_->setBackgroundMaterial("Orxonox/DamageOverlayBottom"); |
---|
[6502] | 128 | damageOverlayBottom_->setSize(Vector2(overlaySize_ * 2.5f, overlaySize_ * 2.5f)); |
---|
| 129 | damageOverlayBottom_->setPosition(Vector2(0.5f - overlaySize_*2.5f/2.0f, 0.5f - overlaySize_*2.5f/2.0f)); |
---|
[6310] | 130 | damageOverlayBottom_->hide(); |
---|
| 131 | |
---|
[9667] | 132 | damageOverlayLeft_ = new OrxonoxOverlay(this->getContext()); |
---|
[6310] | 133 | damageOverlayLeft_->setBackgroundMaterial("Orxonox/DamageOverlayLeft"); |
---|
[6502] | 134 | damageOverlayLeft_->setSize(Vector2(overlaySize_ * 2.5f, overlaySize_ * 2.5f)); |
---|
| 135 | damageOverlayLeft_->setPosition(Vector2(0.5f - overlaySize_*2.5f/2.0f, 0.5f - overlaySize_*2.5f/2.0f)); |
---|
[6310] | 136 | damageOverlayLeft_->hide(); |
---|
| 137 | } |
---|
| 138 | |
---|
[6377] | 139 | if (showArrows_) |
---|
[6310] | 140 | { |
---|
[9667] | 141 | arrowsOverlay1_ = new OrxonoxOverlay(this->getContext()); |
---|
[6289] | 142 | arrowsOverlay1_->setBackgroundMaterial("Orxonox/DirectionArrows1"); |
---|
[6502] | 143 | arrowsOverlay1_->setSize(Vector2(0.02727f, 0.36f * arrowsSize_)); |
---|
| 144 | arrowsOverlay1_->setPickPoint(Vector2(0.5f, 0.5f)); |
---|
| 145 | arrowsOverlay1_->setPosition(Vector2(0.5f, 0.5f)); |
---|
[6210] | 146 | arrowsOverlay1_->hide(); |
---|
[6387] | 147 | |
---|
[9667] | 148 | arrowsOverlay2_ = new OrxonoxOverlay(this->getContext()); |
---|
[6289] | 149 | arrowsOverlay2_->setBackgroundMaterial("Orxonox/DirectionArrows2"); |
---|
[6502] | 150 | arrowsOverlay2_->setSize(Vector2(0.02727f, 0.59f * arrowsSize_)); |
---|
| 151 | arrowsOverlay2_->setPickPoint(Vector2(0.5f, 0.5f)); |
---|
| 152 | arrowsOverlay2_->setPosition(Vector2(0.5f, 0.5f)); |
---|
[6210] | 153 | arrowsOverlay2_->hide(); |
---|
[6387] | 154 | |
---|
[9667] | 155 | arrowsOverlay3_ = new OrxonoxOverlay(this->getContext()); |
---|
[6289] | 156 | arrowsOverlay3_->setBackgroundMaterial("Orxonox/DirectionArrows3"); |
---|
[6502] | 157 | arrowsOverlay3_->setSize(Vector2(0.02727f, 0.77f * arrowsSize_)); |
---|
| 158 | arrowsOverlay3_->setPickPoint(Vector2(0.5f, 0.5f)); |
---|
| 159 | arrowsOverlay3_->setPosition(Vector2(0.5f, 0.5f)); |
---|
[6210] | 160 | arrowsOverlay3_->hide(); |
---|
[6387] | 161 | |
---|
[9667] | 162 | arrowsOverlay4_ = new OrxonoxOverlay(this->getContext()); |
---|
[6289] | 163 | arrowsOverlay4_->setBackgroundMaterial("Orxonox/DirectionArrows4"); |
---|
[6502] | 164 | arrowsOverlay4_->setSize(Vector2(0.02727f, arrowsSize_)); |
---|
| 165 | arrowsOverlay4_->setPickPoint(Vector2(0.5f, 0.5f)); |
---|
| 166 | arrowsOverlay4_->setPosition(Vector2(0.5f, 0.5f)); |
---|
[6210] | 167 | arrowsOverlay4_->hide(); |
---|
| 168 | } |
---|
[6122] | 169 | } |
---|
[6045] | 170 | |
---|
[6058] | 171 | // HACK: Define which objects are targetable when considering the creator of an orxonox::Model |
---|
[6055] | 172 | this->targetMask_.exclude(ClassByString("BaseObject")); |
---|
| 173 | this->targetMask_.include(ClassByString("WorldEntity")); |
---|
| 174 | this->targetMask_.exclude(ClassByString("Projectile")); |
---|
[6091] | 175 | |
---|
| 176 | NewHumanController::localController_s = this; |
---|
[6195] | 177 | |
---|
[6236] | 178 | controlPaused_ = false; |
---|
[6210] | 179 | |
---|
[6377] | 180 | //HumanController::localController_s->getControllableEntity()->getCamera()->setDrag(true); |
---|
[5979] | 181 | } |
---|
| 182 | |
---|
| 183 | NewHumanController::~NewHumanController() |
---|
| 184 | { |
---|
[6055] | 185 | if (this->isInitialized()) |
---|
[5981] | 186 | { |
---|
[6122] | 187 | if (this->crossHairOverlay_) |
---|
| 188 | this->crossHairOverlay_->destroy(); |
---|
[6210] | 189 | if (this->centerOverlay_) |
---|
| 190 | this->centerOverlay_->destroy(); |
---|
| 191 | |
---|
[6598] | 192 | if (this->arrowsOverlay1_) |
---|
| 193 | this->arrowsOverlay1_->destroy(); |
---|
| 194 | if (this->arrowsOverlay2_) |
---|
| 195 | this->arrowsOverlay2_->destroy(); |
---|
| 196 | if (this->arrowsOverlay3_) |
---|
| 197 | this->arrowsOverlay3_->destroy(); |
---|
| 198 | if (this->arrowsOverlay4_) |
---|
| 199 | this->arrowsOverlay4_->destroy(); |
---|
| 200 | if (this->damageOverlayTop_) |
---|
| 201 | this->damageOverlayTop_->destroy(); |
---|
| 202 | if (this->damageOverlayLeft_) |
---|
| 203 | this->damageOverlayLeft_->destroy(); |
---|
| 204 | if (this->damageOverlayRight_) |
---|
| 205 | this->damageOverlayRight_->destroy(); |
---|
| 206 | if (this->damageOverlayBottom_) |
---|
| 207 | this->damageOverlayBottom_->destroy(); |
---|
[5981] | 208 | } |
---|
[5979] | 209 | } |
---|
| 210 | |
---|
[6055] | 211 | void NewHumanController::tick(float dt) |
---|
| 212 | { |
---|
[6122] | 213 | if (GameMode::showsGraphics()) |
---|
[6111] | 214 | { |
---|
[6210] | 215 | |
---|
[6377] | 216 | if (this->controllableEntity_ && !this->controllableEntity_->isInMouseLook()) |
---|
[6122] | 217 | { |
---|
[6157] | 218 | this->updateTarget(); |
---|
[6289] | 219 | |
---|
[6377] | 220 | if (!controlPaused_ ) |
---|
| 221 | { |
---|
[10216] | 222 | if (this->getControllableEntity() && ((this->getControllableEntity()->isExactlyA(ClassByString("SpaceShip")) || (this->getControllableEntity()->isExactlyA(ClassByString("ModularSpaceShip")))) || this->getControllableEntity()->isExactlyA(ClassByString("Rocket")))) |
---|
[6289] | 223 | this->showOverlays(); |
---|
[7163] | 224 | else if (this->getControllableEntity() && this->getControllableEntity()->isExactlyA(ClassByString("FpsPlayer"))) |
---|
| 225 | { |
---|
| 226 | this->showOverlays(); |
---|
| 227 | this->hideArrows(); |
---|
| 228 | } |
---|
[6289] | 229 | |
---|
[6502] | 230 | this->crossHairOverlay_->setPosition(Vector2(static_cast<float>(this->currentYaw_)/2*-1+.5f-overlaySize_/2, static_cast<float>(this->currentPitch_)/2*-1+.5f-overlaySize_/2)); |
---|
[6210] | 231 | |
---|
[6377] | 232 | if (this->controlMode_ == 0 || (this->controlMode_ == 1 && this->firemode_ == 1)) |
---|
[6236] | 233 | { |
---|
[6377] | 234 | if (this->showOverlays_ && this->showArrows_) |
---|
[6236] | 235 | alignArrows(); |
---|
| 236 | } |
---|
[6210] | 237 | else |
---|
| 238 | hideArrows(); |
---|
[6310] | 239 | |
---|
[6377] | 240 | if (this->showDamageOverlay_ && (this->damageOverlayTT_ > 0 || this->damageOverlayTR_ > 0 || this->damageOverlayTB_ > 0 || this->damageOverlayTL_ > 0)) |
---|
| 241 | { |
---|
[6310] | 242 | this->damageOverlayTT_ -= dt; |
---|
| 243 | this->damageOverlayTR_ -= dt; |
---|
| 244 | this->damageOverlayTB_ -= dt; |
---|
| 245 | this->damageOverlayTL_ -= dt; |
---|
[6377] | 246 | if (this->damageOverlayTT_ <= 0) |
---|
[6310] | 247 | this->damageOverlayTop_->hide(); |
---|
[6377] | 248 | if (this->damageOverlayTR_ <= 0) |
---|
[6310] | 249 | this->damageOverlayRight_->hide(); |
---|
[6377] | 250 | if (this->damageOverlayTB_ <= 0) |
---|
[6310] | 251 | this->damageOverlayBottom_->hide(); |
---|
[6377] | 252 | if (this->damageOverlayTL_ <= 0) |
---|
[6310] | 253 | this->damageOverlayLeft_->hide(); |
---|
| 254 | } |
---|
[6195] | 255 | } |
---|
[6122] | 256 | } |
---|
[6279] | 257 | else |
---|
| 258 | this->hideOverlays(); |
---|
[6210] | 259 | |
---|
[6377] | 260 | if (this->acceleration_ > 0) |
---|
[6173] | 261 | { |
---|
[6377] | 262 | if (this->accelerating_) |
---|
[6173] | 263 | HumanController::moveFrontBack(Vector2(1, 0)); |
---|
| 264 | else |
---|
[6388] | 265 | HumanController::moveFrontBack(Vector2(this->acceleration_, 0)); |
---|
[6173] | 266 | this->accelerating_ = false; |
---|
| 267 | //HumanController::moveFrontBack(Vector2(clamp(this->acceleration_ + this->currentAcceleration_, 0.0f, 1.0f), 0)); |
---|
| 268 | } |
---|
[6111] | 269 | } |
---|
[6001] | 270 | |
---|
[6360] | 271 | // Reset pitch and yaw rates |
---|
[6365] | 272 | // TODO: Reactivate this to fix the game pad problem with 0 input |
---|
| 273 | //this->currentPitch_ = 0; |
---|
| 274 | //this->currentYaw_ = 0; |
---|
[6360] | 275 | |
---|
[6001] | 276 | HumanController::tick(dt); |
---|
| 277 | } |
---|
| 278 | |
---|
[6033] | 279 | void NewHumanController::doFire(unsigned int firemode) |
---|
| 280 | { |
---|
[6377] | 281 | if (!this->controllableEntity_) |
---|
[6316] | 282 | return; |
---|
[6033] | 283 | |
---|
[6210] | 284 | this->firemode_ = firemode; |
---|
| 285 | |
---|
[6157] | 286 | if (firemode == 1 && this->controlMode_ == 1) |
---|
| 287 | { |
---|
[6143] | 288 | //unlocked steering, steer on right mouse click |
---|
[6144] | 289 | HumanController::yaw(Vector2(this->currentYaw_, 0)); |
---|
| 290 | HumanController::pitch(Vector2(this->currentPitch_, 0)); |
---|
[6143] | 291 | } |
---|
[6157] | 292 | else |
---|
[9016] | 293 | HumanController::doFire(firemode); //call for formationflight |
---|
[6045] | 294 | } |
---|
| 295 | |
---|
[6377] | 296 | void NewHumanController::hit(Pawn* originator, btManifoldPoint& contactpoint, float damage) |
---|
| 297 | { |
---|
[9016] | 298 | //Used in HumanController for formationFlight |
---|
| 299 | HumanController::hit(originator,contactpoint,damage); |
---|
[9348] | 300 | |
---|
[6377] | 301 | if (this->showDamageOverlay_ && !this->controlPaused_ && this->controllableEntity_ && !this->controllableEntity_->isInMouseLook()) |
---|
| 302 | { |
---|
[6310] | 303 | Vector3 posA; |
---|
[6377] | 304 | if (originator) |
---|
[6310] | 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 | |
---|
[6502] | 318 | float threshold = 0.3f; |
---|
[6377] | 319 | if (relativeHit.x > threshold) // Left |
---|
[6310] | 320 | { |
---|
| 321 | this->damageOverlayLeft_->show(); |
---|
| 322 | this->damageOverlayTL_ = this->damageOverlayTime_; |
---|
| 323 | //this->damageOverlayLeft_->setBackgroundAlpha(0.3); |
---|
| 324 | } |
---|
[6377] | 325 | if (relativeHit.x < -threshold) //Right |
---|
[6310] | 326 | { |
---|
| 327 | this->damageOverlayRight_->show(); |
---|
| 328 | this->damageOverlayTR_ = this->damageOverlayTime_; |
---|
| 329 | //this->damageOverlayRight_->setBackgroundAlpha(0.3); |
---|
| 330 | } |
---|
[6377] | 331 | if (relativeHit.y > threshold) //Top |
---|
[6310] | 332 | { |
---|
[6312] | 333 | this->damageOverlayBottom_->show(); |
---|
| 334 | this->damageOverlayTB_ = this->damageOverlayTime_; |
---|
[6310] | 335 | //this->damageOverlayTop_->setBackgroundAlpha(0.3); |
---|
| 336 | } |
---|
[6377] | 337 | if (relativeHit.y < -threshold) //Bottom |
---|
[6310] | 338 | { |
---|
[6312] | 339 | this->damageOverlayTop_->show(); |
---|
| 340 | this->damageOverlayTT_ = this->damageOverlayTime_; |
---|
[6310] | 341 | //this->damageOverlayBottom_->setBackgroundAlpha(0.3); |
---|
| 342 | } |
---|
| 343 | } |
---|
[6295] | 344 | } |
---|
| 345 | |
---|
[11153] | 346 | void NewHumanController::release(unsigned int firemode) |
---|
[6210] | 347 | { |
---|
| 348 | if (NewHumanController::localController_s) |
---|
[11153] | 349 | NewHumanController::localController_s->doRelease(); |
---|
| 350 | orxout() << "Trigger" << endl; |
---|
[6210] | 351 | } |
---|
| 352 | |
---|
[11153] | 353 | void NewHumanController::doRelease(unsigned int firemode) |
---|
[6210] | 354 | { |
---|
[11153] | 355 | // this->firemode_ = -1; (outdated code from unfire) |
---|
| 356 | // hideArrows(); |
---|
| 357 | if (!this->controllableEntity_) |
---|
| 358 | return; |
---|
| 359 | |
---|
| 360 | this->firemode_ = firemode; |
---|
| 361 | |
---|
| 362 | HumanController::doRelease(firemode); //call for formationflight |
---|
[6210] | 363 | } |
---|
| 364 | |
---|
[7859] | 365 | void NewHumanController::centerCursor() |
---|
| 366 | { |
---|
| 367 | this->currentYaw_ = 0; |
---|
| 368 | this->currentPitch_ = 0; |
---|
| 369 | |
---|
[8316] | 370 | if( KeyBinderManager::exists() ) |
---|
| 371 | KeyBinderManager::getInstance().getCurrent()->resetMouseAxes(); |
---|
[7859] | 372 | } |
---|
| 373 | |
---|
[6111] | 374 | void NewHumanController::updateTarget() |
---|
[6055] | 375 | { |
---|
| 376 | Ogre::RaySceneQuery * rsq = HumanController::localController_s->getControllableEntity()->getScene()->getSceneManager()->createRayQuery(Ogre::Ray()); |
---|
[6033] | 377 | |
---|
[6502] | 378 | Ogre::Ray mouseRay = HumanController::localController_s->getControllableEntity()->getCamera()->getOgreCamera()->getCameraToViewportRay(static_cast<float>(this->currentYaw_)/2*-1+.5f, static_cast<float>(this->currentPitch_)/2*-1+.5f); |
---|
[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()); |
---|
[7163] | 394 | WorldEntity* myWe = static_cast<WorldEntity*>(this->getControllableEntity()); |
---|
[6033] | 395 | |
---|
[6055] | 396 | Ogre::RaySceneQueryResult::iterator itr; |
---|
| 397 | for (itr = result.begin(); itr != result.end(); ++itr) |
---|
| 398 | { |
---|
[8858] | 399 | // orxout() << "testing object as target" << endl; |
---|
[7801] | 400 | if (itr->movable->isInScene() && itr->movable->getMovableType() == "Entity" && itr->distance > 200) |
---|
[6045] | 401 | { |
---|
[6055] | 402 | // Try to cast the user pointer |
---|
[7163] | 403 | WorldEntity* wePtr; |
---|
| 404 | try |
---|
| 405 | { |
---|
[9348] | 406 | wePtr = orxonox_cast<WorldEntity*>(Ogre::any_cast<OrxonoxClass*>(itr->movable->getUserAny())); |
---|
[7163] | 407 | } |
---|
| 408 | catch (...) |
---|
| 409 | { |
---|
| 410 | continue; |
---|
| 411 | } |
---|
| 412 | |
---|
| 413 | // make sure we don't shoot ourselves |
---|
| 414 | if( wePtr==myWe ) |
---|
| 415 | continue; |
---|
| 416 | |
---|
[6055] | 417 | if (wePtr) |
---|
| 418 | { |
---|
[6377] | 419 | // go through all parents of object and look whether they are sightable or not |
---|
[6114] | 420 | bool isSightable = false; |
---|
| 421 | WorldEntity* parent = wePtr->getParent(); |
---|
[6377] | 422 | while (parent) |
---|
[6114] | 423 | { |
---|
[7163] | 424 | if (this->targetMask_.isExcluded(parent->getIdentifier()) || parent==myWe) |
---|
[6114] | 425 | { |
---|
| 426 | parent = parent->getParent(); |
---|
| 427 | continue; |
---|
| 428 | } |
---|
| 429 | else |
---|
| 430 | { |
---|
| 431 | isSightable = true; |
---|
| 432 | break; |
---|
| 433 | } |
---|
| 434 | } |
---|
[6377] | 435 | if (!isSightable) |
---|
[6055] | 436 | continue; |
---|
[6045] | 437 | } |
---|
[6143] | 438 | |
---|
[6377] | 439 | if (this->getControllableEntity() && this->getControllableEntity()->getTarget() != wePtr) |
---|
[6116] | 440 | this->getControllableEntity()->setTarget(wePtr); |
---|
[6091] | 441 | |
---|
[6377] | 442 | if (pawn) |
---|
[6143] | 443 | pawn->setAimPosition( mouseRay.getOrigin() + mouseRay.getDirection() * itr->distance ); |
---|
| 444 | |
---|
[6195] | 445 | //itr->movable->getParentSceneNode()->showBoundingBox(true); |
---|
[6111] | 446 | //return mouseRay.getOrigin() + mouseRay.getDirection() * itr->distance; //or itr->movable->getParentSceneNode()->_getDerivedPosition() |
---|
| 447 | return; |
---|
[6045] | 448 | } |
---|
[6377] | 449 | } |
---|
[6091] | 450 | |
---|
[6377] | 451 | if (pawn) |
---|
[9939] | 452 | pawn->setAimPosition( mouseRay.getOrigin() + mouseRay.getDirection() * 3000 ); |
---|
[6143] | 453 | |
---|
[11071] | 454 | if( this->getControllableEntity() && this->getControllableEntity()->getTarget() != nullptr ) |
---|
| 455 | this->getControllableEntity()->setTarget( nullptr ); |
---|
[6033] | 456 | |
---|
[6091] | 457 | //return this->controllableEntity_->getWorldPosition() + (this->controllableEntity_->getWorldOrientation() * Vector3::NEGATIVE_UNIT_Z * 2000); |
---|
[6058] | 458 | //return this->controllableEntity_->getWorldPosition() + (this->controllableEntity_->getCamera()->getOgreCamera()->getOrientation() * Vector3::NEGATIVE_UNIT_Z); |
---|
[6033] | 459 | } |
---|
| 460 | |
---|
[6149] | 461 | void NewHumanController::frontback(const Vector2& value) |
---|
| 462 | { |
---|
[6173] | 463 | this->accelerating_ = true; |
---|
[6149] | 464 | |
---|
[6173] | 465 | //if (this->acceleration_ == 0) |
---|
[6377] | 466 | HumanController::frontback(value); |
---|
[6149] | 467 | } |
---|
| 468 | |
---|
[5993] | 469 | void NewHumanController::yaw(const Vector2& value) |
---|
| 470 | { |
---|
[6377] | 471 | //SUPER(NewHumanController, yaw, value); |
---|
| 472 | if (this->controlMode_ == 0 || (this->controllableEntity_ && this->controllableEntity_->isInMouseLook())) |
---|
[6091] | 473 | HumanController::yaw(value); |
---|
[6143] | 474 | |
---|
[7163] | 475 | if (this->getControllableEntity() && !this->getControllableEntity()->isExactlyA(ClassByString("FpsPlayer"))) |
---|
| 476 | this->currentYaw_ = value.x; |
---|
[5979] | 477 | } |
---|
[6055] | 478 | |
---|
[5993] | 479 | void NewHumanController::pitch(const Vector2& value) |
---|
[5981] | 480 | { |
---|
[6377] | 481 | //SUPER(NewHumanController, pitch, value); |
---|
| 482 | if (this->controlMode_ == 0 || (this->controllableEntity_ && this->controllableEntity_->isInMouseLook())) |
---|
[6091] | 483 | HumanController::pitch(value); |
---|
| 484 | |
---|
[7163] | 485 | if (this->getControllableEntity() && !this->getControllableEntity()->isExactlyA(ClassByString("FpsPlayer"))) |
---|
| 486 | this->currentPitch_ = value.x; |
---|
[5981] | 487 | } |
---|
[6091] | 488 | |
---|
[6149] | 489 | void NewHumanController::changeMode() |
---|
| 490 | { |
---|
[6365] | 491 | if (NewHumanController::localController_s) |
---|
[6111] | 492 | { |
---|
[6365] | 493 | if (NewHumanController::localController_s->controlMode_ == 0) |
---|
| 494 | { |
---|
[6111] | 495 | NewHumanController::localController_s->controlMode_ = 1; |
---|
[6210] | 496 | NewHumanController::localController_s->hideArrows(); |
---|
[6365] | 497 | } |
---|
| 498 | else |
---|
| 499 | NewHumanController::localController_s->controlMode_ = 0; |
---|
[6111] | 500 | } |
---|
[6091] | 501 | } |
---|
[6143] | 502 | |
---|
[6115] | 503 | void NewHumanController::changedControllableEntity() |
---|
| 504 | { |
---|
[10631] | 505 | HumanController::changedControllableEntity(); // super |
---|
| 506 | |
---|
[6115] | 507 | this->controlMode_ = 0; |
---|
[7859] | 508 | this->centerCursor(); |
---|
[10216] | 509 | if (this->getControllableEntity() && ((this->getControllableEntity()->isExactlyA(ClassByString("SpaceShip")) || (this->getControllableEntity()->isExactlyA(ClassByString("ModularSpaceShip")))) || this->getControllableEntity()->isExactlyA(ClassByString("Rocket")))) |
---|
[6236] | 510 | { |
---|
| 511 | this->showOverlays_ = true; |
---|
[6377] | 512 | if (!this->controlPaused_) |
---|
[6236] | 513 | { |
---|
| 514 | this->showOverlays(); |
---|
| 515 | this->alignArrows(); |
---|
| 516 | } |
---|
| 517 | } |
---|
| 518 | else |
---|
| 519 | { |
---|
| 520 | this->showOverlays_ = false; |
---|
| 521 | this->hideOverlays(); |
---|
| 522 | } |
---|
[6115] | 523 | } |
---|
[6149] | 524 | |
---|
| 525 | void NewHumanController::accelerate() |
---|
| 526 | { |
---|
[6377] | 527 | if (NewHumanController::localController_s) |
---|
[6173] | 528 | NewHumanController::localController_s->acceleration_ = clamp(NewHumanController::localController_s->acceleration_ + 0.2f, 0.00f, 1.0f); |
---|
[6149] | 529 | } |
---|
| 530 | |
---|
| 531 | void NewHumanController::decelerate() |
---|
| 532 | { |
---|
[6377] | 533 | if (NewHumanController::localController_s) |
---|
[6173] | 534 | NewHumanController::localController_s->acceleration_ = clamp(NewHumanController::localController_s->acceleration_ - 0.1f, 0.0f, 1.0f); |
---|
[6149] | 535 | } |
---|
[6195] | 536 | |
---|
[6377] | 537 | void NewHumanController::doResumeControl() |
---|
| 538 | { |
---|
[6195] | 539 | this->controlPaused_ = false; |
---|
[6377] | 540 | if (this->showOverlays_) |
---|
[6236] | 541 | this->showOverlays(); |
---|
[6195] | 542 | } |
---|
| 543 | |
---|
[6377] | 544 | void NewHumanController::doPauseControl() |
---|
| 545 | { |
---|
[6195] | 546 | this->controlPaused_ = true; |
---|
[6236] | 547 | this->hideOverlays(); |
---|
[6195] | 548 | } |
---|
[6210] | 549 | |
---|
[6377] | 550 | void NewHumanController::alignArrows() |
---|
| 551 | { |
---|
| 552 | if (showArrows_) |
---|
| 553 | { |
---|
[6210] | 554 | hideArrows(); |
---|
[6387] | 555 | |
---|
[6210] | 556 | float distance = sqrt(pow(static_cast<float>(this->currentYaw_)/2*-1,2) + pow(static_cast<float>(this->currentPitch_)/2*-1,2)); |
---|
[6387] | 557 | |
---|
[6502] | 558 | if (distance > 0.04f && distance <= 0.59f * arrowsSize_ / 2.0f ) |
---|
[6377] | 559 | { |
---|
[8351] | 560 | this->arrowsOverlay1_->setRotation(Degree(-90 + -1.0f * atan2(static_cast<float>(this->currentPitch_)/2*-1, static_cast<float>(this->currentYaw_)/2*-1) / math::twoPi * 360.0f)); |
---|
[6210] | 561 | this->arrowsOverlay1_->show(); |
---|
| 562 | } |
---|
[6502] | 563 | else if (distance > 0.59f * arrowsSize_ / 2.0f && distance <= 0.77f * arrowsSize_ / 2.0f ) |
---|
[6377] | 564 | { |
---|
[8351] | 565 | this->arrowsOverlay2_->setRotation(Degree(-90 + -1.0f * atan2(static_cast<float>(this->currentPitch_)/2*-1, static_cast<float>(this->currentYaw_)/2*-1) / math::twoPi * 360.0f)); |
---|
[6210] | 566 | this->arrowsOverlay2_->show(); |
---|
| 567 | } |
---|
[6502] | 568 | else if (distance > 0.77f * arrowsSize_ / 2.0f && distance <= arrowsSize_ / 2.0f) |
---|
[6377] | 569 | { |
---|
[8351] | 570 | this->arrowsOverlay3_->setRotation(Degree(-90 + -1.0f * atan2(static_cast<float>(this->currentPitch_)/2*-1, static_cast<float>(this->currentYaw_)/2*-1) / math::twoPi * 360.0f)); |
---|
[6210] | 571 | this->arrowsOverlay3_->show(); |
---|
| 572 | } |
---|
[6502] | 573 | else if (distance > arrowsSize_ / 2.0f) |
---|
[6377] | 574 | { |
---|
[8351] | 575 | this->arrowsOverlay4_->setRotation(Degree(-90 + -1.0f * atan2(static_cast<float>(this->currentPitch_)/2*-1, static_cast<float>(this->currentYaw_)/2*-1) / math::twoPi * 360.0f)); |
---|
[6210] | 576 | this->arrowsOverlay4_->show(); |
---|
| 577 | } |
---|
| 578 | } |
---|
| 579 | } |
---|
| 580 | |
---|
[6377] | 581 | void NewHumanController::showOverlays() |
---|
| 582 | { |
---|
| 583 | if (!GameMode::showsGraphics()) |
---|
[6320] | 584 | return; |
---|
[6236] | 585 | this->crossHairOverlay_->show(); |
---|
| 586 | this->centerOverlay_->show(); |
---|
[6289] | 587 | |
---|
[6377] | 588 | if (showArrows_) |
---|
| 589 | { |
---|
[6236] | 590 | this->arrowsOverlay1_->show(); |
---|
| 591 | this->arrowsOverlay2_->show(); |
---|
| 592 | this->arrowsOverlay3_->show(); |
---|
| 593 | this->arrowsOverlay4_->show(); |
---|
| 594 | } |
---|
| 595 | } |
---|
| 596 | |
---|
[6377] | 597 | void NewHumanController::hideOverlays() |
---|
| 598 | { |
---|
| 599 | if (!GameMode::showsGraphics()) |
---|
[6320] | 600 | return; |
---|
[6236] | 601 | this->crossHairOverlay_->hide(); |
---|
| 602 | this->centerOverlay_->hide(); |
---|
[6289] | 603 | |
---|
[6377] | 604 | if (showDamageOverlay_) |
---|
| 605 | { |
---|
[6310] | 606 | this->damageOverlayTop_->hide(); |
---|
| 607 | this->damageOverlayRight_->hide(); |
---|
| 608 | this->damageOverlayBottom_->hide(); |
---|
| 609 | this->damageOverlayLeft_->hide(); |
---|
| 610 | } |
---|
| 611 | |
---|
[6236] | 612 | this->hideArrows(); |
---|
| 613 | } |
---|
| 614 | |
---|
[6377] | 615 | void NewHumanController::hideArrows() |
---|
| 616 | { |
---|
| 617 | if(!GameMode::showsGraphics()) |
---|
[6320] | 618 | return; |
---|
[6377] | 619 | if (showArrows_) |
---|
| 620 | { |
---|
[6210] | 621 | this->arrowsOverlay1_->hide(); |
---|
| 622 | this->arrowsOverlay2_->hide(); |
---|
| 623 | this->arrowsOverlay3_->hide(); |
---|
| 624 | this->arrowsOverlay4_->hide(); |
---|
| 625 | } |
---|
| 626 | } |
---|
[7163] | 627 | |
---|
| 628 | |
---|
| 629 | |
---|
| 630 | |
---|
| 631 | |
---|
[5979] | 632 | } |
---|