Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/steering/src/orxonox/controllers/NewHumanController.cc @ 6033

Last change on this file since 6033 was 6033, checked in by wirthmi, 15 years ago

Added the ability to raytrace on fire to find the object to user wants to aim at.

File size: 5.8 KB
Line 
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
48namespace 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        CrossHairOverlay = new OrxonoxOverlay(this);
60        CrossHairOverlay->setBackgroundMaterial("Orxonox/Crosshair3");
61        CrossHairOverlay->setSize(Vector2(overlaySize,overlaySize));
62        CrossHairOverlay->show();
63    }
64
65    NewHumanController::~NewHumanController()
66    {
67        if( this->isInitialized() )
68        {
69        }
70    }
71
72    void NewHumanController::tick(float dt) {
73        CrossHairOverlay->setPosition(Vector2(static_cast<float>(this->currentYaw_)/2*-1+.5-overlaySize/2, static_cast<float>(this->currentPitch_)/2*-1+.5-overlaySize/2));
74
75        HumanController::tick(dt);
76    }
77
78    /*void NewHumanController::tick(float dt)
79    {
80        if (GameMode::playsSound() && NewHumanController::localController_s && NewHumanController::localController_s->controllableEntity_)
81        {
82            // Update sound listener
83            Camera* camera = NewHumanController::localController_s->controllableEntity_->getCamera();
84            if (camera)
85            {
86                SoundManager::getInstance().setListenerPosition(camera->getWorldPosition());
87                SoundManager::getInstance().setListenerOrientation(camera->getWorldOrientation());
88            }
89            else
90                COUT(3) << "NewHumanController, Warning: Using a ControllableEntity without Camera" << std::endl;
91        }
92    }*/
93   
94    void NewHumanController::doFire(unsigned int firemode)
95    {
96        //if (HumanController::localController_s && HumanController::localController_s->controllableEntity_) {
97
98/*
99
100 // Get results, create a node/entity on the position
101 for ( itr = result.begin(); itr != result.end(); itr++ )
102 {
103     if (itr->movable && itr->movable->getName() == "Head")
104     {
105         soundMgr->StopSound( &jaguarSoundChannel );
106         soundMgr->PlaySound( jaguarSound, headNode, &jaguarSoundChannel );
107         break;
108     } // if
109 }
110*/
111
112            Ogre::RaySceneQuery * rsq = HumanController::localController_s->getControllableEntity()->getScene()->getSceneManager()->createRayQuery(Ogre::Ray());
113
114std::cout << "X: " << static_cast<float>(this->currentYaw_)/2*-1+.5 << "  Y: " << static_cast<float>(this->currentPitch_)/2*-1+.5 << endl;
115
116            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);
117
118            rsq->setRay(mouseRay);
119            rsq->setSortByDistance(true);
120
121
122            Ogre::RaySceneQueryResult &result = rsq->execute();
123
124            Ogre::RaySceneQueryResult::iterator itr;
125for ( itr = result.begin(); itr != result.end(); itr++ )
126 {
127     std::cout << "distance: " << itr->distance << "  name: " << itr->movable->getName() << " type: " << itr->movable->getMovableType() << endl;
128if (itr->movable->isInScene() && itr->movable->getMovableType() == "Entity") {
129std::cout << " in scene" << endl;
130        itr->movable->getParentSceneNode()->showBoundingBox(true);
131}
132 }
133
134//if (result.front().movable->isInScene()) std::cout << "in scene" << endl;
135// && result.front().movable->getParentSceneNode() != NULL) result.front().movable->getParentSceneNode()->showBoundingBox(true);
136//result.front().movable->setVisible(false);
137
138std::cout << endl;
139/*
140            if (!result.empty()) {
141                Ogre::RaySceneQueryResultEntry obj = result.front();
142                std::cout << "distance: " << obj.distance << "  name: " << obj.movable->getName() << endl;
143            }
144*/
145
146
147            HumanController::localController_s->getControllableEntity()->fire(firemode);
148        //}
149//}
150    }
151
152    void NewHumanController::yaw(const Vector2& value)
153    {
154//         SUPER(NewHumanController, yaw, value);
155        HumanController::yaw(value);
156       
157        this->currentYaw_ = value.x;
158        //std::cout << "Y: " << static_cast<float>(this->currentPitch_) << " X: " << static_cast<float>(this->currentYaw_) << endl;
159    }
160    void NewHumanController::pitch(const Vector2& value)
161    {
162//         SUPER(NewHumanController, pitch, value);
163        HumanController::pitch(value);
164       
165        this->currentPitch_ = value.x;
166        //std::cout << "Y: " << static_cast<float>(this->currentPitch_) << " X: " << static_cast<float>(this->currentYaw_) << endl;
167    }
168
169}
Note: See TracBrowser for help on using the repository browser.