Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/physics/src/orxonox/objects/worldentities/WorldEntity.h @ 2296

Last change on this file since 2296 was 2296, checked in by rgrieder, 15 years ago

Made return value of WorldEntity::getNode() const —> Modifying the node_ will not anymore be allowed.
That change implicates:

  • Removed Ogre::SceneNode from ParticleInterface. It gets connected now by the ParticleEmitter
  • Added functions attachOgreObject and detachOgreObject to WorldEntity
  • changed all getNode()→attachObject(…) to attachOgreObject(…)
  • Property svn:eol-style set to native
File size: 9.0 KB
Line 
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
44namespace orxonox
45{
46    class _OrxonoxExport WorldEntity : public BaseObject, public network::Synchronisable, public btMotionState
47    {
48        public:
49            enum CollisionType
50            {
51                Dynamic,
52                Kinematic,
53                Static
54            };
55
56        public:
57            WorldEntity(BaseObject* creator);
58            virtual ~WorldEntity();
59
60            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
61            void registerVariables();
62
63            inline const Ogre::SceneNode* getNode() const
64                { return this->node_; }
65
66            static const Vector3 FRONT;
67            static const Vector3 BACK;
68            static const Vector3 LEFT;
69            static const Vector3 RIGHT;
70            static const Vector3 DOWN;
71            static const Vector3 UP;
72
73            virtual void setPosition(const Vector3& position) = 0;
74            inline void setPosition(float x, float y, float z)
75                { this->setPosition(Vector3(x, y, z)); }
76            inline const Vector3& getPosition() const
77                { return this->node_->getPosition(); }
78            inline const Vector3& getWorldPosition() const
79                { return this->node_->getWorldPosition(); }
80
81            virtual void translate(const Vector3& distance, Ogre::Node::TransformSpace relativeTo = Ogre::Node::TS_LOCAL) = 0;
82            inline void translate(float x, float y, float z, Ogre::Node::TransformSpace relativeTo = Ogre::Node::TS_LOCAL)
83                { this->translate(Vector3(x, y, z), relativeTo); }
84
85            virtual void setOrientation(const Quaternion& orientation) = 0;
86            inline void setOrientation(float w, float x, float y, float z)
87                { this->setOrientation(Quaternion(w, x, y, z)); }
88            inline void setOrientation(const Vector3& axis, const Radian& angle)
89                { this->setOrientation(Quaternion(angle, axis)); }
90            inline void setOrientation(const Vector3& axis, const Degree& angle)
91                { this->setOrientation(Quaternion(angle, axis)); }
92            inline const Quaternion& getOrientation() const
93                { return this->node_->getOrientation(); }
94            inline const Quaternion& getWorldOrientation() const
95                { return this->node_->getWorldOrientation(); }
96
97            virtual void rotate(const Quaternion& rotation, Ogre::Node::TransformSpace relativeTo = Ogre::Node::TS_LOCAL) = 0;
98            inline void rotate(const Vector3& axis, const Degree& angle, Ogre::Node::TransformSpace relativeTo = Ogre::Node::TS_LOCAL)
99                { this->rotate(Quaternion(angle, axis), relativeTo); }
100            inline void rotate(const Vector3& axis, const Radian& angle, Ogre::Node::TransformSpace relativeTo = Ogre::Node::TS_LOCAL)
101                { this->rotate(Quaternion(angle, axis), relativeTo); }
102
103            virtual void yaw(const Degree& angle, Ogre::Node::TransformSpace relativeTo = Ogre::Node::TS_LOCAL) = 0;
104            inline void yaw(const Radian& angle, Ogre::Node::TransformSpace relativeTo = Ogre::Node::TS_LOCAL)
105                { this->yaw(Degree(angle), relativeTo); }
106            virtual void pitch(const Degree& angle, Ogre::Node::TransformSpace relativeTo = Ogre::Node::TS_LOCAL) = 0;
107            inline void pitch(const Radian& angle, Ogre::Node::TransformSpace relativeTo = Ogre::Node::TS_LOCAL)
108                { this->pitch(Degree(angle), relativeTo); }
109            virtual void roll(const Degree& angle, Ogre::Node::TransformSpace relativeTo = Ogre::Node::TS_LOCAL) = 0;
110            inline void roll(const Radian& angle, Ogre::Node::TransformSpace relativeTo = Ogre::Node::TS_LOCAL)
111                { this->roll(Degree(angle), relativeTo); }
112
113            virtual void lookAt(const Vector3& target, Ogre::Node::TransformSpace relativeTo = Ogre::Node::TS_LOCAL, const Vector3& localDirectionVector = Vector3::NEGATIVE_UNIT_Z) = 0;
114            virtual void setDirection(const Vector3& direction, Ogre::Node::TransformSpace relativeTo = Ogre::Node::TS_LOCAL, const Vector3& localDirectionVector = Vector3::NEGATIVE_UNIT_Z) = 0;
115            inline void setDirection(float x, float y, float z, Ogre::Node::TransformSpace relativeTo = Ogre::Node::TS_LOCAL, const Vector3& localDirectionVector = Vector3::NEGATIVE_UNIT_Z)
116                { this->setDirection(Vector3(x, y, z), relativeTo, localDirectionVector); }
117
118            inline void setScale3D(const Vector3& scale)
119                { this->node_->setScale(scale); }
120            inline void setScale3D(float x, float y, float z)
121                { this->node_->setScale(x, y, z); }
122            inline const Vector3& getScale3D(void) const
123                { return this->node_->getScale(); }
124
125            inline void setScale(float scale)
126                { this->node_->setScale(scale, scale, scale); }
127            inline float getScale() const
128                { Vector3 scale = this->getScale3D(); return (scale.x == scale.y && scale.x == scale.z) ? scale.x : 1; }
129
130            inline void scale3D(const Vector3& scale)
131                { this->node_->scale(scale); }
132            inline void scale3D(float x, float y, float z)
133                { this->node_->scale(x, y, z); }
134            inline void scale(float scale)
135                { this->node_->scale(scale, scale, scale); }
136
137            bool hasPhysics()  { return this->physicalBody_; }
138            bool isKinematic() { return this->physicalBody_ && this->physicalBody_->isKinematicObject(); }
139            bool isDynamic()   { return this->physicalBody_ && !this->physicalBody_->isStaticOrKinematicObject(); }
140
141            void attach(WorldEntity* object);
142            void detach(WorldEntity* object);
143            WorldEntity* getAttachedObject(unsigned int index) const;
144            inline const std::set<WorldEntity*>& getAttachedObjects() const
145                { return this->children_; }
146
147            inline void attachOgreObject(Ogre::MovableObject* object)
148                { this->node_->attachObject(object); }
149            inline void detachOgreObject(Ogre::MovableObject* object)
150                { this->node_->detachObject(object); }
151            inline Ogre::MovableObject* detachOgreObject(const Ogre::String& name)
152                { return this->node_->detachObject(name); }
153
154            inline void attachToParent(WorldEntity* parent)
155                { parent->attach(this); }
156            inline void detachFromParent()
157                { if (this->parent_) { this->parent_->detach(this); } }
158            inline WorldEntity* getParent() const
159                { return this->parent_; }
160
161            void setCollisionRadius(float radius);
162            float getCollisionRadius();
163
164            void setCollisionTypeStr(const std::string& type);
165            std::string getCollisionTypeStr();
166
167            void setMass(float mass);
168            float getMass();
169
170            CollisionType getCollisionType();
171
172        protected:
173            //virtual btCollisionShape* getCollisionShape() = 0;
174
175            void createPhysicalBody();
176            //virtual void attachPhysicalObject(WorldEntity* object);
177            virtual void setCollisionType(CollisionType type);
178
179            Ogre::SceneNode* node_;
180            btRigidBody* physicalBody_;
181
182        private:
183            void updateParent();
184
185            inline void lookAt_xmlport(const Vector3& target)
186                { this->lookAt(target); }
187            inline void setDirection_xmlport(const Vector3& direction)
188                { this->setDirection(direction); }
189            inline void yaw_xmlport(const Degree& angle)
190                { this->yaw(angle); }
191            inline void pitch_xmlport(const Degree& angle)
192                { this->pitch(angle); }
193            inline void roll_xmlport(const Degree& angle)
194                { this->roll(angle); }
195
196            WorldEntity* parent_;
197            unsigned int parentID_;
198            std::set<WorldEntity*> children_;
199    };
200}
201
202#endif /* _WorldEntity_H__ */
Note: See TracBrowser for help on using the repository browser.