Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/objecthierarchy/src/orxonox/objects/worldentities/ControllableEntity.h @ 2006

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

many changes, can't remember everything, but these are the most important:

  • attaching entities to other entities works
  • displaying models, lights and shadows works
  • controlling a spectator works
  • removed an update hack in PositionableEntity because I've found a much better solution

and with "works" I mean: it works on client, server and standalone

File size: 6.0 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();
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 startLocalControl();
60            virtual void stopLocalControl();
61
62            virtual void moveFrontBack(float value) {}
63            virtual void moveRightLeft(float value) {}
64            virtual void moveUpDown(float value) {}
65
66            virtual void rotateYaw(float value) {}
67            virtual void rotatePitch(float value) {}
68            virtual void rotateRoll(float value) {}
69
70            virtual void fire() {}
71            virtual void altFire() {}
72
73            virtual void greet() {}
74            virtual void use() {}
75            virtual void switchCamera() {}
76
77            inline const Vector3& getVelocity() const
78                { return this->velocity_; }
79            inline const Vector3& getAcceleration() const
80                { return this->acceleration_; }
81            inline const std::string& getHudTemplate() const
82                { return this->hudtemplate_; }
83
84        protected:
85            using WorldEntity::setPosition;
86            using WorldEntity::translate;
87            using WorldEntity::setOrientation;
88            using WorldEntity::rotate;
89            using WorldEntity::yaw;
90            using WorldEntity::pitch;
91            using WorldEntity::roll;
92            using WorldEntity::lookAt;
93            using WorldEntity::setDirection;
94
95            void setPosition(const Vector3& position);
96            void translate(const Vector3& distance, Ogre::Node::TransformSpace relativeTo = Ogre::Node::TS_LOCAL);
97            void setOrientation(const Quaternion& orientation);
98            void rotate(const Quaternion& rotation, Ogre::Node::TransformSpace relativeTo = Ogre::Node::TS_LOCAL);
99            void yaw(const Degree& angle, Ogre::Node::TransformSpace relativeTo = Ogre::Node::TS_LOCAL);
100            void pitch(const Degree& angle, Ogre::Node::TransformSpace relativeTo = Ogre::Node::TS_LOCAL);
101            void roll(const Degree& angle, Ogre::Node::TransformSpace relativeTo = Ogre::Node::TS_LOCAL);
102            void lookAt(const Vector3& target, Ogre::Node::TransformSpace relativeTo = Ogre::Node::TS_LOCAL, const Vector3& localDirectionVector = Vector3::NEGATIVE_UNIT_Z);
103            void setDirection(const Vector3& direction, Ogre::Node::TransformSpace relativeTo = Ogre::Node::TS_LOCAL, const Vector3& localDirectionVector = Vector3::NEGATIVE_UNIT_Z);
104
105            void setVelocity(const Vector3& velocity);
106            inline void setVelocity(float x, float y, float z)
107                { this->velocity_.x = x; this->velocity_.y = y; this->velocity_.z = z; }
108
109            inline void setAcceleration(const Vector3& acceleration)
110                { this->acceleration_ = acceleration; }
111            inline void setAcceleration(float x, float y, float z)
112                { this->acceleration_.x = x; this->acceleration_.y = y; this->acceleration_.z = z; }
113
114            inline void setHudTemplate(const std::string& name)
115                { this->hudtemplate_ = name; }
116
117            inline bool isLocallyControlled() const
118                { return this->bControlled_; }
119
120        private:
121            void overwrite();
122            void processOverwrite();
123
124            void processServerPosition();
125            void processServerVelocity();
126            void processServerOrientation();
127
128            void processClientPosition();
129            void processClientVelocity();
130            void processClientOrientation();
131
132            void updatePlayer();
133
134            unsigned int server_overwrite_;
135            unsigned int client_overwrite_;
136
137            Vector3 velocity_;
138            Vector3 acceleration_;
139
140            bool bControlled_;
141            Vector3 server_position_;
142            Vector3 client_position_;
143            Vector3 server_velocity_;
144            Vector3 client_velocity_;
145            Quaternion server_orientation_;
146            Quaternion client_orientation_;
147
148            PlayerInfo* player_;
149            unsigned int playerID_;
150            std::string hudtemplate_;
151            OverlayGroup* hud_;
152            Camera* camera_;
153            bool bDestroyWhenPlayerLeft_;
154    };
155}
156
157#endif /* _ControllableEntity_H__ */
Note: See TracBrowser for help on using the repository browser.