Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Dec 15, 2008, 12:53:05 AM (16 years ago)
Author:
rgrieder
Message:

Merged physics_merge back to presentation branch.

Location:
code/branches/presentation
Files:
2 deleted
89 edited
15 copied

Legend:

Unmodified
Added
Removed
  • code/branches/presentation

  • code/branches/presentation/src/orxonox/CMakeLists.txt

    r2171 r2459  
    4848  tinyxml_orxonox
    4949  tolualib_orxonox
     50  BulletDynamics
     51  BulletCollision
     52  LinearMath
    5053  util
    5154  core
  • code/branches/presentation/src/orxonox/CameraManager.cc

  • code/branches/presentation/src/orxonox/CameraManager.h

  • code/branches/presentation/src/orxonox/OrxonoxPrereqs.h

    r2385 r2459  
    107107
    108108    class WorldEntity;
    109     class PositionableEntity;
     109    class StaticEntity;
     110    class MobileEntity;
     111    class ControllableEntity;
    110112    class MovableEntity;
    111     class ControllableEntity;
    112113    class Sublevel;
    113114
     
    153154
    154155    class Scores;
     156
     157    // collision
     158    class CollisionShape;
     159    class SphereCollisionShape;
     160    class CompoundCollisionShape;
     161    class PlaneCollisionShape;
    155162
    156163    // tools
     
    210217}
    211218
     219// Bullet Physics Engine
     220
     221class btTransform;
     222class btVector3;
     223
     224class btRigidBody;
     225class btCollisionObject;
     226class btGhostObject;
     227
     228class btCollisionShape;
     229class btSphereShape;
     230class btCompoundShape;
     231class btStaticPlaneShape;
     232
     233class btDiscreteDynamicsWorld;
     234class bt32BitAxisSweep3;
     235class btDefaultCollisionConfiguration;
     236class btCollisionDispatcher;
     237class btSequentialImpulseConstraintSolver;
     238
     239// lua
    212240struct lua_State;
    213241
  • code/branches/presentation/src/orxonox/OrxonoxStableHeaders.h

    r2371 r2459  
    4747#include <Ogre.h>
    4848#include <CEGUI.h>
    49 #include "ois/OIS.h"
    5049#include <boost/thread/recursive_mutex.hpp>
    5150//#include <boost/thread/mutex.hpp>
     
    5352//#include <boost/thread/thread.hpp>
    5453#include <boost/static_assert.hpp>
     54
     55#include "BulletDynamics/Dynamics/btRigidBody.h"
     56#include "ois/OIS.h"
    5557#include "tinyxml/ticpp.h"
    5658#include "tinyxml/tinyxml.h"
     
    9799#include "network/synchronisable/Synchronisable.h"
    98100
    99 #include "Settings.h"
     101//#include "Settings.h"
    100102
    101103//#endif /* ifdef NDEBUG */
    102104
    103 #endif /* ORXONOX_COMPILER == ORXONOX_COMPILER_MSVC && !defined(ORXONOX_DISABLE_PCH) */
     105#endif /* defined(ORXONOX_ENABLE_PCH) */
    104106
    105107#endif /* _OrxonoxStableHeaders_H__ */
  • code/branches/presentation/src/orxonox/gamestates/GSLevel.cc

    r2103 r2459  
    5151namespace orxonox
    5252{
    53     SetCommandLineArgument(level, "sample2.oxw").shortcut("l");
     53    SetCommandLineArgument(level, "physicstest2.oxw").shortcut("l");
    5454
    5555    GSLevel::GSLevel()
  • code/branches/presentation/src/orxonox/gamestates/GSRoot.cc

    r2171 r2459  
    146146        /*** HACK *** HACK ***/
    147147        // Call the Tickable objects
     148        float leveldt = time.getDeltaTime();
     149        if (leveldt > 1.0f)
     150        {
     151            // just loaded
     152            leveldt = 0.0f;
     153        }
    148154        for (ObjectList<Tickable>::iterator it = ObjectList<Tickable>::begin(); it; ++it)
    149             it->tick(time.getDeltaTime());
     155            it->tick(leveldt);
    150156        /*** HACK *** HACK ***/
    151157
  • code/branches/presentation/src/orxonox/objects/CMakeLists.txt

    r2171 r2459  
    1313)
    1414
     15ADD_SOURCE_DIRECTORY(SRC_FILES collisionshapes)
    1516ADD_SOURCE_DIRECTORY(SRC_FILES controllers)
    1617ADD_SOURCE_DIRECTORY(SRC_FILES gametypes)
  • code/branches/presentation/src/orxonox/objects/Level.cc

    • Property svn:mergeinfo changed (with no actual effect on merging)
  • code/branches/presentation/src/orxonox/objects/Level.h

    • Property svn:mergeinfo changed (with no actual effect on merging)
  • code/branches/presentation/src/orxonox/objects/Scene.cc

    r2371 r2459  
    2222 *   Author:
    2323 *      Fabian 'x3n' Landau
     24 *      Reto Grieder (physics)
    2425 *   Co-authors:
    2526 *      ...
     
    3536#include <OgreLight.h>
    3637
     38#include "BulletCollision/BroadphaseCollision/btAxisSweep3.h"
     39#include "BulletCollision/CollisionDispatch/btDefaultCollisionConfiguration.h"
     40#include "BulletDynamics/ConstraintSolver/btSequentialImpulseConstraintSolver.h"
     41#include "BulletDynamics/Dynamics/btDiscreteDynamicsWorld.h"
     42
    3743#include "core/CoreIncludes.h"
    3844#include "core/Core.h"
    3945#include "core/XMLPort.h"
     46#include "tools/BulletConversions.h"
     47#include "objects/worldentities/WorldEntity.h"
    4048
    4149namespace orxonox
     
    6977            this->rootSceneNode_ = this->sceneManager_->getRootSceneNode();
    7078        }
     79
     80        // No physics yet, XMLPort will do that.
     81        const int defaultMaxWorldSize = 100000;
     82        this->negativeWorldRange_ = Vector3::UNIT_SCALE * -defaultMaxWorldSize;
     83        this->positiveWorldRange_ = Vector3::UNIT_SCALE *  defaultMaxWorldSize;
     84        this->gravity_ = Vector3::ZERO;
     85        this->physicalWorld_   = 0;
     86        this->solver_          = 0;
     87        this->dispatcher_      = 0;
     88        this->collisionConfig_ = 0;
     89        this->broadphase_      = 0;
    7190
    7291        // test test test
     
    91110            if (Ogre::Root::getSingletonPtr())
    92111            {
    93 //                this->sceneManager_->destroySceneNode(this->rootSceneNode_->getName()); // TODO: remove getName() for newer versions of Ogre
    94112                Ogre::Root::getSingleton().destroySceneManager(this->sceneManager_);
    95113            }
     
    98116                delete this->sceneManager_;
    99117            }
     118
     119            this->setPhysicalWorld(false);
    100120        }
    101121    }
     
    109129        XMLPortParam(Scene, "shadow", setShadow, getShadow, xmlelement, mode).defaultValues(true);
    110130
     131        XMLPortParam(Scene, "negativeWorldRange", setNegativeWorldRange, getNegativeWorldRange, xmlelement, mode);
     132        XMLPortParam(Scene, "positiveWorldRange", setPositiveWorldRange, getPositiveWorldRange, xmlelement, mode);
     133        XMLPortParam(Scene, "hasPhysics", setPhysicalWorld, hasPhysics, xmlelement, mode).defaultValues(true);
     134
    111135        XMLPortObjectExtended(Scene, BaseObject, "", addObject, getObject, xmlelement, mode, true, false);
    112136    }
     
    114138    void Scene::registerVariables()
    115139    {
    116         registerVariable(this->skybox_,     variableDirection::toclient, new NetworkCallback<Scene>(this, &Scene::networkcallback_applySkybox));
    117         registerVariable(this->ambientLight_, variableDirection::toclient, new NetworkCallback<Scene>(this, &Scene::networkcallback_applyAmbientLight));
     140        registerVariable(this->skybox_,             variableDirection::toclient, new NetworkCallback<Scene>(this, &Scene::networkcallback_applySkybox));
     141        registerVariable(this->ambientLight_,       variableDirection::toclient, new NetworkCallback<Scene>(this, &Scene::networkcallback_applyAmbientLight));
     142        registerVariable(this->negativeWorldRange_, variableDirection::toclient, new NetworkCallback<Scene>(this, &Scene::networkcallback_negativeWorldRange));
     143        registerVariable(this->positiveWorldRange_, variableDirection::toclient, new NetworkCallback<Scene>(this, &Scene::networkcallback_positiveWorldRange));
     144        registerVariable(this->gravity_,            variableDirection::toclient, new NetworkCallback<Scene>(this, &Scene::networkcallback_gravity));
     145        registerVariable(this->bHasPhysics_,        variableDirection::toclient, new NetworkCallback<Scene>(this, &Scene::networkcallback_hasPhysics));
     146    }
     147
     148    void Scene::setNegativeWorldRange(const Vector3& range)
     149    {
     150        if (range.length() < 10.0f)
     151        {
     152            CCOUT(2) << "Warning: Setting the negative world range to a very small value: "
     153                     << omni_cast<std::string>(range) << std::endl;
     154        }
     155        if (this->hasPhysics())
     156        {
     157            CCOUT(2) << "Warning: Attempting to set the physical world range at run time. "
     158                     << "This causes a complete physical reload which might take some time." << std::endl;
     159            this->setPhysicalWorld(false);
     160            this->negativeWorldRange_ = range;
     161            this->setPhysicalWorld(true);
     162        }
     163        else
     164            this->negativeWorldRange_ = range;
     165    }
     166
     167    void Scene::setPositiveWorldRange(const Vector3& range)
     168    {
     169        if (range.length() < 10.0f)
     170        {
     171            CCOUT(2) << "Warning: Setting the positive world range to a very small value: "
     172                     << omni_cast<std::string>(range) << std::endl;
     173        }
     174        if (this->hasPhysics())
     175        {
     176            CCOUT(2) << "Warning: Attempting to set the physical world range at run time. "
     177                     << "This causes a complete physical reload which might take some time." << std::endl;
     178            this->setPhysicalWorld(false);
     179            this->positiveWorldRange_ = range;
     180            this->setPhysicalWorld(true);
     181        }
     182        else
     183            this->positiveWorldRange_ = range;
     184    }
     185
     186    void Scene::setGravity(const Vector3& gravity)
     187    {
     188        this->gravity_ = gravity;
     189        if (this->hasPhysics())
     190            this->physicalWorld_->setGravity(omni_cast<btVector3>(this->gravity_));
     191    }
     192
     193    void Scene::setPhysicalWorld(bool wantPhysics)
     194    {
     195        this->bHasPhysics_ = wantPhysics;
     196        if (wantPhysics && !hasPhysics())
     197        {
     198            // Note: These are all little known default classes and values.
     199            //       It would require further investigation to properly dertermine the right choices.
     200            this->broadphase_      = new bt32BitAxisSweep3(
     201                omni_cast<btVector3>(this->negativeWorldRange_), omni_cast<btVector3>(this->positiveWorldRange_));
     202            this->collisionConfig_ = new btDefaultCollisionConfiguration();
     203            this->dispatcher_      = new btCollisionDispatcher(this->collisionConfig_);
     204            this->solver_          = new btSequentialImpulseConstraintSolver;
     205
     206            this->physicalWorld_   = new btDiscreteDynamicsWorld(this->dispatcher_, this->broadphase_, this->solver_, this->collisionConfig_);
     207            this->physicalWorld_->setGravity(omni_cast<btVector3>(this->gravity_));
     208        }
     209        else if (!wantPhysics && hasPhysics())
     210        {
     211            // Remove all WorldEntities and shove them to the queue since they would still like to be in a physical world.
     212            for (std::set<WorldEntity*>::const_iterator it = this->physicalObjects_.begin();
     213                it != this->physicalObjects_.end(); ++it)
     214            {
     215                this->physicalWorld_->removeRigidBody((*it)->getPhysicalBody());
     216                this->physicalObjectQueue_.insert(*it);
     217            }
     218            this->physicalObjects_.clear();
     219
     220            delete this->physicalWorld_;
     221            delete this->solver_;
     222            delete this->dispatcher_;
     223            delete this->collisionConfig_;
     224            delete this->broadphase_;
     225            this->physicalWorld_   = 0;
     226            this->solver_          = 0;
     227            this->dispatcher_      = 0;
     228            this->collisionConfig_ = 0;
     229            this->broadphase_      = 0;
     230        }
     231    }
     232
     233    void Scene::tick(float dt)
     234    {
     235        if (!Core::showsGraphics())
     236        {
     237            // We need to update the scene nodes if we don't render
     238            this->rootSceneNode_->_update(true, false);
     239        }
     240        if (this->hasPhysics())
     241        {
     242            // TODO: This here is bad practice! It will slow down the first tick() by ages.
     243            //       Rather have an initialise() method as well, called by the Level after everything has been loaded.
     244            if (this->physicalObjectQueue_.size() > 0)
     245            {
     246                // Add all scheduled WorldEntities
     247                for (std::set<WorldEntity*>::const_iterator it = this->physicalObjectQueue_.begin();
     248                    it != this->physicalObjectQueue_.end(); ++it)
     249                {
     250                    this->physicalWorld_->addRigidBody((*it)->getPhysicalBody());
     251                }
     252                this->physicalObjectQueue_.clear();
     253            }
     254
     255            // Note: 60 means that Bullet will do physics correctly down to 1 frames per seconds.
     256            //       Under that mark, the simulation will "loose time" and get unusable.
     257            physicalWorld_->stepSimulation(dt, 60);
     258        }
    118259    }
    119260
     
    165306    }
    166307
    167     void Scene::tick(float dt)
    168     {
    169         if (!Core::showsGraphics())
    170         {
    171             // We need to update the scene nodes if we don't render
    172             this->rootSceneNode_->_update(true, false);
    173         }
     308    void Scene::addPhysicalObject(WorldEntity* object)
     309    {
     310        if (object)
     311        {
     312            std::set<WorldEntity*>::iterator it = this->physicalObjects_.find(object);
     313            if (it != this->physicalObjects_.end())
     314                return;
     315
     316            this->physicalObjectQueue_.insert(object);
     317        }
     318    }
     319
     320    void Scene::removePhysicalObject(WorldEntity* object)
     321    {
     322        // check queue first
     323        std::set<WorldEntity*>::iterator it = this->physicalObjectQueue_.find(object);
     324        if (it != this->physicalObjectQueue_.end())
     325        {
     326            this->physicalObjectQueue_.erase(it);
     327            return;
     328        }
     329
     330        it = this->physicalObjects_.find(object);
     331        if (it == this->physicalObjects_.end())
     332            return;
     333        this->physicalObjects_.erase(it);
     334
     335        if (this->hasPhysics())
     336            this->physicalWorld_->removeRigidBody(object->getPhysicalBody());
    174337    }
    175338}
  • code/branches/presentation/src/orxonox/objects/Scene.h

    r2371 r2459  
    2222 *   Author:
    2323 *      Fabian 'x3n' Landau
     24 *      Reto Grieder (physics)
    2425 *   Co-authors:
    2526 *      ...
     
    7677                { this->setAmbientLight(this->ambientLight_); }
    7778
    78             Ogre::SceneManager*    sceneManager_;
    79             Ogre::SceneNode*       rootSceneNode_;
    80             std::string            skybox_;
    81             ColourValue            ambientLight_;
    82             std::list<BaseObject*> objects_;
    83             bool                   bShadows_;
     79            Ogre::SceneManager*      sceneManager_;
     80            Ogre::SceneNode*         rootSceneNode_;
     81
     82            std::string              skybox_;
     83            ColourValue              ambientLight_;
     84            std::list<BaseObject*>   objects_;
     85            bool                     bShadows_;
     86
     87
     88        /////////////
     89        // Physics //
     90        /////////////
     91
     92        public:
     93            inline bool hasPhysics()
     94                { return this->physicalWorld_ != 0; }
     95            void setPhysicalWorld(bool wantsPhysics);
     96
     97            void setNegativeWorldRange(const Vector3& range);
     98            inline const Vector3& getNegativeWorldRange() const
     99                { return this->negativeWorldRange_; }
     100
     101            void setPositiveWorldRange(const Vector3& range);
     102            inline const Vector3& getPositiveWorldRange() const
     103                { return this->positiveWorldRange_; }
     104
     105            void setGravity(const Vector3& gravity);
     106            inline const Vector3& getGravity() const
     107                { return this->gravity_; }
     108
     109            void addPhysicalObject(WorldEntity* object);
     110            void removePhysicalObject(WorldEntity* object);
     111
     112        private:
     113            inline void networkcallback_hasPhysics()
     114                { this->setPhysicalWorld(this->bHasPhysics_); }
     115            inline void networkcallback_negativeWorldRange()
     116                { this->setNegativeWorldRange(this->negativeWorldRange_); }
     117            inline void networkcallback_positiveWorldRange()
     118                { this->setPositiveWorldRange(this->positiveWorldRange_); }
     119            inline void networkcallback_gravity()
     120                { this->setGravity(this->gravity_); }
     121
     122            // Bullet objects
     123            btDiscreteDynamicsWorld*             physicalWorld_;
     124            bt32BitAxisSweep3*                   broadphase_;
     125            btDefaultCollisionConfiguration*     collisionConfig_;
     126            btCollisionDispatcher*               dispatcher_;
     127            btSequentialImpulseConstraintSolver* solver_;
     128
     129            std::set<WorldEntity*>               physicalObjectQueue_;
     130            std::set<WorldEntity*>               physicalObjects_;
     131            bool                                 bHasPhysics_;
     132            Vector3                              negativeWorldRange_;
     133            Vector3                              positiveWorldRange_;
     134            Vector3                              gravity_;
    84135    };
    85136}
  • code/branches/presentation/src/orxonox/objects/collisionshapes

  • code/branches/presentation/src/orxonox/objects/pickup/Usable.h

  • code/branches/presentation/src/orxonox/objects/quest/AddQuest.cc

  • code/branches/presentation/src/orxonox/objects/quest/AddQuest.h

  • code/branches/presentation/src/orxonox/objects/quest/AddQuestHint.cc

  • code/branches/presentation/src/orxonox/objects/quest/AddQuestHint.h

  • code/branches/presentation/src/orxonox/objects/quest/AddReward.cc

  • code/branches/presentation/src/orxonox/objects/quest/AddReward.h

  • code/branches/presentation/src/orxonox/objects/quest/ChangeQuestStatus.cc

  • code/branches/presentation/src/orxonox/objects/quest/ChangeQuestStatus.h

  • code/branches/presentation/src/orxonox/objects/quest/CompleteQuest.cc

  • code/branches/presentation/src/orxonox/objects/quest/CompleteQuest.h

  • code/branches/presentation/src/orxonox/objects/quest/FailQuest.cc

  • code/branches/presentation/src/orxonox/objects/quest/FailQuest.h

  • code/branches/presentation/src/orxonox/objects/quest/GlobalQuest.cc

  • code/branches/presentation/src/orxonox/objects/quest/GlobalQuest.h

  • code/branches/presentation/src/orxonox/objects/quest/LocalQuest.cc

  • code/branches/presentation/src/orxonox/objects/quest/LocalQuest.h

  • code/branches/presentation/src/orxonox/objects/quest/Quest.cc

  • code/branches/presentation/src/orxonox/objects/quest/Quest.h

  • code/branches/presentation/src/orxonox/objects/quest/QuestDescription.cc

  • code/branches/presentation/src/orxonox/objects/quest/QuestDescription.h

  • code/branches/presentation/src/orxonox/objects/quest/QuestEffect.cc

  • code/branches/presentation/src/orxonox/objects/quest/QuestEffect.h

  • code/branches/presentation/src/orxonox/objects/quest/QuestEffectBeacon.cc

    r2435 r2459  
    5353        Constructor. Registers the object and initializes defaults.
    5454    */
    55     QuestEffectBeacon::QuestEffectBeacon(BaseObject* creator) : PositionableEntity(creator)
     55    QuestEffectBeacon::QuestEffectBeacon(BaseObject* creator) : StaticEntity(creator)
    5656    {
    5757        RegisterObject(QuestEffectBeacon);
  • code/branches/presentation/src/orxonox/objects/quest/QuestEffectBeacon.h

    r2435 r2459  
    3737#include "OrxonoxPrereqs.h"
    3838
    39 #include "orxonox/objects/worldentities/PositionableEntity.h"
     39#include "orxonox/objects/worldentities/StaticEntity.h"
    4040
    4141namespace orxonox
     
    8080        Damian 'Mozork' Frick
    8181    */
    82     class _OrxonoxExport QuestEffectBeacon : public PositionableEntity
     82    class _OrxonoxExport QuestEffectBeacon : public StaticEntity
    8383    {
    8484        public:
  • code/branches/presentation/src/orxonox/objects/quest/QuestHint.cc

  • code/branches/presentation/src/orxonox/objects/quest/QuestHint.h

  • code/branches/presentation/src/orxonox/objects/quest/QuestItem.cc

  • code/branches/presentation/src/orxonox/objects/quest/QuestItem.h

  • code/branches/presentation/src/orxonox/objects/quest/QuestManager.cc

  • code/branches/presentation/src/orxonox/objects/quest/QuestManager.h

  • code/branches/presentation/src/orxonox/objects/quest/Rewardable.cc

  • code/branches/presentation/src/orxonox/objects/quest/Rewardable.h

  • code/branches/presentation/src/orxonox/objects/weaponSystem/WeaponSystem.cc

  • code/branches/presentation/src/orxonox/objects/weaponSystem/WeaponSystem.h

  • code/branches/presentation/src/orxonox/objects/worldentities/Backlight.cc

  • code/branches/presentation/src/orxonox/objects/worldentities/Backlight.h

    r2420 r2459  
    3232#include "OrxonoxPrereqs.h"
    3333
    34 #include "PositionableEntity.h"
     34#include "StaticEntity.h"
    3535#include "tools/BillboardSet.h"
    3636
    3737namespace orxonox
    3838{
    39     class _OrxonoxExport Backlight : public PositionableEntity
     39    class _OrxonoxExport Backlight : public StaticEntity
    4040    {
    4141        public:
  • code/branches/presentation/src/orxonox/objects/worldentities/Billboard.cc

    r2371 r2459  
    3030#include "Billboard.h"
    3131
     32#include <OgreBillboardSet.h>
     33
    3234#include "core/CoreIncludes.h"
    3335#include "core/XMLPort.h"
     
    3840    CreateFactory(Billboard);
    3941
    40     Billboard::Billboard(BaseObject* creator) : PositionableEntity(creator)
     42    Billboard::Billboard(BaseObject* creator) : StaticEntity(creator)
    4143    {
    4244        RegisterObject(Billboard);
     
    5052        {
    5153            if (this->isInitialized() && this->billboard_.getBillboardSet())
    52                 this->getNode()->detachObject(this->billboard_.getName());
     54                this->detachOgreObject(this->billboard_.getName());
    5355        }
    5456    }
     
    7678                this->billboard_.setBillboardSet(this->getScene()->getSceneManager(), this->material_, this->colour_, 1);
    7779                if (this->billboard_.getBillboardSet())
    78                     this->getNode()->attachObject(this->billboard_.getBillboardSet());
     80                     this->attachOgreObject(this->billboard_.getBillboardSet());
    7981                this->billboard_.setVisible(this->isVisible());
    8082            }
     
    9294                this->billboard_.setBillboardSet(this->getScene()->getSceneManager(), this->material_, this->colour_, 1);
    9395                if (this->billboard_.getBillboardSet())
    94                     this->getNode()->attachObject(this->billboard_.getBillboardSet());
     96                    this->attachOgreObject(this->billboard_.getBillboardSet());
    9597                this->billboard_.setVisible(this->isVisible());
    9698            }
  • code/branches/presentation/src/orxonox/objects/worldentities/Billboard.h

    r2087 r2459  
    3131
    3232#include "OrxonoxPrereqs.h"
    33 #include "PositionableEntity.h"
     33#include "StaticEntity.h"
    3434#include "util/Math.h"
    3535#include "tools/BillboardSet.h"
     
    3737namespace orxonox
    3838{
    39     class _OrxonoxExport Billboard : public PositionableEntity
     39    class _OrxonoxExport Billboard : public StaticEntity
    4040    {
    4141        public:
  • code/branches/presentation/src/orxonox/objects/worldentities/CMakeLists.txt

    r2420 r2459  
    11SET( SRC_FILES
    22  WorldEntity.cc
    3   PositionableEntity.cc
     3  StaticEntity.cc
    44  MovableEntity.cc
     5  MobileEntity.cc
    56  ControllableEntity.cc
    67  Model.cc
  • code/branches/presentation/src/orxonox/objects/worldentities/Camera.cc

    r2420 r2459  
    4848    CreateFactory(Camera);
    4949
    50     Camera::Camera(BaseObject* creator) : PositionableEntity(creator)
     50    Camera::Camera(BaseObject* creator) : StaticEntity(creator)
    5151    {
    5252        RegisterObject(Camera);
     
    5656
    5757        this->camera_ = this->getScene()->getSceneManager()->createCamera(getUniqueNumberString());
    58         this->getNode()->attachObject(this->camera_);
     58        this->attachOgreObject(this->camera_);
    5959
    6060        this->bHasFocus_ = false;
  • code/branches/presentation/src/orxonox/objects/worldentities/Camera.h

    r2420 r2459  
    3333
    3434#include <OgrePrerequisites.h>
    35 #include "objects/worldentities/PositionableEntity.h"
     35#include "objects/worldentities/StaticEntity.h"
    3636#include "objects/Tickable.h"
    3737
    3838namespace orxonox
    3939{
    40     class _OrxonoxExport Camera : public PositionableEntity, public Tickable
     40    class _OrxonoxExport Camera : public StaticEntity, public Tickable
    4141    {
    4242        friend class CameraManager;
  • code/branches/presentation/src/orxonox/objects/worldentities/CameraPosition.cc

    r2087 r2459  
    3838    CreateFactory(CameraPosition);
    3939
    40     CameraPosition::CameraPosition(BaseObject* creator) : PositionableEntity(creator)
     40    CameraPosition::CameraPosition(BaseObject* creator) : StaticEntity(creator)
    4141    {
    4242        RegisterObject(CameraPosition);
  • code/branches/presentation/src/orxonox/objects/worldentities/CameraPosition.h

    r2087 r2459  
    3232#include "OrxonoxPrereqs.h"
    3333
    34 #include "objects/worldentities/PositionableEntity.h"
     34#include "objects/worldentities/StaticEntity.h"
    3535
    3636namespace orxonox
    3737{
    38     class _OrxonoxExport CameraPosition : public PositionableEntity
     38    class _OrxonoxExport CameraPosition : public StaticEntity
    3939    {
    4040        public:
  • code/branches/presentation/src/orxonox/objects/worldentities/ControllableEntity.cc

    r2415 r2459  
    2323 *      Fabian 'x3n' Landau
    2424 *   Co-authors:
    25  *      ...
     25 *      Reto Grieder
    2626 *
    2727 */
     
    4444    CreateFactory(ControllableEntity);
    4545
    46     ControllableEntity::ControllableEntity(BaseObject* creator) : WorldEntity(creator)
     46    ControllableEntity::ControllableEntity(BaseObject* creator) : MobileEntity(creator)
    4747    {
    4848        RegisterObject(ControllableEntity);
     
    5757        this->bDestroyWhenPlayerLeft_ = false;
    5858
    59         this->velocity_ = Vector3::ZERO;
    60         this->acceleration_ = Vector3::ZERO;
    61 
    62         this->server_position_ = Vector3::ZERO;
    63         this->client_position_ = Vector3::ZERO;
    64         this->server_velocity_ = Vector3::ZERO;
    65         this->client_velocity_ = Vector3::ZERO;
    66         this->server_orientation_ = Quaternion::IDENTITY;
    67         this->client_orientation_ = Quaternion::IDENTITY;
    68        
     59        this->server_position_        = Vector3::ZERO;
     60        this->client_position_        = Vector3::ZERO;
     61        this->server_linear_velocity_  = Vector3::ZERO;
     62        this->client_linear_velocity_ = Vector3::ZERO;
     63        this->server_orientation_      = Quaternion::IDENTITY;
     64        this->client_orientation_      = Quaternion::IDENTITY;
     65        this->server_angular_velocity_ = Vector3::ZERO;
     66        this->client_angular_velocity_ = Vector3::ZERO;
     67
     68
    6969        this->setPriority( priority::very_high );
    70 
    7170        this->registerVariables();
    7271    }
     
    229228    void ControllableEntity::tick(float dt)
    230229    {
     230        MobileEntity::tick(dt);
     231
    231232        if (this->isActive())
    232233        {
    233             this->velocity_ += (dt * this->acceleration_);
    234             this->node_->translate(dt * this->velocity_, Ogre::Node::TS_LOCAL);
    235 
    236             if (Core::isMaster())
     234            // Check whether Bullet doesn't do the physics for us
     235            if (!this->isDynamic())
    237236            {
    238                 this->server_velocity_ = this->velocity_;
    239                 this->server_position_ = this->node_->getPosition();
     237                if (Core::isMaster())
     238                {
     239                    this->server_position_ = this->getPosition();
     240                    this->server_orientation_ = this->getOrientation();
     241                    this->server_linear_velocity_ = this->getVelocity();
     242                    this->server_angular_velocity_ = this->getAngularVelocity();
     243                }
     244                else if (this->bControlled_)
     245                {
     246                    this->client_position_ = this->getPosition();
     247                    this->client_orientation_ = this->getOrientation();
     248                    this->client_linear_velocity_ = this->getVelocity();
     249                    this->client_angular_velocity_ = this->getAngularVelocity();
     250                }
    240251            }
    241             else if (this->bControlled_)
    242             {
    243 //                COUT(2) << "setting client position" << endl;
    244                 this->client_velocity_ = this->velocity_;
    245                 this->client_position_ = this->node_->getPosition();
    246             }
    247252        }
    248253    }
     
    251256    {
    252257        registerVariable(this->cameraPositionTemplate_, variableDirection::toclient);
    253  
    254         registerVariable(this->client_overwrite_,   variableDirection::toserver);
    255          
    256         registerVariable(this->server_position_,    variableDirection::toclient, new NetworkCallback<ControllableEntity>(this, &ControllableEntity::processServerPosition));
    257         registerVariable(this->server_velocity_,    variableDirection::toclient, new NetworkCallback<ControllableEntity>(this, &ControllableEntity::processServerVelocity));
    258         registerVariable(this->server_orientation_, variableDirection::toclient, new NetworkCallback<ControllableEntity>(this, &ControllableEntity::processServerOrientation));
    259         registerVariable(this->server_overwrite_,   variableDirection::toclient, new NetworkCallback<ControllableEntity>(this, &ControllableEntity::processOverwrite));
    260  
    261         registerVariable(this->client_position_,    variableDirection::toserver, new NetworkCallback<ControllableEntity>(this, &ControllableEntity::processClientPosition));
    262         registerVariable(this->client_velocity_,    variableDirection::toserver, new NetworkCallback<ControllableEntity>(this, &ControllableEntity::processClientVelocity));
    263         registerVariable(this->client_orientation_, variableDirection::toserver, new NetworkCallback<ControllableEntity>(this, &ControllableEntity::processClientOrientation));
    264  
    265  
    266         registerVariable(this->playerID_, variableDirection::toclient, new NetworkCallback<ControllableEntity>(this, &ControllableEntity::networkcallback_changedplayerID));
     258
     259        registerVariable(this->server_position_,         variableDirection::toclient, new NetworkCallback<ControllableEntity>(this, &ControllableEntity::processServerPosition));
     260        registerVariable(this->server_linear_velocity_,  variableDirection::toclient, new NetworkCallback<ControllableEntity>(this, &ControllableEntity::processServerLinearVelocity));
     261        registerVariable(this->server_orientation_,      variableDirection::toclient, new NetworkCallback<ControllableEntity>(this, &ControllableEntity::processServerOrientation));
     262        registerVariable(this->server_angular_velocity_, variableDirection::toclient, new NetworkCallback<ControllableEntity>(this, &ControllableEntity::processServerAngularVelocity));
     263
     264        registerVariable(this->server_overwrite_,        variableDirection::toclient, new NetworkCallback<ControllableEntity>(this, &ControllableEntity::processOverwrite));
     265        registerVariable(this->client_overwrite_,        variableDirection::toserver);
     266
     267        registerVariable(this->client_position_,         variableDirection::toserver, new NetworkCallback<ControllableEntity>(this, &ControllableEntity::processClientPosition));
     268        registerVariable(this->client_linear_velocity_,  variableDirection::toserver, new NetworkCallback<ControllableEntity>(this, &ControllableEntity::processClientLinearVelocity));
     269        registerVariable(this->client_orientation_,      variableDirection::toserver, new NetworkCallback<ControllableEntity>(this, &ControllableEntity::processClientOrientation));
     270        registerVariable(this->client_angular_velocity_, variableDirection::toserver, new NetworkCallback<ControllableEntity>(this, &ControllableEntity::processClientAngularVelocity));
     271
     272        registerVariable(this->playerID_,                variableDirection::toclient, new NetworkCallback<ControllableEntity>(this, &ControllableEntity::networkcallback_changedplayerID));
    267273    }
    268274
     
    270276    {
    271277        if (!this->bControlled_)
    272             this->node_->setPosition(this->server_position_);
    273     }
    274 
    275     void ControllableEntity::processServerVelocity()
     278            this->setPosition(this->server_position_);
     279    }
     280
     281    void ControllableEntity::processServerLinearVelocity()
    276282    {
    277283        if (!this->bControlled_)
    278             this->velocity_ = this->server_velocity_;
     284            this->setVelocity(this->server_linear_velocity_);
    279285    }
    280286
     
    282288    {
    283289        if (!this->bControlled_)
    284             this->node_->setOrientation(this->server_orientation_);
     290            this->setOrientation(this->server_orientation_);
     291    }
     292
     293    void ControllableEntity::processServerAngularVelocity()
     294    {
     295        if (!this->bControlled_)
     296            this->setAngularVelocity(this->server_angular_velocity_);
    285297    }
    286298
     
    290302        {
    291303            this->setPosition(this->server_position_);
    292             this->setVelocity(this->server_velocity_);
    293304            this->setOrientation(this->server_orientation_);
     305            this->setVelocity(this->server_linear_velocity_);
     306            this->setAngularVelocity(this->server_angular_velocity_);
    294307
    295308            this->client_overwrite_ = this->server_overwrite_;
     
    301314        if (this->server_overwrite_ == this->client_overwrite_)
    302315        {
    303 //            COUT(2) << "callback: setting client position" << endl;
    304             this->node_->setPosition(this->client_position_);
    305             this->server_position_ = this->client_position_;
    306         }
    307 //        else
    308 //          COUT(2) << "callback: not setting client position" << endl;
    309     }
    310 
    311     void ControllableEntity::processClientVelocity()
     316            this->setPosition(this->client_position_);
     317            // The call above increments the overwrite. This is not desired to reduce traffic
     318            --this->server_overwrite_;
     319        }
     320    }
     321
     322    void ControllableEntity::processClientLinearVelocity()
    312323    {
    313324        if (this->server_overwrite_ == this->client_overwrite_)
    314325        {
    315             this->velocity_ = this->client_velocity_;
    316             this->server_velocity_ = this->client_velocity_;
     326            this->setVelocity(this->client_linear_velocity_);
     327            // The call above increments the overwrite. This is not desired to reduce traffic
     328            --this->server_overwrite_;
    317329        }
    318330    }
     
    322334        if (this->server_overwrite_ == this->client_overwrite_)
    323335        {
    324             this->node_->setOrientation(this->client_orientation_);
    325             this->server_orientation_ = this->client_orientation_;
    326         }
    327     }
    328 
     336            this->setOrientation(this->client_orientation_);
     337            // The call above increments the overwrite. This is not desired to reduce traffic
     338            --this->server_overwrite_;
     339        }
     340    }
     341
     342    void ControllableEntity::processClientAngularVelocity()
     343    {
     344        if (this->server_overwrite_ == this->client_overwrite_)
     345        {
     346            this->setAngularVelocity(this->client_angular_velocity_);
     347            // The call above increments the overwrite. This is not desired to reduce traffic
     348            --this->server_overwrite_;
     349        }
     350    }
    329351
    330352    void ControllableEntity::setPosition(const Vector3& position)
     
    332354        if (Core::isMaster())
    333355        {
    334             this->node_->setPosition(position);
    335             this->server_position_ = position;
     356            MobileEntity::setPosition(position);
     357            this->server_position_ = this->getPosition();
    336358            ++this->server_overwrite_;
    337359        }
    338360        else if (this->bControlled_)
    339361        {
    340             this->node_->setPosition(position);
    341             this->client_position_ = position;
     362            MobileEntity::setPosition(position);
     363            this->client_position_ = this->getPosition();
     364        }
     365    }
     366
     367    void ControllableEntity::setOrientation(const Quaternion& orientation)
     368    {
     369        if (Core::isMaster())
     370        {
     371            MobileEntity::setOrientation(orientation);
     372            this->server_orientation_ = this->getOrientation();
     373            ++this->server_overwrite_;
     374        }
     375        else if (this->bControlled_)
     376        {
     377            MobileEntity::setOrientation(orientation);
     378            this->client_orientation_ = this->getOrientation();
    342379        }
    343380    }
     
    347384        if (Core::isMaster())
    348385        {
    349             this->velocity_ = velocity;
    350             this->server_velocity_ = velocity;
     386            MobileEntity::setVelocity(velocity);
     387            this->server_linear_velocity_ = this->getVelocity();
    351388            ++this->server_overwrite_;
    352389        }
    353390        else if (this->bControlled_)
    354391        {
    355             this->velocity_ = velocity;
    356             this->client_velocity_ = velocity;
    357         }
    358     }
    359 
    360     void ControllableEntity::translate(const Vector3& distance, Ogre::Node::TransformSpace relativeTo)
     392            MobileEntity::setVelocity(velocity);
     393            this->client_linear_velocity_ = this->getVelocity();
     394        }
     395    }
     396
     397    void ControllableEntity::setAngularVelocity(const Vector3& velocity)
    361398    {
    362399        if (Core::isMaster())
    363400        {
    364             this->node_->translate(distance, relativeTo);
    365             this->server_position_ = this->node_->getPosition();
     401            MobileEntity::setAngularVelocity(velocity);
     402            this->server_angular_velocity_ = this->getAngularVelocity();
    366403            ++this->server_overwrite_;
    367404        }
    368405        else if (this->bControlled_)
    369406        {
    370             this->node_->translate(distance, relativeTo);
    371             this->client_position_ = this->node_->getPosition();
    372         }
    373     }
    374 
    375     void ControllableEntity::setOrientation(const Quaternion& orientation)
    376     {
     407            MobileEntity::setAngularVelocity(velocity);
     408            this->client_angular_velocity_ = this->getAngularVelocity();
     409        }
     410    }
     411
     412    void ControllableEntity::setWorldTransform(const btTransform& worldTrans)
     413    {
     414        MobileEntity::setWorldTransform(worldTrans);
    377415        if (Core::isMaster())
    378416        {
    379             this->node_->setOrientation(orientation);
    380             this->server_orientation_ = orientation;
    381             ++this->server_overwrite_;
     417            this->server_position_ = this->getPosition();
     418            this->server_orientation_ = this->getOrientation();
     419            this->server_linear_velocity_ = this->getVelocity();
     420            this->server_angular_velocity_ = this->getAngularVelocity();
    382421        }
    383422        else if (this->bControlled_)
    384423        {
    385             this->node_->setOrientation(orientation);
    386             this->client_orientation_ = orientation;
    387         }
    388     }
    389 
    390     void ControllableEntity::rotate(const Quaternion& rotation, Ogre::Node::TransformSpace relativeTo)
    391     {
    392         if (Core::isMaster())
    393         {
    394             this->node_->rotate(rotation, relativeTo);
    395             this->server_orientation_ = this->node_->getOrientation();
    396             ++this->server_overwrite_;
    397         }
    398         else if (this->bControlled_)
    399         {
    400             this->node_->rotate(rotation, relativeTo);
    401             this->client_orientation_ = this->node_->getOrientation();
    402         }
    403     }
    404 
    405     void ControllableEntity::yaw(const Degree& angle, Ogre::Node::TransformSpace relativeTo)
    406     {
    407         if (Core::isMaster())
    408         {
    409             this->node_->yaw(angle, relativeTo);
    410             this->server_orientation_ = this->node_->getOrientation();
    411             ++this->server_overwrite_;
    412         }
    413         else if (this->bControlled_)
    414         {
    415             this->node_->yaw(angle, relativeTo);
    416             this->client_orientation_ = this->node_->getOrientation();
    417         }
    418     }
    419 
    420     void ControllableEntity::pitch(const Degree& angle, Ogre::Node::TransformSpace relativeTo)
    421     {
    422         if (Core::isMaster())
    423         {
    424             this->node_->pitch(angle, relativeTo);
    425             this->server_orientation_ = this->node_->getOrientation();
    426             ++this->server_overwrite_;
    427         }
    428         else if (this->bControlled_)
    429         {
    430             this->node_->pitch(angle, relativeTo);
    431             this->client_orientation_ = this->node_->getOrientation();
    432         }
    433     }
    434 
    435     void ControllableEntity::roll(const Degree& angle, Ogre::Node::TransformSpace relativeTo)
    436     {
    437         if (Core::isMaster())
    438         {
    439             this->node_->roll(angle, relativeTo);
    440             this->server_orientation_ = this->node_->getOrientation();
    441             ++this->server_overwrite_;
    442         }
    443         else if (this->bControlled_)
    444         {
    445             this->node_->roll(angle, relativeTo);
    446             this->client_orientation_ = this->node_->getOrientation();
    447         }
    448     }
    449 
    450     void ControllableEntity::lookAt(const Vector3& target, Ogre::Node::TransformSpace relativeTo, const Vector3& localDirectionVector)
    451     {
    452         if (Core::isMaster())
    453         {
    454             this->node_->lookAt(target, relativeTo, localDirectionVector);
    455             this->server_orientation_ = this->node_->getOrientation();
    456             ++this->server_overwrite_;
    457         }
    458         else if (this->bControlled_)
    459         {
    460             this->node_->lookAt(target, relativeTo, localDirectionVector);
    461             this->client_orientation_ = this->node_->getOrientation();
    462         }
    463     }
    464 
    465     void ControllableEntity::setDirection(const Vector3& direction, Ogre::Node::TransformSpace relativeTo, const Vector3& localDirectionVector)
    466     {
    467         if (Core::isMaster())
    468         {
    469             this->node_->setDirection(direction, relativeTo, localDirectionVector);
    470             this->server_orientation_ = this->node_->getOrientation();
    471             ++this->server_overwrite_;
    472         }
    473         else if (this->bControlled_)
    474         {
    475             this->node_->setDirection(direction, relativeTo, localDirectionVector);
    476             this->client_orientation_ = this->node_->getOrientation();
     424            this->client_position_ = this->getPosition();
     425            this->client_orientation_ = this->getOrientation();
     426            this->client_linear_velocity_ = this->getVelocity();
     427            this->client_angular_velocity_ = this->getAngularVelocity();
    477428        }
    478429    }
  • code/branches/presentation/src/orxonox/objects/worldentities/ControllableEntity.h

    r2087 r2459  
    2323 *      Fabian 'x3n' Landau
    2424 *   Co-authors:
    25  *      ...
     25 *      Reto Grieder
    2626 *
    2727 */
     
    3232#include "OrxonoxPrereqs.h"
    3333
    34 #include "WorldEntity.h"
    35 #include "objects/Tickable.h"
     34#include "MobileEntity.h"
    3635
    3736namespace orxonox
    3837{
    39     class _OrxonoxExport ControllableEntity : public WorldEntity, public Tickable
     38    class _OrxonoxExport ControllableEntity : public MobileEntity
    4039    {
    4140        public:
     
    7271            virtual void switchCamera();
    7372
    74             inline const Vector3& getVelocity() const
    75                 { return this->velocity_; }
    76             inline const Vector3& getAcceleration() const
    77                 { return this->acceleration_; }
    7873            inline const std::string& getHudTemplate() const
    7974                { return this->hudtemplate_; }
    80 
    81             using WorldEntity::setPosition;
    82             using WorldEntity::translate;
    83             using WorldEntity::setOrientation;
    84             using WorldEntity::rotate;
    85             using WorldEntity::yaw;
    86             using WorldEntity::pitch;
    87             using WorldEntity::roll;
    88             using WorldEntity::lookAt;
    89             using WorldEntity::setDirection;
    90 
    91             void setPosition(const Vector3& position);
    92             void translate(const Vector3& distance, Ogre::Node::TransformSpace relativeTo = Ogre::Node::TS_LOCAL);
    93             void setOrientation(const Quaternion& orientation);
    94             void rotate(const Quaternion& rotation, Ogre::Node::TransformSpace relativeTo = Ogre::Node::TS_LOCAL);
    95             void yaw(const Degree& angle, Ogre::Node::TransformSpace relativeTo = Ogre::Node::TS_LOCAL);
    96             void pitch(const Degree& angle, Ogre::Node::TransformSpace relativeTo = Ogre::Node::TS_LOCAL);
    97             void roll(const Degree& angle, Ogre::Node::TransformSpace relativeTo = Ogre::Node::TS_LOCAL);
    98             void lookAt(const Vector3& target, Ogre::Node::TransformSpace relativeTo = Ogre::Node::TS_LOCAL, const Vector3& localDirectionVector = Vector3::NEGATIVE_UNIT_Z);
    99             void setDirection(const Vector3& direction, Ogre::Node::TransformSpace relativeTo = Ogre::Node::TS_LOCAL, const Vector3& localDirectionVector = Vector3::NEGATIVE_UNIT_Z);
    100 
    101             void setVelocity(const Vector3& velocity);
    102             inline void setVelocity(float x, float y, float z)
    103                 { this->velocity_.x = x; this->velocity_.y = y; this->velocity_.z = z; }
    104 
    105             inline void setAcceleration(const Vector3& acceleration)
    106                 { this->acceleration_ = acceleration; }
    107             inline void setAcceleration(float x, float y, float z)
    108                 { this->acceleration_.x = x; this->acceleration_.y = y; this->acceleration_.z = z; }
    10975
    11076            inline Camera* getCamera() const
     
    12389                { return this->cameraPositionTemplate_; }
    12490
     91            using WorldEntity::setPosition;
     92            using WorldEntity::setOrientation;
     93            using MobileEntity::setVelocity;
     94            using MobileEntity::setAngularVelocity;
     95
     96            void setPosition(const Vector3& position);
     97            void setOrientation(const Quaternion& orientation);
     98            void setVelocity(const Vector3& velocity);
     99            void setAngularVelocity(const Vector3& velocity);
     100
    125101        protected:
    126102            virtual void startLocalControl();
     
    133109                { return this->bControlled_; }
    134110
    135             Vector3 acceleration_;
    136 
    137111        private:
    138112            void overwrite();
     
    140114
    141115            void processServerPosition();
    142             void processServerVelocity();
     116            void processServerLinearVelocity();
    143117            void processServerOrientation();
     118            void processServerAngularVelocity();
    144119
    145120            void processClientPosition();
    146             void processClientVelocity();
     121            void processClientLinearVelocity();
    147122            void processClientOrientation();
     123            void processClientAngularVelocity();
    148124
    149125            void networkcallback_changedplayerID();
     126
     127            // Bullet btMotionState related
     128            void setWorldTransform(const btTransform& worldTrans);
    150129
    151130            unsigned int server_overwrite_;
    152131            unsigned int client_overwrite_;
    153132
    154             Vector3 velocity_;
    155 
    156133            bool bControlled_;
    157134            Vector3 server_position_;
    158135            Vector3 client_position_;
    159             Vector3 server_velocity_;
    160             Vector3 client_velocity_;
     136            Vector3 server_linear_velocity_;
     137            Vector3 client_linear_velocity_;
    161138            Quaternion server_orientation_;
    162139            Quaternion client_orientation_;
     140            Vector3 server_angular_velocity_;
     141            Vector3 client_angular_velocity_;
    163142
    164143            PlayerInfo* player_;
  • code/branches/presentation/src/orxonox/objects/worldentities/Light.cc

    r2371 r2459  
    4747    CreateFactory(Light);
    4848
    49     Light::Light(BaseObject* creator) : PositionableEntity(creator)
     49    Light::Light(BaseObject* creator) : StaticEntity(creator)
    5050    {
    5151        RegisterObject(Light);
     
    5353        if (this->getScene() && this->getScene()->getSceneManager())
    5454        this->light_ = this->getScene()->getSceneManager()->createLight("Light" + convertToString(Light::lightCounter_s++));
    55         this->getNode()->attachObject(this->light_);
     55        this->attachOgreObject(this->light_);
    5656
    5757        this->registerVariables();
  • code/branches/presentation/src/orxonox/objects/worldentities/Light.h

    r2087 r2459  
    3131
    3232#include "OrxonoxPrereqs.h"
    33 #include "PositionableEntity.h"
     33#include "StaticEntity.h"
    3434
    3535#include <string>
     
    4040namespace orxonox
    4141{
    42     class _OrxonoxExport Light : public PositionableEntity
     42    class _OrxonoxExport Light : public StaticEntity
    4343    {
    4444        public:
  • code/branches/presentation/src/orxonox/objects/worldentities/Model.cc

    r2415 r2459  
    2929#include "OrxonoxStableHeaders.h"
    3030
     31#include <OgreEntity.h>
    3132#include "Model.h"
    3233#include "core/CoreIncludes.h"
     
    3839    CreateFactory(Model);
    3940
    40     Model::Model(BaseObject* creator) : PositionableEntity(creator)
     41    Model::Model(BaseObject* creator) : StaticEntity(creator)
    4142    {
    4243        RegisterObject(Model);
     
    4849    {
    4950        if (this->isInitialized() && this->mesh_.getEntity())
    50             this->getNode()->detachObject(this->mesh_.getEntity());
     51            this->detachOgreObject(this->mesh_.getEntity());
    5152    }
    5253
     
    6869    {
    6970        if (this->mesh_.getEntity())
    70             this->getNode()->detachObject(this->mesh_.getEntity());
     71            this->detachOgreObject(this->mesh_.getEntity());
    7172
    7273        this->mesh_.setMeshSource(this->getScene()->getSceneManager(), this->meshSrc_);
     
    7475        if (this->mesh_.getEntity())
    7576        {
    76             this->getNode()->attachObject(this->mesh_.getEntity());
     77            this->attachOgreObject(this->mesh_.getEntity());
    7778            this->mesh_.getEntity()->setCastShadows(this->bCastShadows_);
    7879            this->mesh_.setVisible(this->isVisible());
  • code/branches/presentation/src/orxonox/objects/worldentities/Model.h

    r2087 r2459  
    3131
    3232#include "OrxonoxPrereqs.h"
    33 #include "PositionableEntity.h"
     33#include "StaticEntity.h"
    3434#include "tools/Mesh.h"
    3535
    3636namespace orxonox
    3737{
    38     class _OrxonoxExport Model : public PositionableEntity
     38    class _OrxonoxExport Model : public StaticEntity
    3939    {
    4040        public:
     
    7070}
    7171
    72 #endif /* _PositionableEntity_H__ */
     72#endif /* _Model_H__ */
  • code/branches/presentation/src/orxonox/objects/worldentities/MovableEntity.cc

    r2415 r2459  
    2222 *   Author:
    2323 *      Fabian 'x3n' Landau
     24 *      Reto Grieder
    2425 *   Co-authors:
    2526 *      ...
     
    3839{
    3940    static const float MAX_RESYNCHRONIZE_TIME = 3.0f;
     41    static const float CONTINUOUS_SYNCHRONIZATION_TIME = 10.0f;
    4042
    4143    CreateFactory(MovableEntity);
    4244
    43     MovableEntity::MovableEntity(BaseObject* creator) : WorldEntity(creator)
     45    MovableEntity::MovableEntity(BaseObject* creator) : MobileEntity(creator)
    4446    {
    4547        RegisterObject(MovableEntity);
    4648
    47         this->velocity_ = Vector3::ZERO;
    48         this->acceleration_ = Vector3::ZERO;
    49         this->rotationAxis_ = Vector3::ZERO;
    50         this->rotationRate_ = 0;
    51         this->momentum_ = 0;
    52 
    53         this->overwrite_position_ = Vector3::ZERO;
     49        this->overwrite_position_    = Vector3::ZERO;
    5450        this->overwrite_orientation_ = Quaternion::IDENTITY;
    5551       
    5652        this->setPriority( priority::low );
     53
     54        // Resynchronise every few seconds because we only work with velocities (no positions)
     55        continuousResynchroTimer_ = new Timer<MovableEntity>(CONTINUOUS_SYNCHRONIZATION_TIME + rnd(-1, 1),
     56                true, this, createExecutor(createFunctor(&MovableEntity::resynchronize)), false);
    5757
    5858        this->registerVariables();
     
    6161    MovableEntity::~MovableEntity()
    6262    {
     63        if (this->isInitialized())
     64            delete this->continuousResynchroTimer_;
    6365    }
    6466
     
    6668    {
    6769        SUPER(MovableEntity, XMLPort, xmlelement, mode);
    68 
    69         XMLPortParamTemplate(MovableEntity, "velocity", setVelocity, getVelocity, xmlelement, mode, const Vector3&);
    70         XMLPortParamTemplate(MovableEntity, "rotationaxis", setRotationAxis, getRotationAxis, xmlelement, mode, const Vector3&);
    71         XMLPortParamTemplate(MovableEntity, "rotationrate", setRotationRate, getRotationRate, xmlelement, mode, const Degree&);
    72     }
    73 
    74     void MovableEntity::tick(float dt)
    75     {
    76         if (this->isActive())
    77         {
    78             this->velocity_ += (dt * this->acceleration_);
    79             this->node_->translate(dt * this->velocity_);
    80 
    81             this->rotationRate_ += (dt * this->momentum_);
    82             this->node_->rotate(this->rotationAxis_, this->rotationRate_  * dt);
    83         }
    8470    }
    8571
    8672    void MovableEntity::registerVariables()
    8773    {
    88         registerVariable(this->velocity_.x, variableDirection::toclient);
    89         registerVariable(this->velocity_.y, variableDirection::toclient);
    90         registerVariable(this->velocity_.z, variableDirection::toclient);
    91  
    92         registerVariable(this->rotationAxis_.x, variableDirection::toclient);
    93         registerVariable(this->rotationAxis_.y, variableDirection::toclient);
    94         registerVariable(this->rotationAxis_.z, variableDirection::toclient);
    95  
    96         registerVariable(this->rotationRate_, variableDirection::toclient);
    97  
     74        registerVariable(this->linearVelocity_,        variableDirection::toclient, new NetworkCallback<MovableEntity>(this, &MovableEntity::processLinearVelocity));
     75        registerVariable(this->angularVelocity_,       variableDirection::toclient, new NetworkCallback<MovableEntity>(this, &MovableEntity::processAngularVelocity));
     76
    9877        registerVariable(this->overwrite_position_,    variableDirection::toclient, new NetworkCallback<MovableEntity>(this, &MovableEntity::overwritePosition));
    9978        registerVariable(this->overwrite_orientation_, variableDirection::toclient, new NetworkCallback<MovableEntity>(this, &MovableEntity::overwriteOrientation));
    100     }
    101 
    102     void MovableEntity::overwritePosition()
    103     {
    104         this->node_->setPosition(this->overwrite_position_);
    105     }
    106 
    107     void MovableEntity::overwriteOrientation()
    108     {
    109         this->node_->setOrientation(this->overwrite_orientation_);
    11079    }
    11180
     
    12493        this->overwrite_orientation_ = this->getOrientation();
    12594    }
    126 
    127     void MovableEntity::setPosition(const Vector3& position)
    128     {
    129         this->node_->setPosition(position);
    130         this->overwrite_position_ = this->node_->getPosition();
    131     }
    132 
    133     void MovableEntity::translate(const Vector3& distance, Ogre::Node::TransformSpace relativeTo)
    134     {
    135         this->node_->translate(distance, relativeTo);
    136         this->overwrite_position_ = this->node_->getPosition();
    137     }
    138 
    139     void MovableEntity::setOrientation(const Quaternion& orientation)
    140     {
    141         this->node_->setOrientation(orientation);
    142         this->overwrite_orientation_ = this->node_->getOrientation();
    143     }
    144 
    145     void MovableEntity::rotate(const Quaternion& rotation, Ogre::Node::TransformSpace relativeTo)
    146     {
    147         this->node_->rotate(rotation, relativeTo);
    148         this->overwrite_orientation_ = this->node_->getOrientation();
    149     }
    150 
    151     void MovableEntity::yaw(const Degree& angle, Ogre::Node::TransformSpace relativeTo)
    152     {
    153         this->node_->yaw(angle, relativeTo);
    154         this->overwrite_orientation_ = this->node_->getOrientation();
    155     }
    156 
    157     void MovableEntity::pitch(const Degree& angle, Ogre::Node::TransformSpace relativeTo)
    158     {
    159         this->node_->pitch(angle, relativeTo);
    160         this->overwrite_orientation_ = this->node_->getOrientation();
    161     }
    162 
    163     void MovableEntity::roll(const Degree& angle, Ogre::Node::TransformSpace relativeTo)
    164     {
    165         this->node_->roll(angle, relativeTo);
    166         this->overwrite_orientation_ = this->node_->getOrientation();
    167     }
    168 
    169     void MovableEntity::lookAt(const Vector3& target, Ogre::Node::TransformSpace relativeTo, const Vector3& localDirectionVector)
    170     {
    171         this->node_->lookAt(target, relativeTo, localDirectionVector);
    172         this->overwrite_orientation_ = this->node_->getOrientation();
    173     }
    174 
    175     void MovableEntity::setDirection(const Vector3& direction, Ogre::Node::TransformSpace relativeTo, const Vector3& localDirectionVector)
    176     {
    177         this->node_->setDirection(direction, relativeTo, localDirectionVector);
    178         this->overwrite_orientation_ = this->node_->getOrientation();
    179     }
    18095}
  • code/branches/presentation/src/orxonox/objects/worldentities/MovableEntity.h

    r2171 r2459  
    2222 *   Author:
    2323 *      Fabian 'x3n' Landau
     24 *      Reto Grieder
    2425 *   Co-authors:
    2526 *      ...
     
    3233#include "OrxonoxPrereqs.h"
    3334
    34 #include "WorldEntity.h"
    35 #include "objects/Tickable.h"
     35#include "MobileEntity.h"
    3636#include "network/ClientConnectionListener.h"
    3737
    3838namespace orxonox
    3939{
    40     class _OrxonoxExport MovableEntity : public WorldEntity, public Tickable, public ClientConnectionListener
     40    class _OrxonoxExport MovableEntity : public MobileEntity, public ClientConnectionListener
    4141    {
    4242        public:
     
    4545
    4646            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
    47             virtual void tick(float dt);
    4847            void registerVariables();
    4948
    5049            using WorldEntity::setPosition;
    51             using WorldEntity::translate;
    5250            using WorldEntity::setOrientation;
    53             using WorldEntity::rotate;
    54             using WorldEntity::yaw;
    55             using WorldEntity::pitch;
    56             using WorldEntity::roll;
    57             using WorldEntity::lookAt;
    58             using WorldEntity::setDirection;
    5951
    60             void setPosition(const Vector3& position);
    61             void translate(const Vector3& distance, Ogre::Node::TransformSpace relativeTo = Ogre::Node::TS_LOCAL);
    62             void setOrientation(const Quaternion& orientation);
    63             void rotate(const Quaternion& rotation, Ogre::Node::TransformSpace relativeTo = Ogre::Node::TS_LOCAL);
    64             void yaw(const Degree& angle, Ogre::Node::TransformSpace relativeTo = Ogre::Node::TS_LOCAL);
    65             void pitch(const Degree& angle, Ogre::Node::TransformSpace relativeTo = Ogre::Node::TS_LOCAL);
    66             void roll(const Degree& angle, Ogre::Node::TransformSpace relativeTo = Ogre::Node::TS_LOCAL);
    67             void lookAt(const Vector3& target, Ogre::Node::TransformSpace relativeTo = Ogre::Node::TS_LOCAL, const Vector3& localDirectionVector = Vector3::NEGATIVE_UNIT_Z);
    68             void setDirection(const Vector3& direction, Ogre::Node::TransformSpace relativeTo = Ogre::Node::TS_LOCAL, const Vector3& localDirectionVector = Vector3::NEGATIVE_UNIT_Z);
    69 
    70             inline void setVelocity(const Vector3& velocity)
    71                 { this->velocity_ = velocity; }
    72             inline void setVelocity(float x, float y, float z)
    73                 { this->velocity_.x = x; this->velocity_.y = y; this->velocity_.z = z; }
    74             inline const Vector3& getVelocity() const
    75                 { return this->velocity_; }
    76 
    77             inline void setAcceleration(const Vector3& acceleration)
    78                 { this->acceleration_ = acceleration; }
    79             inline void setAcceleration(float x, float y, float z)
    80                 { this->acceleration_.x = x; this->acceleration_.y = y; this->acceleration_.z = z; }
    81             inline const Vector3& getAcceleration() const
    82                 { return this->acceleration_; }
    83 
    84             inline void setRotationAxis(const Vector3& axis)
    85                 { this->rotationAxis_ = axis; this->rotationAxis_.normalise(); }
    86             inline void setRotationAxis(float x, float y, float z)
    87                 { this->rotationAxis_.x = x; this->rotationAxis_.y = y; this->rotationAxis_.z = z; rotationAxis_.normalise(); }
    88             inline const Vector3& getRotationAxis() const
    89                 { return this->rotationAxis_; }
    90 
    91             inline void setRotationRate(const Degree& angle)
    92                 { this->rotationRate_ = angle; }
    93             inline void setRotationRate(const Radian& angle)
    94                 { this->rotationRate_ = angle; }
    95             inline const Degree& getRotationRate() const
    96                 { return this->rotationRate_; }
    97 
    98             inline void setMomentum(const Degree& angle)
    99                 { this->momentum_ = angle; }
    100             inline void setMomentum(const Radian& angle)
    101                 { this->momentum_ = angle; }
    102             inline const Degree& getMomentum() const
    103                 { return this->momentum_; }
     52            inline void setPosition(const Vector3& position)
     53                { MobileEntity::setPosition(position); this->overwrite_position_ = this->getPosition(); }
     54            inline void setOrientation(const Quaternion& orientation)
     55                { MobileEntity::setOrientation(orientation); this->overwrite_orientation_ = this->getOrientation(); }
    10456
    10557        private:
     
    10860            void resynchronize();
    10961
    110             void overwritePosition();
    111             void overwriteOrientation();
     62            inline void processLinearVelocity()
     63                { this->setVelocity(this->linearVelocity_); }
     64            inline void processAngularVelocity()
     65                { this->setAngularVelocity(this->angularVelocity_); }
    11266
    113             Vector3 velocity_;
    114             Vector3 acceleration_;
    115             Vector3 rotationAxis_;
    116             Degree rotationRate_;
    117             Degree momentum_;
     67            inline void overwritePosition()
     68                { this->setPosition(this->overwrite_position_); }
     69            inline void overwriteOrientation()
     70                { this->setOrientation(this->overwrite_orientation_); }
    11871
    119             Vector3 overwrite_position_;
     72            Vector3    overwrite_position_;
    12073            Quaternion overwrite_orientation_;
     74            Timer<MovableEntity>* continuousResynchroTimer_;
    12175    };
    12276}
  • code/branches/presentation/src/orxonox/objects/worldentities/ParticleEmitter.cc

    r2371 r2459  
    3333
    3434#include "OrxonoxStableHeaders.h"
     35#include "ParticleEmitter.h"
    3536
    36 #include "ParticleEmitter.h"
     37#include <OgreParticleSystem.h>
    3738
    3839#include "tools/ParticleInterface.h"
     
    4647    CreateFactory(ParticleEmitter);
    4748
    48     ParticleEmitter::ParticleEmitter(BaseObject* creator) : PositionableEntity(creator)
     49    ParticleEmitter::ParticleEmitter(BaseObject* creator) : StaticEntity(creator)
    4950    {
    5051        RegisterObject(ParticleEmitter);
     
    6263    {
    6364        if (this->isInitialized() && this->particles_)
     65        {
     66            this->detachOgreObject(this->particles_->getParticleSystem());
    6467            delete this->particles_;
     68        }
    6569    }
    6670
     
    105109            {
    106110                this->particles_ = new ParticleInterface(this->getScene()->getSceneManager(), this->source_, this->LOD_);
    107                 this->particles_->addToSceneNode(this->getNode());
     111                this->attachOgreObject(particles_->getParticleSystem());
    108112                this->particles_->setVisible(this->isVisible());
    109113                this->particles_->setEnabled(this->isActive());
  • code/branches/presentation/src/orxonox/objects/worldentities/ParticleEmitter.h

    r2087 r2459  
    3131
    3232#include "OrxonoxPrereqs.h"
    33 #include "PositionableEntity.h"
     33#include "StaticEntity.h"
    3434
    3535namespace orxonox
    3636{
    37     class _OrxonoxExport ParticleEmitter : public PositionableEntity
     37    class _OrxonoxExport ParticleEmitter : public StaticEntity
    3838    {
    3939        public:
  • code/branches/presentation/src/orxonox/objects/worldentities/ParticleSpawner.cc

  • code/branches/presentation/src/orxonox/objects/worldentities/ParticleSpawner.h

  • code/branches/presentation/src/orxonox/objects/worldentities/Planet.cc

    r2436 r2459  
    3333
    3434#include <OgreEntity.h>
    35 #include <OgreMesh.h>
     35#include <OgreBillboardSet.h>
    3636#include <OgreHardwareVertexBuffer.h>
    3737#include <OgreMeshManager.h>
     
    6363    {
    6464        if (this->isInitialized() && this->mesh_.getEntity())
    65             this->getNode()->detachObject(this->mesh_.getEntity());
     65            this->detachOgreObject(this->mesh_.getEntity());
    6666    }   
    6767
     
    108108        billboard_.setBillboardSet(this->getScene()->getSceneManager(), this->atmosphere_, Vector3(0,0,0));
    109109
    110         this->getNode()->attachObject(this->billboard_.getBillboardSet());   
     110        this->attachOgreObject(this->billboard_.getBillboardSet());   
    111111        this->billboard_.getBillboardSet()->setUseAccurateFacing(true);
    112112        this->setCastShadows(true);
     
    118118    {
    119119        if (this->mesh_.getEntity())
    120             this->getNode()->detachObject(this->mesh_.getEntity());
     120            this->detachOgreObject(this->mesh_.getEntity());
    121121
    122122        this->mesh_.setMeshSource(this->getScene()->getSceneManager(), this->meshSrc_);
     
    124124        if (this->mesh_.getEntity())
    125125        {
    126             this->getNode()->attachObject(this->mesh_.getEntity());
     126            this->attachOgreObject(this->mesh_.getEntity());
    127127            this->mesh_.getEntity()->setCastShadows(this->bCastShadows_);
    128128            this->mesh_.setVisible(this->isVisible());
  • code/branches/presentation/src/orxonox/objects/worldentities/Planet.h

    r2436 r2459  
    3131
    3232#include "OrxonoxPrereqs.h"
     33
     34#include <OgreMesh.h>
    3335
    3436#include "tools/BillboardSet.h"
  • code/branches/presentation/src/orxonox/objects/worldentities/SpawnPoint.cc

    r2087 r2459  
    3838    CreateFactory(SpawnPoint);
    3939
    40     SpawnPoint::SpawnPoint(BaseObject* creator) : PositionableEntity(creator)
     40    SpawnPoint::SpawnPoint(BaseObject* creator) : StaticEntity(creator)
    4141    {
    4242        RegisterObject(SpawnPoint);
  • code/branches/presentation/src/orxonox/objects/worldentities/SpawnPoint.h

    r2087 r2459  
    3434#include "core/Identifier.h"
    3535#include "core/Template.h"
    36 #include "PositionableEntity.h"
    3736#include "objects/worldentities/pawns/Pawn.h"
     37#include "objects/worldentities/StaticEntity.h"
    3838
    3939namespace orxonox
    4040{
    41     class _OrxonoxExport SpawnPoint : public PositionableEntity
     41    class _OrxonoxExport SpawnPoint : public StaticEntity
    4242    {
    4343        public:
  • code/branches/presentation/src/orxonox/objects/worldentities/WorldEntity.cc

    r2371 r2459  
    2222 *   Author:
    2323 *      Fabian 'x3n' Landau
     24 *      Reto Grieder (physics)
    2425 *   Co-authors:
    2526 *      ...
     
    3132
    3233#include <cassert>
     34#include <OgreSceneNode.h>
    3335#include <OgreSceneManager.h>
    34 
     36#include "BulletDynamics/Dynamics/btRigidBody.h"
     37
     38#include "util/Exception.h"
     39#include "util/Convert.h"
    3540#include "core/CoreIncludes.h"
    3641#include "core/XMLPort.h"
    37 #include "util/Convert.h"
    38 #include "util/Exception.h"
    3942
    4043#include "objects/Scene.h"
     44#include "objects/collisionshapes/CompoundCollisionShape.h"
    4145
    4246namespace orxonox
     
    6468        this->node_->setOrientation(Quaternion::IDENTITY);
    6569
     70        // Default behaviour does not include physics
     71        this->physicalBody_ = 0;
     72        this->bPhysicsActive_ = false;
     73        this->collisionShape_ = new CompoundCollisionShape(this);
     74        this->collisionType_ = None;
     75        this->collisionTypeSynchronised_ = None;
     76        this->mass_           = 0;
     77        this->childrenMass_   = 0;
     78        // Use bullet default values
     79        this->restitution_    = 0;
     80        this->angularFactor_  = 1;
     81        this->linearDamping_  = 0;
     82        this->angularDamping_ = 0;
     83        this->friction_       = 0.5;
     84
    6685        this->registerVariables();
    6786    }
     
    7493            if (this->getScene()->getSceneManager())
    7594                this->getScene()->getSceneManager()->destroySceneNode(this->node_->getName());
     95
     96            // TODO: Detach from parent and detach all children.
     97
     98            if (this->physicalBody_)
     99            {
     100                this->deactivatePhysics();
     101                delete this->physicalBody_;
     102            }
     103            delete this->collisionShape_;
    76104        }
    77105    }
     
    81109        SUPER(WorldEntity, XMLPort, xmlelement, mode);
    82110
    83         XMLPortParamTemplate(WorldEntity, "position", setPosition, getPosition, xmlelement, mode, const Vector3&);
     111        XMLPortParamTemplate(WorldEntity, "position",    setPosition,    getPosition,    xmlelement, mode, const Vector3&);
    84112        XMLPortParamTemplate(WorldEntity, "orientation", setOrientation, getOrientation, xmlelement, mode, const Quaternion&);
    85         XMLPortParamLoadOnly(WorldEntity, "lookat", lookAt_xmlport, xmlelement, mode);
    86         XMLPortParamLoadOnly(WorldEntity, "direction", setDirection_xmlport, xmlelement, mode);
    87         XMLPortParamLoadOnly(WorldEntity, "yaw", yaw_xmlport, xmlelement, mode);
    88         XMLPortParamLoadOnly(WorldEntity, "pitch", pitch_xmlport, xmlelement, mode);
    89         XMLPortParamLoadOnly(WorldEntity, "roll", roll_xmlport, xmlelement, mode);
    90         XMLPortParamTemplate(WorldEntity, "scale3D", setScale3D, getScale3D, xmlelement, mode, const Vector3&);
    91         XMLPortParam(WorldEntity, "scale", setScale, getScale, xmlelement, mode);
    92 
     113        XMLPortParamTemplate(WorldEntity, "scale3D",     setScale3D,     getScale3D,     xmlelement, mode, const Vector3&);
     114        XMLPortParam        (WorldEntity, "scale",       setScale,       getScale,       xmlelement, mode);
     115        XMLPortParamLoadOnly(WorldEntity, "lookat",      lookAt_xmlport,       xmlelement, mode);
     116        XMLPortParamLoadOnly(WorldEntity, "direction",   setDirection_xmlport, xmlelement, mode);
     117        XMLPortParamLoadOnly(WorldEntity, "yaw",         yaw_xmlport,          xmlelement, mode);
     118        XMLPortParamLoadOnly(WorldEntity, "pitch",       pitch_xmlport,        xmlelement, mode);
     119        XMLPortParamLoadOnly(WorldEntity, "roll",        roll_xmlport,         xmlelement, mode);
     120
     121        // Physics
     122        XMLPortParam(WorldEntity, "collisionType",  setCollisionTypeStr, getCollisionTypeStr, xmlelement, mode);
     123        XMLPortParam(WorldEntity, "mass",           setMass,             getMass,             xmlelement, mode);
     124        XMLPortParam(WorldEntity, "restitution",    setRestitution,      getRestitution,      xmlelement, mode);
     125        XMLPortParam(WorldEntity, "angularFactor",  setAngularFactor,    getAngularFactor,    xmlelement, mode);
     126        XMLPortParam(WorldEntity, "linearDamping",  setLinearDamping,    getLinearDamping,    xmlelement, mode);
     127        XMLPortParam(WorldEntity, "angularDamping", setAngularDamping,   getAngularDamping,   xmlelement, mode);
     128        XMLPortParam(WorldEntity, "friction",       setFriction,         getFriction,         xmlelement, mode);
     129
     130        // Other attached WorldEntities
    93131        XMLPortObject(WorldEntity, WorldEntity, "attached", attach, getAttachedObject, xmlelement, mode);
     132        // Attached collision shapes
     133        XMLPortObject(WorldEntity, CollisionShape, "collisionShapes", attachCollisionShape, getAttachedCollisionShape, xmlelement, mode);
    94134    }
    95135
    96136    void WorldEntity::registerVariables()
    97137    {
    98         registerVariable(this->bActive_,  variableDirection::toclient, new NetworkCallback<WorldEntity>(this, &WorldEntity::changedActivity));
    99         registerVariable(this->bVisible_, variableDirection::toclient, new NetworkCallback<WorldEntity>(this, &WorldEntity::changedVisibility));
    100  
    101         registerVariable(this->getScale3D().x, variableDirection::toclient);
    102         registerVariable(this->getScale3D().y, variableDirection::toclient);
    103         registerVariable(this->getScale3D().z, variableDirection::toclient);
    104  
    105         registerVariable(this->parentID_, variableDirection::toclient, new NetworkCallback<WorldEntity>(this, &WorldEntity::updateParent));
    106     }
    107 
    108     void WorldEntity::updateParent()
     138        registerVariable(this->bActive_,        variableDirection::toclient, new NetworkCallback<WorldEntity>(this, &WorldEntity::changedActivity));
     139        registerVariable(this->bVisible_,       variableDirection::toclient, new NetworkCallback<WorldEntity>(this, &WorldEntity::changedVisibility));
     140
     141        registerVariable(this->getScale3D(),    variableDirection::toclient, new NetworkCallback<WorldEntity>(this, &WorldEntity::scaleChanged));
     142
     143        registerVariable((int&)this->collisionTypeSynchronised_,
     144                                                variableDirection::toclient, new NetworkCallback<WorldEntity>(this, &WorldEntity::collisionTypeChanged));
     145        registerVariable(this->mass_,           variableDirection::toclient, new NetworkCallback<WorldEntity>(this, &WorldEntity::massChanged));
     146        registerVariable(this->restitution_,    variableDirection::toclient, new NetworkCallback<WorldEntity>(this, &WorldEntity::restitutionChanged));
     147        registerVariable(this->angularFactor_,  variableDirection::toclient, new NetworkCallback<WorldEntity>(this, &WorldEntity::angularFactorChanged));
     148        registerVariable(this->linearDamping_,  variableDirection::toclient, new NetworkCallback<WorldEntity>(this, &WorldEntity::linearDampingChanged));
     149        registerVariable(this->angularDamping_, variableDirection::toclient, new NetworkCallback<WorldEntity>(this, &WorldEntity::angularDampingChanged));
     150        registerVariable(this->friction_,       variableDirection::toclient, new NetworkCallback<WorldEntity>(this, &WorldEntity::frictionChanged));
     151        registerVariable(this->bPhysicsActiveSynchronised_,
     152                                                variableDirection::toclient, new NetworkCallback<WorldEntity>(this, &WorldEntity::physicsActivityChanged));
     153
     154        registerVariable(this->parentID_,       variableDirection::toclient, new NetworkCallback<WorldEntity>(this, &WorldEntity::parentChanged));
     155    }
     156
     157    void WorldEntity::parentChanged()
    109158    {
    110159        if (this->parentID_ != OBJECTID_UNKNOWN)
     
    116165    }
    117166
     167    void WorldEntity::collisionTypeChanged()
     168    {
     169        if (this->collisionTypeSynchronised_ != Dynamic &&
     170            this->collisionTypeSynchronised_ != Kinematic &&
     171            this->collisionTypeSynchronised_ != Static &&
     172            this->collisionTypeSynchronised_ != None)
     173        {
     174            CCOUT(1) << "Error when collsion Type was received over network. Unknown enum value:" << this->collisionTypeSynchronised_ << std::endl;
     175        }
     176        else if (this->collisionTypeSynchronised_ != collisionType_)
     177        {
     178            if (this->parent_)
     179                CCOUT(2) << "Warning: Network connection tried to set the collision type of an attached WE. Ignoring." << std::endl;
     180            else
     181                this->setCollisionType(this->collisionTypeSynchronised_);
     182        }
     183    }
     184
     185    void WorldEntity::physicsActivityChanged()
     186    {
     187        if (this->bPhysicsActiveSynchronised_)
     188            this->activatePhysics();
     189        else
     190            this->deactivatePhysics();
     191    }
     192
    118193    void WorldEntity::attach(WorldEntity* object)
    119194    {
     195        // check first whether attaching is even allowed
     196        if (object->hasPhysics())
     197        {
     198            if (!this->hasPhysics())
     199            {
     200                COUT(2) << "Warning: Cannot attach a physical object to a non physical one." << std::endl;
     201                return;
     202            }
     203            else if (object->isDynamic())
     204            {
     205                COUT(2) << "Warning: Cannot attach a dynamic object to a WorldEntity." << std::endl;
     206                return;
     207            }
     208            else if (object->isKinematic() && this->isDynamic())
     209            {
     210                COUT(2) << "Warning: Cannot attach a kinematic object to a dynamic one." << std::endl;
     211                return;
     212            }
     213            else if (object->isKinematic())
     214            {
     215                COUT(2) << "Warning: Cannot attach a kinematic object to a static or kinematic one: Not yet implemented." << std::endl;
     216                return;
     217            }
     218            else
     219            {
     220                object->deactivatePhysics();
     221            }
     222        }
     223
    120224        if (object->getParent())
    121225            object->detachFromParent();
     
    131235        object->parent_ = this;
    132236        object->parentID_ = this->getObjectID();
     237
     238        // collision shapes
     239        this->attachCollisionShape(object->getCollisionShape());
     240        // mass
     241        this->childrenMass_ += object->getMass();
     242        recalculateMassProps();
    133243    }
    134244
    135245    void WorldEntity::detach(WorldEntity* object)
    136246    {
     247        // collision shapes
     248        this->detachCollisionShape(object->getCollisionShape());
     249        // mass
     250        if (object->getMass() > 0.0f)
     251        {
     252            this->childrenMass_ -= object->getMass();
     253            recalculateMassProps();
     254        }
     255
    137256        this->node_->removeChild(object->node_);
    138257        this->children_.erase(object);
    139258        object->parent_ = 0;
    140259        object->parentID_ = OBJECTID_UNKNOWN;
    141 
    142260//        this->getScene()->getRootSceneNode()->addChild(object->node_);
     261
     262        // Note: It is possible that the object has physics but was disabled when attaching
     263        object->activatePhysics();
    143264    }
    144265
     
    154275        return 0;
    155276    }
     277
     278    void WorldEntity::attachOgreObject(Ogre::MovableObject* object)
     279    {
     280        this->node_->attachObject(object);
     281    }
     282
     283    void WorldEntity::detachOgreObject(Ogre::MovableObject* object)
     284    {
     285        this->node_->detachObject(object);
     286    }
     287
     288    Ogre::MovableObject* WorldEntity::detachOgreObject(const Ogre::String& name)
     289    {
     290        return this->node_->detachObject(name);
     291    }
     292
     293    void WorldEntity::attachCollisionShape(CollisionShape* shape)
     294    {
     295        this->collisionShape_->addChildShape(shape);
     296        // Note: this->collisionShape_ already notifies us of any changes.
     297    }
     298
     299    void WorldEntity::detachCollisionShape(CollisionShape* shape)
     300    {
     301        this->collisionShape_->removeChildShape(shape);
     302        // Note: this->collisionShape_ already notifies us of any changes.
     303    }
     304
     305    CollisionShape* WorldEntity::getAttachedCollisionShape(unsigned int index) const
     306    {
     307        return this->collisionShape_->getChildShape(index);
     308    }
     309
     310    void WorldEntity::activatePhysics()
     311    {
     312        if (this->isActive() && this->hasPhysics() && !this->isPhysicsActive() && !this->parent_)
     313        {
     314            this->getScene()->addPhysicalObject(this);
     315            this->bPhysicsActive_ = true;
     316        }
     317    }
     318
     319    void WorldEntity::deactivatePhysics()
     320    {
     321        if (this->isPhysicsActive())
     322        {
     323            this->getScene()->removePhysicalObject(this);
     324            this->bPhysicsActive_ = false;
     325        }
     326    }
     327
     328    bool WorldEntity::addedToPhysicalWorld() const
     329    {
     330        return this->physicalBody_ && this->physicalBody_->isInWorld();
     331    }
     332
     333#ifndef _NDEBUG
     334    const Vector3& WorldEntity::getPosition() const
     335    {
     336        return this->node_->getPosition();
     337    }
     338
     339    const Quaternion& WorldEntity::getOrientation() const
     340    {
     341        return this->node_->getOrientation();
     342    }
     343
     344    const Vector3& WorldEntity::getScale3D() const
     345    {
     346        return this->node_->getScale();
     347    }
     348#endif
     349
     350    const Vector3& WorldEntity::getWorldPosition() const
     351    {
     352        return this->node_->_getDerivedPosition();
     353    }
     354
     355    const Quaternion& WorldEntity::getWorldOrientation() const
     356    {
     357        return this->node_->_getDerivedOrientation();
     358    }
     359
     360    void WorldEntity::translate(const Vector3& distance, TransformSpace::Space relativeTo)
     361    {
     362        switch (relativeTo)
     363        {
     364        case TransformSpace::Local:
     365            // position is relative to parent so transform downwards
     366            this->setPosition(this->getPosition() + this->getOrientation() * distance);
     367            break;
     368        case TransformSpace::Parent:
     369            this->setPosition(this->getPosition() + distance);
     370            break;
     371        case TransformSpace::World:
     372            // position is relative to parent so transform upwards
     373            if (this->node_->getParent())
     374                setPosition(getPosition() + (node_->getParent()->_getDerivedOrientation().Inverse() * distance)
     375                    / node_->getParent()->_getDerivedScale());
     376            else
     377                this->setPosition(this->getPosition() + distance);
     378            break;
     379        }
     380    }
     381
     382    void WorldEntity::rotate(const Quaternion& rotation, TransformSpace::Space relativeTo)
     383    {
     384        switch(relativeTo)
     385        {
     386        case TransformSpace::Local:
     387            this->setOrientation(this->getOrientation() * rotation);
     388            break;
     389        case TransformSpace::Parent:
     390            // Rotations are normally relative to local axes, transform up
     391            this->setOrientation(rotation * this->getOrientation());
     392            break;
     393        case TransformSpace::World:
     394            // Rotations are normally relative to local axes, transform up
     395            this->setOrientation(this->getOrientation() * this->getWorldOrientation().Inverse()
     396                * rotation * this->getWorldOrientation());
     397            break;
     398        }
     399    }
     400
     401    void WorldEntity::lookAt(const Vector3& target, TransformSpace::Space relativeTo, const Vector3& localDirectionVector)
     402    {
     403        Vector3 origin;
     404        switch (relativeTo)
     405        {
     406        case TransformSpace::Local:
     407            origin = Vector3::ZERO;
     408            break;
     409        case TransformSpace::Parent:
     410            origin = this->getPosition();
     411            break;
     412        case TransformSpace::World:
     413            origin = this->getWorldPosition();
     414            break;
     415        }
     416        this->setDirection(target - origin, relativeTo, localDirectionVector);
     417    }
     418
     419    void WorldEntity::setDirection(const Vector3& direction, TransformSpace::Space relativeTo, const Vector3& localDirectionVector)
     420    {
     421        Quaternion savedOrientation(this->getOrientation());
     422        Ogre::Node::TransformSpace ogreRelativeTo;
     423        switch (relativeTo)
     424        {
     425        case TransformSpace::Local:
     426            ogreRelativeTo = Ogre::Node::TS_LOCAL; break;
     427        case TransformSpace::Parent:
     428            ogreRelativeTo = Ogre::Node::TS_PARENT; break;
     429        case TransformSpace::World:
     430            ogreRelativeTo = Ogre::Node::TS_WORLD; break;
     431        }
     432        this->node_->setDirection(direction, ogreRelativeTo, localDirectionVector);
     433        Quaternion newOrientation(this->node_->getOrientation());
     434        this->node_->setOrientation(savedOrientation);
     435        this->setOrientation(newOrientation);
     436    }
     437
     438    void WorldEntity::setScale3D(const Vector3& scale)
     439    {
     440        if (this->hasPhysics())
     441        {
     442            CCOUT(2) << "Warning: Cannot set the scale of a physical object: Not yet implemented." << std::endl;
     443            return;
     444        }
     445
     446        this->node_->setScale(scale);
     447    }
     448
     449    void WorldEntity::setCollisionType(CollisionType type)
     450    {
     451        // If we are already attached to a parent, this would be a bad idea..
     452        if (this->parent_)
     453        {
     454            CCOUT(2) << "Warning: Cannot set the collision type of a WorldEntity with a parent." << std::endl;
     455            return;
     456        }
     457        else if (this->addedToPhysicalWorld())
     458        {
     459            CCOUT(2) << "Warning: Cannot set the collision type at run time." << std::endl;
     460            return;
     461        }
     462
     463        // Check for type legality. Could be StaticEntity or MobileEntity
     464        if (!this->isCollisionTypeLegal(type))
     465            return;
     466        if (type != None && !this->getScene()->hasPhysics())
     467        {
     468            CCOUT(2) << "Warning: Cannot have physical bodies in a non physical scene." << std::endl;
     469            return;
     470        }
     471
     472        // Check whether we have to create or destroy.
     473        if (type != None && this->collisionType_ == None)
     474        {
     475            // Check whether there was some scaling applied.
     476            if (!this->node_->getScale().positionEquals(Vector3(1, 1, 1), 0.001))
     477            {
     478                CCOUT(2) << "Warning: Cannot create a physical body if there is scaling applied to the node: Not yet implemented." << std::endl;
     479                return;
     480            }
     481
     482            // Create new rigid body
     483            btRigidBody::btRigidBodyConstructionInfo bodyConstructionInfo(0, this, this->collisionShape_->getCollisionShape());
     484            this->physicalBody_ = new btRigidBody(bodyConstructionInfo);
     485            this->physicalBody_->setUserPointer(this);
     486            this->physicalBody_->setActivationState(DISABLE_DEACTIVATION);
     487        }
     488        else if (type == None && this->collisionType_ != None)
     489        {
     490            // Destroy rigid body
     491            assert(this->physicalBody_);
     492            deactivatePhysics();
     493            delete this->physicalBody_;
     494            this->physicalBody_ = 0;
     495            this->collisionType_ = None;
     496            this->collisionTypeSynchronised_ = None;
     497            return;
     498        }
     499
     500        // Change type
     501        switch (type)
     502        {
     503        case Dynamic:
     504            this->physicalBody_->setCollisionFlags(this->physicalBody_->getCollisionFlags() & !(btCollisionObject::CF_STATIC_OBJECT | btCollisionObject::CF_KINEMATIC_OBJECT));
     505            break;
     506        case Kinematic:
     507            this->physicalBody_->setCollisionFlags(this->physicalBody_->getCollisionFlags() & !btCollisionObject::CF_STATIC_OBJECT | btCollisionObject::CF_KINEMATIC_OBJECT);
     508            break;
     509        case Static:
     510            this->physicalBody_->setCollisionFlags(this->physicalBody_->getCollisionFlags() & !btCollisionObject::CF_KINEMATIC_OBJECT | btCollisionObject::CF_STATIC_OBJECT);
     511            break;
     512        case None:
     513            return; // this->collisionType_ was None too
     514        }
     515
     516        // Only sets this->collisionShape_
     517        // However the assertion is to ensure that the internal bullet setting is right
     518        updateCollisionType();
     519        assert(this->collisionType_ == type);
     520
     521        // update mass and inertia tensor
     522        recalculateMassProps();
     523        resetPhysicsProps();
     524        activatePhysics();
     525    }
     526
     527    void WorldEntity::setCollisionTypeStr(const std::string& typeStr)
     528    {
     529        std::string typeStrLower = getLowercase(typeStr);
     530        CollisionType type;
     531        if (typeStrLower == "dynamic")
     532            type = Dynamic;
     533        else if (typeStrLower == "static")
     534            type = Static;
     535        else if (typeStrLower == "kinematic")
     536            type = Kinematic;
     537        else if (typeStrLower == "none")
     538            type = None;
     539        else
     540            ThrowException(ParseError, std::string("Attempting to set an unknown collision type: '") + typeStr + "'.");
     541        this->setCollisionType(type);
     542    }
     543
     544    std::string WorldEntity::getCollisionTypeStr() const
     545    {
     546        switch (this->getCollisionType())
     547        {
     548            case Dynamic:
     549                return "dynamic";
     550            case Kinematic:
     551                return "kinematic";
     552            case Static:
     553                return "static";
     554            case None:
     555                return "none";
     556            default:
     557                assert(false);
     558                return "";
     559        }
     560    }
     561
     562    void WorldEntity::updateCollisionType()
     563    {
     564        if (!this->physicalBody_)
     565            this->collisionType_ = None;
     566        else if (this->physicalBody_->isKinematicObject())
     567            this->collisionType_ = Kinematic;
     568        else if (this->physicalBody_->isStaticObject())
     569            this->collisionType_ = Static;
     570        else
     571            this->collisionType_ = Dynamic;
     572        this->collisionTypeSynchronised_ = this->collisionType_;
     573    }
     574
     575    void WorldEntity::notifyChildMassChanged() // Called by a child WE
     576    {
     577        // Note: CollisionShape changes of a child get handled over the internal CompoundCollisionShape already
     578        // Recalculate mass
     579        this->childrenMass_ = 0.0f;
     580        for (std::set<WorldEntity*>::const_iterator it = this->children_.begin(); it != this->children_.end(); ++it)
     581            this->childrenMass_ += (*it)->getMass();
     582        recalculateMassProps();
     583        // Notify parent WE
     584        if (this->parent_)
     585            parent_->notifyChildMassChanged();
     586    }
     587
     588    void WorldEntity::notifyCollisionShapeChanged() // called by this->collisionShape_
     589    {
     590        if (hasPhysics())
     591        {
     592            // Bullet doesn't like sudden changes of the collision shape, so we remove and add it again
     593            if (this->addedToPhysicalWorld())
     594            {
     595                this->deactivatePhysics();
     596                this->physicalBody_->setCollisionShape(this->collisionShape_->getCollisionShape());
     597                this->activatePhysics();
     598            }
     599            else
     600                this->physicalBody_->setCollisionShape(this->collisionShape_->getCollisionShape());
     601        }
     602        recalculateMassProps();
     603    }
     604
     605    void WorldEntity::recalculateMassProps()
     606    {
     607        // Store local inertia for faster access. Evaluates to (0,0,0) if there is no collision shape.
     608        float totalMass = this->mass_ + this->childrenMass_;
     609        this->collisionShape_->calculateLocalInertia(totalMass, this->localInertia_);
     610        if (this->hasPhysics())
     611        {
     612            if (this->isStatic())
     613            {
     614                // Just set everything to zero
     615                this->physicalBody_->setMassProps(0.0f, btVector3(0, 0, 0));
     616            }
     617            else if ((this->mass_ + this->childrenMass_) == 0.0f)
     618            {
     619                // Use default values to avoid very large or very small values
     620                CCOUT(4) << "Warning: Setting the internal physical mass to 1.0 because mass_ is 0.0." << std::endl;
     621                btVector3 inertia(0, 0, 0);
     622                this->collisionShape_->calculateLocalInertia(1.0f, inertia);
     623                this->physicalBody_->setMassProps(1.0f, inertia);
     624            }
     625            else
     626            {
     627                this->physicalBody_->setMassProps(totalMass, this->localInertia_);
     628            }
     629        }
     630    }
     631
     632    void WorldEntity::resetPhysicsProps()
     633    {
     634        if (this->hasPhysics())
     635        {
     636            this->physicalBody_->setRestitution(this->restitution_);
     637            this->physicalBody_->setAngularFactor(this->angularFactor_);
     638            this->physicalBody_->setDamping(this->linearDamping_, this->angularDamping_);
     639            this->physicalBody_->setFriction(this->friction_);
     640        }
     641    }
    156642}
  • code/branches/presentation/src/orxonox/objects/worldentities/WorldEntity.h

    r2371 r2459  
    2222 *   Author:
    2323 *      Fabian 'x3n' Landau
     24 *      Reto Grieder (physics)
    2425 *   Co-authors:
    2526 *      ...
     
    3233#include "OrxonoxPrereqs.h"
    3334
    34 #define OGRE_FORCE_ANGLE_TYPES
    35 
     35#ifdef _NDEBUG
    3636#include <OgreSceneNode.h>
     37#else
     38#include <OgrePrerequisites.h>
     39#endif
     40#include "LinearMath/btMotionState.h"
    3741
    3842#include "network/synchronisable/Synchronisable.h"
     
    4246namespace orxonox
    4347{
    44     class _OrxonoxExport WorldEntity : public BaseObject, public Synchronisable
     48    class _OrxonoxExport WorldEntity : public BaseObject, public Synchronisable, public btMotionState
    4549    {
    4650        public:
     
    5155            void registerVariables();
    5256
    53             inline Ogre::SceneNode* getNode() const
     57            inline const Ogre::SceneNode* getNode() const
    5458                { return this->node_; }
    5559
     
    6468            inline void setPosition(float x, float y, float z)
    6569                { this->setPosition(Vector3(x, y, z)); }
    66             inline const Vector3& getPosition() const
    67                 { return this->node_->getPosition(); }
    68             inline const Vector3& getWorldPosition() const
    69                 { return this->node_->getWorldPosition(); }
    70 
    71             virtual void translate(const Vector3& distance, Ogre::Node::TransformSpace relativeTo = Ogre::Node::TS_LOCAL) = 0;
    72             inline void translate(float x, float y, float z, Ogre::Node::TransformSpace relativeTo = Ogre::Node::TS_LOCAL)
     70            const Vector3& getPosition() const;
     71            const Vector3& getWorldPosition() const;
     72
     73            void translate(const Vector3& distance, TransformSpace::Space relativeTo = TransformSpace::Parent);
     74            inline void translate(float x, float y, float z, TransformSpace::Space relativeTo = TransformSpace::Parent)
    7375                { this->translate(Vector3(x, y, z), relativeTo); }
    7476
     
    8082            inline void setOrientation(const Vector3& axis, const Degree& angle)
    8183                { this->setOrientation(Quaternion(angle, axis)); }
    82             inline const Quaternion& getOrientation() const
    83                 { return this->node_->getOrientation(); }
    84             inline const Quaternion& getWorldOrientation() const
    85                 { return this->node_->getWorldOrientation(); }
    86 
    87             virtual void rotate(const Quaternion& rotation, Ogre::Node::TransformSpace relativeTo = Ogre::Node::TS_LOCAL) = 0;
    88             inline void rotate(const Vector3& axis, const Degree& angle, Ogre::Node::TransformSpace relativeTo = Ogre::Node::TS_LOCAL)
     84            const Quaternion& getOrientation() const;
     85            const Quaternion& getWorldOrientation() const;
     86
     87            void rotate(const Quaternion& rotation, TransformSpace::Space relativeTo = TransformSpace::Local);
     88            inline void rotate(const Vector3& axis, const Degree& angle, TransformSpace::Space relativeTo = TransformSpace::Local)
    8989                { this->rotate(Quaternion(angle, axis), relativeTo); }
    90             inline void rotate(const Vector3& axis, const Radian& angle, Ogre::Node::TransformSpace relativeTo = Ogre::Node::TS_LOCAL)
    91                 { this->rotate(Quaternion(angle, axis), relativeTo); }
    92 
    93             virtual void yaw(const Degree& angle, Ogre::Node::TransformSpace relativeTo = Ogre::Node::TS_LOCAL) = 0;
    94             inline void yaw(const Radian& angle, Ogre::Node::TransformSpace relativeTo = Ogre::Node::TS_LOCAL)
    95                 { this->yaw(Degree(angle), relativeTo); }
    96             virtual void pitch(const Degree& angle, Ogre::Node::TransformSpace relativeTo = Ogre::Node::TS_LOCAL) = 0;
    97             inline void pitch(const Radian& angle, Ogre::Node::TransformSpace relativeTo = Ogre::Node::TS_LOCAL)
    98                 { this->pitch(Degree(angle), relativeTo); }
    99             virtual void roll(const Degree& angle, Ogre::Node::TransformSpace relativeTo = Ogre::Node::TS_LOCAL) = 0;
    100             inline void roll(const Radian& angle, Ogre::Node::TransformSpace relativeTo = Ogre::Node::TS_LOCAL)
    101                 { this->roll(Degree(angle), relativeTo); }
    102 
    103             virtual void lookAt(const Vector3& target, Ogre::Node::TransformSpace relativeTo = Ogre::Node::TS_LOCAL, const Vector3& localDirectionVector = Vector3::NEGATIVE_UNIT_Z) = 0;
    104             virtual void setDirection(const Vector3& direction, Ogre::Node::TransformSpace relativeTo = Ogre::Node::TS_LOCAL, const Vector3& localDirectionVector = Vector3::NEGATIVE_UNIT_Z) = 0;
    105             inline void setDirection(float x, float y, float z, Ogre::Node::TransformSpace relativeTo = Ogre::Node::TS_LOCAL, const Vector3& localDirectionVector = Vector3::NEGATIVE_UNIT_Z)
     90
     91            inline void yaw(const Degree& angle, TransformSpace::Space relativeTo = TransformSpace::Local)
     92                { this->rotate(Quaternion(angle, Vector3::UNIT_Y), relativeTo); }
     93            inline void pitch(const Degree& angle, TransformSpace::Space relativeTo = TransformSpace::Local)
     94                { this->rotate(Quaternion(angle, Vector3::UNIT_X), relativeTo); }
     95            inline void roll(const Degree& angle, TransformSpace::Space relativeTo = TransformSpace::Local)
     96                { this->rotate(Quaternion(angle, Vector3::UNIT_Z), relativeTo); }
     97
     98            void lookAt(const Vector3& target, TransformSpace::Space relativeTo = TransformSpace::Parent, const Vector3& localDirectionVector = Vector3::NEGATIVE_UNIT_Z);
     99            void setDirection(const Vector3& direction, TransformSpace::Space relativeTo = TransformSpace::Local, const Vector3& localDirectionVector = Vector3::NEGATIVE_UNIT_Z);
     100            inline void setDirection(float x, float y, float z, TransformSpace::Space relativeTo = TransformSpace::Local, const Vector3& localDirectionVector = Vector3::NEGATIVE_UNIT_Z)
    106101                { this->setDirection(Vector3(x, y, z), relativeTo, localDirectionVector); }
    107102
    108             inline void setScale3D(const Vector3& scale)
    109                 { this->node_->setScale(scale); }
     103            virtual void setScale3D(const Vector3& scale);
    110104            inline void setScale3D(float x, float y, float z)
    111                 { this->node_->setScale(x, y, z); }
    112             inline const Vector3& getScale3D(void) const
    113                 { return this->node_->getScale(); }
    114 
    115             inline void setScale(float scale)
    116                 { this->node_->setScale(scale, scale, scale); }
     105                { this->setScale3D(Vector3(x, y, z)); }
     106            const Vector3& getScale3D(void) const;
     107
     108            void setScale(float scale)
     109                { this->setScale3D(scale, scale, scale); }
    117110            inline float getScale() const
    118111                { Vector3 scale = this->getScale3D(); return (scale.x == scale.y && scale.x == scale.z) ? scale.x : 1; }
    119112
    120113            inline void scale3D(const Vector3& scale)
    121                 { this->node_->scale(scale); }
     114                { this->setScale3D(this->getScale3D() * scale); }
    122115            inline void scale3D(float x, float y, float z)
    123                 { this->node_->scale(x, y, z); }
     116                { this->scale3D(Vector3(x, y, z)); }
    124117            inline void scale(float scale)
    125                 { this->node_->scale(scale, scale, scale); }
     118                { this->scale3D(scale, scale, scale); }
    126119
    127120            void attach(WorldEntity* object);
     
    130123            inline const std::set<WorldEntity*>& getAttachedObjects() const
    131124                { return this->children_; }
     125
     126            void attachOgreObject(Ogre::MovableObject* object);
     127            void detachOgreObject(Ogre::MovableObject* object);
     128            Ogre::MovableObject* detachOgreObject(const Ogre::String& name);
    132129
    133130            inline void attachToParent(WorldEntity* parent)
     
    138135                { return this->parent_; }
    139136
     137            void notifyChildPropsChanged();
     138
    140139        protected:
    141140            Ogre::SceneNode* node_;
    142141
    143142        private:
    144             void updateParent();
    145 
    146143            inline void lookAt_xmlport(const Vector3& target)
    147144                { this->lookAt(target); }
     
    155152                { this->roll(angle); }
    156153
     154            // network callbacks
     155            void parentChanged();
     156            inline void scaleChanged()
     157                { this->setScale3D(this->getScale3D()); }
     158
    157159            WorldEntity* parent_;
    158160            unsigned int parentID_;
    159161            std::set<WorldEntity*> children_;
     162
     163
     164        /////////////
     165        // Physics //
     166        /////////////
     167
     168        public:
     169            enum CollisionType
     170            {
     171                Dynamic,
     172                Kinematic,
     173                Static,
     174                None
     175            };
     176
     177            bool hasPhysics()       const { return getCollisionType() != None     ; }
     178            bool isStatic()         const { return getCollisionType() == Static   ; }
     179            bool isKinematic()      const { return getCollisionType() == Kinematic; }
     180            bool isDynamic()        const { return getCollisionType() == Dynamic  ; }
     181            bool isPhysicsActive()  const { return this->bPhysicsActive_; }
     182            bool addedToPhysicalWorld() const;
     183
     184            void activatePhysics();
     185            void deactivatePhysics();
     186
     187            inline CollisionType getCollisionType() const
     188                { return this->collisionType_; }
     189            void setCollisionType(CollisionType type);
     190
     191            void setCollisionTypeStr(const std::string& type);
     192            std::string getCollisionTypeStr() const;
     193
     194            inline void setMass(float mass)
     195                { this->mass_ = mass; recalculateMassProps(); }
     196            inline float getMass() const
     197                { return this->mass_; }
     198
     199            inline float getTotalMass() const
     200                { return this->mass_ + this->childrenMass_; }
     201
     202            inline const btVector3& getLocalInertia() const
     203                { return this->localInertia_; }
     204
     205            inline void setRestitution(float restitution)
     206                { this->restitution_ = restitution; resetPhysicsProps(); }
     207            inline float getRestitution() const
     208                { return this->restitution_; }
     209
     210            inline void setAngularFactor(float angularFactor)
     211                { this->angularFactor_ = angularFactor; resetPhysicsProps(); }
     212            inline float getAngularFactor() const
     213                { return this->angularFactor_; }
     214
     215            inline void setLinearDamping(float linearDamping)
     216                { this->linearDamping_ = linearDamping; resetPhysicsProps(); }
     217            inline float getLinearDamping() const
     218                { return this->linearDamping_; }
     219
     220            inline void setAngularDamping(float angularDamping)
     221                { this->angularDamping_ = angularDamping; resetPhysicsProps(); }
     222            inline float getAngularDamping() const
     223                { return this->angularDamping_; }
     224
     225            inline void setFriction(float friction)
     226                { this->friction_ = friction; resetPhysicsProps(); }
     227            inline float getFriction() const
     228                { return this->friction_; }
     229
     230            void attachCollisionShape(CollisionShape* shape);
     231            void detachCollisionShape(CollisionShape* shape);
     232            CollisionShape* getAttachedCollisionShape(unsigned int index) const;
     233
     234            inline CompoundCollisionShape* getCollisionShape()
     235                { return this->collisionShape_; }
     236            inline btRigidBody* getPhysicalBody()
     237                { return this->physicalBody_; }
     238
     239            void notifyCollisionShapeChanged();
     240            void notifyChildMassChanged();
     241
     242        protected:
     243            virtual bool isCollisionTypeLegal(CollisionType type) const = 0;
     244
     245            btRigidBody*  physicalBody_;
     246
     247        private:
     248            void updateCollisionType();
     249            void recalculateMassProps();
     250            void resetPhysicsProps();
     251
     252            // network callbacks
     253            void collisionTypeChanged();
     254            void physicsActivityChanged();
     255            inline void massChanged()
     256                { this->setMass(this->mass_); }
     257            inline void restitutionChanged()
     258                { this->setRestitution(this->restitution_); }
     259            inline void angularFactorChanged()
     260                { this->setAngularFactor(this->angularFactor_); }
     261            inline void linearDampingChanged()
     262                { this->setLinearDamping(this->linearDamping_); }
     263            inline void angularDampingChanged()
     264                { this->setAngularDamping(this->angularDamping_); }
     265            inline void frictionChanged()
     266                { this->setFriction(this->friction_); }
     267
     268            CollisionType                collisionType_;
     269            CollisionType                collisionTypeSynchronised_;
     270            bool                         bPhysicsActive_;
     271            bool                         bPhysicsActiveSynchronised_;
     272            CompoundCollisionShape*      collisionShape_;
     273            btScalar                     mass_;
     274            btVector3                    localInertia_;
     275            btScalar                     restitution_;
     276            btScalar                     angularFactor_;
     277            btScalar                     linearDamping_;
     278            btScalar                     angularDamping_;
     279            btScalar                     friction_;
     280            btScalar                     childrenMass_;
    160281    };
     282
     283    // Inline heavily used functions for release builds. In debug, we better avoid including OgreSceneNode here.
     284#ifdef _NDEBUG
     285    inline const Vector3& WorldEntity::getPosition() const
     286        { return this->node_->getPosition(); }
     287    inline const Quaternion& WorldEntity::getOrientation() const
     288        { return this->node_->getrOrientation(); }
     289    inline const Vector3& WorldEntity::getScale3D(void) const
     290        { return this->node_->getScale(); }
     291#endif
    161292}
    162293
  • code/branches/presentation/src/orxonox/objects/worldentities/pawns/SpaceShip.cc

    r2371 r2459  
    3030#include "SpaceShip.h"
    3131
     32#include "BulletDynamics/Dynamics/btRigidBody.h"
     33
     34#include "util/Math.h"
     35#include "util/Exception.h"
    3236#include "core/CoreIncludes.h"
    3337#include "core/ConfigValueIncludes.h"
    3438#include "core/XMLPort.h"
    35 #include "util/Math.h"
    3639
    3740namespace orxonox
    3841{
     42    const float orientationGain = 100;
    3943    CreateFactory(SpaceShip);
    4044
     
    4347        RegisterObject(SpaceShip);
    4448
    45         this->zeroDegree_ = 0;
     49        this->primaryThrust_  = 100;
     50        this->auxilaryThrust_ =  30;
     51        this->rotationThrust_ =  10;
    4652
    47         this->maxSpeed_ = 0;
    48         this->maxSecondarySpeed_ = 0;
    49         this->maxRotation_ = 0;
    50         this->translationAcceleration_ = 0;
    51         this->rotationAcceleration_ = 0;
    52         this->translationDamping_ = 0;
    53 
    54         this->yawRotation_ = 0;
    55         this->pitchRotation_ = 0;
    56         this->rollRotation_ = 0;
     53        this->localLinearAcceleration_.setValue(0, 0, 0);
     54        this->localAngularAcceleration_.setValue(0, 0, 0);
    5755
    5856        this->bInvertYAxis_ = false;
    5957
    6058        this->setDestroyWhenPlayerLeft(true);
     59
     60        // SpaceShip is always a physical object per default
     61        // Be aware of this call: The collision type legality check will not reach derived classes!
     62        this->setCollisionType(WorldEntity::Dynamic);
    6163
    6264        this->setConfigValues();
     
    7274        SUPER(SpaceShip, XMLPort, xmlelement, mode);
    7375
    74         XMLPortParam(SpaceShip, "maxspeed",          setMaxSpeed,          getMaxSpeed,          xmlelement, mode);
    75         XMLPortParam(SpaceShip, "maxsecondaryspeed", setMaxSecondarySpeed, getMaxSecondarySpeed, xmlelement, mode);
    76         XMLPortParam(SpaceShip, "maxrotation",       setMaxRotation,       getMaxRotation,       xmlelement, mode);
    77         XMLPortParam(SpaceShip, "transacc",          setTransAcc,          getTransAcc,          xmlelement, mode);
    78         XMLPortParam(SpaceShip, "rotacc",            setRotAcc,            getRotAcc,            xmlelement, mode);
    79         XMLPortParam(SpaceShip, "transdamp",         setTransDamp,         getTransDamp,         xmlelement, mode);
     76        XMLPortParamVariable(SpaceShip, "primaryThrust",  primaryThrust_,  xmlelement, mode);
     77        XMLPortParamVariable(SpaceShip, "auxilaryThrust", auxilaryThrust_, xmlelement, mode);
     78        XMLPortParamVariable(SpaceShip, "rotationThrust", rotationThrust_, xmlelement, mode);
    8079    }
    8180
    8281    void SpaceShip::registerVariables()
    8382    {
    84         registerVariable(this->maxSpeed_,                variableDirection::toclient);
    85         registerVariable(this->maxSecondarySpeed_,       variableDirection::toclient);
    86         registerVariable(this->maxRotation_,             variableDirection::toclient);
    87         registerVariable(this->translationAcceleration_, variableDirection::toclient);
    88         registerVariable(this->rotationAcceleration_,    variableDirection::toclient);
    89         registerVariable(this->translationDamping_,      variableDirection::toclient);
     83        registerVariable(this->primaryThrust_,  variableDirection::toclient);
     84        registerVariable(this->auxilaryThrust_, variableDirection::toclient);
     85        registerVariable(this->rotationThrust_, variableDirection::toclient);
    9086    }
    9187
     
    9591    }
    9692
     93    bool SpaceShip::isCollisionTypeLegal(WorldEntity::CollisionType type) const
     94    {
     95        if (type != WorldEntity::Dynamic)
     96        {
     97            CCOUT(1) << "Error: Cannot tell a SpaceShip not to be dynamic! Ignoring." << std::endl;
     98            assert(false); // Only in debug mode
     99            return false;
     100        }
     101        else
     102            return true;
     103    }
     104
    97105    void SpaceShip::tick(float dt)
    98106    {
    99         if (this->isLocallyControlled())
    100         {
    101             // #####################################
    102             // ############# STEERING ##############
    103             // #####################################
    104 
    105             Vector3 velocity = this->getVelocity();
    106             if (velocity.x > this->maxSecondarySpeed_)
    107                 velocity.x = this->maxSecondarySpeed_;
    108             if (velocity.x < -this->maxSecondarySpeed_)
    109                 velocity.x = -this->maxSecondarySpeed_;
    110             if (velocity.y > this->maxSecondarySpeed_)
    111                 velocity.y = this->maxSecondarySpeed_;
    112             if (velocity.y < -this->maxSecondarySpeed_)
    113                 velocity.y = -this->maxSecondarySpeed_;
    114             if (velocity.z > this->maxSecondarySpeed_)
    115                 velocity.z = this->maxSecondarySpeed_;
    116             if (velocity.z < -this->maxSpeed_)
    117                 velocity.z = -this->maxSpeed_;
    118 
    119             // normalize velocity and acceleration
    120             for (size_t dimension = 0; dimension < 3; ++dimension)
    121             {
    122                 if (this->acceleration_[dimension] == 0)
    123                 {
    124                     if (velocity[dimension] > 0)
    125                     {
    126                         velocity[dimension] -= (this->translationDamping_ * dt);
    127                         if (velocity[dimension] < 0)
    128                             velocity[dimension] = 0;
    129                     }
    130                     else if (velocity[dimension] < 0)
    131                     {
    132                         velocity[dimension] += (this->translationDamping_ * dt);
    133                         if (velocity[dimension] > 0)
    134                             velocity[dimension] = 0;
    135                     }
    136                 }
    137             }
    138 
    139             this->setVelocity(velocity);
    140         }
    141 
    142 
    143107        SUPER(SpaceShip, tick, dt);
    144 
    145108
    146109        if (this->isLocallyControlled())
    147110        {
    148             this->yaw(this->yawRotation_ * dt);
    149             if (this->bInvertYAxis_)
    150                 this->pitch(Degree(-this->pitchRotation_ * dt));
     111            this->localLinearAcceleration_.setX(this->localLinearAcceleration_.x() * getMass() * this->auxilaryThrust_);
     112            this->localLinearAcceleration_.setY(this->localLinearAcceleration_.y() * getMass() * this->auxilaryThrust_);
     113            if (this->localLinearAcceleration_.z() > 0)
     114                this->localLinearAcceleration_.setZ(this->localLinearAcceleration_.z() * getMass() * this->auxilaryThrust_);
    151115            else
    152                 this->pitch(Degree( this->pitchRotation_ * dt));
    153             this->roll(this->rollRotation_ * dt);
     116                this->localLinearAcceleration_.setZ(this->localLinearAcceleration_.z() * getMass() * this->primaryThrust_);
     117            this->physicalBody_->applyCentralForce(physicalBody_->getWorldTransform().getBasis() * this->localLinearAcceleration_);
     118            this->localLinearAcceleration_.setValue(0, 0, 0);
    154119
    155             this->acceleration_.x = 0;
    156             this->acceleration_.y = 0;
    157             this->acceleration_.z = 0;
    158 
    159             this->yawRotation_   = this->zeroDegree_;
    160             this->pitchRotation_ = this->zeroDegree_;
    161             this->rollRotation_  = this->zeroDegree_;
     120            this->localAngularAcceleration_ *= this->getLocalInertia() * this->rotationThrust_;
     121            this->physicalBody_->applyTorque(physicalBody_->getWorldTransform().getBasis() * this->localAngularAcceleration_);
     122            this->localAngularAcceleration_.setValue(0, 0, 0);
    162123        }
    163124    }
     
    165126    void SpaceShip::moveFrontBack(const Vector2& value)
    166127    {
    167         this->acceleration_.z = -this->translationAcceleration_ * value.x;
     128        this->localLinearAcceleration_.setZ(this->localLinearAcceleration_.z() - value.x);
    168129    }
    169130
    170131    void SpaceShip::moveRightLeft(const Vector2& value)
    171132    {
    172         this->acceleration_.x = this->translationAcceleration_ * value.x;
     133        this->localLinearAcceleration_.setX(this->localLinearAcceleration_.x() + value.x);
    173134    }
    174135
    175136    void SpaceShip::moveUpDown(const Vector2& value)
    176137    {
    177         this->acceleration_.y = this->translationAcceleration_ * value.x;
     138        this->localLinearAcceleration_.setY(this->localLinearAcceleration_.y() + value.x);
    178139    }
    179140
    180141    void SpaceShip::rotateYaw(const Vector2& value)
    181142    {
    182         Degree temp = value.x * value.x * sgn(value.x) * this->rotationAcceleration_;
    183         if (temp > this->maxRotation_)
    184             temp = this->maxRotation_;
    185         if (temp < -this->maxRotation_)
    186             temp = -this->maxRotation_;
    187         this->yawRotation_ = Degree(temp);
     143        this->localAngularAcceleration_.setY(this->localLinearAcceleration_.y() + value.x);
    188144    }
    189145
    190146    void SpaceShip::rotatePitch(const Vector2& value)
    191147    {
    192         Degree temp = value.x * value.x * sgn(value.x) * this->rotationAcceleration_;
    193         if (temp > this->maxRotation_)
    194             temp = this->maxRotation_;
    195         if (temp < -this->maxRotation_)
    196             temp = -this->maxRotation_;
    197         this->pitchRotation_ = Degree(temp);
     148        this->localAngularAcceleration_.setX(this->localLinearAcceleration_.x() + value.x);
    198149    }
    199150
    200151    void SpaceShip::rotateRoll(const Vector2& value)
    201152    {
    202         Degree temp = value.x * value.x * sgn(value.x) * this->rotationAcceleration_;
    203         if (temp > this->maxRotation_)
    204             temp = this->maxRotation_;
    205         if (temp < -this->maxRotation_)
    206             temp = -this->maxRotation_;
    207         this->rollRotation_ = Degree(temp);
     153        this->localAngularAcceleration_.setZ(this->localLinearAcceleration_.z() - value.x);
    208154    }
    209155
  • code/branches/presentation/src/orxonox/objects/worldentities/pawns/SpaceShip.h

    r2087 r2459  
    3232#include "OrxonoxPrereqs.h"
    3333
     34#include "LinearMath/btVector3.h"
     35
    3436#include "Pawn.h"
    3537
     
    5759            virtual void fire();
    5860
    59             void setMaxSpeed(float value)
    60                 { this->maxSpeed_ = value; }
    61             void setMaxSecondarySpeed(float value)
    62                 { this->maxSecondarySpeed_ = value; }
    63             void setMaxRotation(const Degree& value)
    64                 { this->maxRotation_ = value; }
    65             void setTransAcc(float value)
    66                 { this->translationAcceleration_ = value; }
    67             void setRotAcc(const Degree& value)
    68                 { this->rotationAcceleration_ = value; }
    69             void setTransDamp(float value)
    70                 { this->translationDamping_ = value; }
    71 
    72             inline float getMaxSpeed() const
    73                 { return this->maxSpeed_; }
    74             inline float getMaxSecondarySpeed() const
    75                 { return this->maxSecondarySpeed_; }
    76             inline float getMaxRotation() const
    77                 { return this->maxRotation_.valueDegrees(); }
    78             inline float getTransAcc() const
    79                 { return this->translationAcceleration_; }
    80             inline float getRotAcc() const
    81                 { return this->rotationAcceleration_.valueDegrees(); }
    82             inline float getTransDamp() const
    83                 { return this->translationDamping_; }
    84 
    8561        protected:
    8662            bool bInvertYAxis_;
    8763
    88             float maxSpeed_;
    89             float maxSecondarySpeed_;
    90             float translationAcceleration_;
    91             float translationDamping_;
     64            float primaryThrust_;
     65            float auxilaryThrust_;
     66            float rotationThrust_;
    9267
    93             Degree maxRotation_;
    94             Degree rotationAcceleration_;
     68            btVector3 localLinearAcceleration_;
     69            btVector3 localAngularAcceleration_;
    9570
    96             Degree zeroDegree_;
    97             Degree pitchRotation_;
    98             Degree yawRotation_;
    99             Degree rollRotation_;
     71        private:
     72            virtual bool isCollisionTypeLegal(WorldEntity::CollisionType type) const;
    10073    };
    10174}
  • code/branches/presentation/src/orxonox/objects/worldentities/pawns/Spectator.cc

    r2371 r2459  
    2929#include "OrxonoxStableHeaders.h"
    3030#include "Spectator.h"
     31
     32#include <OgreBillboardSet.h>
    3133
    3234#include "core/CoreIncludes.h"
     
    5052
    5153        this->speed_ = 100;
    52         this->rotationSpeed_ = 3;
     54        this->rotationGain_ = 3;
    5355
    5456        this->yaw_ = 0;
    5557        this->pitch_ = 0;
    5658        this->roll_ = 0;
     59        this->localVelocity_ = Vector3::ZERO;
    5760        this->setHudTemplate("spectatorhud");
    5861        this->hudmode_ = 0;
     
    6366        this->greetingFlare_->setBillboardSet(this->getScene()->getSceneManager(), "Examples/Flare", ColourValue(1.0, 1.0, 0.8), Vector3(0, 20, 0), 1);
    6467        if (this->greetingFlare_->getBillboardSet())
    65             this->getNode()->attachObject(this->greetingFlare_->getBillboardSet());
     68            this->attachOgreObject(this->greetingFlare_->getBillboardSet());
    6669        this->greetingFlare_->setVisible(false);
    6770        this->bGreetingFlareVisible_ = false;
     
    7881            {
    7982                if (this->greetingFlare_->getBillboardSet())
    80                     this->getNode()->detachObject(this->greetingFlare_->getBillboardSet());
     83                    this->detachOgreObject(this->greetingFlare_->getBillboardSet());
    8184                delete this->greetingFlare_;
    8285            }
     
    108111        if (this->isLocallyControlled())
    109112        {
    110             Vector3 velocity = this->getVelocity();
    111             velocity.normalise();
    112             this->setVelocity(velocity * this->speed_);
    113 
    114             this->yaw(Radian(this->yaw_ * this->rotationSpeed_));
    115             this->pitch(Radian(this->pitch_ * this->rotationSpeed_));
    116             this->roll(Radian(this->roll_ * this->rotationSpeed_));
     113            float localSpeedSquared = this->localVelocity_.squaredLength();
     114            float localSpeed;
     115            if (localSpeedSquared > 1.0)
     116                localSpeed = this->speed_ / sqrtf(localSpeedSquared);
     117            else
     118                localSpeed = this->speed_;
     119
     120            this->localVelocity_.x *= localSpeed;
     121            this->localVelocity_.y *= localSpeed;
     122            this->localVelocity_.z *= localSpeed;
     123            this->setVelocity(this->getOrientation() * this->localVelocity_);
     124            this->localVelocity_.x = 0;
     125            this->localVelocity_.y = 0;
     126            this->localVelocity_.z = 0;
     127
     128            this->yaw  (Radian(this->yaw_   * this->rotationGain_));
     129            this->pitch(Radian(this->pitch_ * this->rotationGain_));
     130            this->roll (Radian(this->roll_  * this->rotationGain_));
    117131
    118132            this->yaw_ = this->pitch_ = this->roll_ = 0;
     
    120134
    121135        SUPER(Spectator, tick, dt);
    122 
    123         if (this->isLocallyControlled())
    124         {
    125             this->setVelocity(Vector3::ZERO);
    126         }
    127136    }
    128137
     
    143152    void Spectator::moveFrontBack(const Vector2& value)
    144153    {
    145         this->setVelocity(this->getVelocity() + value.y * this->speed_ * WorldEntity::FRONT);
     154        this->localVelocity_.z -= value.x;
    146155    }
    147156
    148157    void Spectator::moveRightLeft(const Vector2& value)
    149158    {
    150         this->setVelocity(this->getVelocity() + value.y * this->speed_ * WorldEntity::RIGHT);
     159        this->localVelocity_.x += value.x;
    151160    }
    152161
    153162    void Spectator::moveUpDown(const Vector2& value)
    154163    {
    155         this->setVelocity(this->getVelocity() + value.y * this->speed_ * WorldEntity::UP);
     164        this->localVelocity_.y += value.x;
    156165    }
    157166
    158167    void Spectator::rotateYaw(const Vector2& value)
    159168    {
    160         this->yaw_ = value.y;
     169        this->yaw_ += value.y;
    161170    }
    162171
    163172    void Spectator::rotatePitch(const Vector2& value)
    164173    {
    165         this->pitch_ = value.y;
     174        this->pitch_ += value.y;
    166175    }
    167176
    168177    void Spectator::rotateRoll(const Vector2& value)
    169178    {
    170         this->roll_ = value.y;
     179        this->roll_ += value.y;
    171180    }
    172181
  • code/branches/presentation/src/orxonox/objects/worldentities/pawns/Spectator.h

    r2087 r2459  
    6969
    7070            float speed_;
    71             float rotationSpeed_;
     71            float rotationGain_;
    7272
    7373            float yaw_;
    7474            float pitch_;
    7575            float roll_;
     76
     77            Vector3 localVelocity_;
    7678
    7779            int hudmode_;
  • code/branches/presentation/src/orxonox/objects/worldentities/triggers/DistanceTrigger.cc

  • code/branches/presentation/src/orxonox/objects/worldentities/triggers/DistanceTrigger.h

  • code/branches/presentation/src/orxonox/objects/worldentities/triggers/Trigger.cc

    r2420 r2459  
    3131
    3232#include <OgreBillboard.h>
     33#include <OgreBillboardSet.h>
    3334#include "util/Debug.h"
    3435#include "core/CoreIncludes.h"
     
    4445  CreateFactory(Trigger);
    4546
    46   Trigger::Trigger(BaseObject* creator) : PositionableEntity(creator)
     47  Trigger::Trigger(BaseObject* creator) : StaticEntity(creator)
    4748  {
    4849    RegisterObject(Trigger);
     
    7172
    7273      if (this->debugBillboard_.getBillboardSet())
    73         this->getNode()->attachObject(this->debugBillboard_.getBillboardSet());
     74          this->attachOgreObject(this->debugBillboard_.getBillboardSet());
    7475    }
    7576
  • code/branches/presentation/src/orxonox/objects/worldentities/triggers/Trigger.h

    r2420 r2459  
    3636
    3737#include "objects/Tickable.h"
    38 #include "objects/worldentities/PositionableEntity.h"
     38#include "objects/worldentities/StaticEntity.h"
    3939#include "tools/BillboardSet.h"
    4040
     
    4848  };
    4949
    50   class _OrxonoxExport Trigger : public PositionableEntity, public Tickable
     50  class _OrxonoxExport Trigger : public StaticEntity, public Tickable
    5151  {
    5252    public:
  • code/branches/presentation/src/orxonox/tools/BillboardSet.cc

    r2171 r2459  
    3434
    3535#include <OgreSceneManager.h>
     36#include <OgreBillboardSet.h>
    3637#include <OgreBillboard.h>
    3738
  • code/branches/presentation/src/orxonox/tools/BillboardSet.h

    r2087 r2459  
    3333
    3434#include <string>
    35 #include <OgreBillboardSet.h>
     35#include <OgrePrerequisites.h>
    3636
    3737#include "util/Math.h"
  • code/branches/presentation/src/orxonox/tools/Mesh.cc

    r2171 r2459  
    3131
    3232#include <sstream>
     33#include <OgreEntity.h>
    3334#include <OgreSceneManager.h>
    3435#include <cassert>
  • code/branches/presentation/src/orxonox/tools/Mesh.h

    r2087 r2459  
    3333
    3434#include <string>
    35 #include <OgreEntity.h>
     35#include <OgrePrerequisites.h>
    3636
    3737namespace orxonox
  • code/branches/presentation/src/orxonox/tools/ParticleInterface.cc

    r2171 r2459  
    5757
    5858        this->scenemanager_ = scenemanager;
    59         this->sceneNode_ = 0;
    6059        this->particleSystem_ = 0;
    6160
     
    8786        {
    8887            this->particleSystem_->removeAllEmitters();
    89             this->detachFromSceneNode();
    9088            this->scenemanager_->destroyParticleSystem(this->particleSystem_);
    91         }
    92     }
    93 
    94     void ParticleInterface::addToSceneNode(Ogre::SceneNode* sceneNode)
    95     {
    96         if (this->sceneNode_)
    97             this->detachFromSceneNode();
    98 
    99         if (this->particleSystem_)
    100         {
    101             this->sceneNode_ = sceneNode;
    102             this->sceneNode_->attachObject(this->particleSystem_);
    103         }
    104     }
    105 
    106     void ParticleInterface::detachFromSceneNode()
    107     {
    108         if (this->sceneNode_)
    109         {
    110             if (this->particleSystem_)
    111                 this->sceneNode_->detachObject(this->particleSystem_);
    112             this->sceneNode_ = 0;
    11389        }
    11490    }
  • code/branches/presentation/src/orxonox/tools/ParticleInterface.h

    r2087 r2459  
    3333
    3434#include <string>
    35 #include <OgreParticleEmitter.h>
     35#include <OgrePrerequisites.h>
    3636
    3737#include "core/OrxonoxClass.h"
     
    5353            inline Ogre::ParticleSystem* getParticleSystem() const
    5454                { return this->particleSystem_; }
    55 
    56             void addToSceneNode(Ogre::SceneNode* sceneNode);
    57             void detachFromSceneNode();
    5855
    5956            Ogre::ParticleEmitter* createNewEmitter();
     
    9693            static unsigned int       counter_s;
    9794
    98             Ogre::SceneNode*          sceneNode_;
    9995            Ogre::ParticleSystem*     particleSystem_;
    10096            bool                      bVisible_;
Note: See TracChangeset for help on using the changeset viewer.