Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/objecthierarchy2/src/orxonox/objects/worldentities/WorldEntity.h @ 2256

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

The SpaceShips HUD is working again (Speedbar and Radar)

  • Property svn:eol-style set to native
File size: 8.1 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 Synchronisable
45    {
46        public:
47            WorldEntity(BaseObject* creator);
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            static const Vector3 FRONT;
57            static const Vector3 BACK;
58            static const Vector3 LEFT;
59            static const Vector3 RIGHT;
60            static const Vector3 DOWN;
61            static const Vector3 UP;
62
63            virtual void setPosition(const Vector3& position) = 0;
64            inline void setPosition(float x, float y, float z)
65                { this->setPosition(Vector3(x, y, z)); }
66            inline const Vector3& getPosition() const
67                { return this->node_->getPosition(); }
68            inline const Vector3& getWorldPosition() const
69                { return this->node_->getWorldPosition(); }
70
71            virtual void translate(const Vector3& distance, Ogre::Node::TransformSpace relativeTo = Ogre::Node::TS_LOCAL) = 0;
72            inline void translate(float x, float y, float z, Ogre::Node::TransformSpace relativeTo = Ogre::Node::TS_LOCAL)
73                { this->translate(Vector3(x, y, z), relativeTo); }
74
75            virtual inline const Vector3& getVelocity() const
76                { return Vector3::ZERO; }
77
78            virtual void setOrientation(const Quaternion& orientation) = 0;
79            inline void setOrientation(float w, float x, float y, float z)
80                { this->setOrientation(Quaternion(w, x, y, z)); }
81            inline void setOrientation(const Vector3& axis, const Radian& angle)
82                { this->setOrientation(Quaternion(angle, axis)); }
83            inline void setOrientation(const Vector3& axis, const Degree& angle)
84                { this->setOrientation(Quaternion(angle, axis)); }
85            inline const Quaternion& getOrientation() const
86                { return this->node_->getOrientation(); }
87            inline const Quaternion& getWorldOrientation() const
88                { return this->node_->getWorldOrientation(); }
89
90            virtual void rotate(const Quaternion& rotation, Ogre::Node::TransformSpace relativeTo = Ogre::Node::TS_LOCAL) = 0;
91            inline void rotate(const Vector3& axis, const Degree& angle, Ogre::Node::TransformSpace relativeTo = Ogre::Node::TS_LOCAL)
92                { this->rotate(Quaternion(angle, axis), relativeTo); }
93            inline void rotate(const Vector3& axis, const Radian& angle, Ogre::Node::TransformSpace relativeTo = Ogre::Node::TS_LOCAL)
94                { this->rotate(Quaternion(angle, axis), relativeTo); }
95
96            virtual void yaw(const Degree& angle, Ogre::Node::TransformSpace relativeTo = Ogre::Node::TS_LOCAL) = 0;
97            inline void yaw(const Radian& angle, Ogre::Node::TransformSpace relativeTo = Ogre::Node::TS_LOCAL)
98                { this->yaw(Degree(angle), relativeTo); }
99            virtual void pitch(const Degree& angle, Ogre::Node::TransformSpace relativeTo = Ogre::Node::TS_LOCAL) = 0;
100            inline void pitch(const Radian& angle, Ogre::Node::TransformSpace relativeTo = Ogre::Node::TS_LOCAL)
101                { this->pitch(Degree(angle), relativeTo); }
102            virtual void roll(const Degree& angle, Ogre::Node::TransformSpace relativeTo = Ogre::Node::TS_LOCAL) = 0;
103            inline void roll(const Radian& angle, Ogre::Node::TransformSpace relativeTo = Ogre::Node::TS_LOCAL)
104                { this->roll(Degree(angle), relativeTo); }
105
106            virtual void lookAt(const Vector3& target, Ogre::Node::TransformSpace relativeTo = Ogre::Node::TS_LOCAL, const Vector3& localDirectionVector = Vector3::NEGATIVE_UNIT_Z) = 0;
107            virtual void setDirection(const Vector3& direction, Ogre::Node::TransformSpace relativeTo = Ogre::Node::TS_LOCAL, const Vector3& localDirectionVector = Vector3::NEGATIVE_UNIT_Z) = 0;
108            inline void setDirection(float x, float y, float z, Ogre::Node::TransformSpace relativeTo = Ogre::Node::TS_LOCAL, const Vector3& localDirectionVector = Vector3::NEGATIVE_UNIT_Z)
109                { this->setDirection(Vector3(x, y, z), relativeTo, localDirectionVector); }
110
111            inline void setScale3D(const Vector3& scale)
112                { this->node_->setScale(scale); this->changedScale(); }
113            inline void setScale3D(float x, float y, float z)
114                { this->node_->setScale(x, y, z); this->changedScale(); }
115            inline const Vector3& getScale3D() const
116                { return this->node_->getScale(); }
117            inline const Vector3& getWorldScale3D() const
118                { return this->node_->_getDerivedScale(); }
119
120            inline void setScale(float scale)
121                { this->node_->setScale(scale, scale, scale); this->changedScale(); }
122            inline float getScale() const
123                { Vector3 scale = this->getScale3D(); return (scale.x == scale.y && scale.x == scale.z) ? scale.x : 1; }
124            inline float getWorldScale() const
125                { Vector3 scale = this->getWorldScale3D(); return (scale.x == scale.y && scale.x == scale.z) ? scale.x : 1; }
126
127            inline void scale3D(const Vector3& scale)
128                { this->node_->scale(scale); this->changedScale(); }
129            inline void scale3D(float x, float y, float z)
130                { this->node_->scale(x, y, z); this->changedScale(); }
131            inline void scale(float scale)
132                { this->node_->scale(scale, scale, scale); }
133
134            virtual void changedScale() {}
135
136            void attach(WorldEntity* object);
137            void detach(WorldEntity* object);
138            WorldEntity* getAttachedObject(unsigned int index) const;
139            inline const std::set<WorldEntity*>& getAttachedObjects() const
140                { return this->children_; }
141
142            inline void attachToParent(WorldEntity* parent)
143                { parent->attach(this); }
144            inline void detachFromParent()
145                { if (this->parent_) { this->parent_->detach(this); } }
146            inline WorldEntity* getParent() const
147                { return this->parent_; }
148
149        protected:
150            Ogre::SceneNode* node_;
151
152        private:
153            void updateParent();
154
155            inline void lookAt_xmlport(const Vector3& target)
156                { this->lookAt(target); }
157            inline void setDirection_xmlport(const Vector3& direction)
158                { this->setDirection(direction); }
159            inline void yaw_xmlport(const Degree& angle)
160                { this->yaw(angle); }
161            inline void pitch_xmlport(const Degree& angle)
162                { this->pitch(angle); }
163            inline void roll_xmlport(const Degree& angle)
164                { this->roll(angle); }
165
166            WorldEntity* parent_;
167            unsigned int parentID_;
168            std::set<WorldEntity*> children_;
169    };
170
171    SUPER_FUNCTION(5, WorldEntity, changedScale, false);
172}
173
174#endif /* _WorldEntity_H__ */
Note: See TracBrowser for help on using the repository browser.