Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 2301 was 2300, checked in by rgrieder, 16 years ago

Still getting physics and its implications straight:

  • Removed PositionableEntity —> StaticEntity is now the way to go. They cannot be translated in any way during physics simulation. The trick will be to remove them and add them again to Bullet. This however is not yet implemented.
  • Forgot a few consts in WorldEntity
  • Fixed a bug with infinite masses
  • WE throws exception if you try to apply physics when the SceneNode is not in the root space of the Scene.
  • Moved velocity_ to MovableEntity
  • Outside world reference of WE/ME are now always the non-physical values. getPosition() will always return node_→getPosition() and when setting it, both RigidBody and SceneNode are translated. This accounts for velocity, orientation and position.
  • Property svn:eol-style set to native
File size: 9.4 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            WorldEntity(BaseObject* creator);
50            virtual ~WorldEntity();
51
52            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
53            void registerVariables();
54
55            inline const 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 attach(WorldEntity* object);
130            void detach(WorldEntity* object);
131            WorldEntity* getAttachedObject(unsigned int index) const;
132            inline const std::set<WorldEntity*>& getAttachedObjects() const
133                { return this->children_; }
134
135            inline void attachOgreObject(Ogre::MovableObject* object)
136                { this->node_->attachObject(object); }
137            inline void detachOgreObject(Ogre::MovableObject* object)
138                { this->node_->detachObject(object); }
139            inline Ogre::MovableObject* detachOgreObject(const Ogre::String& name)
140                { return this->node_->detachObject(name); }
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            Ogre::SceneNode* node_;
151
152        private:
153            void updateParent();
154
155            inline void lookAt_xmlport(const Vector3& target)
156                { this->lookAt(target); }
157            inline void setDirection_xmlport(const Vector3& direction)
158                { this->setDirection(direction); }
159            inline void yaw_xmlport(const Degree& angle)
160                { this->yaw(angle); }
161            inline void pitch_xmlport(const Degree& angle)
162                { this->pitch(angle); }
163            inline void roll_xmlport(const Degree& angle)
164                { this->roll(angle); }
165
166            WorldEntity* parent_;
167            unsigned int parentID_;
168            std::set<WorldEntity*> children_;
169
170
171        /////////////
172        // Physics //
173        /////////////
174
175        public:
176            enum CollisionType
177            {
178                Dynamic,
179                Kinematic,
180                Static,
181                None
182            };
183
184            bool hasPhysics() const { return getCollisionType() != None; }
185
186            CollisionType getCollisionType() const { return this->collisionType_; }
187            void setCollisionType(CollisionType type);
188
189            void setCollisionTypeStr(const std::string& type);
190            std::string getCollisionTypeStr() const;
191
192            bool isStatic()    const { return getCollisionType() == Static   ; }
193            bool isKinematic() const { return getCollisionType() == Kinematic; }
194            bool isDynamic()   const { return getCollisionType() == Dynamic  ; }
195
196            void setMass(float mass);
197            float getMass() const;
198
199            void setCollisionRadius(float radius);
200            float getCollisionRadius() const;
201
202        protected:
203            //virtual btCollisionShape* getCollisionShape() = 0;
204            //virtual void attachPhysicalObject(WorldEntity* object);
205
206            virtual bool isCollisionTypeLegal(CollisionType type) const = 0;
207            bool checkPhysics() const;
208            void updateCollisionType();
209
210            btRigidBody*  physicalBody_;
211
212        private:
213            CollisionType collisionType_;
214
215    };
216}
217
218#endif /* _WorldEntity_H__ */
Note: See TracBrowser for help on using the repository browser.