Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/objecthierarchy2/src/orxonox/objects/worldentities/ControllableEntity.h @ 2182

Last change on this file since 2182 was 2087, checked in by landauf, 16 years ago

merged objecthierarchy branch back to trunk

  • Property svn:eol-style set to native
File size: 6.7 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 *      ...
26 *
27 */
28
29#ifndef _ControllableEntity_H__
30#define _ControllableEntity_H__
31
32#include "OrxonoxPrereqs.h"
33
34#include "WorldEntity.h"
35#include "objects/Tickable.h"
36
37namespace orxonox
38{
39    class _OrxonoxExport ControllableEntity : public WorldEntity, public Tickable
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
49            virtual void setPlayer(PlayerInfo* player);
50            virtual void removePlayer();
51            inline PlayerInfo* getPlayer() const
52                { return this->player_; }
53
54            inline void setDestroyWhenPlayerLeft(bool bDestroy)
55                { this->bDestroyWhenPlayerLeft_ = bDestroy; }
56            inline bool getDestroyWhenPlayerLeft() const
57                { return this->bDestroyWhenPlayerLeft_; }
58
59            virtual void moveFrontBack(const Vector2& value) {}
60            virtual void moveRightLeft(const Vector2& value) {}
61            virtual void moveUpDown(const Vector2& value) {}
62
63            virtual void rotateYaw(const Vector2& value) {}
64            virtual void rotatePitch(const Vector2& value) {}
65            virtual void rotateRoll(const Vector2& value) {}
66
67            virtual void fire() {}
68            virtual void altFire() {}
69
70            virtual void greet() {}
71            virtual void use() {}
72            virtual void switchCamera();
73
74            inline const Vector3& getVelocity() const
75                { return this->velocity_; }
76            inline const Vector3& getAcceleration() const
77                { return this->acceleration_; }
78            inline const std::string& getHudTemplate() const
79                { return this->hudtemplate_; }
80
81            using WorldEntity::setPosition;
82            using WorldEntity::translate;
83            using WorldEntity::setOrientation;
84            using WorldEntity::rotate;
85            using WorldEntity::yaw;
86            using WorldEntity::pitch;
87            using WorldEntity::roll;
88            using WorldEntity::lookAt;
89            using WorldEntity::setDirection;
90
91            void setPosition(const Vector3& position);
92            void translate(const Vector3& distance, Ogre::Node::TransformSpace relativeTo = Ogre::Node::TS_LOCAL);
93            void setOrientation(const Quaternion& orientation);
94            void rotate(const Quaternion& rotation, Ogre::Node::TransformSpace relativeTo = Ogre::Node::TS_LOCAL);
95            void yaw(const Degree& angle, Ogre::Node::TransformSpace relativeTo = Ogre::Node::TS_LOCAL);
96            void pitch(const Degree& angle, Ogre::Node::TransformSpace relativeTo = Ogre::Node::TS_LOCAL);
97            void roll(const Degree& angle, Ogre::Node::TransformSpace relativeTo = Ogre::Node::TS_LOCAL);
98            void lookAt(const Vector3& target, Ogre::Node::TransformSpace relativeTo = Ogre::Node::TS_LOCAL, const Vector3& localDirectionVector = Vector3::NEGATIVE_UNIT_Z);
99            void setDirection(const Vector3& direction, Ogre::Node::TransformSpace relativeTo = Ogre::Node::TS_LOCAL, const Vector3& localDirectionVector = Vector3::NEGATIVE_UNIT_Z);
100
101            void setVelocity(const Vector3& velocity);
102            inline void setVelocity(float x, float y, float z)
103                { this->velocity_.x = x; this->velocity_.y = y; this->velocity_.z = z; }
104
105            inline void setAcceleration(const Vector3& acceleration)
106                { this->acceleration_ = acceleration; }
107            inline void setAcceleration(float x, float y, float z)
108                { this->acceleration_.x = x; this->acceleration_.y = y; this->acceleration_.z = z; }
109
110            inline Camera* getCamera() const
111                { return this->camera_; }
112            inline OverlayGroup* getHUD() const
113                { return this->hud_; }
114
115            void addCameraPosition(CameraPosition* position);
116            CameraPosition* getCameraPosition(unsigned int index) const;
117            inline const std::list<CameraPosition*>& getCameraPositions() const
118                { return this->cameraPositions_; }
119
120            inline void setCameraPositionTemplate(const std::string& name)
121                { this->cameraPositionTemplate_ = name; }
122            inline const std::string& getCameraPositionTemkplate() const
123                { return this->cameraPositionTemplate_; }
124
125        protected:
126            virtual void startLocalControl();
127            virtual void stopLocalControl();
128
129            inline void setHudTemplate(const std::string& name)
130                { this->hudtemplate_ = name; }
131
132            inline bool isLocallyControlled() const
133                { return this->bControlled_; }
134
135            Vector3 acceleration_;
136
137        private:
138            void overwrite();
139            void processOverwrite();
140
141            void processServerPosition();
142            void processServerVelocity();
143            void processServerOrientation();
144
145            void processClientPosition();
146            void processClientVelocity();
147            void processClientOrientation();
148
149            void networkcallback_changedplayerID();
150
151            unsigned int server_overwrite_;
152            unsigned int client_overwrite_;
153
154            Vector3 velocity_;
155
156            bool bControlled_;
157            Vector3 server_position_;
158            Vector3 client_position_;
159            Vector3 server_velocity_;
160            Vector3 client_velocity_;
161            Quaternion server_orientation_;
162            Quaternion client_orientation_;
163
164            PlayerInfo* player_;
165            unsigned int playerID_;
166            std::string hudtemplate_;
167            OverlayGroup* hud_;
168            Camera* camera_;
169            bool bDestroyWhenPlayerLeft_;
170
171            std::list<CameraPosition*> cameraPositions_;
172            std::string cameraPositionTemplate_;
173    };
174}
175
176#endif /* _ControllableEntity_H__ */
Note: See TracBrowser for help on using the repository browser.