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 | #include <OgreSceneNode.h> |
---|
36 | |
---|
37 | #include "LinearMath/btMotionState.h" |
---|
38 | #include "BulletDynamics/Dynamics/btRigidBody.h" |
---|
39 | |
---|
40 | #include "network/Synchronisable.h" |
---|
41 | #include "core/BaseObject.h" |
---|
42 | #include "util/Math.h" |
---|
43 | |
---|
44 | namespace orxonox |
---|
45 | { |
---|
46 | class _OrxonoxExport WorldEntity : public BaseObject, public network::Synchronisable, public btMotionState |
---|
47 | { |
---|
48 | public: |
---|
49 | WorldEntity(BaseObject* creator); |
---|
50 | virtual ~WorldEntity(); |
---|
51 | |
---|
52 | virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); |
---|
53 | void registerVariables(); |
---|
54 | |
---|
55 | inline Ogre::SceneNode* getNode() const |
---|
56 | { return this->node_; } |
---|
57 | |
---|
58 | static const Vector3 FRONT; |
---|
59 | static const Vector3 BACK; |
---|
60 | static const Vector3 LEFT; |
---|
61 | static const Vector3 RIGHT; |
---|
62 | static const Vector3 DOWN; |
---|
63 | static const Vector3 UP; |
---|
64 | |
---|
65 | virtual void setPosition(const Vector3& position) = 0; |
---|
66 | inline void setPosition(float x, float y, float z) |
---|
67 | { this->setPosition(Vector3(x, y, z)); } |
---|
68 | inline const Vector3& getPosition() const |
---|
69 | { return this->node_->getPosition(); } |
---|
70 | inline const Vector3& getWorldPosition() const |
---|
71 | { return this->node_->getWorldPosition(); } |
---|
72 | |
---|
73 | virtual void translate(const Vector3& distance, Ogre::Node::TransformSpace relativeTo = Ogre::Node::TS_LOCAL) = 0; |
---|
74 | inline void translate(float x, float y, float z, Ogre::Node::TransformSpace relativeTo = Ogre::Node::TS_LOCAL) |
---|
75 | { this->translate(Vector3(x, y, z), relativeTo); } |
---|
76 | |
---|
77 | virtual void setOrientation(const Quaternion& orientation) = 0; |
---|
78 | inline void setOrientation(float w, float x, float y, float z) |
---|
79 | { this->setOrientation(Quaternion(w, x, y, z)); } |
---|
80 | inline void setOrientation(const Vector3& axis, const Radian& angle) |
---|
81 | { this->setOrientation(Quaternion(angle, axis)); } |
---|
82 | inline void setOrientation(const Vector3& axis, const Degree& angle) |
---|
83 | { this->setOrientation(Quaternion(angle, axis)); } |
---|
84 | inline const Quaternion& getOrientation() const |
---|
85 | { return this->node_->getOrientation(); } |
---|
86 | inline const Quaternion& getWorldOrientation() const |
---|
87 | { return this->node_->getWorldOrientation(); } |
---|
88 | |
---|
89 | virtual void rotate(const Quaternion& rotation, Ogre::Node::TransformSpace relativeTo = Ogre::Node::TS_LOCAL) = 0; |
---|
90 | inline void rotate(const Vector3& axis, const Degree& angle, Ogre::Node::TransformSpace relativeTo = Ogre::Node::TS_LOCAL) |
---|
91 | { this->rotate(Quaternion(angle, axis), relativeTo); } |
---|
92 | inline void rotate(const Vector3& axis, const Radian& angle, Ogre::Node::TransformSpace relativeTo = Ogre::Node::TS_LOCAL) |
---|
93 | { this->rotate(Quaternion(angle, axis), relativeTo); } |
---|
94 | |
---|
95 | virtual void yaw(const Degree& angle, Ogre::Node::TransformSpace relativeTo = Ogre::Node::TS_LOCAL) = 0; |
---|
96 | inline void yaw(const Radian& angle, Ogre::Node::TransformSpace relativeTo = Ogre::Node::TS_LOCAL) |
---|
97 | { this->yaw(Degree(angle), relativeTo); } |
---|
98 | virtual void pitch(const Degree& angle, Ogre::Node::TransformSpace relativeTo = Ogre::Node::TS_LOCAL) = 0; |
---|
99 | inline void pitch(const Radian& angle, Ogre::Node::TransformSpace relativeTo = Ogre::Node::TS_LOCAL) |
---|
100 | { this->pitch(Degree(angle), relativeTo); } |
---|
101 | virtual void roll(const Degree& angle, Ogre::Node::TransformSpace relativeTo = Ogre::Node::TS_LOCAL) = 0; |
---|
102 | inline void roll(const Radian& angle, Ogre::Node::TransformSpace relativeTo = Ogre::Node::TS_LOCAL) |
---|
103 | { this->roll(Degree(angle), relativeTo); } |
---|
104 | |
---|
105 | virtual void lookAt(const Vector3& target, Ogre::Node::TransformSpace relativeTo = Ogre::Node::TS_LOCAL, const Vector3& localDirectionVector = Vector3::NEGATIVE_UNIT_Z) = 0; |
---|
106 | virtual void setDirection(const Vector3& direction, Ogre::Node::TransformSpace relativeTo = Ogre::Node::TS_LOCAL, const Vector3& localDirectionVector = Vector3::NEGATIVE_UNIT_Z) = 0; |
---|
107 | inline void setDirection(float x, float y, float z, Ogre::Node::TransformSpace relativeTo = Ogre::Node::TS_LOCAL, const Vector3& localDirectionVector = Vector3::NEGATIVE_UNIT_Z) |
---|
108 | { this->setDirection(Vector3(x, y, z), relativeTo, localDirectionVector); } |
---|
109 | |
---|
110 | inline void setScale3D(const Vector3& scale) |
---|
111 | { this->node_->setScale(scale); } |
---|
112 | inline void setScale3D(float x, float y, float z) |
---|
113 | { this->node_->setScale(x, y, z); } |
---|
114 | inline const Vector3& getScale3D(void) const |
---|
115 | { return this->node_->getScale(); } |
---|
116 | |
---|
117 | inline void setScale(float scale) |
---|
118 | { this->node_->setScale(scale, scale, scale); } |
---|
119 | inline float getScale() const |
---|
120 | { Vector3 scale = this->getScale3D(); return (scale.x == scale.y && scale.x == scale.z) ? scale.x : 1; } |
---|
121 | |
---|
122 | inline void scale3D(const Vector3& scale) |
---|
123 | { this->node_->scale(scale); } |
---|
124 | inline void scale3D(float x, float y, float z) |
---|
125 | { this->node_->scale(x, y, z); } |
---|
126 | inline void scale(float scale) |
---|
127 | { this->node_->scale(scale, scale, scale); } |
---|
128 | |
---|
129 | void setcollisionRadius(float radius); |
---|
130 | float getcollisionRadius(); |
---|
131 | |
---|
132 | bool hasPhysics() { return this->physicalBody_; } |
---|
133 | bool isKinematic() { return this->physicalBody_ && this->physicalBody_->isKinematicObject(); } |
---|
134 | bool isDynamic() { return this->physicalBody_ && !this->physicalBody_->isStaticOrKinematicObject(); } |
---|
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 | //virtual btCollisionShape* getCollisionShape() = 0; |
---|
151 | |
---|
152 | void createPhysicalBody(); |
---|
153 | virtual void attachPhysicalObject(WorldEntity* object) { } |
---|
154 | |
---|
155 | Ogre::SceneNode* node_; |
---|
156 | bool bAddedToPhysicalWorld_; |
---|
157 | btRigidBody* physicalBody_; |
---|
158 | |
---|
159 | private: |
---|
160 | void updateParent(); |
---|
161 | |
---|
162 | inline void lookAt_xmlport(const Vector3& target) |
---|
163 | { this->lookAt(target); } |
---|
164 | inline void setDirection_xmlport(const Vector3& direction) |
---|
165 | { this->setDirection(direction); } |
---|
166 | inline void yaw_xmlport(const Degree& angle) |
---|
167 | { this->yaw(angle); } |
---|
168 | inline void pitch_xmlport(const Degree& angle) |
---|
169 | { this->pitch(angle); } |
---|
170 | inline void roll_xmlport(const Degree& angle) |
---|
171 | { this->roll(angle); } |
---|
172 | |
---|
173 | // Bullet btMotionState related |
---|
174 | virtual void setWorldTransform(const btTransform& worldTrans) |
---|
175 | { |
---|
176 | } |
---|
177 | |
---|
178 | // Bullet btMotionState related |
---|
179 | virtual void getWorldTransform(btTransform& worldTrans) const |
---|
180 | { |
---|
181 | } |
---|
182 | |
---|
183 | WorldEntity* parent_; |
---|
184 | unsigned int parentID_; |
---|
185 | std::set<WorldEntity*> children_; |
---|
186 | }; |
---|
187 | } |
---|
188 | |
---|
189 | #endif /* _WorldEntity_H__ */ |
---|