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