Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/orxonox/worldentities/ControllableEntity.h @ 7163

Last change on this file since 7163 was 7163, checked in by dafrick, 14 years ago

Merged presentation3 branch into trunk.

  • Property svn:eol-style set to native
File size: 8.1 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 *      Fabian 'x3n' Landau
24 *   Co-authors:
25 *      Reto Grieder
26 *
27 */
28
29#ifndef _ControllableEntity_H__
30#define _ControllableEntity_H__
31
32#include "OrxonoxPrereqs.h"
33
34#include <list>
35#include <string>
36#include "util/Math.h"
37#include "MobileEntity.h"
38
39namespace orxonox
40{
41    class _OrxonoxExport ControllableEntity : public MobileEntity
42    {
43        friend class PlayerInfo; // PlayerInfo uses setPlayer and removePlayer
44
45        public:
46            ControllableEntity(BaseObject* creator);
47            virtual ~ControllableEntity();
48
49            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
50            virtual void tick(float dt);
51            void setConfigValues();
52
53            virtual void changedPlayer() {}
54
55            inline PlayerInfo* getPlayer() const
56                { return this->player_; }
57
58            inline void setDestroyWhenPlayerLeft(bool bDestroy)
59                { this->bDestroyWhenPlayerLeft_ = bDestroy; }
60            inline bool getDestroyWhenPlayerLeft() const
61                { return this->bDestroyWhenPlayerLeft_; }
62
63            virtual void moveFrontBack(const Vector2& value) {}
64            virtual void moveRightLeft(const Vector2& value) {}
65            virtual void moveUpDown(const Vector2& value) {}
66
67            virtual void rotateYaw(const Vector2& value);
68            virtual void rotatePitch(const Vector2& value);
69            virtual void rotateRoll(const Vector2& value);
70
71            inline void moveFrontBack(float value)
72                { this->moveFrontBack(Vector2(value, 0)); }
73            inline void moveRightLeft(float value)
74                { this->moveRightLeft(Vector2(value, 0)); }
75            inline void moveUpDown(float value)
76                { this->moveUpDown(Vector2(value, 0)); }
77
78            inline void rotateYaw(float value)
79                { this->rotateYaw(Vector2(value, 0)); }
80            inline void rotatePitch(float value)
81                { this->rotatePitch(Vector2(value, 0)); }
82            inline void rotateRoll(float value)
83                { this->rotateRoll(Vector2(value, 0)); }
84
85            void fire(unsigned int firemode);
86            virtual void fired(unsigned int firemode) {}
87            virtual void reload() {}
88
89            virtual void boost() {}
90            virtual void greet() {}
91            virtual void useItem() {}
92            virtual void dropItems() {}
93            virtual void switchCamera();
94            virtual void mouseLook();
95
96            inline const std::string& getHudTemplate() const
97                { return this->hudtemplate_; }
98
99            inline Camera* getCamera() const
100                { return this->camera_; }
101            inline OverlayGroup* getHUD() const
102                { return this->hud_; }
103
104            void addCameraPosition(CameraPosition* position);
105            CameraPosition* getCameraPosition(unsigned int index) const;
106            inline const std::list<SmartPtr<CameraPosition> >& getCameraPositions() const
107                { return this->cameraPositions_; }
108
109            inline void setCameraPositionTemplate(const std::string& name)
110                { this->cameraPositionTemplate_ = name; }
111            inline const std::string& getCameraPositionTemkplate() const
112                { return this->cameraPositionTemplate_; }
113
114            inline void setReverseCamera(CameraPosition* camera)
115                { this->reverseCamera_ = camera; }
116            inline CameraPosition* getReverseCamera() const
117                { return this->reverseCamera_; }
118
119            using WorldEntity::setPosition;
120            using WorldEntity::setOrientation;
121            using MobileEntity::setVelocity;
122            using MobileEntity::setAngularVelocity;
123
124            void setPosition(const Vector3& position);
125            void setOrientation(const Quaternion& orientation);
126            void setVelocity(const Vector3& velocity);
127            void setAngularVelocity(const Vector3& velocity);
128
129            inline bool hasLocalController() const
130                { return this->bHasLocalController_; }
131            inline bool hasHumanController() const
132                { return this->bHasHumanController_; }
133
134            inline bool isInMouseLook() const
135                { return this->bMouseLook_; }
136            inline float getMouseLookSpeed() const
137                { return this->mouseLookSpeed_; }
138            inline CameraPosition* getCurrentCameraPosition()
139                { return this->currentCameraPosition_; }
140
141            inline Controller* getXMLController() const
142                { return this->xmlcontroller_; }
143
144            inline Controller* getController() const
145                { return this->controller_; }
146            inline void setController(Controller* val)
147                { this->controller_ = val; }
148
149            virtual void setTarget( WorldEntity* target );
150            virtual WorldEntity* getTarget()
151                { return this->target_.get(); }
152            void setTargetInternal( uint32_t targetID );
153
154        protected:
155            virtual void setPlayer(PlayerInfo* player); // don't call this directly, use friend class PlayerInfo instead
156            virtual void removePlayer();                // don't call this directly, use friend class PlayerInfo instead
157
158            virtual void startLocalHumanControl();
159            virtual void stopLocalHumanControl();
160            virtual void parentChanged();
161
162            inline void setHudTemplate(const std::string& name)
163                { this->hudtemplate_ = name; }
164
165            Ogre::SceneNode* cameraPositionRootNode_;
166
167        private:
168            void registerVariables();
169            void setXMLController(Controller* controller);
170
171            void overwrite();
172            void processOverwrite();
173
174            void processServerPosition();
175            void processServerLinearVelocity();
176            void processServerOrientation();
177            void processServerAngularVelocity();
178
179            void processClientPosition();
180            void processClientLinearVelocity();
181            void processClientOrientation();
182            void processClientAngularVelocity();
183
184            void networkcallback_changedplayerID();
185
186            // Bullet btMotionState related
187            void setWorldTransform(const btTransform& worldTrans);
188
189            unsigned int server_overwrite_;
190            unsigned int client_overwrite_;
191
192            bool bHasLocalController_;
193            bool bHasHumanController_;
194            bool bDestroyWhenPlayerLeft_;
195
196            Vector3 server_position_;
197            Vector3 client_position_;
198            Vector3 server_linear_velocity_;
199            Vector3 client_linear_velocity_;
200            Quaternion server_orientation_;
201            Quaternion client_orientation_;
202            Vector3 server_angular_velocity_;
203            Vector3 client_angular_velocity_;
204
205            PlayerInfo* player_;
206            unsigned int playerID_;
207
208            std::string hudtemplate_;
209            OverlayGroup* hud_;
210
211            Camera* camera_;
212            bool bMouseLook_;
213            float mouseLookSpeed_;
214            std::list<SmartPtr<CameraPosition> > cameraPositions_;
215            CameraPosition* currentCameraPosition_;
216            std::string cameraPositionTemplate_;
217            Controller* xmlcontroller_;
218            Controller* controller_;
219            CameraPosition* reverseCamera_;
220            WeakPtr<WorldEntity> target_;
221    };
222}
223
224#endif /* _ControllableEntity_H__ */
Note: See TracBrowser for help on using the repository browser.