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