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