[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 | |
---|
[6033] | 31 | #include <OgreRay.h> |
---|
| 32 | #include <OgreSceneQuery.h> |
---|
| 33 | #include <OgreCamera.h> |
---|
| 34 | #include <OgreSceneManager.h> |
---|
[5981] | 35 | |
---|
[5979] | 36 | #include "core/CoreIncludes.h" |
---|
| 37 | #include "core/ConsoleCommand.h" |
---|
| 38 | #include "worldentities/ControllableEntity.h" |
---|
| 39 | #include "infos/PlayerInfo.h" |
---|
[6055] | 40 | #include "overlays/OrxonoxOverlay.h" |
---|
[5979] | 41 | #include "graphics/Camera.h" |
---|
| 42 | #include "sound/SoundManager.h" |
---|
| 43 | #include "Scene.h" |
---|
| 44 | |
---|
| 45 | namespace orxonox |
---|
| 46 | { |
---|
[6091] | 47 | SetConsoleCommand(NewHumanController, changeMode, false).keybindMode(KeybindMode::OnPress); |
---|
| 48 | |
---|
[5979] | 49 | CreateUnloadableFactory(NewHumanController); |
---|
| 50 | |
---|
[6091] | 51 | NewHumanController* NewHumanController::localController_s = 0; |
---|
| 52 | |
---|
[5979] | 53 | NewHumanController::NewHumanController(BaseObject* creator) : HumanController(creator) |
---|
| 54 | { |
---|
| 55 | RegisterObject(NewHumanController); |
---|
[6001] | 56 | |
---|
[6055] | 57 | overlaySize_ = 0.08; |
---|
| 58 | controlMode_ = 0; |
---|
[6033] | 59 | |
---|
[6055] | 60 | crossHairOverlay_ = new OrxonoxOverlay(this); |
---|
| 61 | crossHairOverlay_->setBackgroundMaterial("Orxonox/Crosshair3"); |
---|
| 62 | crossHairOverlay_->setSize(Vector2(overlaySize_, overlaySize_)); |
---|
| 63 | crossHairOverlay_->show(); |
---|
[6045] | 64 | |
---|
[6058] | 65 | // HACK: Define which objects are targetable when considering the creator of an orxonox::Model |
---|
[6055] | 66 | this->targetMask_.exclude(ClassByString("BaseObject")); |
---|
| 67 | this->targetMask_.include(ClassByString("WorldEntity")); |
---|
| 68 | this->targetMask_.exclude(ClassByString("Projectile")); |
---|
[6091] | 69 | |
---|
| 70 | NewHumanController::localController_s = this; |
---|
[5979] | 71 | } |
---|
| 72 | |
---|
| 73 | NewHumanController::~NewHumanController() |
---|
| 74 | { |
---|
[6055] | 75 | if (this->isInitialized()) |
---|
[5981] | 76 | { |
---|
| 77 | } |
---|
[5979] | 78 | } |
---|
| 79 | |
---|
[6055] | 80 | void NewHumanController::tick(float dt) |
---|
| 81 | { |
---|
| 82 | crossHairOverlay_->setPosition(Vector2(static_cast<float>(this->currentYaw_)/2*-1+.5-overlaySize_/2, static_cast<float>(this->currentPitch_)/2*-1+.5-overlaySize_/2)); |
---|
[6001] | 83 | |
---|
| 84 | HumanController::tick(dt); |
---|
| 85 | } |
---|
| 86 | |
---|
[5993] | 87 | /*void NewHumanController::tick(float dt) |
---|
[5979] | 88 | { |
---|
| 89 | if (GameMode::playsSound() && NewHumanController::localController_s && NewHumanController::localController_s->controllableEntity_) |
---|
| 90 | { |
---|
| 91 | // Update sound listener |
---|
| 92 | Camera* camera = NewHumanController::localController_s->controllableEntity_->getCamera(); |
---|
| 93 | if (camera) |
---|
| 94 | { |
---|
| 95 | SoundManager::getInstance().setListenerPosition(camera->getWorldPosition()); |
---|
| 96 | SoundManager::getInstance().setListenerOrientation(camera->getWorldOrientation()); |
---|
| 97 | } |
---|
| 98 | else |
---|
| 99 | COUT(3) << "NewHumanController, Warning: Using a ControllableEntity without Camera" << std::endl; |
---|
| 100 | } |
---|
[5993] | 101 | }*/ |
---|
| 102 | |
---|
[6033] | 103 | void NewHumanController::doFire(unsigned int firemode) |
---|
| 104 | { |
---|
| 105 | //if (HumanController::localController_s && HumanController::localController_s->controllableEntity_) { |
---|
| 106 | |
---|
| 107 | /* |
---|
[6055] | 108 | // Get results, create a node/entity on the position |
---|
| 109 | for ( itr = result.begin(); itr != result.end(); itr++ ) |
---|
| 110 | { |
---|
| 111 | if (itr->movable && itr->movable->getName() == "Head") |
---|
| 112 | { |
---|
| 113 | soundMgr->StopSound( &jaguarSoundChannel ); |
---|
| 114 | soundMgr->PlaySound( jaguarSound, headNode, &jaguarSoundChannel ); |
---|
| 115 | break; |
---|
| 116 | } // if |
---|
| 117 | } |
---|
[6033] | 118 | */ |
---|
| 119 | |
---|
[6055] | 120 | HumanController::localController_s->getControllableEntity()->fire(firemode); |
---|
[6045] | 121 | } |
---|
| 122 | |
---|
[6055] | 123 | Vector3 NewHumanController::getTarget() |
---|
| 124 | { |
---|
| 125 | Ogre::RaySceneQuery * rsq = HumanController::localController_s->getControllableEntity()->getScene()->getSceneManager()->createRayQuery(Ogre::Ray()); |
---|
[6033] | 126 | |
---|
[6058] | 127 | Ogre::Ray mouseRay = HumanController::localController_s->getControllableEntity()->getCamera()->getOgreCamera()->getCameraToViewportRay(static_cast<float>(this->currentYaw_)/2*-1+.5, static_cast<float>(this->currentPitch_)/2*-1+.5); |
---|
[6033] | 128 | |
---|
[6055] | 129 | rsq->setRay(mouseRay); |
---|
| 130 | rsq->setSortByDistance(true); |
---|
[6033] | 131 | |
---|
[6055] | 132 | /* |
---|
| 133 | Distance of objects: |
---|
| 134 | ignore everything under 200 maybe even take 1000 as min distance to shoot at |
---|
[6033] | 135 | |
---|
[6055] | 136 | shots are regularly traced and are entities!!!!!!!!! this is the biggest problem |
---|
| 137 | they vanish only after a distance of 10'000 |
---|
| 138 | */ |
---|
[6045] | 139 | |
---|
| 140 | |
---|
[6055] | 141 | Ogre::RaySceneQueryResult& result = rsq->execute(); |
---|
[6033] | 142 | |
---|
[6055] | 143 | Ogre::RaySceneQueryResult::iterator itr; |
---|
| 144 | for (itr = result.begin(); itr != result.end(); ++itr) |
---|
| 145 | { |
---|
| 146 | if (itr->movable->isInScene() && itr->movable->getMovableType() == "Entity" && itr->distance > 500) |
---|
[6045] | 147 | { |
---|
[6055] | 148 | // Try to cast the user pointer |
---|
| 149 | WorldEntity* wePtr = dynamic_cast<WorldEntity*>(itr->movable->getUserObject()); |
---|
| 150 | if (wePtr) |
---|
| 151 | { |
---|
| 152 | BaseObject* creator = wePtr->getCreator(); |
---|
| 153 | if (this->targetMask_.isExcluded(creator->getIdentifier())) |
---|
| 154 | continue; |
---|
[6045] | 155 | } |
---|
[6091] | 156 | |
---|
[6055] | 157 | itr->movable->getParentSceneNode()->showBoundingBox(true); |
---|
[6091] | 158 | //std::cout << itr->movable->getParentSceneNode()->_getDerivedPosition() << endl; |
---|
| 159 | return mouseRay.getOrigin() + mouseRay.getDirection() * itr->distance; //or itr->movable->getParentSceneNode()->_getDerivedPosition() |
---|
[6045] | 160 | } |
---|
[6091] | 161 | |
---|
[6055] | 162 | } |
---|
[6033] | 163 | |
---|
[6091] | 164 | return mouseRay.getOrigin() + mouseRay.getDirection() * 1200; |
---|
[6033] | 165 | |
---|
[6091] | 166 | //return this->controllableEntity_->getWorldPosition() + (this->controllableEntity_->getWorldOrientation() * Vector3::NEGATIVE_UNIT_Z * 2000); |
---|
[6058] | 167 | //return this->controllableEntity_->getWorldPosition() + (this->controllableEntity_->getCamera()->getOgreCamera()->getOrientation() * Vector3::NEGATIVE_UNIT_Z); |
---|
[6033] | 168 | } |
---|
| 169 | |
---|
[5993] | 170 | void NewHumanController::yaw(const Vector2& value) |
---|
| 171 | { |
---|
| 172 | // SUPER(NewHumanController, yaw, value); |
---|
[6091] | 173 | if (this->controlMode_ == 0) |
---|
| 174 | HumanController::yaw(value); |
---|
[5993] | 175 | |
---|
| 176 | this->currentYaw_ = value.x; |
---|
[6033] | 177 | //std::cout << "Y: " << static_cast<float>(this->currentPitch_) << " X: " << static_cast<float>(this->currentYaw_) << endl; |
---|
[5979] | 178 | } |
---|
[6055] | 179 | |
---|
[5993] | 180 | void NewHumanController::pitch(const Vector2& value) |
---|
[5981] | 181 | { |
---|
[5993] | 182 | // SUPER(NewHumanController, pitch, value); |
---|
[6091] | 183 | if (this->controlMode_ == 0) |
---|
| 184 | HumanController::pitch(value); |
---|
| 185 | |
---|
[5993] | 186 | this->currentPitch_ = value.x; |
---|
[6033] | 187 | //std::cout << "Y: " << static_cast<float>(this->currentPitch_) << " X: " << static_cast<float>(this->currentYaw_) << endl; |
---|
[5981] | 188 | } |
---|
[6091] | 189 | |
---|
| 190 | void NewHumanController::changeMode() { |
---|
| 191 | if (NewHumanController::localController_s->controlMode_ == 0) |
---|
| 192 | NewHumanController::localController_s->controlMode_ = 1; |
---|
| 193 | else |
---|
| 194 | NewHumanController::localController_s->controlMode_ = 0; |
---|
| 195 | } |
---|
[5979] | 196 | } |
---|