| 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 | #include <OgreSceneManager.h> | 
|---|
| 35 | #include <OgreSceneNode.h> | 
|---|
| 36 |  | 
|---|
| 37 | #include "util/Math.h" | 
|---|
| 38 | #include "util/XMLIncludes.h" | 
|---|
| 39 | #include "network/Synchronisable.h" | 
|---|
| 40 | #include "core/BaseObject.h" | 
|---|
| 41 | #include "core/Tickable.h" | 
|---|
| 42 | #include "../tools/Mesh.h" | 
|---|
| 43 |  | 
|---|
| 44 | namespace orxonox | 
|---|
| 45 | { | 
|---|
| 46 | class _OrxonoxExport WorldEntity : public BaseObject, public Tickable, public network::Synchronisable | 
|---|
| 47 | { | 
|---|
| 48 | public: | 
|---|
| 49 | WorldEntity(); | 
|---|
| 50 | virtual ~WorldEntity(); | 
|---|
| 51 |  | 
|---|
| 52 | virtual void tick(float dt); | 
|---|
| 53 | virtual void loadParams(TiXmlElement* xmlElem); | 
|---|
| 54 | virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); | 
|---|
| 55 | virtual inline bool create(){ return Synchronisable::create(); } | 
|---|
| 56 |  | 
|---|
| 57 | void attachWorldEntity(WorldEntity* entity); | 
|---|
| 58 | const WorldEntity* getAttachedWorldEntity(unsigned int index) const; | 
|---|
| 59 |  | 
|---|
| 60 | inline Ogre::SceneNode* getNode() | 
|---|
| 61 | { return this->node_; } | 
|---|
| 62 |  | 
|---|
| 63 | inline void setNode(Ogre::SceneNode* node) | 
|---|
| 64 | { this->node_ = node; } | 
|---|
| 65 |  | 
|---|
| 66 | inline void setPosition(const Vector3& pos) | 
|---|
| 67 | { this->node_->setPosition(pos); } | 
|---|
| 68 | inline void setPositionLoader1(const Vector3& pos) | 
|---|
| 69 | { this->node_->setPosition(pos); } | 
|---|
| 70 | inline void setPositionLoader2(Real x, Real y, Real z) | 
|---|
| 71 | { this->node_->setPosition(x, y, z); } | 
|---|
| 72 | inline void setPosition(Real x, Real y, Real z) | 
|---|
| 73 | { this->node_->setPosition(x, y, z); } | 
|---|
| 74 | inline const Vector3& getPosition() const | 
|---|
| 75 | { return this->node_->getPosition(); } | 
|---|
| 76 |  | 
|---|
| 77 | inline void translate(const Vector3 &d, Ogre::Node::TransformSpace relativeTo=Ogre::Node::TS_PARENT) | 
|---|
| 78 | { this->node_->translate(d, relativeTo); } | 
|---|
| 79 | inline void translate(Real x, Real y, Real z, Ogre::Node::TransformSpace relativeTo=Ogre::Node::TS_PARENT) | 
|---|
| 80 | { this->node_->translate(x, y, z, relativeTo); } | 
|---|
| 81 | inline void translate(const Matrix3 &axes, const Vector3 &move, Ogre::Node::TransformSpace relativeTo=Ogre::Node::TS_PARENT) | 
|---|
| 82 | { this->node_->translate(axes, move, relativeTo); } | 
|---|
| 83 | inline void translate(const Matrix3 &axes, Real x, Real y, Real z, Ogre::Node::TransformSpace relativeTo=Ogre::Node::TS_PARENT) | 
|---|
| 84 | { this->node_->translate(axes, x, y, z, relativeTo); } | 
|---|
| 85 |  | 
|---|
| 86 | inline void yaw(const Radian &angle, Ogre::Node::TransformSpace relativeTo=Ogre::Node::TS_LOCAL) | 
|---|
| 87 | { this->node_->yaw(angle, relativeTo); } | 
|---|
| 88 | inline void pitch(const Radian &angle, Ogre::Node::TransformSpace relativeTo=Ogre::Node::TS_LOCAL) | 
|---|
| 89 | { this->node_->pitch(angle, relativeTo); } | 
|---|
| 90 | inline void roll(const Radian &angle, Ogre::Node::TransformSpace relativeTo=Ogre::Node::TS_LOCAL) | 
|---|
| 91 | { this->node_->roll(angle, relativeTo); } | 
|---|
| 92 | void setYawPitchRoll(const Degree& yaw, const Degree& pitch, const Degree& roll); | 
|---|
| 93 |  | 
|---|
| 94 | inline void setYaw(const Degree &angle) | 
|---|
| 95 | { this->node_->yaw(angle, Ogre::Node::TS_LOCAL); } | 
|---|
| 96 | inline void setPitch(const Degree &angle) | 
|---|
| 97 | { this->node_->pitch(angle, Ogre::Node::TS_LOCAL); } | 
|---|
| 98 | inline void setRoll(const Degree &angle) | 
|---|
| 99 | { this->node_->roll(angle, Ogre::Node::TS_LOCAL); } | 
|---|
| 100 |  | 
|---|
| 101 | inline const Ogre::Quaternion& getOrientation() | 
|---|
| 102 | { return this->node_->getOrientation(); } | 
|---|
| 103 | inline void setOrientation(const Ogre::Quaternion& quat) | 
|---|
| 104 | { this->node_->setOrientation(quat); } | 
|---|
| 105 | inline void rotate(const Vector3 &axis, const Radian &angle, Ogre::Node::TransformSpace relativeTo=Ogre::Node::TS_LOCAL) | 
|---|
| 106 | { this->node_->rotate(axis, angle, relativeTo); } | 
|---|
| 107 | inline void setDirectionLoader(Real x, Real y, Real z) | 
|---|
| 108 | { this->setDirection(x, y, z); } | 
|---|
| 109 | inline void setDirection(Real x, Real y, Real z, Ogre::Node::TransformSpace relativeTo=Ogre::Node::TS_LOCAL, const Vector3 &localDirectionVector=Vector3::NEGATIVE_UNIT_Z) | 
|---|
| 110 | { this->node_->setDirection(x, y, z, relativeTo, localDirectionVector); } | 
|---|
| 111 | inline void setDirection(const Vector3 &vec, Ogre::Node::TransformSpace relativeTo=Ogre::Node::TS_LOCAL, const Vector3 &localDirectionVector=Vector3::NEGATIVE_UNIT_Z) | 
|---|
| 112 | { this->node_->setDirection(vec, relativeTo, localDirectionVector); } | 
|---|
| 113 | inline void lookAt(const Vector3 &targetPoint, Ogre::Node::TransformSpace relativeTo, const Vector3 &localDirectionVector=Vector3::NEGATIVE_UNIT_Z) | 
|---|
| 114 | { this->node_->lookAt(targetPoint, relativeTo, localDirectionVector); } | 
|---|
| 115 |  | 
|---|
| 116 | inline void setScale(const Vector3 &scale) | 
|---|
| 117 | { this->node_->setScale(scale); } | 
|---|
| 118 | inline void setScale(Real x, Real y, Real z) | 
|---|
| 119 | { this->node_->setScale(x, y, z); } | 
|---|
| 120 | inline void setScale(Real scale) | 
|---|
| 121 | { this->node_->setScale(scale, scale, scale); } | 
|---|
| 122 | inline void setTotalScale(Real scale) | 
|---|
| 123 | { this->node_->setScale(scale, scale, scale); } | 
|---|
| 124 | inline const Vector3& getScale(void) const | 
|---|
| 125 | { return this->node_->getScale(); } | 
|---|
| 126 | inline void scale(const Vector3 &scale) | 
|---|
| 127 | { this->node_->scale(scale); } | 
|---|
| 128 | inline void scale(Real x, Real y, Real z) | 
|---|
| 129 | { this->node_->scale(x, y, z); } | 
|---|
| 130 | inline void scale(Real scale) | 
|---|
| 131 | { this->node_->scale(scale, scale, scale); } | 
|---|
| 132 |  | 
|---|
| 133 | inline void attachObject(Ogre::MovableObject *obj) | 
|---|
| 134 | { this->node_->attachObject(obj); } | 
|---|
| 135 | inline void attachObject(Mesh &mesh) | 
|---|
| 136 | { this->node_->attachObject(mesh.getEntity()); } | 
|---|
| 137 | inline void detachObject(Ogre::MovableObject *obj) | 
|---|
| 138 | { this->node_->detachObject(obj); } | 
|---|
| 139 | inline void detachAllObjects() | 
|---|
| 140 | { this->node_->detachAllObjects(); } | 
|---|
| 141 |  | 
|---|
| 142 | inline void setVelocity(const Vector3& velocity) | 
|---|
| 143 | { this->velocity_ = velocity; } | 
|---|
| 144 | inline void setVelocity(Real x, Real y, Real z) | 
|---|
| 145 | { this->velocity_.x = x; this->velocity_.y = y; this->velocity_.z = z; } | 
|---|
| 146 | inline const Vector3& getVelocity() const | 
|---|
| 147 | { return this->velocity_; } | 
|---|
| 148 |  | 
|---|
| 149 | inline void setAcceleration(const Vector3& acceleration) | 
|---|
| 150 | { this->acceleration_ = acceleration; } | 
|---|
| 151 | inline void setAcceleration(Real x, Real y, Real z) | 
|---|
| 152 | { this->acceleration_.x = x; this->acceleration_.y = y; this->acceleration_.z = z; } | 
|---|
| 153 | inline const Vector3& getAcceleration() const | 
|---|
| 154 | { return this->acceleration_; } | 
|---|
| 155 |  | 
|---|
| 156 | inline void setRotationAxisLoader(const Vector3& axis) | 
|---|
| 157 | { this->rotationAxis_ = axis; rotationAxis_.normalise(); } | 
|---|
| 158 | inline void setRotationAxis(const Vector3& axis) | 
|---|
| 159 | { this->rotationAxis_ = axis; rotationAxis_.normalise(); } | 
|---|
| 160 | inline void setRotationAxis(Real x, Real y, Real z) | 
|---|
| 161 | { this->rotationAxis_.x = x; this->rotationAxis_.y = y; this->rotationAxis_.z = z; rotationAxis_.normalise(); } | 
|---|
| 162 | inline const Vector3& getRotationAxis() const | 
|---|
| 163 | { return this->rotationAxis_; } | 
|---|
| 164 |  | 
|---|
| 165 | //            inline void setRotationRate(const Radian& angle) | 
|---|
| 166 | //                { this->rotationRate_ = angle; } | 
|---|
| 167 | inline void setRotationRate(const Degree& angle) | 
|---|
| 168 | { this->rotationRate_ = angle; this->setStatic(angle == Degree(0)); } | 
|---|
| 169 | inline const Radian& getRotationRate() const | 
|---|
| 170 | { return this->rotationRate_; } | 
|---|
| 171 |  | 
|---|
| 172 | inline void setMomentum(const Radian& angle) | 
|---|
| 173 | { this->momentum_ = angle; } | 
|---|
| 174 | inline void setMomentum(const Degree& angle) | 
|---|
| 175 | { this->momentum_ = angle; } | 
|---|
| 176 | inline const Radian& getMomentum() const | 
|---|
| 177 | { return this->momentum_; } | 
|---|
| 178 |  | 
|---|
| 179 | inline void setStatic(bool bStatic) | 
|---|
| 180 | { this->bStatic_ = bStatic; } | 
|---|
| 181 | inline bool isStatic() | 
|---|
| 182 | { return this->bStatic_; } | 
|---|
| 183 |  | 
|---|
| 184 | protected: | 
|---|
| 185 | void registerAllVariables(); | 
|---|
| 186 |  | 
|---|
| 187 | Vector3 velocity_; | 
|---|
| 188 | Vector3 acceleration_; | 
|---|
| 189 | Vector3 rotationAxis_; | 
|---|
| 190 | Radian rotationRate_; | 
|---|
| 191 | Radian momentum_; | 
|---|
| 192 |  | 
|---|
| 193 | private: | 
|---|
| 194 | static unsigned int worldEntityCounter_s; | 
|---|
| 195 | Ogre::SceneNode* node_; | 
|---|
| 196 | bool bStatic_; | 
|---|
| 197 | std::vector<WorldEntity*> attachedWorldEntities_; | 
|---|
| 198 | }; | 
|---|
| 199 | } | 
|---|
| 200 |  | 
|---|
| 201 | #endif /* _WorldEntity_H__ */ | 
|---|