Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/objecthierarchy/src/orxonox/objects/worldentities/WorldEntity.h @ 1940

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

did some first (and very unfinished) steps to deal with different players on server and client

File size: 6.5 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 _WorldEntity_H__
30#define _WorldEntity_H__
31
32#include "OrxonoxPrereqs.h"
33
34#define OGRE_FORCE_ANGLE_TYPES
35
36#include <OgreSceneNode.h>
37
38#include "network/Synchronisable.h"
39#include "core/BaseObject.h"
40#include "util/Math.h"
41
42namespace orxonox
43{
44    class _OrxonoxExport WorldEntity : public BaseObject, public network::Synchronisable
45    {
46        public:
47            WorldEntity();
48            virtual ~WorldEntity();
49
50            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
51            void registerVariables();
52
53            inline Ogre::SceneNode* getNode() const
54                { return this->node_; }
55
56            virtual void setPosition(const Vector3& position) = 0;
57            inline void setPosition(float x, float y, float z)
58                { this->setPosition(Vector3(x, y, z)); }
59            inline const Vector3& getPosition() const
60                { return this->node_->getPosition(); }
61            inline const Vector3& getWorldPosition() const
62                { return this->node_->getWorldPosition(); }
63
64            virtual void translate(const Vector3& distance, Ogre::Node::TransformSpace relativeTo = Ogre::Node::TS_LOCAL) = 0;
65            inline void translate(float x, float y, float z, Ogre::Node::TransformSpace relativeTo = Ogre::Node::TS_LOCAL)
66                { this->translate(Vector3(x, y, z), relativeTo); }
67
68            virtual void setOrientation(const Quaternion& orientation) = 0;
69            inline void setOrientation(float w, float x, float y, float z)
70                { this->setOrientation(Quaternion(w, x, y, z)); }
71            inline void setOrientation(const Vector3& axis, const Radian& angle)
72                { this->setOrientation(Quaternion(angle, axis)); }
73            inline const Quaternion& getOrientation() const
74                { return this->node_->getOrientation(); }
75            inline const Quaternion& getWorldOrientation() const
76                { return this->node_->getWorldOrientation(); }
77
78            virtual void rotate(const Quaternion& rotation, Ogre::Node::TransformSpace relativeTo = Ogre::Node::TS_LOCAL) = 0;
79            inline void rotate(const Vector3& axis, const Radian& angle, Ogre::Node::TransformSpace relativeTo = Ogre::Node::TS_LOCAL)
80                { this->rotate(Quaternion(angle, axis), relativeTo); }
81
82            virtual void yaw(const Radian& angle, Ogre::Node::TransformSpace relativeTo = Ogre::Node::TS_LOCAL) = 0;
83            virtual void pitch(const Radian& angle, Ogre::Node::TransformSpace relativeTo = Ogre::Node::TS_LOCAL) = 0;
84            virtual void roll(const Radian& angle, Ogre::Node::TransformSpace relativeTo = Ogre::Node::TS_LOCAL) = 0;
85
86            virtual void lookAt(const Vector3& target, Ogre::Node::TransformSpace relativeTo = Ogre::Node::TS_LOCAL, const Vector3& localDirectionVector = Vector3::NEGATIVE_UNIT_Z) = 0;
87            virtual void setDirection(const Vector3& direction, Ogre::Node::TransformSpace relativeTo = Ogre::Node::TS_LOCAL, const Vector3& localDirectionVector = Vector3::NEGATIVE_UNIT_Z) = 0;
88            inline void setDirection(float x, float y, float z, Ogre::Node::TransformSpace relativeTo = Ogre::Node::TS_LOCAL, const Vector3& localDirectionVector = Vector3::NEGATIVE_UNIT_Z)
89                { this->setDirection(Vector3(x, y, z), relativeTo, localDirectionVector); }
90
91            inline void setScale3D(const Vector3& scale)
92                { this->node_->setScale(scale); }
93            inline void setScale3D(float x, float y, float z)
94                { this->node_->setScale(x, y, z); }
95            inline const Vector3& getScale3D(void) const
96                { return this->node_->getScale(); }
97
98            inline void setScale(float scale)
99                { this->node_->setScale(scale, scale, scale); }
100            inline float getScale() const
101                { Vector3 scale = this->getScale3D(); return (scale.x == scale.y && scale.x == scale.z) ? scale.x : 1; }
102
103            inline void scale3D(const Vector3& scale)
104                { this->node_->scale(scale); }
105            inline void scale3D(float x, float y, float z)
106                { this->node_->scale(x, y, z); }
107            inline void scale(float scale)
108                { this->node_->scale(scale, scale, scale); }
109
110            void attach(WorldEntity* object);
111            void detach(WorldEntity* object);
112            WorldEntity* getAttachedObject(unsigned int index) const;
113            inline const std::set<WorldEntity*>& getAttachedObjects() const
114                { return this->children_; }
115
116            inline void attachToParent(WorldEntity* parent)
117                { parent->attach(this); }
118            inline void detachFromParent()
119                { this->parent_->detach(this); }
120            inline WorldEntity* getParent() const
121                { return this->parent_; }
122
123        protected:
124            Ogre::SceneNode* node_;
125
126        private:
127            void updateParent();
128
129            inline void lookAt_xmlport(const Vector3& target)
130                { this->lookAt(target); }
131            inline void setDirection_xmlport(const Vector3& direction)
132                { this->setDirection(direction); }
133            inline void yaw_xmlport(const Radian& angle)
134                { this->yaw(angle); }
135            inline void pitch_xmlport(const Radian& angle)
136                { this->pitch(angle); }
137            inline void roll_xmlport(const Radian& angle)
138                { this->roll(angle); }
139
140            WorldEntity* parent_;
141            unsigned int parentID_;
142            std::set<WorldEntity*> children_;
143    };
144}
145
146#endif /* _WorldEntity_H__ */
Note: See TracBrowser for help on using the repository browser.