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: |
---|
23 | * Michael Wirth |
---|
24 | * Co-authors: |
---|
25 | * ... |
---|
26 | * |
---|
27 | */ |
---|
28 | |
---|
29 | #include "NewHumanController.h" |
---|
30 | |
---|
31 | #include <OgreRay.h> |
---|
32 | #include <OgreSceneQuery.h> |
---|
33 | #include <OgreCamera.h> |
---|
34 | #include <OgreSceneManager.h> |
---|
35 | |
---|
36 | #include "core/CoreIncludes.h" |
---|
37 | #include "core/ConsoleCommand.h" |
---|
38 | #include "worldentities/ControllableEntity.h" |
---|
39 | #include "worldentities/pawns/Pawn.h" |
---|
40 | #include "gametypes/Gametype.h" |
---|
41 | #include "infos/PlayerInfo.h" |
---|
42 | #include "overlays/Map.h" |
---|
43 | #include "graphics/Camera.h" |
---|
44 | #include "sound/SoundManager.h" |
---|
45 | #include "Radar.h" |
---|
46 | #include "Scene.h" |
---|
47 | |
---|
48 | namespace orxonox |
---|
49 | { |
---|
50 | |
---|
51 | CreateUnloadableFactory(NewHumanController); |
---|
52 | |
---|
53 | NewHumanController::NewHumanController(BaseObject* creator) : HumanController(creator) |
---|
54 | { |
---|
55 | RegisterObject(NewHumanController); |
---|
56 | |
---|
57 | overlaySize = 0.08; |
---|
58 | |
---|
59 | controlMode = 0; |
---|
60 | |
---|
61 | CrossHairOverlay = new OrxonoxOverlay(this); |
---|
62 | CrossHairOverlay->setBackgroundMaterial("Orxonox/Crosshair3"); |
---|
63 | CrossHairOverlay->setSize(Vector2(overlaySize,overlaySize)); |
---|
64 | CrossHairOverlay->show(); |
---|
65 | } |
---|
66 | |
---|
67 | NewHumanController::~NewHumanController() |
---|
68 | { |
---|
69 | if( this->isInitialized() ) |
---|
70 | { |
---|
71 | } |
---|
72 | } |
---|
73 | |
---|
74 | void NewHumanController::tick(float dt) { |
---|
75 | CrossHairOverlay->setPosition(Vector2(static_cast<float>(this->currentYaw_)/2*-1+.5-overlaySize/2, static_cast<float>(this->currentPitch_)/2*-1+.5-overlaySize/2)); |
---|
76 | |
---|
77 | HumanController::tick(dt); |
---|
78 | } |
---|
79 | |
---|
80 | /*void NewHumanController::tick(float dt) |
---|
81 | { |
---|
82 | if (GameMode::playsSound() && NewHumanController::localController_s && NewHumanController::localController_s->controllableEntity_) |
---|
83 | { |
---|
84 | // Update sound listener |
---|
85 | Camera* camera = NewHumanController::localController_s->controllableEntity_->getCamera(); |
---|
86 | if (camera) |
---|
87 | { |
---|
88 | SoundManager::getInstance().setListenerPosition(camera->getWorldPosition()); |
---|
89 | SoundManager::getInstance().setListenerOrientation(camera->getWorldOrientation()); |
---|
90 | } |
---|
91 | else |
---|
92 | COUT(3) << "NewHumanController, Warning: Using a ControllableEntity without Camera" << std::endl; |
---|
93 | } |
---|
94 | }*/ |
---|
95 | |
---|
96 | void NewHumanController::doFire(unsigned int firemode) |
---|
97 | { |
---|
98 | //if (HumanController::localController_s && HumanController::localController_s->controllableEntity_) { |
---|
99 | |
---|
100 | /* |
---|
101 | |
---|
102 | // Get results, create a node/entity on the position |
---|
103 | for ( itr = result.begin(); itr != result.end(); itr++ ) |
---|
104 | { |
---|
105 | if (itr->movable && itr->movable->getName() == "Head") |
---|
106 | { |
---|
107 | soundMgr->StopSound( &jaguarSoundChannel ); |
---|
108 | soundMgr->PlaySound( jaguarSound, headNode, &jaguarSoundChannel ); |
---|
109 | break; |
---|
110 | } // if |
---|
111 | } |
---|
112 | */ |
---|
113 | |
---|
114 | HumanController::localController_s->getControllableEntity()->fire(firemode); |
---|
115 | //} |
---|
116 | //} |
---|
117 | } |
---|
118 | |
---|
119 | Vector3 NewHumanController::getTarget() { |
---|
120 | Ogre::RaySceneQuery * rsq = HumanController::localController_s->getControllableEntity()->getScene()->getSceneManager()->createRayQuery(Ogre::Ray()); |
---|
121 | |
---|
122 | //std::cout << "X: " << static_cast<float>(this->currentYaw_)/2*-1+.5 << " Y: " << static_cast<float>(this->currentPitch_)/2*-1+.5 << endl; |
---|
123 | |
---|
124 | Ogre::Ray mouseRay = HumanController::localController_s->getControllableEntity()->getCamera()->getCamera()->getCameraToViewportRay(static_cast<float>(this->currentYaw_)/2*-1+.5, static_cast<float>(this->currentPitch_)/2*-1+.5); |
---|
125 | |
---|
126 | rsq->setRay(mouseRay); |
---|
127 | rsq->setSortByDistance(true); |
---|
128 | |
---|
129 | /* |
---|
130 | Distance of objects: |
---|
131 | ignore everything under 200 maybe even take 1000 as min distance to shoot at |
---|
132 | |
---|
133 | shots are regularly traced and are entities!!!!!!!!! this is the biggest problem |
---|
134 | they vanish only after a distance of 10'000 |
---|
135 | */ |
---|
136 | |
---|
137 | |
---|
138 | Ogre::RaySceneQueryResult &result = rsq->execute(); |
---|
139 | |
---|
140 | Ogre::RaySceneQueryResult::iterator itr; |
---|
141 | for ( itr = result.begin(); itr != result.end(); itr++ ) |
---|
142 | { |
---|
143 | //std::cout << "distance: " << itr->distance << " name: " << itr->movable->getName() << " type: " << itr->movable->getMovableType(); |
---|
144 | if (itr->movable->isInScene() && itr->movable->getMovableType() == "Entity" && itr->distance > 500) { |
---|
145 | //std::cout << " TAGGED"; |
---|
146 | itr->movable->getParentSceneNode()->showBoundingBox(true); |
---|
147 | std::cout << itr->movable->getParentSceneNode()->_getDerivedPosition() << endl; |
---|
148 | return itr->movable->getParentSceneNode()->_getDerivedPosition(); |
---|
149 | } |
---|
150 | //std::cout << endl; |
---|
151 | } |
---|
152 | |
---|
153 | //if (result.front().movable->isInScene()) std::cout << "in scene" << endl; |
---|
154 | // && result.front().movable->getParentSceneNode() != NULL) result.front().movable->getParentSceneNode()->showBoundingBox(true); |
---|
155 | //result.front().movable->setVisible(false); |
---|
156 | |
---|
157 | //std::cout << endl; |
---|
158 | /* |
---|
159 | if (!result.empty()) { |
---|
160 | Ogre::RaySceneQueryResultEntry obj = result.front(); |
---|
161 | std::cout << "distance: " << obj.distance << " name: " << obj.movable->getName() << endl; |
---|
162 | } |
---|
163 | */ |
---|
164 | return this->controllableEntity_->getWorldPosition() + (this->controllableEntity_->getWorldOrientation() * Vector3::NEGATIVE_UNIT_Z); |
---|
165 | //return this->controllableEntity_->getWorldPosition() + (this->controllableEntity_->getCamera()->getCamera()->getOrientation() * Vector3::NEGATIVE_UNIT_Z); |
---|
166 | } |
---|
167 | |
---|
168 | void NewHumanController::yaw(const Vector2& value) |
---|
169 | { |
---|
170 | // SUPER(NewHumanController, yaw, value); |
---|
171 | HumanController::yaw(value); |
---|
172 | |
---|
173 | this->currentYaw_ = value.x; |
---|
174 | //std::cout << "Y: " << static_cast<float>(this->currentPitch_) << " X: " << static_cast<float>(this->currentYaw_) << endl; |
---|
175 | } |
---|
176 | void NewHumanController::pitch(const Vector2& value) |
---|
177 | { |
---|
178 | // SUPER(NewHumanController, pitch, value); |
---|
179 | HumanController::pitch(value); |
---|
180 | |
---|
181 | this->currentPitch_ = value.x; |
---|
182 | //std::cout << "Y: " << static_cast<float>(this->currentPitch_) << " X: " << static_cast<float>(this->currentYaw_) << endl; |
---|
183 | } |
---|
184 | |
---|
185 | } |
---|