Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

maybe fixed backlight crash

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