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