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 | |
---|
42 | namespace orxonox |
---|
43 | { |
---|
44 | class _OrxonoxExport WorldEntity : public BaseObject, public network::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); } |
---|
110 | inline void setScale3D(float x, float y, float z) |
---|
111 | { this->node_->setScale(x, y, z); } |
---|
112 | inline const Vector3& getScale3D(void) const |
---|
113 | { return this->node_->getScale(); } |
---|
114 | |
---|
115 | inline void setScale(float scale) |
---|
116 | { this->node_->setScale(scale, scale, scale); } |
---|
117 | inline float getScale() const |
---|
118 | { Vector3 scale = this->getScale3D(); return (scale.x == scale.y && scale.x == scale.z) ? scale.x : 1; } |
---|
119 | |
---|
120 | inline void scale3D(const Vector3& scale) |
---|
121 | { this->node_->scale(scale); } |
---|
122 | inline void scale3D(float x, float y, float z) |
---|
123 | { this->node_->scale(x, y, z); } |
---|
124 | inline void scale(float scale) |
---|
125 | { this->node_->scale(scale, scale, scale); } |
---|
126 | |
---|
127 | void attach(WorldEntity* object); |
---|
128 | void detach(WorldEntity* object); |
---|
129 | WorldEntity* getAttachedObject(unsigned int index) const; |
---|
130 | inline const std::set<WorldEntity*>& getAttachedObjects() const |
---|
131 | { return this->children_; } |
---|
132 | |
---|
133 | inline void attachToParent(WorldEntity* parent) |
---|
134 | { parent->attach(this); } |
---|
135 | inline void detachFromParent() |
---|
136 | { this->parent_->detach(this); } |
---|
137 | inline WorldEntity* getParent() const |
---|
138 | { return this->parent_; } |
---|
139 | |
---|
140 | protected: |
---|
141 | Ogre::SceneNode* node_; |
---|
142 | |
---|
143 | private: |
---|
144 | void updateParent(); |
---|
145 | |
---|
146 | inline void lookAt_xmlport(const Vector3& target) |
---|
147 | { this->lookAt(target); } |
---|
148 | inline void setDirection_xmlport(const Vector3& direction) |
---|
149 | { this->setDirection(direction); } |
---|
150 | inline void yaw_xmlport(const Degree& angle) |
---|
151 | { this->yaw(angle); } |
---|
152 | inline void pitch_xmlport(const Degree& angle) |
---|
153 | { this->pitch(angle); } |
---|
154 | inline void roll_xmlport(const Degree& angle) |
---|
155 | { this->roll(angle); } |
---|
156 | |
---|
157 | WorldEntity* parent_; |
---|
158 | unsigned int parentID_; |
---|
159 | std::set<WorldEntity*> children_; |
---|
160 | }; |
---|
161 | } |
---|
162 | |
---|
163 | #endif /* _WorldEntity_H__ */ |
---|