Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 3089 was 3089, checked in by landauf, 15 years ago

merged map branch back to trunk

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