Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/physics/src/orxonox/objects/worldentities/ControllableEntity.h @ 2427

Last change on this file since 2427 was 2427, checked in by rgrieder, 15 years ago

Changed the way setPosition, setVelocity, setOrientation and setAngularVelocity is handled in MobileEntity and upwards.
This allows to introduce a lost feature: Position of an enemy ship on the client can't be set anymore at all (local changes were allowed before).

  • Property svn:eol-style set to native
File size: 5.3 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 "MobileEntity.h"
35
36namespace orxonox
37{
38    class _OrxonoxExport ControllableEntity : public MobileEntity
39    {
40        public:
41            ControllableEntity(BaseObject* creator);
42            virtual ~ControllableEntity();
43
44            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
45            virtual void tick(float dt);
46            void registerVariables();
47
48            virtual void setPlayer(PlayerInfo* player);
49            virtual void removePlayer();
50            inline PlayerInfo* getPlayer() const
51                { return this->player_; }
52
53            inline void setDestroyWhenPlayerLeft(bool bDestroy)
54                { this->bDestroyWhenPlayerLeft_ = bDestroy; }
55            inline bool getDestroyWhenPlayerLeft() const
56                { return this->bDestroyWhenPlayerLeft_; }
57
58            virtual void moveFrontBack(const Vector2& value) {}
59            virtual void moveRightLeft(const Vector2& value) {}
60            virtual void moveUpDown(const Vector2& value) {}
61
62            virtual void rotateYaw(const Vector2& value) {}
63            virtual void rotatePitch(const Vector2& value) {}
64            virtual void rotateRoll(const Vector2& value) {}
65
66            virtual void fire() {}
67            virtual void altFire() {}
68
69            virtual void greet() {}
70            virtual void use() {}
71            virtual void switchCamera();
72
73            inline const std::string& getHudTemplate() const
74                { return this->hudtemplate_; }
75
76            inline Camera* getCamera() const
77                { return this->camera_; }
78            inline OverlayGroup* getHUD() const
79                { return this->hud_; }
80
81            void addCameraPosition(CameraPosition* position);
82            CameraPosition* getCameraPosition(unsigned int index) const;
83            inline const std::list<CameraPosition*>& getCameraPositions() const
84                { return this->cameraPositions_; }
85
86            inline void setCameraPositionTemplate(const std::string& name)
87                { this->cameraPositionTemplate_ = name; }
88            inline const std::string& getCameraPositionTemkplate() const
89                { return this->cameraPositionTemplate_; }
90
91            using WorldEntity::setPosition;
92            using WorldEntity::setOrientation;
93            using MobileEntity::setVelocity;
94            using MobileEntity::setAngularVelocity;
95
96            void setPosition(const Vector3& position);
97            void setOrientation(const Quaternion& orientation);
98            void setVelocity(const Vector3& velocity);
99            void setAngularVelocity(const Vector3& velocity);
100
101        protected:
102            virtual void startLocalControl();
103            virtual void stopLocalControl();
104
105            inline void setHudTemplate(const std::string& name)
106                { this->hudtemplate_ = name; }
107
108            inline bool isLocallyControlled() const
109                { return this->bControlled_; }
110
111        private:
112            void overwrite();
113            void processOverwrite();
114
115            void processServerPosition();
116            void processServerLinearVelocity();
117            void processServerOrientation();
118            void processServerAngularVelocity();
119
120            void processClientPosition();
121            void processClientLinearVelocity();
122            void processClientOrientation();
123            void processClientAngularVelocity();
124
125            void networkcallback_changedplayerID();
126
127            // Bullet btMotionState related
128            void setWorldTransform(const btTransform& worldTrans);
129
130            unsigned int server_overwrite_;
131            unsigned int client_overwrite_;
132
133            bool bControlled_;
134            Vector3 server_position_;
135            Vector3 client_position_;
136            Vector3 server_linear_velocity_;
137            Vector3 client_linear_velocity_;
138            Quaternion server_orientation_;
139            Quaternion client_orientation_;
140            Vector3 server_angular_velocity_;
141            Vector3 client_angular_velocity_;
142
143            PlayerInfo* player_;
144            unsigned int playerID_;
145            std::string hudtemplate_;
146            OverlayGroup* hud_;
147            Camera* camera_;
148            bool bDestroyWhenPlayerLeft_;
149
150            std::list<CameraPosition*> cameraPositions_;
151            std::string cameraPositionTemplate_;
152    };
153}
154
155#endif /* _ControllableEntity_H__ */
Note: See TracBrowser for help on using the repository browser.