~ubuntu-branches/debian/sid/ember/sid

« back to all changes in this revision

Viewing changes to src/components/ogre/AvatarController.h

  • Committer: Bazaar Package Importer
  • Author(s): Michael Koch
  • Date: 2009-10-22 23:21:17 UTC
  • mfrom: (1.1.1 upstream) (2.1.1 sid)
  • Revision ID: james.westby@ubuntu.com-20091022232117-isr8u3402qmu7ilo
Tags: 0.5.7-1
* New upstream release.
  - Compile against current ogre (Closes: #551431)
  - Removed debian/patches/ember-gcc4.4.patch. Merged upstream.
  - Updated Depends on ember-media.
* Add libboost-thread-dev tp Build-Depends.
* Make debian/rules independent from upstream version.
* Updated watch file to allow automatic download of new upstream
  tarballs.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
    Copyright (C) 2004  Erik Hjortsberg
3
 
 
4
 
    This program is free software; you can redistribute it and/or modify
5
 
    it under the terms of the GNU General Public License as published by
6
 
    the Free Software Foundation; either version 2 of the License, or
7
 
    (at your option) any later version.
8
 
 
9
 
    This program is distributed in the hope that it will be useful,
10
 
    but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 
    GNU General Public License for more details.
13
 
 
14
 
    You should have received a copy of the GNU General Public License
15
 
    along with this program; if not, write to the Free Software
16
 
    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
 
*/
18
 
 
19
 
#ifndef AVATARCONTROLLER_H
20
 
#define AVATARCONTROLLER_H
21
 
 
22
 
#include "EmberOgrePrerequisites.h"
23
 
 
24
 
 
25
 
// #include <SDL.h>
26
 
#include <sigc++/trackable.h>
27
 
 
28
 
#include "services/input/Input.h"
29
 
#include "services/input/InputCommandMapper.h"
30
 
#include "framework/ConsoleObject.h"
31
 
#include "EntityWorldPickListener.h"
32
 
 
33
 
 
34
 
 
35
 
namespace EmberOgre {
36
 
class Avatar;
37
 
class EmberEntity;
38
 
class AvatarCamera;
39
 
 
40
 
class GUIManager;
41
 
 
42
 
class InputManager;
43
 
class AvatarController;
44
 
 
45
 
/**
46
 
The movement mode of the avatar, run or walk.
47
 
*/
48
 
class AvatarMovementMode {
49
 
public: 
50
 
        enum Mode
51
 
        {
52
 
                MM_WALK = 0,
53
 
                MM_RUN = 1
54
 
        };
55
 
};
56
 
        
57
 
        
58
 
/**
59
 
Used for sending the current desired movement to the actual avatar.
60
 
*/
61
 
struct AvatarControllerMovement
62
 
{
63
 
        AvatarControllerMovement();
64
 
        
65
 
        float rotationDegHoriz;
66
 
        float rotationDegVert;
67
 
        Ogre::Real timeSlice;
68
 
        Ogre::Vector3 movementDirection;
69
 
        AvatarMovementMode::Mode mode;
70
 
        bool isMoving; 
71
 
        Ogre::Quaternion cameraOrientation;
72
 
};
73
 
 
74
 
/**
75
 
Listens for left mouse button pressed in movement mode and moves the character forward.
76
 
*/
77
 
class AvatarControllerInputListener
78
 
{
79
 
public:
80
 
        AvatarControllerInputListener(AvatarController& controller);
81
 
 
82
 
protected:
83
 
 
84
 
        void input_MouseButtonPressed(Ember::Input::MouseButton button, Ember::Input::InputMode mode);
85
 
        void input_MouseButtonReleased(Ember::Input::MouseButton button, Ember::Input::InputMode mode);
86
 
        AvatarController& mController;
87
 
};
88
 
 
89
 
/**
90
 
Controls the avatar. All avatar movement is handled by an instance of this class.
91
 
*/
92
 
class AvatarController
93
 
: public Ogre::FrameListener, 
94
 
public sigc::trackable,
95
 
public Ember::ConsoleObject
96
 
{
97
 
public:
98
 
    friend class AvatarControllerInputListener;
99
 
 
100
 
    AvatarController(Avatar& avatar, Ogre::RenderWindow& window, GUIManager& guiManager, Ogre::Camera& camera);
101
 
 
102
 
        virtual ~AvatarController();
103
 
 
104
 
        /**
105
 
        Each frame we check if we should update the avatar.
106
 
        */
107
 
        virtual bool frameStarted(const Ogre::FrameEvent & event);
108
 
        
109
 
        
110
 
        /**
111
 
        Emitted when the movement mode changes between run and walk.
112
 
        */
113
 
        sigc::signal<void, AvatarMovementMode::Mode> EventMovementModeChanged;
114
 
 
115
 
        
116
 
 
117
 
        void createAvatarCameras(Ogre::SceneNode* avatarSceneNode);
118
 
        
119
 
        /**
120
 
         * Gets the AvatarCamera.
121
 
         * @return 
122
 
         */
123
 
        AvatarCamera* getAvatarCamera() const;
124
 
 
125
 
        /**
126
 
         *    Detaches the camera from the avatar and attaches it to the free flying node.
127
 
         */
128
 
        void detachCamera();
129
 
        
130
 
        /**
131
 
         *    Attaches the camera to the avatar.
132
 
         */
133
 
        void attachCamera();
134
 
        
135
 
        /**
136
 
         *    Gets the current movement for this frame.
137
 
         * @return 
138
 
         */
139
 
        const AvatarControllerMovement& getCurrentMovement() const;
140
 
 
141
 
        const Ember::ConsoleCommandWrapper RunToggle;
142
 
        const Ember::ConsoleCommandWrapper ToggleCameraAttached;
143
 
 
144
 
        const Ember::ConsoleCommandWrapper CharacterMoveForward;
145
 
        const Ember::ConsoleCommandWrapper CharacterMoveBackward;
146
 
        const Ember::ConsoleCommandWrapper CharacterMoveDownwards;
147
 
        const Ember::ConsoleCommandWrapper CharacterMoveUpwards;
148
 
        const Ember::ConsoleCommandWrapper CharacterStrafeLeft;
149
 
        const Ember::ConsoleCommandWrapper CharacterStrafeRight;
150
 
/*      const Ember::ConsoleCommandWrapper CharacterRotateLeft;
151
 
        const Ember::ConsoleCommandWrapper CharacterRotateRight;*/
152
 
        
153
 
        const Ember::ConsoleCommandWrapper MoveCameraTo;
154
 
        
155
 
 
156
 
        /**
157
 
         *    Reimplements the ConsoleObject::runCommand method
158
 
         * @param command 
159
 
         * @param args 
160
 
         */
161
 
        virtual void runCommand(const std::string &command, const std::string &args);
162
 
        
163
 
        /**
164
 
        Moves the avatar to the specified point.
165
 
        A terrain decal will be shown.
166
 
        */
167
 
        void moveToPoint(const Ogre::Vector3& point);
168
 
        
169
 
        /**
170
 
         *    Teleports the avatar to the specified point.
171
 
         * @param point 
172
 
         * @param locationEntity 
173
 
         */
174
 
        void teleportTo(const Ogre::Vector3& point, EmberEntity* locationEntity);
175
 
 
176
 
protected:
177
 
 
178
 
        Ember::InputCommandMapper mMovementCommandMapper;
179
 
        
180
 
        Ogre::RenderWindow& mWindow;
181
 
        
182
 
        GUIManager& mGUIManager;
183
 
 
184
 
 
185
 
//      void checkMovementKeys(const Ogre::FrameEvent & event, const Input& input);
186
 
 
187
 
 
188
 
        AvatarCamera* mAvatarCamera;
189
 
        Ogre::Camera& mCamera;
190
 
 
191
 
        
192
 
        /**
193
 
         * Avatar
194
 
         */
195
 
        Avatar& mAvatar;
196
 
        
197
 
    EmberEntity* mEntityUnderCursor;
198
 
    EmberEntity* mSelectedEntity;
199
 
    
200
 
    AvatarControllerMovement movementForFrame, mPreviousMovementForFrame;
201
 
                
202
 
        Ogre::SceneNode* mFreeFlyingCameraNode;
203
 
        bool mIsAttached;
204
 
        /**
205
 
        True if we're in running mode.
206
 
        */
207
 
        bool mIsRunning;
208
 
        
209
 
        Ogre::Vector3 mMovementDirection;
210
 
    
211
 
        /**
212
 
        Listen for double clicks and send the avatar to the double clicked position.
213
 
        */
214
 
        void entityPicker_PickedEntity(const EntityPickResult& result, const MousePickerArgs& args);
215
 
        
216
 
        /**
217
 
        Creates the terrain decal needed for displaying where the avatar is heading.
218
 
        */
219
 
        void createDecal(Ogre::Vector3 position);
220
 
        
221
 
        /**
222
 
        A decal object for showing a decal on the terrain when the user uses the "move to here" functionality.
223
 
        The decal will be shown at the destination, and removed when the user either gets close to it, or aborts the "move to here" movement (for example by moving manually).
224
 
        */
225
 
        Ogre::MovableObject* mDecalObject;
226
 
        
227
 
        /**
228
 
        The scene node to which the decal object for showing the destination of a "move to here" movement operation is attached.
229
 
        */
230
 
        Ogre::SceneNode* mDecalNode;
231
 
        
232
 
        /**
233
 
        Controller for making the decal pulsate a little.
234
 
        @note Not used currently.
235
 
        */
236
 
//      Ogre::WaveformControllerFunction* mPulsatingController;
237
 
        
238
 
        AvatarControllerInputListener mControllerInputListener;
239
 
};
240
 
 
241
 
 
242
 
 
243
 
}
244
 
 
245
 
#endif // AvatarController_H