[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(); |
---|
| 219 | |
---|
[6502] | 220 | 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] | 221 | |
---|
[6377] | 222 | if (this->controlMode_ == 0 || (this->controlMode_ == 1 && this->firemode_ == 1)) |
---|
[6236] | 223 | { |
---|
[6377] | 224 | if (this->showOverlays_ && this->showArrows_) |
---|
[6236] | 225 | alignArrows(); |
---|
| 226 | } |
---|
[6210] | 227 | else |
---|
| 228 | hideArrows(); |
---|
[6310] | 229 | |
---|
[6377] | 230 | if (this->showDamageOverlay_ && (this->damageOverlayTT_ > 0 || this->damageOverlayTR_ > 0 || this->damageOverlayTB_ > 0 || this->damageOverlayTL_ > 0)) |
---|
| 231 | { |
---|
[6310] | 232 | this->damageOverlayTT_ -= dt; |
---|
| 233 | this->damageOverlayTR_ -= dt; |
---|
| 234 | this->damageOverlayTB_ -= dt; |
---|
| 235 | this->damageOverlayTL_ -= dt; |
---|
[6377] | 236 | if (this->damageOverlayTT_ <= 0) |
---|
[6310] | 237 | this->damageOverlayTop_->hide(); |
---|
[6377] | 238 | if (this->damageOverlayTR_ <= 0) |
---|
[6310] | 239 | this->damageOverlayRight_->hide(); |
---|
[6377] | 240 | if (this->damageOverlayTB_ <= 0) |
---|
[6310] | 241 | this->damageOverlayBottom_->hide(); |
---|
[6377] | 242 | if (this->damageOverlayTL_ <= 0) |
---|
[6310] | 243 | this->damageOverlayLeft_->hide(); |
---|
| 244 | } |
---|
[6195] | 245 | } |
---|
[6122] | 246 | } |
---|
[6279] | 247 | else |
---|
| 248 | this->hideOverlays(); |
---|
[6210] | 249 | |
---|
[6377] | 250 | if (this->acceleration_ > 0) |
---|
[6173] | 251 | { |
---|
[6377] | 252 | if (this->accelerating_) |
---|
[6173] | 253 | HumanController::moveFrontBack(Vector2(1, 0)); |
---|
| 254 | else |
---|
[6388] | 255 | HumanController::moveFrontBack(Vector2(this->acceleration_, 0)); |
---|
[6173] | 256 | this->accelerating_ = false; |
---|
| 257 | //HumanController::moveFrontBack(Vector2(clamp(this->acceleration_ + this->currentAcceleration_, 0.0f, 1.0f), 0)); |
---|
| 258 | } |
---|
[6111] | 259 | } |
---|
[6001] | 260 | |
---|
[6360] | 261 | // Reset pitch and yaw rates |
---|
[6365] | 262 | // TODO: Reactivate this to fix the game pad problem with 0 input |
---|
| 263 | //this->currentPitch_ = 0; |
---|
| 264 | //this->currentYaw_ = 0; |
---|
[6360] | 265 | |
---|
[6001] | 266 | HumanController::tick(dt); |
---|
| 267 | } |
---|
| 268 | |
---|
[6033] | 269 | void NewHumanController::doFire(unsigned int firemode) |
---|
| 270 | { |
---|
[6377] | 271 | if (!this->controllableEntity_) |
---|
[6316] | 272 | return; |
---|
[6033] | 273 | |
---|
[6210] | 274 | this->firemode_ = firemode; |
---|
| 275 | |
---|
[6157] | 276 | if (firemode == 1 && this->controlMode_ == 1) |
---|
| 277 | { |
---|
[6143] | 278 | //unlocked steering, steer on right mouse click |
---|
[6144] | 279 | HumanController::yaw(Vector2(this->currentYaw_, 0)); |
---|
| 280 | HumanController::pitch(Vector2(this->currentPitch_, 0)); |
---|
[6143] | 281 | } |
---|
[6157] | 282 | else |
---|
[6143] | 283 | HumanController::localController_s->getControllableEntity()->fire(firemode); |
---|
| 284 | |
---|
[6045] | 285 | } |
---|
| 286 | |
---|
[6377] | 287 | void NewHumanController::hit(Pawn* originator, btManifoldPoint& contactpoint, float damage) |
---|
| 288 | { |
---|
| 289 | if (this->showDamageOverlay_ && !this->controlPaused_ && this->controllableEntity_ && !this->controllableEntity_->isInMouseLook()) |
---|
| 290 | { |
---|
[6310] | 291 | Vector3 posA; |
---|
[6377] | 292 | if (originator) |
---|
[6310] | 293 | posA = originator->getWorldPosition(); |
---|
| 294 | else |
---|
| 295 | posA = multi_cast<Vector3>(contactpoint.getPositionWorldOnA()); |
---|
| 296 | //Vector3 posB = multi_cast<Vector3>(contactpoint.getPositionWorldOnB()); |
---|
| 297 | //posA and posB are almost identical |
---|
[6295] | 298 | |
---|
[6310] | 299 | Vector3 relativeHit = this->getControllableEntity()->getWorldOrientation().UnitInverse() * (this->getControllableEntity()->getWorldPosition() - posA); |
---|
[6295] | 300 | |
---|
[6310] | 301 | //back is z positive |
---|
| 302 | //x is left positive |
---|
| 303 | //y is down positive |
---|
| 304 | relativeHit.normalise(); |
---|
| 305 | |
---|
[6502] | 306 | float threshold = 0.3f; |
---|
[6377] | 307 | if (relativeHit.x > threshold) // Left |
---|
[6310] | 308 | { |
---|
| 309 | this->damageOverlayLeft_->show(); |
---|
| 310 | this->damageOverlayTL_ = this->damageOverlayTime_; |
---|
| 311 | //this->damageOverlayLeft_->setBackgroundAlpha(0.3); |
---|
| 312 | } |
---|
[6377] | 313 | if (relativeHit.x < -threshold) //Right |
---|
[6310] | 314 | { |
---|
| 315 | this->damageOverlayRight_->show(); |
---|
| 316 | this->damageOverlayTR_ = this->damageOverlayTime_; |
---|
| 317 | //this->damageOverlayRight_->setBackgroundAlpha(0.3); |
---|
| 318 | } |
---|
[6377] | 319 | if (relativeHit.y > threshold) //Top |
---|
[6310] | 320 | { |
---|
[6312] | 321 | this->damageOverlayBottom_->show(); |
---|
| 322 | this->damageOverlayTB_ = this->damageOverlayTime_; |
---|
[6310] | 323 | //this->damageOverlayTop_->setBackgroundAlpha(0.3); |
---|
| 324 | } |
---|
[6377] | 325 | if (relativeHit.y < -threshold) //Bottom |
---|
[6310] | 326 | { |
---|
[6312] | 327 | this->damageOverlayTop_->show(); |
---|
| 328 | this->damageOverlayTT_ = this->damageOverlayTime_; |
---|
[6310] | 329 | //this->damageOverlayBottom_->setBackgroundAlpha(0.3); |
---|
| 330 | } |
---|
| 331 | } |
---|
[6295] | 332 | } |
---|
| 333 | |
---|
[6210] | 334 | void NewHumanController::unfire() |
---|
| 335 | { |
---|
| 336 | if (NewHumanController::localController_s) |
---|
| 337 | NewHumanController::localController_s->doUnfire(); |
---|
| 338 | } |
---|
| 339 | |
---|
| 340 | void NewHumanController::doUnfire() |
---|
| 341 | { |
---|
| 342 | this->firemode_ = -1; |
---|
| 343 | hideArrows(); |
---|
| 344 | } |
---|
| 345 | |
---|
[6111] | 346 | void NewHumanController::updateTarget() |
---|
[6055] | 347 | { |
---|
| 348 | Ogre::RaySceneQuery * rsq = HumanController::localController_s->getControllableEntity()->getScene()->getSceneManager()->createRayQuery(Ogre::Ray()); |
---|
[6033] | 349 | |
---|
[6502] | 350 | 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] | 351 | |
---|
[6055] | 352 | rsq->setRay(mouseRay); |
---|
| 353 | rsq->setSortByDistance(true); |
---|
[6033] | 354 | |
---|
[6055] | 355 | /* |
---|
| 356 | Distance of objects: |
---|
| 357 | ignore everything under 200 maybe even take 1000 as min distance to shoot at |
---|
[6033] | 358 | |
---|
[6055] | 359 | shots are regularly traced and are entities!!!!!!!!! this is the biggest problem |
---|
| 360 | they vanish only after a distance of 10'000 |
---|
| 361 | */ |
---|
[6045] | 362 | |
---|
| 363 | |
---|
[6055] | 364 | Ogre::RaySceneQueryResult& result = rsq->execute(); |
---|
[6111] | 365 | Pawn* pawn = orxonox_cast<Pawn*>(this->getControllableEntity()); |
---|
[6033] | 366 | |
---|
[6055] | 367 | Ogre::RaySceneQueryResult::iterator itr; |
---|
| 368 | for (itr = result.begin(); itr != result.end(); ++itr) |
---|
| 369 | { |
---|
| 370 | if (itr->movable->isInScene() && itr->movable->getMovableType() == "Entity" && itr->distance > 500) |
---|
[6045] | 371 | { |
---|
[6055] | 372 | // Try to cast the user pointer |
---|
[6501] | 373 | WorldEntity* wePtr = dynamic_cast<WorldEntity*>(Ogre::any_cast<OrxonoxClass*>(itr->movable->getUserAny())); |
---|
[6055] | 374 | if (wePtr) |
---|
| 375 | { |
---|
[6377] | 376 | // go through all parents of object and look whether they are sightable or not |
---|
[6114] | 377 | bool isSightable = false; |
---|
| 378 | WorldEntity* parent = wePtr->getParent(); |
---|
[6377] | 379 | while (parent) |
---|
[6114] | 380 | { |
---|
| 381 | if (this->targetMask_.isExcluded(parent->getIdentifier())) |
---|
| 382 | { |
---|
| 383 | parent = parent->getParent(); |
---|
| 384 | continue; |
---|
| 385 | } |
---|
| 386 | else |
---|
| 387 | { |
---|
| 388 | isSightable = true; |
---|
| 389 | break; |
---|
| 390 | } |
---|
| 391 | } |
---|
[6377] | 392 | if (!isSightable) |
---|
[6055] | 393 | continue; |
---|
[6045] | 394 | } |
---|
[6143] | 395 | |
---|
[6377] | 396 | if (this->getControllableEntity() && this->getControllableEntity()->getTarget() != wePtr) |
---|
[6116] | 397 | this->getControllableEntity()->setTarget(wePtr); |
---|
[6091] | 398 | |
---|
[6377] | 399 | if (pawn) |
---|
[6143] | 400 | pawn->setAimPosition( mouseRay.getOrigin() + mouseRay.getDirection() * itr->distance ); |
---|
| 401 | |
---|
[6195] | 402 | //itr->movable->getParentSceneNode()->showBoundingBox(true); |
---|
[6111] | 403 | //return mouseRay.getOrigin() + mouseRay.getDirection() * itr->distance; //or itr->movable->getParentSceneNode()->_getDerivedPosition() |
---|
| 404 | return; |
---|
[6045] | 405 | } |
---|
[6377] | 406 | } |
---|
[6091] | 407 | |
---|
[6377] | 408 | if (pawn) |
---|
[6111] | 409 | pawn->setAimPosition( mouseRay.getOrigin() + mouseRay.getDirection() * 1200 ); |
---|
[6143] | 410 | |
---|
| 411 | if( this->getControllableEntity() && this->getControllableEntity()->getTarget() != 0 ) |
---|
| 412 | this->getControllableEntity()->setTarget( 0 ); |
---|
[6033] | 413 | |
---|
[6091] | 414 | //return this->controllableEntity_->getWorldPosition() + (this->controllableEntity_->getWorldOrientation() * Vector3::NEGATIVE_UNIT_Z * 2000); |
---|
[6058] | 415 | //return this->controllableEntity_->getWorldPosition() + (this->controllableEntity_->getCamera()->getOgreCamera()->getOrientation() * Vector3::NEGATIVE_UNIT_Z); |
---|
[6033] | 416 | } |
---|
| 417 | |
---|
[6149] | 418 | void NewHumanController::frontback(const Vector2& value) |
---|
| 419 | { |
---|
[6173] | 420 | this->accelerating_ = true; |
---|
[6149] | 421 | |
---|
[6173] | 422 | //if (this->acceleration_ == 0) |
---|
[6377] | 423 | HumanController::frontback(value); |
---|
[6149] | 424 | } |
---|
| 425 | |
---|
[5993] | 426 | void NewHumanController::yaw(const Vector2& value) |
---|
| 427 | { |
---|
[6377] | 428 | //SUPER(NewHumanController, yaw, value); |
---|
| 429 | if (this->controlMode_ == 0 || (this->controllableEntity_ && this->controllableEntity_->isInMouseLook())) |
---|
[6091] | 430 | HumanController::yaw(value); |
---|
[6143] | 431 | |
---|
[5993] | 432 | this->currentYaw_ = value.x; |
---|
[5979] | 433 | } |
---|
[6055] | 434 | |
---|
[5993] | 435 | void NewHumanController::pitch(const Vector2& value) |
---|
[5981] | 436 | { |
---|
[6377] | 437 | //SUPER(NewHumanController, pitch, value); |
---|
| 438 | if (this->controlMode_ == 0 || (this->controllableEntity_ && this->controllableEntity_->isInMouseLook())) |
---|
[6091] | 439 | HumanController::pitch(value); |
---|
| 440 | |
---|
[5993] | 441 | this->currentPitch_ = value.x; |
---|
[5981] | 442 | } |
---|
[6091] | 443 | |
---|
[6149] | 444 | void NewHumanController::changeMode() |
---|
| 445 | { |
---|
[6365] | 446 | if (NewHumanController::localController_s) |
---|
[6111] | 447 | { |
---|
[6365] | 448 | if (NewHumanController::localController_s->controlMode_ == 0) |
---|
| 449 | { |
---|
[6111] | 450 | NewHumanController::localController_s->controlMode_ = 1; |
---|
[6210] | 451 | NewHumanController::localController_s->hideArrows(); |
---|
[6365] | 452 | } |
---|
| 453 | else |
---|
| 454 | NewHumanController::localController_s->controlMode_ = 0; |
---|
[6111] | 455 | } |
---|
[6091] | 456 | } |
---|
[6143] | 457 | |
---|
[6115] | 458 | void NewHumanController::changedControllableEntity() |
---|
| 459 | { |
---|
| 460 | this->controlMode_ = 0; |
---|
| 461 | this->currentYaw_ = 0; |
---|
| 462 | this->currentPitch_ = 0; |
---|
[6377] | 463 | if (this->getControllableEntity() && (this->getControllableEntity()->isExactlyA(ClassByString("SpaceShip")) || this->getControllableEntity()->isExactlyA(ClassByString("Rocket")))) |
---|
[6236] | 464 | { |
---|
| 465 | this->showOverlays_ = true; |
---|
[6377] | 466 | if (!this->controlPaused_) |
---|
[6236] | 467 | { |
---|
| 468 | this->showOverlays(); |
---|
| 469 | this->alignArrows(); |
---|
| 470 | } |
---|
| 471 | } |
---|
| 472 | else |
---|
| 473 | { |
---|
| 474 | this->showOverlays_ = false; |
---|
| 475 | this->hideOverlays(); |
---|
| 476 | } |
---|
[6115] | 477 | } |
---|
[6149] | 478 | |
---|
| 479 | void NewHumanController::accelerate() |
---|
| 480 | { |
---|
[6377] | 481 | if (NewHumanController::localController_s) |
---|
[6173] | 482 | NewHumanController::localController_s->acceleration_ = clamp(NewHumanController::localController_s->acceleration_ + 0.2f, 0.00f, 1.0f); |
---|
[6149] | 483 | } |
---|
| 484 | |
---|
| 485 | void NewHumanController::decelerate() |
---|
| 486 | { |
---|
[6377] | 487 | if (NewHumanController::localController_s) |
---|
[6173] | 488 | NewHumanController::localController_s->acceleration_ = clamp(NewHumanController::localController_s->acceleration_ - 0.1f, 0.0f, 1.0f); |
---|
[6149] | 489 | } |
---|
[6195] | 490 | |
---|
[6377] | 491 | void NewHumanController::doResumeControl() |
---|
| 492 | { |
---|
[6195] | 493 | this->controlPaused_ = false; |
---|
[6377] | 494 | if (this->showOverlays_) |
---|
[6236] | 495 | this->showOverlays(); |
---|
[6195] | 496 | } |
---|
| 497 | |
---|
[6377] | 498 | void NewHumanController::doPauseControl() |
---|
| 499 | { |
---|
[6195] | 500 | this->controlPaused_ = true; |
---|
[6236] | 501 | this->hideOverlays(); |
---|
[6195] | 502 | } |
---|
[6210] | 503 | |
---|
[6377] | 504 | void NewHumanController::alignArrows() |
---|
| 505 | { |
---|
| 506 | if (showArrows_) |
---|
| 507 | { |
---|
[6210] | 508 | hideArrows(); |
---|
[6387] | 509 | |
---|
[6210] | 510 | float distance = sqrt(pow(static_cast<float>(this->currentYaw_)/2*-1,2) + pow(static_cast<float>(this->currentPitch_)/2*-1,2)); |
---|
[6387] | 511 | |
---|
[6502] | 512 | if (distance > 0.04f && distance <= 0.59f * arrowsSize_ / 2.0f ) |
---|
[6377] | 513 | { |
---|
[6502] | 514 | 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] | 515 | this->arrowsOverlay1_->show(); |
---|
| 516 | } |
---|
[6502] | 517 | else if (distance > 0.59f * arrowsSize_ / 2.0f && distance <= 0.77f * arrowsSize_ / 2.0f ) |
---|
[6377] | 518 | { |
---|
[6502] | 519 | 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] | 520 | this->arrowsOverlay2_->show(); |
---|
| 521 | } |
---|
[6502] | 522 | else if (distance > 0.77f * arrowsSize_ / 2.0f && distance <= arrowsSize_ / 2.0f) |
---|
[6377] | 523 | { |
---|
[6502] | 524 | 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] | 525 | this->arrowsOverlay3_->show(); |
---|
| 526 | } |
---|
[6502] | 527 | else if (distance > arrowsSize_ / 2.0f) |
---|
[6377] | 528 | { |
---|
[6502] | 529 | 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] | 530 | this->arrowsOverlay4_->show(); |
---|
| 531 | } |
---|
| 532 | } |
---|
| 533 | } |
---|
| 534 | |
---|
[6377] | 535 | void NewHumanController::showOverlays() |
---|
| 536 | { |
---|
| 537 | if (!GameMode::showsGraphics()) |
---|
[6320] | 538 | return; |
---|
[6236] | 539 | this->crossHairOverlay_->show(); |
---|
| 540 | this->centerOverlay_->show(); |
---|
[6289] | 541 | |
---|
[6377] | 542 | if (showArrows_) |
---|
| 543 | { |
---|
[6236] | 544 | this->arrowsOverlay1_->show(); |
---|
| 545 | this->arrowsOverlay2_->show(); |
---|
| 546 | this->arrowsOverlay3_->show(); |
---|
| 547 | this->arrowsOverlay4_->show(); |
---|
| 548 | } |
---|
| 549 | } |
---|
| 550 | |
---|
[6377] | 551 | void NewHumanController::hideOverlays() |
---|
| 552 | { |
---|
| 553 | if (!GameMode::showsGraphics()) |
---|
[6320] | 554 | return; |
---|
[6236] | 555 | this->crossHairOverlay_->hide(); |
---|
| 556 | this->centerOverlay_->hide(); |
---|
[6289] | 557 | |
---|
[6377] | 558 | if (showDamageOverlay_) |
---|
| 559 | { |
---|
[6310] | 560 | this->damageOverlayTop_->hide(); |
---|
| 561 | this->damageOverlayRight_->hide(); |
---|
| 562 | this->damageOverlayBottom_->hide(); |
---|
| 563 | this->damageOverlayLeft_->hide(); |
---|
| 564 | } |
---|
| 565 | |
---|
[6236] | 566 | this->hideArrows(); |
---|
| 567 | } |
---|
| 568 | |
---|
[6377] | 569 | void NewHumanController::hideArrows() |
---|
| 570 | { |
---|
| 571 | if(!GameMode::showsGraphics()) |
---|
[6320] | 572 | return; |
---|
[6377] | 573 | if (showArrows_) |
---|
| 574 | { |
---|
[6210] | 575 | this->arrowsOverlay1_->hide(); |
---|
| 576 | this->arrowsOverlay2_->hide(); |
---|
| 577 | this->arrowsOverlay3_->hide(); |
---|
| 578 | this->arrowsOverlay4_->hide(); |
---|
| 579 | } |
---|
| 580 | } |
---|
[5979] | 581 | } |
---|