Changeset 2442 for code/branches/physics_merge/src/orxonox
- Timestamp:
- Dec 14, 2008, 4:16:52 PM (16 years ago)
- Location:
- code/branches/physics_merge
- Files:
-
- 1 added
- 2 deleted
- 84 edited
- 14 copied
Legend:
- Unmodified
- Added
- Removed
-
code/branches/physics_merge
- Property svn:mergeinfo changed
-
code/branches/physics_merge/src/orxonox/CMakeLists.txt
r2171 r2442 48 48 tinyxml_orxonox 49 49 tolualib_orxonox 50 LibBulletDynamics 51 LibBulletCollision 52 LibLinearMath 50 53 util 51 54 core -
code/branches/physics_merge/src/orxonox/CameraManager.cc
- Property svn:mergeinfo changed
/code/trunk/src/orxonox/CameraManager.cc (added) merged: 1913-2085
- Property svn:mergeinfo changed
-
code/branches/physics_merge/src/orxonox/CameraManager.h
- Property svn:mergeinfo changed
/code/trunk/src/orxonox/CameraManager.h (added) merged: 1913-2085
- Property svn:mergeinfo changed
-
code/branches/physics_merge/src/orxonox/OrxonoxPrereqs.h
r2385 r2442 107 107 108 108 class WorldEntity; 109 class PositionableEntity; 109 class StaticEntity; 110 class MobileEntity; 111 class ControllableEntity; 110 112 class MovableEntity; 111 class ControllableEntity;112 113 class Sublevel; 113 114 … … 153 154 154 155 class Scores; 156 157 // collision 158 class CollisionShape; 159 class SphereCollisionShape; 160 class CompoundCollisionShape; 161 class PlaneCollisionShape; 155 162 156 163 // tools … … 210 217 } 211 218 219 // Bullet Physics Engine 220 221 class btTransform; 222 class btVector3; 223 224 class btRigidBody; 225 class btCollisionObject; 226 class btGhostObject; 227 228 class btCollisionShape; 229 class btSphereShape; 230 class btCompoundShape; 231 class btStaticPlaneShape; 232 233 class btDiscreteDynamicsWorld; 234 235 // lua 212 236 struct lua_State; 213 237 -
code/branches/physics_merge/src/orxonox/OrxonoxStableHeaders.h
r2371 r2442 48 48 #include <CEGUI.h> 49 49 #include "ois/OIS.h" 50 //#include "btBulletCollisionCommon.h" 51 //#include "btBulletDynamicsCommon.h" 50 52 #include <boost/thread/recursive_mutex.hpp> 51 53 //#include <boost/thread/mutex.hpp> … … 97 99 #include "network/synchronisable/Synchronisable.h" 98 100 99 #include "Settings.h"101 //#include "Settings.h" 100 102 101 103 //#endif /* ifdef NDEBUG */ 102 104 103 #endif /* ORXONOX_COMPILER == ORXONOX_COMPILER_MSVC && !defined(ORXONOX_DISABLE_PCH) */105 #endif /* defined(ORXONOX_ENABLE_PCH) */ 104 106 105 107 #endif /* _OrxonoxStableHeaders_H__ */ -
code/branches/physics_merge/src/orxonox/gamestates/GSLevel.cc
r2103 r2442 51 51 namespace orxonox 52 52 { 53 SetCommandLineArgument(level, " sample2.oxw").shortcut("l");53 SetCommandLineArgument(level, "physicstest2.oxw").shortcut("l"); 54 54 55 55 GSLevel::GSLevel() -
code/branches/physics_merge/src/orxonox/gamestates/GSRoot.cc
r2171 r2442 146 146 /*** HACK *** HACK ***/ 147 147 // Call the Tickable objects 148 float leveldt = time.getDeltaTime(); 149 if (leveldt > 1.0f) 150 { 151 // just loaded 152 leveldt = 0.0f; 153 } 148 154 for (ObjectList<Tickable>::iterator it = ObjectList<Tickable>::begin(); it; ++it) 149 it->tick( time.getDeltaTime());155 it->tick(leveldt); 150 156 /*** HACK *** HACK ***/ 151 157 -
code/branches/physics_merge/src/orxonox/objects/CMakeLists.txt
r2171 r2442 13 13 ) 14 14 15 ADD_SOURCE_DIRECTORY(SRC_FILES collisionshapes) 15 16 ADD_SOURCE_DIRECTORY(SRC_FILES controllers) 16 17 ADD_SOURCE_DIRECTORY(SRC_FILES gametypes) -
code/branches/physics_merge/src/orxonox/objects/Scene.cc
r2371 r2442 23 23 * Fabian 'x3n' Landau 24 24 * Co-authors: 25 * ...25 * Reto Grieder (physics) 26 26 * 27 27 */ … … 35 35 #include <OgreLight.h> 36 36 37 #include "BulletCollision/BroadphaseCollision/btAxisSweep3.h" 38 #include "BulletCollision/CollisionDispatch/btDefaultCollisionConfiguration.h" 39 #include "BulletDynamics/ConstraintSolver/btSequentialImpulseConstraintSolver.h" 40 #include "BulletDynamics/Dynamics/btDiscreteDynamicsWorld.h" 41 37 42 #include "core/CoreIncludes.h" 38 43 #include "core/Core.h" 39 44 #include "core/XMLPort.h" 45 #include "tools/BulletConversions.h" 46 #include "objects/worldentities/WorldEntity.h" 40 47 41 48 namespace orxonox … … 69 76 this->rootSceneNode_ = this->sceneManager_->getRootSceneNode(); 70 77 } 78 79 // No physics for default 80 this->physicalWorld_ = 0; 71 81 72 82 // test test test … … 91 101 if (Ogre::Root::getSingletonPtr()) 92 102 { 93 // this->sceneManager_->destroySceneNode(this->rootSceneNode_->getName()); // TODO: remove getName() for newer versions of Ogre94 103 Ogre::Root::getSingleton().destroySceneManager(this->sceneManager_); 95 104 } … … 109 118 XMLPortParam(Scene, "shadow", setShadow, getShadow, xmlelement, mode).defaultValues(true); 110 119 120 //const int defaultMaxWorldSize = 100000; 121 //Vector3 worldAabbMin(-defaultMaxWorldSize, -defaultMaxWorldSize, -defaultMaxWorldSize); 122 //Vector3 worldAabbMax( defaultMaxWorldSize, defaultMaxWorldSize, defaultMaxWorldSize); 123 //XMLPortParamVariable(Scene, "negativeWorldRange", worldAabbMin, xmlelement, mode); 124 //XMLPortParamVariable(Scene, "positiveWorldRange", worldAabbMax, xmlelement, mode); 125 XMLPortParam(Scene, "hasPhysics", setPhysicalWorld, hasPhysics, xmlelement, mode).defaultValue(0, true);//.defaultValue(1, worldAabbMin).defaultValue(2, worldAabbMax); 126 111 127 XMLPortObjectExtended(Scene, BaseObject, "", addObject, getObject, xmlelement, mode, true, false); 112 128 } … … 114 130 void Scene::registerVariables() 115 131 { 116 registerVariable(this->skybox_, variableDirection::toclient, new NetworkCallback<Scene>(this, &Scene::networkcallback_applySkybox));132 registerVariable(this->skybox_, variableDirection::toclient, new NetworkCallback<Scene>(this, &Scene::networkcallback_applySkybox)); 117 133 registerVariable(this->ambientLight_, variableDirection::toclient, new NetworkCallback<Scene>(this, &Scene::networkcallback_applyAmbientLight)); 134 registerVariable(this->bHasPhysics_, variableDirection::toclient, new NetworkCallback<Scene>(this, &Scene::networkcallback_hasPhysics)); 135 } 136 137 void Scene::setPhysicalWorld(bool wantPhysics)//, const Vector3& worldAabbMin, const Vector3& worldAabbMax) 138 { 139 this->bHasPhysics_ = wantPhysics; 140 if (wantPhysics && !hasPhysics()) 141 { 142 //float x = worldAabbMin.x; 143 //float y = worldAabbMin.y; 144 //float z = worldAabbMin.z; 145 btVector3 worldAabbMin(-100000, -100000, -100000); 146 //x = worldAabbMax.x; 147 //y = worldAabbMax.y; 148 //z = worldAabbMax.z; 149 btVector3 worldAabbMax(100000, 100000, 100000); 150 151 btDefaultCollisionConfiguration* collisionConfig = new btDefaultCollisionConfiguration(); 152 btCollisionDispatcher* dispatcher = new btCollisionDispatcher(collisionConfig); 153 bt32BitAxisSweep3* broadphase = new bt32BitAxisSweep3(worldAabbMin,worldAabbMax); 154 btSequentialImpulseConstraintSolver* solver = new btSequentialImpulseConstraintSolver; 155 156 this->physicalWorld_ = new btDiscreteDynamicsWorld(dispatcher, broadphase, solver, collisionConfig); 157 158 // Disable Gravity for space 159 this->physicalWorld_->setGravity(btVector3(0,0,0)); 160 } 161 else 162 { 163 // TODO: Destroy Bullet physics 164 } 165 } 166 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 } 174 if (physicalWorld_) 175 { 176 if (this->physicsQueue_.size() > 0) 177 { 178 // Add all scheduled WorldEntities 179 for (std::set<btRigidBody*>::const_iterator it = this->physicsQueue_.begin(); 180 it != this->physicsQueue_.end(); ++it) 181 { 182 if (!(*it)->isInWorld()) 183 { 184 //COUT(0) << "body position: " << omni_cast<Vector3>((*it)->getWorldTransform().getOrigin()) << std::endl; 185 //COUT(0) << "body velocity: " << omni_cast<Vector3>((*it)->getLinearVelocity()) << std::endl; 186 //COUT(0) << "body orientation: " << omni_cast<Quaternion>((*it)->getWorldTransform().getRotation()) << std::endl; 187 //COUT(0) << "body angular: " << omni_cast<Vector3>((*it)->getAngularVelocity()) << std::endl; 188 //COUT(0) << "body mass: " << omni_cast<float>((*it)->getInvMass()) << std::endl; 189 //COUT(0) << "body inertia: " << omni_cast<Vector3>((*it)->getInvInertiaDiagLocal()) << std::endl; 190 this->physicalWorld_->addRigidBody(*it); 191 } 192 } 193 this->physicsQueue_.clear(); 194 } 195 196 // TODO: This is not stable! If physics cannot be calculated real time anymore, 197 // framerate will drop exponentially. 198 physicalWorld_->stepSimulation(dt,(int)(dt/0.0166666f + 1.0f)); 199 } 118 200 } 119 201 … … 165 247 } 166 248 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); 249 void Scene::addRigidBody(btRigidBody* body) 250 { 251 if (!this->physicalWorld_) 252 COUT(1) << "Error: Cannot add WorldEntity body to physical Scene: No physics." << std::endl; 253 else if (body) 254 this->physicsQueue_.insert(body); 255 } 256 257 void Scene::removeRigidBody(btRigidBody* body) 258 { 259 if (!this->physicalWorld_) 260 COUT(1) << "Error: Cannot remove WorldEntity body from physical Scene: No physics." << std::endl; 261 else if (body) 262 { 263 this->physicalWorld_->removeRigidBody(body); 264 // Also check queue 265 std::set<btRigidBody*>::iterator it = this->physicsQueue_.find(body); 266 if (it != this->physicsQueue_.end()) 267 this->physicsQueue_.erase(it); 173 268 } 174 269 } -
code/branches/physics_merge/src/orxonox/objects/Scene.h
r2371 r2442 53 53 { return this->rootSceneNode_; } 54 54 55 inline btDiscreteDynamicsWorld* getPhysicalWorld() const 56 { return this->physicalWorld_; } 57 55 58 void setSkybox(const std::string& skybox); 56 59 inline const std::string& getSkybox() const … … 65 68 { return this->bShadows_; } 66 69 70 inline bool hasPhysics() 71 { return this->physicalWorld_ != 0; } 72 void setPhysicalWorld(bool wantsPhysics);//, const Vector3& worldAabbMin, const Vector3& worldAabbMax); 73 74 void addRigidBody(btRigidBody* body); 75 void removeRigidBody(btRigidBody* body); 76 67 77 virtual void tick(float dt); 68 78 … … 75 85 void networkcallback_applyAmbientLight() 76 86 { this->setAmbientLight(this->ambientLight_); } 87 void networkcallback_hasPhysics() 88 { this->setPhysicalWorld(this->bHasPhysics_); } 77 89 78 Ogre::SceneManager* sceneManager_; 79 Ogre::SceneNode* rootSceneNode_; 80 std::string skybox_; 81 ColourValue ambientLight_; 82 std::list<BaseObject*> objects_; 83 bool bShadows_; 90 Ogre::SceneManager* sceneManager_; 91 Ogre::SceneNode* rootSceneNode_; 92 93 btDiscreteDynamicsWorld* physicalWorld_; 94 std::set<btRigidBody*> physicsQueue_; 95 bool bHasPhysics_; 96 97 std::string skybox_; 98 ColourValue ambientLight_; 99 std::list<BaseObject*> objects_; 100 bool bShadows_; 84 101 }; 85 102 } -
code/branches/physics_merge/src/orxonox/objects/collisionshapes
- Property svn:mergeinfo changed
-
code/branches/physics_merge/src/orxonox/objects/collisionshapes/CollisionShape.cc
r2440 r2442 45 45 CollisionShape::CollisionShape(BaseObject* creator) 46 46 : BaseObject(creator) 47 , network::Synchronisable(creator)47 , Synchronisable(creator) 48 48 { 49 49 RegisterObject(CollisionShape); … … 76 76 void CollisionShape::registerVariables() 77 77 { 78 REGISTERDATA(this->parentID_, network::direction::toclient, new network::NetworkCallback<CollisionShape>(this, &CollisionShape::parentChanged));78 registerVariable(this->parentID_, variableDirection::toclient, new NetworkCallback<CollisionShape>(this, &CollisionShape::parentChanged)); 79 79 } 80 80 -
code/branches/physics_merge/src/orxonox/objects/collisionshapes/CollisionShape.h
r2440 r2442 35 35 #include "util/Math.h" 36 36 #include "core/BaseObject.h" 37 #include "network/ Synchronisable.h"37 #include "network/synchronisable/Synchronisable.h" 38 38 39 39 namespace orxonox 40 40 { 41 class _OrxonoxExport CollisionShape : public BaseObject, public network::Synchronisable41 class _OrxonoxExport CollisionShape : public BaseObject, public Synchronisable 42 42 { 43 43 public: -
code/branches/physics_merge/src/orxonox/objects/collisionshapes/PlaneCollisionShape.cc
r2440 r2442 57 57 void PlaneCollisionShape::registerVariables() 58 58 { 59 REGISTERDATA(this->normal_, network::direction::toclient, new network::NetworkCallback<PlaneCollisionShape>(this, &PlaneCollisionShape::updatePlane));60 REGISTERDATA(this->offset_, network::direction::toclient, new network::NetworkCallback<PlaneCollisionShape>(this, &PlaneCollisionShape::updatePlane));59 registerVariable(this->normal_, variableDirection::toclient, new NetworkCallback<PlaneCollisionShape>(this, &PlaneCollisionShape::updatePlane)); 60 registerVariable(this->offset_, variableDirection::toclient, new NetworkCallback<PlaneCollisionShape>(this, &PlaneCollisionShape::updatePlane)); 61 61 } 62 62 -
code/branches/physics_merge/src/orxonox/objects/collisionshapes/SphereCollisionShape.cc
r2440 r2442 58 58 void SphereCollisionShape::registerVariables() 59 59 { 60 REGISTERDATA(this->radius_, network::direction::toclient, new network::NetworkCallback<SphereCollisionShape>(this, &SphereCollisionShape::updateSphere));60 registerVariable(this->radius_, variableDirection::toclient, new NetworkCallback<SphereCollisionShape>(this, &SphereCollisionShape::updateSphere)); 61 61 } 62 62 -
code/branches/physics_merge/src/orxonox/objects/pickup/Usable.h
- Property svn:mergeinfo changed (with no actual effect on merging)
-
code/branches/physics_merge/src/orxonox/objects/quest/AddQuest.cc
- Property svn:mergeinfo changed (with no actual effect on merging)
-
code/branches/physics_merge/src/orxonox/objects/quest/AddQuest.h
- Property svn:mergeinfo changed (with no actual effect on merging)
-
code/branches/physics_merge/src/orxonox/objects/quest/AddQuestHint.cc
- Property svn:mergeinfo changed (with no actual effect on merging)
-
code/branches/physics_merge/src/orxonox/objects/quest/AddQuestHint.h
- Property svn:mergeinfo changed (with no actual effect on merging)
-
code/branches/physics_merge/src/orxonox/objects/quest/AddReward.cc
- Property svn:mergeinfo changed (with no actual effect on merging)
-
code/branches/physics_merge/src/orxonox/objects/quest/AddReward.h
- Property svn:mergeinfo changed (with no actual effect on merging)
-
code/branches/physics_merge/src/orxonox/objects/quest/ChangeQuestStatus.cc
- Property svn:mergeinfo changed (with no actual effect on merging)
-
code/branches/physics_merge/src/orxonox/objects/quest/ChangeQuestStatus.h
- Property svn:mergeinfo changed (with no actual effect on merging)
-
code/branches/physics_merge/src/orxonox/objects/quest/CompleteQuest.cc
- Property svn:mergeinfo changed (with no actual effect on merging)
-
code/branches/physics_merge/src/orxonox/objects/quest/CompleteQuest.h
- Property svn:mergeinfo changed (with no actual effect on merging)
-
code/branches/physics_merge/src/orxonox/objects/quest/FailQuest.cc
- Property svn:mergeinfo changed (with no actual effect on merging)
-
code/branches/physics_merge/src/orxonox/objects/quest/FailQuest.h
- Property svn:mergeinfo changed (with no actual effect on merging)
-
code/branches/physics_merge/src/orxonox/objects/quest/GlobalQuest.cc
- Property svn:mergeinfo changed (with no actual effect on merging)
-
code/branches/physics_merge/src/orxonox/objects/quest/GlobalQuest.h
- Property svn:mergeinfo changed (with no actual effect on merging)
-
code/branches/physics_merge/src/orxonox/objects/quest/LocalQuest.cc
- Property svn:mergeinfo changed (with no actual effect on merging)
-
code/branches/physics_merge/src/orxonox/objects/quest/LocalQuest.h
- Property svn:mergeinfo changed (with no actual effect on merging)
-
code/branches/physics_merge/src/orxonox/objects/quest/Quest.cc
- Property svn:mergeinfo changed (with no actual effect on merging)
-
code/branches/physics_merge/src/orxonox/objects/quest/Quest.h
- Property svn:mergeinfo changed (with no actual effect on merging)
-
code/branches/physics_merge/src/orxonox/objects/quest/QuestDescription.cc
- Property svn:mergeinfo changed (with no actual effect on merging)
-
code/branches/physics_merge/src/orxonox/objects/quest/QuestDescription.h
- Property svn:mergeinfo changed (with no actual effect on merging)
-
code/branches/physics_merge/src/orxonox/objects/quest/QuestEffect.cc
- Property svn:mergeinfo changed (with no actual effect on merging)
-
code/branches/physics_merge/src/orxonox/objects/quest/QuestEffect.h
- Property svn:mergeinfo changed (with no actual effect on merging)
-
code/branches/physics_merge/src/orxonox/objects/quest/QuestEffectBeacon.cc
r2435 r2442 53 53 Constructor. Registers the object and initializes defaults. 54 54 */ 55 QuestEffectBeacon::QuestEffectBeacon(BaseObject* creator) : PositionableEntity(creator)55 QuestEffectBeacon::QuestEffectBeacon(BaseObject* creator) : StaticEntity(creator) 56 56 { 57 57 RegisterObject(QuestEffectBeacon); -
code/branches/physics_merge/src/orxonox/objects/quest/QuestEffectBeacon.h
r2435 r2442 37 37 #include "OrxonoxPrereqs.h" 38 38 39 #include "orxonox/objects/worldentities/ PositionableEntity.h"39 #include "orxonox/objects/worldentities/StaticEntity.h" 40 40 41 41 namespace orxonox … … 80 80 Damian 'Mozork' Frick 81 81 */ 82 class _OrxonoxExport QuestEffectBeacon : public PositionableEntity82 class _OrxonoxExport QuestEffectBeacon : public StaticEntity 83 83 { 84 84 public: -
code/branches/physics_merge/src/orxonox/objects/quest/QuestHint.cc
- Property svn:mergeinfo changed (with no actual effect on merging)
-
code/branches/physics_merge/src/orxonox/objects/quest/QuestHint.h
- Property svn:mergeinfo changed (with no actual effect on merging)
-
code/branches/physics_merge/src/orxonox/objects/quest/QuestItem.cc
- Property svn:mergeinfo changed (with no actual effect on merging)
-
code/branches/physics_merge/src/orxonox/objects/quest/QuestItem.h
- Property svn:mergeinfo changed (with no actual effect on merging)
-
code/branches/physics_merge/src/orxonox/objects/quest/QuestManager.cc
- Property svn:mergeinfo changed (with no actual effect on merging)
-
code/branches/physics_merge/src/orxonox/objects/quest/QuestManager.h
- Property svn:mergeinfo changed (with no actual effect on merging)
-
code/branches/physics_merge/src/orxonox/objects/quest/Rewardable.cc
- Property svn:mergeinfo changed (with no actual effect on merging)
-
code/branches/physics_merge/src/orxonox/objects/quest/Rewardable.h
- Property svn:mergeinfo changed (with no actual effect on merging)
-
code/branches/physics_merge/src/orxonox/objects/weaponSystem/WeaponSystem.cc
- Property svn:mergeinfo changed (with no actual effect on merging)
-
code/branches/physics_merge/src/orxonox/objects/weaponSystem/WeaponSystem.h
- Property svn:mergeinfo changed
/code/branches/physics/src/orxonox/objects/weaponSystem/WeaponSystem.h (added) merged: 2192
- Property svn:mergeinfo changed
-
code/branches/physics_merge/src/orxonox/objects/worldentities/Backlight.cc
- Property svn:mergeinfo changed
/code/trunk/src/orxonox/objects/worldentities/Backlight.cc (added) merged: 1913-2085
- Property svn:mergeinfo changed
-
code/branches/physics_merge/src/orxonox/objects/worldentities/Backlight.h
- Property svn:mergeinfo changed
/code/branches/physics/src/orxonox/objects/worldentities/Backlight.h (added) merged: 2151,2184,2300 /code/trunk/src/orxonox/objects/worldentities/Backlight.h (added) merged: 1913-2085
r2420 r2442 32 32 #include "OrxonoxPrereqs.h" 33 33 34 #include " PositionableEntity.h"34 #include "StaticEntity.h" 35 35 #include "tools/BillboardSet.h" 36 36 37 37 namespace orxonox 38 38 { 39 class _OrxonoxExport Backlight : public PositionableEntity39 class _OrxonoxExport Backlight : public StaticEntity 40 40 { 41 41 public: - Property svn:mergeinfo changed
-
code/branches/physics_merge/src/orxonox/objects/worldentities/Billboard.cc
r2371 r2442 30 30 #include "Billboard.h" 31 31 32 #include <OgreBillboardSet.h> 33 32 34 #include "core/CoreIncludes.h" 33 35 #include "core/XMLPort.h" … … 38 40 CreateFactory(Billboard); 39 41 40 Billboard::Billboard(BaseObject* creator) : PositionableEntity(creator)42 Billboard::Billboard(BaseObject* creator) : StaticEntity(creator) 41 43 { 42 44 RegisterObject(Billboard); … … 50 52 { 51 53 if (this->isInitialized() && this->billboard_.getBillboardSet()) 52 this-> getNode()->detachObject(this->billboard_.getName());54 this->detachOgreObject(this->billboard_.getName()); 53 55 } 54 56 } … … 76 78 this->billboard_.setBillboardSet(this->getScene()->getSceneManager(), this->material_, this->colour_, 1); 77 79 if (this->billboard_.getBillboardSet()) 78 this->getNode()->attachObject(this->billboard_.getBillboardSet());80 this->attachOgreObject(this->billboard_.getBillboardSet()); 79 81 this->billboard_.setVisible(this->isVisible()); 80 82 } … … 92 94 this->billboard_.setBillboardSet(this->getScene()->getSceneManager(), this->material_, this->colour_, 1); 93 95 if (this->billboard_.getBillboardSet()) 94 this-> getNode()->attachObject(this->billboard_.getBillboardSet());96 this->attachOgreObject(this->billboard_.getBillboardSet()); 95 97 this->billboard_.setVisible(this->isVisible()); 96 98 } -
code/branches/physics_merge/src/orxonox/objects/worldentities/Billboard.h
r2087 r2442 31 31 32 32 #include "OrxonoxPrereqs.h" 33 #include " PositionableEntity.h"33 #include "StaticEntity.h" 34 34 #include "util/Math.h" 35 35 #include "tools/BillboardSet.h" … … 37 37 namespace orxonox 38 38 { 39 class _OrxonoxExport Billboard : public PositionableEntity39 class _OrxonoxExport Billboard : public StaticEntity 40 40 { 41 41 public: -
code/branches/physics_merge/src/orxonox/objects/worldentities/CMakeLists.txt
r2420 r2442 1 1 SET( SRC_FILES 2 2 WorldEntity.cc 3 PositionableEntity.cc3 StaticEntity.cc 4 4 MovableEntity.cc 5 MobileEntity.cc 5 6 ControllableEntity.cc 6 7 Model.cc -
code/branches/physics_merge/src/orxonox/objects/worldentities/Camera.cc
- Property svn:mergeinfo changed
/code/branches/physics/src/orxonox/objects/worldentities/Camera.cc (added) merged: 2151,2184,2296,2300 /code/trunk/src/orxonox/objects/worldentities/Camera.cc (added) merged: 1913-2085
r2420 r2442 48 48 CreateFactory(Camera); 49 49 50 Camera::Camera(BaseObject* creator) : PositionableEntity(creator)50 Camera::Camera(BaseObject* creator) : StaticEntity(creator) 51 51 { 52 52 RegisterObject(Camera); … … 56 56 57 57 this->camera_ = this->getScene()->getSceneManager()->createCamera(getUniqueNumberString()); 58 this-> getNode()->attachObject(this->camera_);58 this->attachOgreObject(this->camera_); 59 59 60 60 this->bHasFocus_ = false; - Property svn:mergeinfo changed
-
code/branches/physics_merge/src/orxonox/objects/worldentities/Camera.h
- Property svn:mergeinfo changed
/code/branches/physics/src/orxonox/objects/worldentities/Camera.h (added) merged: 2151,2184,2300 /code/trunk/src/orxonox/objects/worldentities/Camera.h (added) merged: 1913-2085
r2420 r2442 33 33 34 34 #include <OgrePrerequisites.h> 35 #include "objects/worldentities/ PositionableEntity.h"35 #include "objects/worldentities/StaticEntity.h" 36 36 #include "objects/Tickable.h" 37 37 38 38 namespace orxonox 39 39 { 40 class _OrxonoxExport Camera : public PositionableEntity, public Tickable40 class _OrxonoxExport Camera : public StaticEntity, public Tickable 41 41 { 42 42 friend class CameraManager; - Property svn:mergeinfo changed
-
code/branches/physics_merge/src/orxonox/objects/worldentities/CameraPosition.cc
r2087 r2442 38 38 CreateFactory(CameraPosition); 39 39 40 CameraPosition::CameraPosition(BaseObject* creator) : PositionableEntity(creator)40 CameraPosition::CameraPosition(BaseObject* creator) : StaticEntity(creator) 41 41 { 42 42 RegisterObject(CameraPosition); -
code/branches/physics_merge/src/orxonox/objects/worldentities/CameraPosition.h
r2087 r2442 32 32 #include "OrxonoxPrereqs.h" 33 33 34 #include "objects/worldentities/ PositionableEntity.h"34 #include "objects/worldentities/StaticEntity.h" 35 35 36 36 namespace orxonox 37 37 { 38 class _OrxonoxExport CameraPosition : public PositionableEntity38 class _OrxonoxExport CameraPosition : public StaticEntity 39 39 { 40 40 public: -
code/branches/physics_merge/src/orxonox/objects/worldentities/ControllableEntity.cc
r2415 r2442 23 23 * Fabian 'x3n' Landau 24 24 * Co-authors: 25 * ...25 * Reto Grieder 26 26 * 27 27 */ … … 44 44 CreateFactory(ControllableEntity); 45 45 46 ControllableEntity::ControllableEntity(BaseObject* creator) : WorldEntity(creator)46 ControllableEntity::ControllableEntity(BaseObject* creator) : MobileEntity(creator) 47 47 { 48 48 RegisterObject(ControllableEntity); … … 57 57 this->bDestroyWhenPlayerLeft_ = false; 58 58 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 69 69 this->setPriority( priority::very_high ); 70 71 70 this->registerVariables(); 72 71 } … … 229 228 void ControllableEntity::tick(float dt) 230 229 { 230 MobileEntity::tick(dt); 231 231 232 if (this->isActive()) 232 233 { 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()) 237 236 { 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 } 240 251 } 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 }247 252 } 248 253 } … … 251 256 { 252 257 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)); 267 273 } 268 274 … … 270 276 { 271 277 if (!this->bControlled_) 272 this-> node_->setPosition(this->server_position_);273 } 274 275 void ControllableEntity::processServer Velocity()278 this->setPosition(this->server_position_); 279 } 280 281 void ControllableEntity::processServerLinearVelocity() 276 282 { 277 283 if (!this->bControlled_) 278 this-> velocity_ = this->server_velocity_;284 this->setVelocity(this->server_linear_velocity_); 279 285 } 280 286 … … 282 288 { 283 289 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_); 285 297 } 286 298 … … 290 302 { 291 303 this->setPosition(this->server_position_); 292 this->setVelocity(this->server_velocity_);293 304 this->setOrientation(this->server_orientation_); 305 this->setVelocity(this->server_linear_velocity_); 306 this->setAngularVelocity(this->server_angular_velocity_); 294 307 295 308 this->client_overwrite_ = this->server_overwrite_; … … 301 314 if (this->server_overwrite_ == this->client_overwrite_) 302 315 { 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() 312 323 { 313 324 if (this->server_overwrite_ == this->client_overwrite_) 314 325 { 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_; 317 329 } 318 330 } … … 322 334 if (this->server_overwrite_ == this->client_overwrite_) 323 335 { 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 } 329 351 330 352 void ControllableEntity::setPosition(const Vector3& position) … … 332 354 if (Core::isMaster()) 333 355 { 334 this->node_->setPosition(position);335 this->server_position_ = position;356 MobileEntity::setPosition(position); 357 this->server_position_ = this->getPosition(); 336 358 ++this->server_overwrite_; 337 359 } 338 360 else if (this->bControlled_) 339 361 { 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(); 342 379 } 343 380 } … … 347 384 if (Core::isMaster()) 348 385 { 349 this->velocity_ = velocity;350 this->server_ velocity_ = velocity;386 MobileEntity::setVelocity(velocity); 387 this->server_linear_velocity_ = this->getVelocity(); 351 388 ++this->server_overwrite_; 352 389 } 353 390 else if (this->bControlled_) 354 391 { 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) 361 398 { 362 399 if (Core::isMaster()) 363 400 { 364 this->node_->translate(distance, relativeTo);365 this->server_ position_ = this->node_->getPosition();401 MobileEntity::setAngularVelocity(velocity); 402 this->server_angular_velocity_ = this->getAngularVelocity(); 366 403 ++this->server_overwrite_; 367 404 } 368 405 else if (this->bControlled_) 369 406 { 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); 377 415 if (Core::isMaster()) 378 416 { 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(); 382 421 } 383 422 else if (this->bControlled_) 384 423 { 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(); 477 428 } 478 429 } -
code/branches/physics_merge/src/orxonox/objects/worldentities/ControllableEntity.h
r2087 r2442 23 23 * Fabian 'x3n' Landau 24 24 * Co-authors: 25 * ...25 * Reto Grieder 26 26 * 27 27 */ … … 32 32 #include "OrxonoxPrereqs.h" 33 33 34 #include "WorldEntity.h" 35 #include "objects/Tickable.h" 34 #include "MobileEntity.h" 36 35 37 36 namespace orxonox 38 37 { 39 class _OrxonoxExport ControllableEntity : public WorldEntity, public Tickable38 class _OrxonoxExport ControllableEntity : public MobileEntity 40 39 { 41 40 public: … … 72 71 virtual void switchCamera(); 73 72 74 inline const Vector3& getVelocity() const75 { return this->velocity_; }76 inline const Vector3& getAcceleration() const77 { return this->acceleration_; }78 73 inline const std::string& getHudTemplate() const 79 74 { 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; }109 75 110 76 inline Camera* getCamera() const … … 123 89 { return this->cameraPositionTemplate_; } 124 90 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 125 101 protected: 126 102 virtual void startLocalControl(); … … 133 109 { return this->bControlled_; } 134 110 135 Vector3 acceleration_;136 137 111 private: 138 112 void overwrite(); … … 140 114 141 115 void processServerPosition(); 142 void processServer Velocity();116 void processServerLinearVelocity(); 143 117 void processServerOrientation(); 118 void processServerAngularVelocity(); 144 119 145 120 void processClientPosition(); 146 void processClient Velocity();121 void processClientLinearVelocity(); 147 122 void processClientOrientation(); 123 void processClientAngularVelocity(); 148 124 149 125 void networkcallback_changedplayerID(); 126 127 // Bullet btMotionState related 128 void setWorldTransform(const btTransform& worldTrans); 150 129 151 130 unsigned int server_overwrite_; 152 131 unsigned int client_overwrite_; 153 132 154 Vector3 velocity_;155 156 133 bool bControlled_; 157 134 Vector3 server_position_; 158 135 Vector3 client_position_; 159 Vector3 server_ velocity_;160 Vector3 client_ velocity_;136 Vector3 server_linear_velocity_; 137 Vector3 client_linear_velocity_; 161 138 Quaternion server_orientation_; 162 139 Quaternion client_orientation_; 140 Vector3 server_angular_velocity_; 141 Vector3 client_angular_velocity_; 163 142 164 143 PlayerInfo* player_; -
code/branches/physics_merge/src/orxonox/objects/worldentities/Light.cc
r2371 r2442 47 47 CreateFactory(Light); 48 48 49 Light::Light(BaseObject* creator) : PositionableEntity(creator)49 Light::Light(BaseObject* creator) : StaticEntity(creator) 50 50 { 51 51 RegisterObject(Light); … … 53 53 if (this->getScene() && this->getScene()->getSceneManager()) 54 54 this->light_ = this->getScene()->getSceneManager()->createLight("Light" + convertToString(Light::lightCounter_s++)); 55 this-> getNode()->attachObject(this->light_);55 this->attachOgreObject(this->light_); 56 56 57 57 this->registerVariables(); -
code/branches/physics_merge/src/orxonox/objects/worldentities/Light.h
r2087 r2442 31 31 32 32 #include "OrxonoxPrereqs.h" 33 #include " PositionableEntity.h"33 #include "StaticEntity.h" 34 34 35 35 #include <string> … … 40 40 namespace orxonox 41 41 { 42 class _OrxonoxExport Light : public PositionableEntity42 class _OrxonoxExport Light : public StaticEntity 43 43 { 44 44 public: -
code/branches/physics_merge/src/orxonox/objects/worldentities/Model.cc
r2415 r2442 29 29 #include "OrxonoxStableHeaders.h" 30 30 31 #include <OgreEntity.h> 31 32 #include "Model.h" 32 33 #include "core/CoreIncludes.h" … … 38 39 CreateFactory(Model); 39 40 40 Model::Model(BaseObject* creator) : PositionableEntity(creator)41 Model::Model(BaseObject* creator) : StaticEntity(creator) 41 42 { 42 43 RegisterObject(Model); … … 48 49 { 49 50 if (this->isInitialized() && this->mesh_.getEntity()) 50 this-> getNode()->detachObject(this->mesh_.getEntity());51 this->detachOgreObject(this->mesh_.getEntity()); 51 52 } 52 53 … … 68 69 { 69 70 if (this->mesh_.getEntity()) 70 this-> getNode()->detachObject(this->mesh_.getEntity());71 this->detachOgreObject(this->mesh_.getEntity()); 71 72 72 73 this->mesh_.setMeshSource(this->getScene()->getSceneManager(), this->meshSrc_); … … 74 75 if (this->mesh_.getEntity()) 75 76 { 76 this-> getNode()->attachObject(this->mesh_.getEntity());77 this->attachOgreObject(this->mesh_.getEntity()); 77 78 this->mesh_.getEntity()->setCastShadows(this->bCastShadows_); 78 79 this->mesh_.setVisible(this->isVisible()); -
code/branches/physics_merge/src/orxonox/objects/worldentities/Model.h
r2087 r2442 31 31 32 32 #include "OrxonoxPrereqs.h" 33 #include " PositionableEntity.h"33 #include "StaticEntity.h" 34 34 #include "tools/Mesh.h" 35 35 36 36 namespace orxonox 37 37 { 38 class _OrxonoxExport Model : public PositionableEntity38 class _OrxonoxExport Model : public StaticEntity 39 39 { 40 40 public: … … 70 70 } 71 71 72 #endif /* _ PositionableEntity_H__ */72 #endif /* _Model_H__ */ -
code/branches/physics_merge/src/orxonox/objects/worldentities/MovableEntity.cc
r2415 r2442 22 22 * Author: 23 23 * Fabian 'x3n' Landau 24 * Reto Grieder 24 25 * Co-authors: 25 26 * ... … … 38 39 { 39 40 static const float MAX_RESYNCHRONIZE_TIME = 3.0f; 41 static const float CONTINUOUS_SYNCHRONIZATION_TIME = 10.0f; 40 42 41 43 CreateFactory(MovableEntity); 42 44 43 MovableEntity::MovableEntity(BaseObject* creator) : WorldEntity(creator)45 MovableEntity::MovableEntity(BaseObject* creator) : MobileEntity(creator) 44 46 { 45 47 RegisterObject(MovableEntity); 46 48 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; 54 50 this->overwrite_orientation_ = Quaternion::IDENTITY; 55 51 56 52 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); 57 57 58 58 this->registerVariables(); … … 61 61 MovableEntity::~MovableEntity() 62 62 { 63 if (this->isInitialized()) 64 delete this->continuousResynchroTimer_; 63 65 } 64 66 … … 66 68 { 67 69 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 }84 70 } 85 71 86 72 void MovableEntity::registerVariables() 87 73 { 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 98 77 registerVariable(this->overwrite_position_, variableDirection::toclient, new NetworkCallback<MovableEntity>(this, &MovableEntity::overwritePosition)); 99 78 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_);110 79 } 111 80 … … 124 93 this->overwrite_orientation_ = this->getOrientation(); 125 94 } 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 }180 95 } -
code/branches/physics_merge/src/orxonox/objects/worldentities/MovableEntity.h
r2171 r2442 22 22 * Author: 23 23 * Fabian 'x3n' Landau 24 * Reto Grieder 24 25 * Co-authors: 25 26 * ... … … 32 33 #include "OrxonoxPrereqs.h" 33 34 34 #include "WorldEntity.h" 35 #include "objects/Tickable.h" 35 #include "MobileEntity.h" 36 36 #include "network/ClientConnectionListener.h" 37 37 38 38 namespace orxonox 39 39 { 40 class _OrxonoxExport MovableEntity : public WorldEntity, public Tickable, public ClientConnectionListener40 class _OrxonoxExport MovableEntity : public MobileEntity, public ClientConnectionListener 41 41 { 42 42 public: … … 45 45 46 46 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); 47 virtual void tick(float dt);48 47 void registerVariables(); 49 48 50 49 using WorldEntity::setPosition; 51 using WorldEntity::translate;52 50 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;59 51 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(); } 104 56 105 57 private: … … 108 60 void resynchronize(); 109 61 110 void overwritePosition(); 111 void overwriteOrientation(); 62 inline void processLinearVelocity() 63 { this->setVelocity(this->linearVelocity_); } 64 inline void processAngularVelocity() 65 { this->setAngularVelocity(this->angularVelocity_); } 112 66 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_); } 118 71 119 Vector3 overwrite_position_;72 Vector3 overwrite_position_; 120 73 Quaternion overwrite_orientation_; 74 Timer<MovableEntity>* continuousResynchroTimer_; 121 75 }; 122 76 } -
code/branches/physics_merge/src/orxonox/objects/worldentities/ParticleEmitter.cc
r2371 r2442 33 33 34 34 #include "OrxonoxStableHeaders.h" 35 #include "ParticleEmitter.h" 35 36 36 #include "ParticleEmitter.h"37 #include <OgreParticleSystem.h> 37 38 38 39 #include "tools/ParticleInterface.h" … … 46 47 CreateFactory(ParticleEmitter); 47 48 48 ParticleEmitter::ParticleEmitter(BaseObject* creator) : PositionableEntity(creator)49 ParticleEmitter::ParticleEmitter(BaseObject* creator) : StaticEntity(creator) 49 50 { 50 51 RegisterObject(ParticleEmitter); … … 62 63 { 63 64 if (this->isInitialized() && this->particles_) 65 { 66 this->detachOgreObject(this->particles_->getParticleSystem()); 64 67 delete this->particles_; 68 } 65 69 } 66 70 … … 105 109 { 106 110 this->particles_ = new ParticleInterface(this->getScene()->getSceneManager(), this->source_, this->LOD_); 107 this-> particles_->addToSceneNode(this->getNode());111 this->attachOgreObject(particles_->getParticleSystem()); 108 112 this->particles_->setVisible(this->isVisible()); 109 113 this->particles_->setEnabled(this->isActive()); -
code/branches/physics_merge/src/orxonox/objects/worldentities/ParticleEmitter.h
r2087 r2442 31 31 32 32 #include "OrxonoxPrereqs.h" 33 #include " PositionableEntity.h"33 #include "StaticEntity.h" 34 34 35 35 namespace orxonox 36 36 { 37 class _OrxonoxExport ParticleEmitter : public PositionableEntity37 class _OrxonoxExport ParticleEmitter : public StaticEntity 38 38 { 39 39 public: -
code/branches/physics_merge/src/orxonox/objects/worldentities/ParticleSpawner.cc
- Property svn:mergeinfo changed
/code/trunk/src/orxonox/objects/worldentities/ParticleSpawner.cc (added) merged: 1913-2085
- Property svn:mergeinfo changed
-
code/branches/physics_merge/src/orxonox/objects/worldentities/ParticleSpawner.h
- Property svn:mergeinfo changed
/code/trunk/src/orxonox/objects/worldentities/ParticleSpawner.h (added) merged: 1913-2085
- Property svn:mergeinfo changed
-
code/branches/physics_merge/src/orxonox/objects/worldentities/Planet.cc
r2436 r2442 63 63 { 64 64 if (this->isInitialized() && this->mesh_.getEntity()) 65 this-> getNode()->detachObject(this->mesh_.getEntity());65 this->detachOgreObject(this->mesh_.getEntity()); 66 66 } 67 67 … … 108 108 billboard_.setBillboardSet(this->getScene()->getSceneManager(), this->atmosphere_, Vector3(0,0,0)); 109 109 110 this-> getNode()->attachObject(this->billboard_.getBillboardSet());110 this->attachOgreObject(this->billboard_.getBillboardSet()); 111 111 this->billboard_.getBillboardSet()->setUseAccurateFacing(true); 112 112 this->setCastShadows(true); … … 118 118 { 119 119 if (this->mesh_.getEntity()) 120 this-> getNode()->detachObject(this->mesh_.getEntity());120 this->detachOgreObject(this->mesh_.getEntity()); 121 121 122 122 this->mesh_.setMeshSource(this->getScene()->getSceneManager(), this->meshSrc_); … … 124 124 if (this->mesh_.getEntity()) 125 125 { 126 this-> getNode()->attachObject(this->mesh_.getEntity());126 this->attachOgreObject(this->mesh_.getEntity()); 127 127 this->mesh_.getEntity()->setCastShadows(this->bCastShadows_); 128 128 this->mesh_.setVisible(this->isVisible()); -
code/branches/physics_merge/src/orxonox/objects/worldentities/SpawnPoint.cc
r2087 r2442 38 38 CreateFactory(SpawnPoint); 39 39 40 SpawnPoint::SpawnPoint(BaseObject* creator) : PositionableEntity(creator)40 SpawnPoint::SpawnPoint(BaseObject* creator) : StaticEntity(creator) 41 41 { 42 42 RegisterObject(SpawnPoint); -
code/branches/physics_merge/src/orxonox/objects/worldentities/SpawnPoint.h
r2087 r2442 34 34 #include "core/Identifier.h" 35 35 #include "core/Template.h" 36 #include "PositionableEntity.h"37 36 #include "objects/worldentities/pawns/Pawn.h" 37 #include "objects/worldentities/StaticEntity.h" 38 38 39 39 namespace orxonox 40 40 { 41 class _OrxonoxExport SpawnPoint : public PositionableEntity41 class _OrxonoxExport SpawnPoint : public StaticEntity 42 42 { 43 43 public: -
code/branches/physics_merge/src/orxonox/objects/worldentities/StaticEntity.cc
r2440 r2442 44 44 { 45 45 RegisterObject(StaticEntity); 46 47 this->setPriority(priority::very_low); 46 48 47 49 this->registerVariables(); … … 54 56 void StaticEntity::registerVariables() 55 57 { 56 REGISTERDATA(this->getPosition(), network::direction::toclient, new network::NetworkCallback<StaticEntity>(this, &StaticEntity::positionChanged));57 REGISTERDATA(this->getOrientation(), network::direction::toclient, new network::NetworkCallback<StaticEntity>(this, &StaticEntity::orientationChanged));58 registerVariable(this->getPosition(), variableDirection::toclient, new NetworkCallback<StaticEntity>(this, &StaticEntity::positionChanged)); 59 registerVariable(this->getOrientation(), variableDirection::toclient, new NetworkCallback<StaticEntity>(this, &StaticEntity::orientationChanged)); 58 60 } 59 61 -
code/branches/physics_merge/src/orxonox/objects/worldentities/WorldEntity.cc
r2371 r2442 22 22 * Author: 23 23 * Fabian 'x3n' Landau 24 * Reto Grieder (physics) 24 25 * Co-authors: 25 26 * ... … … 31 32 32 33 #include <cassert> 34 #include <OgreSceneNode.h> 33 35 #include <OgreSceneManager.h> 34 36 #include "BulletDynamics/Dynamics/btRigidBody.h" 37 38 #include "util/Exception.h" 39 #include "util/Convert.h" 35 40 #include "core/CoreIncludes.h" 36 41 #include "core/XMLPort.h" 37 #include "util/Convert.h"38 #include "util/Exception.h"39 42 40 43 #include "objects/Scene.h" 44 #include "objects/collisionshapes/CompoundCollisionShape.h" 41 45 42 46 namespace orxonox … … 64 68 this->node_->setOrientation(Quaternion::IDENTITY); 65 69 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 66 85 this->registerVariables(); 67 86 } … … 74 93 if (this->getScene()->getSceneManager()) 75 94 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_; 76 104 } 77 105 } … … 81 109 SUPER(WorldEntity, XMLPort, xmlelement, mode); 82 110 83 XMLPortParamTemplate(WorldEntity, "position", setPosition, getPosition,xmlelement, mode, const Vector3&);111 XMLPortParamTemplate(WorldEntity, "position", setPosition, getPosition, xmlelement, mode, const Vector3&); 84 112 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 93 131 XMLPortObject(WorldEntity, WorldEntity, "attached", attach, getAttachedObject, xmlelement, mode); 132 // Attached collision shapes 133 XMLPortObject(WorldEntity, CollisionShape, "collisionShapes", attachCollisionShape, getAttachedCollisionShape, xmlelement, mode); 94 134 } 95 135 96 136 void WorldEntity::registerVariables() 97 137 { 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() 109 158 { 110 159 if (this->parentID_ != OBJECTID_UNKNOWN) … … 116 165 } 117 166 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 118 193 void WorldEntity::attach(WorldEntity* object) 119 194 { 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 120 224 if (object->getParent()) 121 225 object->detachFromParent(); … … 131 235 object->parent_ = this; 132 236 object->parentID_ = this->getObjectID(); 237 238 // collision shapes 239 this->attachCollisionShape(object->getCollisionShape()); 240 // mass 241 this->childrenMass_ += object->getMass(); 242 recalculateMassProps(); 133 243 } 134 244 135 245 void WorldEntity::detach(WorldEntity* object) 136 246 { 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 137 256 this->node_->removeChild(object->node_); 138 257 this->children_.erase(object); 139 258 object->parent_ = 0; 140 259 object->parentID_ = OBJECTID_UNKNOWN; 141 142 260 // 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(); 143 264 } 144 265 … … 154 275 return 0; 155 276 } 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()->addRigidBody(this->physicalBody_); 315 this->bPhysicsActive_ = true; 316 } 317 } 318 319 void WorldEntity::deactivatePhysics() 320 { 321 if (this->isPhysicsActive()) 322 { 323 this->getScene()->removeRigidBody(this->physicalBody_); 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; // exception gets issued anyway 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 if (this->hasPhysics()) 608 { 609 if (this->isStatic()) 610 { 611 // Just set everything to zero 612 this->physicalBody_->setMassProps(0.0f, btVector3(0, 0, 0)); 613 } 614 else if ((this->mass_ + this->childrenMass_) == 0.0f) 615 { 616 // Use default values to avoid very large or very small values 617 CCOUT(4) << "Warning: Setting the internal physical mass to 1.0 because mass_ is 0.0." << std::endl; 618 this->physicalBody_->setMassProps(1.0f, this->collisionShape_->getLocalInertia(1.0f)); 619 } 620 else 621 { 622 float mass = this->mass_ + this->childrenMass_; 623 this->physicalBody_->setMassProps(mass, this->collisionShape_->getLocalInertia(mass)); 624 } 625 } 626 } 627 628 void WorldEntity::resetPhysicsProps() 629 { 630 if (this->hasPhysics()) 631 { 632 this->physicalBody_->setRestitution(this->restitution_); 633 this->physicalBody_->setAngularFactor(this->angularFactor_); 634 this->physicalBody_->setDamping(this->linearDamping_, this->angularDamping_); 635 this->physicalBody_->setFriction(this->friction_); 636 } 637 } 156 638 } -
code/branches/physics_merge/src/orxonox/objects/worldentities/WorldEntity.h
r2371 r2442 22 22 * Author: 23 23 * Fabian 'x3n' Landau 24 * Reto Grieder (physics) 24 25 * Co-authors: 25 26 * ... … … 32 33 #include "OrxonoxPrereqs.h" 33 34 34 #define OGRE_FORCE_ANGLE_TYPES 35 35 #ifdef _NDEBUG 36 36 #include <OgreSceneNode.h> 37 #else 38 #include <OgrePrerequisites.h> 39 #endif 40 #include "LinearMath/btMotionState.h" 37 41 38 42 #include "network/synchronisable/Synchronisable.h" … … 42 46 namespace orxonox 43 47 { 44 class _OrxonoxExport WorldEntity : public BaseObject, public Synchronisable 48 class _OrxonoxExport WorldEntity : public BaseObject, public Synchronisable, public btMotionState 45 49 { 46 50 public: … … 51 55 void registerVariables(); 52 56 53 inline Ogre::SceneNode* getNode() const57 inline const Ogre::SceneNode* getNode() const 54 58 { return this->node_; } 55 59 … … 64 68 inline void setPosition(float x, float y, float z) 65 69 { 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) 73 75 { this->translate(Vector3(x, y, z), relativeTo); } 74 76 … … 80 82 inline void setOrientation(const Vector3& axis, const Degree& angle) 81 83 { 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) 89 89 { 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) 106 101 { this->setDirection(Vector3(x, y, z), relativeTo, localDirectionVector); } 107 102 108 inline void setScale3D(const Vector3& scale) 109 { this->node_->setScale(scale); } 103 virtual void setScale3D(const Vector3& scale); 110 104 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); } 117 110 inline float getScale() const 118 111 { Vector3 scale = this->getScale3D(); return (scale.x == scale.y && scale.x == scale.z) ? scale.x : 1; } 119 112 120 113 inline void scale3D(const Vector3& scale) 121 { this-> node_->scale(scale); }114 { this->setScale3D(this->getScale3D() * scale); } 122 115 inline void scale3D(float x, float y, float z) 123 { this-> node_->scale(x, y, z); }116 { this->scale3D(Vector3(x, y, z)); } 124 117 inline void scale(float scale) 125 { this-> node_->scale(scale, scale, scale); }118 { this->scale3D(scale, scale, scale); } 126 119 127 120 void attach(WorldEntity* object); … … 130 123 inline const std::set<WorldEntity*>& getAttachedObjects() const 131 124 { return this->children_; } 125 126 void attachOgreObject(Ogre::MovableObject* object); 127 void detachOgreObject(Ogre::MovableObject* object); 128 Ogre::MovableObject* detachOgreObject(const Ogre::String& name); 132 129 133 130 inline void attachToParent(WorldEntity* parent) … … 138 135 { return this->parent_; } 139 136 137 void notifyChildPropsChanged(); 138 140 139 protected: 141 140 Ogre::SceneNode* node_; 142 141 143 142 private: 144 void updateParent();145 146 143 inline void lookAt_xmlport(const Vector3& target) 147 144 { this->lookAt(target); } … … 155 152 { this->roll(angle); } 156 153 154 // network callbacks 155 void parentChanged(); 156 inline void scaleChanged() 157 { this->setScale3D(this->getScale3D()); } 158 157 159 WorldEntity* parent_; 158 160 unsigned int parentID_; 159 161 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 void setRestitution(float restitution) 203 { this->restitution_ = restitution; resetPhysicsProps(); } 204 inline float getRestitution() const 205 { return this->restitution_; } 206 207 inline void setAngularFactor(float angularFactor) 208 { this->angularFactor_ = angularFactor; resetPhysicsProps(); } 209 inline float getAngularFactor() const 210 { return this->angularFactor_; } 211 212 inline void setLinearDamping(float linearDamping) 213 { this->linearDamping_ = linearDamping; resetPhysicsProps(); } 214 inline float getLinearDamping() const 215 { return this->linearDamping_; } 216 217 inline void setAngularDamping(float angularDamping) 218 { this->angularDamping_ = angularDamping; resetPhysicsProps(); } 219 inline float getAngularDamping() const 220 { return this->angularDamping_; } 221 222 inline void setFriction(float friction) 223 { this->friction_ = friction; resetPhysicsProps(); } 224 inline float getFriction() const 225 { return this->friction_; } 226 227 void attachCollisionShape(CollisionShape* shape); 228 void detachCollisionShape(CollisionShape* shape); 229 CollisionShape* getAttachedCollisionShape(unsigned int index) const; 230 231 inline CompoundCollisionShape* getCollisionShape() 232 { return this->collisionShape_; } 233 inline btRigidBody* getPhysicalBody() 234 { return this->physicalBody_; } 235 236 void notifyCollisionShapeChanged(); 237 void notifyChildMassChanged(); 238 239 protected: 240 virtual bool isCollisionTypeLegal(CollisionType type) const = 0; 241 242 btRigidBody* physicalBody_; 243 244 private: 245 void updateCollisionType(); 246 void recalculateMassProps(); 247 void resetPhysicsProps(); 248 249 // network callbacks 250 void collisionTypeChanged(); 251 void physicsActivityChanged(); 252 inline void massChanged() 253 { this->setMass(this->mass_); } 254 inline void restitutionChanged() 255 { this->setRestitution(this->restitution_); } 256 inline void angularFactorChanged() 257 { this->setAngularFactor(this->angularFactor_); } 258 inline void linearDampingChanged() 259 { this->setLinearDamping(this->linearDamping_); } 260 inline void angularDampingChanged() 261 { this->setAngularDamping(this->angularDamping_); } 262 inline void frictionChanged() 263 { this->setFriction(this->friction_); } 264 265 CollisionType collisionType_; 266 CollisionType collisionTypeSynchronised_; 267 bool bPhysicsActive_; 268 bool bPhysicsActiveSynchronised_; 269 CompoundCollisionShape* collisionShape_; 270 btScalar mass_; 271 btScalar restitution_; 272 btScalar angularFactor_; 273 btScalar linearDamping_; 274 btScalar angularDamping_; 275 btScalar friction_; 276 btScalar childrenMass_; 160 277 }; 278 279 // Inline heavily used functions for release builds. In debug, we better avoid including OgreSceneNode here. 280 #ifdef _NDEBUG 281 inline const Vector3& WorldEntity::getPosition() const 282 { return this->node_->getPosition(); } 283 inline const Quaternion& WorldEntity::getOrientation() const 284 { return this->node_->getrOrientation(); } 285 inline const Vector3& WorldEntity::getScale3D(void) const 286 { return this->node_->getScale(); } 287 #endif 161 288 } 162 289 -
code/branches/physics_merge/src/orxonox/objects/worldentities/pawns/SpaceShip.cc
r2371 r2442 30 30 #include "SpaceShip.h" 31 31 32 #include "BulletDynamics/Dynamics/btRigidBody.h" 33 34 #include "util/Math.h" 35 #include "util/Exception.h" 32 36 #include "core/CoreIncludes.h" 33 37 #include "core/ConfigValueIncludes.h" 34 38 #include "core/XMLPort.h" 35 #include "util/Math.h"36 39 37 40 namespace orxonox 38 41 { 42 const float orientationGain = 100; 39 43 CreateFactory(SpaceShip); 40 44 … … 78 82 XMLPortParam(SpaceShip, "rotacc", setRotAcc, getRotAcc, xmlelement, mode); 79 83 XMLPortParam(SpaceShip, "transdamp", setTransDamp, getTransDamp, xmlelement, mode); 84 85 if (this->physicalBody_) 86 { 87 this->physicalBody_->setDamping(0.7, 0.3); 88 } 80 89 } 81 90 … … 97 106 void SpaceShip::tick(float dt) 98 107 { 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 acceleration120 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 143 108 SUPER(SpaceShip, tick, dt); 144 145 146 if (this->isLocallyControlled())147 {148 this->yaw(this->yawRotation_ * dt);149 if (this->bInvertYAxis_)150 this->pitch(Degree(-this->pitchRotation_ * dt));151 else152 this->pitch(Degree( this->pitchRotation_ * dt));153 this->roll(this->rollRotation_ * dt);154 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_;162 }163 109 } 164 110 165 111 void SpaceShip::moveFrontBack(const Vector2& value) 166 112 { 167 this->acceleration_.z = -this->translationAcceleration_ * value.x; 113 assert(this->physicalBody_); 114 this->physicalBody_->applyCentralForce(physicalBody_->getWorldTransform().getBasis() * btVector3(0.0f, 0.0f, -getMass() * value.x * 100)); 168 115 } 169 116 170 117 void SpaceShip::moveRightLeft(const Vector2& value) 171 118 { 172 this-> acceleration_.x = this->translationAcceleration_ * value.x;119 this->physicalBody_->applyCentralForce(physicalBody_->getWorldTransform().getBasis() * btVector3(getMass() * value.x * 100, 0.0f, 0.0f)); 173 120 } 174 121 175 122 void SpaceShip::moveUpDown(const Vector2& value) 176 123 { 177 this-> acceleration_.y = this->translationAcceleration_ * value.x;124 this->physicalBody_->applyCentralForce(physicalBody_->getWorldTransform().getBasis() * btVector3(0.0f, getMass() * value.x * 100, 0.0f)); 178 125 } 179 126 180 127 void SpaceShip::rotateYaw(const Vector2& value) 181 128 { 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); 129 this->physicalBody_->applyTorque(physicalBody_->getWorldTransform().getBasis() * btVector3(0.0f, 1 / this->physicalBody_->getInvInertiaDiagLocal().y() * value.y * orientationGain, 0.0f)); 188 130 } 189 131 190 132 void SpaceShip::rotatePitch(const Vector2& value) 191 133 { 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); 134 this->physicalBody_->applyTorque(physicalBody_->getWorldTransform().getBasis() * btVector3(1 / this->physicalBody_->getInvInertiaDiagLocal().x() * value.y * orientationGain, 0.0f, 0.0f)); 198 135 } 199 136 200 137 void SpaceShip::rotateRoll(const Vector2& value) 201 138 { 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); 139 this->physicalBody_->applyTorque(physicalBody_->getWorldTransform().getBasis() * btVector3(0.0f, 0.0f, -1 / this->physicalBody_->getInvInertiaDiagLocal().z() * value.y * orientationGain)); 208 140 } 209 141 -
code/branches/physics_merge/src/orxonox/objects/worldentities/pawns/Spectator.cc
r2371 r2442 29 29 #include "OrxonoxStableHeaders.h" 30 30 #include "Spectator.h" 31 32 #include <OgreBillboardSet.h> 31 33 32 34 #include "core/CoreIncludes.h" … … 63 65 this->greetingFlare_->setBillboardSet(this->getScene()->getSceneManager(), "Examples/Flare", ColourValue(1.0, 1.0, 0.8), Vector3(0, 20, 0), 1); 64 66 if (this->greetingFlare_->getBillboardSet()) 65 this-> getNode()->attachObject(this->greetingFlare_->getBillboardSet());67 this->attachOgreObject(this->greetingFlare_->getBillboardSet()); 66 68 this->greetingFlare_->setVisible(false); 67 69 this->bGreetingFlareVisible_ = false; … … 78 80 { 79 81 if (this->greetingFlare_->getBillboardSet()) 80 this-> getNode()->detachObject(this->greetingFlare_->getBillboardSet());82 this->detachOgreObject(this->greetingFlare_->getBillboardSet()); 81 83 delete this->greetingFlare_; 82 84 } … … 110 112 Vector3 velocity = this->getVelocity(); 111 113 velocity.normalise(); 112 this->setVelocity( velocity * this->speed_);114 this->setVelocity(this->getOrientation() * velocity * this->speed_); 113 115 114 116 this->yaw(Radian(this->yaw_ * this->rotationSpeed_)); -
code/branches/physics_merge/src/orxonox/objects/worldentities/triggers/DistanceTrigger.cc
- Property svn:mergeinfo changed
/code/trunk/src/orxonox/objects/worldentities/triggers/DistanceTrigger.cc (added) merged: 1913-2085
- Property svn:mergeinfo changed
-
code/branches/physics_merge/src/orxonox/objects/worldentities/triggers/DistanceTrigger.h
- Property svn:mergeinfo changed
/code/trunk/src/orxonox/objects/worldentities/triggers/DistanceTrigger.h (added) merged: 1913-2085
- Property svn:mergeinfo changed
-
code/branches/physics_merge/src/orxonox/objects/worldentities/triggers/Trigger.cc
- Property svn:mergeinfo changed
r2420 r2442 31 31 32 32 #include <OgreBillboard.h> 33 #include <OgreBillboardSet.h> 33 34 #include "util/Debug.h" 34 35 #include "core/CoreIncludes.h" … … 44 45 CreateFactory(Trigger); 45 46 46 Trigger::Trigger(BaseObject* creator) : PositionableEntity(creator)47 Trigger::Trigger(BaseObject* creator) : StaticEntity(creator) 47 48 { 48 49 RegisterObject(Trigger); … … 71 72 72 73 if (this->debugBillboard_.getBillboardSet()) 73 this->getNode()->attachObject(this->debugBillboard_.getBillboardSet());74 this->attachOgreObject(this->debugBillboard_.getBillboardSet()); 74 75 } 75 76 -
code/branches/physics_merge/src/orxonox/objects/worldentities/triggers/Trigger.h
- Property svn:mergeinfo changed
/code/branches/physics/src/orxonox/objects/worldentities/triggers/Trigger.h (added) merged: 2151,2184,2300 /code/trunk/src/orxonox/objects/worldentities/triggers/Trigger.h (added) merged: 1913-2085
r2420 r2442 36 36 37 37 #include "objects/Tickable.h" 38 #include "objects/worldentities/ PositionableEntity.h"38 #include "objects/worldentities/StaticEntity.h" 39 39 #include "tools/BillboardSet.h" 40 40 … … 48 48 }; 49 49 50 class _OrxonoxExport Trigger : public PositionableEntity, public Tickable50 class _OrxonoxExport Trigger : public StaticEntity, public Tickable 51 51 { 52 52 public: - Property svn:mergeinfo changed
-
code/branches/physics_merge/src/orxonox/tools/BillboardSet.cc
r2171 r2442 34 34 35 35 #include <OgreSceneManager.h> 36 #include <OgreBillboardSet.h> 36 37 #include <OgreBillboard.h> 37 38 -
code/branches/physics_merge/src/orxonox/tools/BillboardSet.h
r2087 r2442 33 33 34 34 #include <string> 35 #include <Ogre BillboardSet.h>35 #include <OgrePrerequisites.h> 36 36 37 37 #include "util/Math.h" -
code/branches/physics_merge/src/orxonox/tools/BulletConversions.h
r2440 r2442 37 37 #include "LinearMath/btVector3.h" 38 38 39 // Vector3 to btVector3 40 template <> 41 struct ConverterExplicit<orxonox::Vector3, btVector3> 39 namespace orxonox 42 40 { 43 static bool convert(btVector3* output, const orxonox::Vector3& input) 41 // Vector3 to btVector3 42 template <> 43 struct ConverterExplicit<orxonox::Vector3, btVector3> 44 44 { 45 output->setX(input.x); 46 output->setY(input.y); 47 output->setZ(input.z); 48 return true; 49 } 50 }; 45 static bool convert(btVector3* output, const orxonox::Vector3& input) 46 { 47 output->setX(input.x); 48 output->setY(input.y); 49 output->setZ(input.z); 50 return true; 51 } 52 }; 51 53 52 // btVector3 to Vector3 53 template <> 54 struct ConverterExplicit<btVector3, orxonox::Vector3> 55 { 56 static bool convert(orxonox::Vector3* output, const btVector3& input) 54 // btVector3 to Vector3 55 template <> 56 struct ConverterExplicit<btVector3, orxonox::Vector3> 57 57 { 58 output->x = input.x(); 59 output->y = input.y(); 60 output->z = input.z(); 61 return true; 62 } 63 }; 58 static bool convert(orxonox::Vector3* output, const btVector3& input) 59 { 60 output->x = input.x(); 61 output->y = input.y(); 62 output->z = input.z(); 63 return true; 64 } 65 }; 64 66 65 // Quaternion to btQuaternion 66 template <> 67 struct ConverterExplicit<orxonox::Quaternion, btQuaternion> 68 { 69 static bool convert(btQuaternion* output, const orxonox::Quaternion& input) 67 // Quaternion to btQuaternion 68 template <> 69 struct ConverterExplicit<orxonox::Quaternion, btQuaternion> 70 70 { 71 output->setW(input.w); 72 output->setX(input.x); 73 output->setY(input.y); 74 output->setZ(input.z); 75 return true; 76 } 77 }; 71 static bool convert(btQuaternion* output, const orxonox::Quaternion& input) 72 { 73 output->setW(input.w); 74 output->setX(input.x); 75 output->setY(input.y); 76 output->setZ(input.z); 77 return true; 78 } 79 }; 78 80 79 // btQuaternion to Vector3 80 template <> 81 struct ConverterExplicit<btQuaternion, orxonox::Quaternion> 82 { 83 static bool convert(orxonox::Quaternion* output, const btQuaternion& input) 81 // btQuaternion to Vector3 82 template <> 83 struct ConverterExplicit<btQuaternion, orxonox::Quaternion> 84 84 { 85 output->w = input.w(); 86 output->x = input.x(); 87 output->y = input.y(); 88 output->z = input.z(); 89 return true; 90 } 91 }; 85 static bool convert(orxonox::Quaternion* output, const btQuaternion& input) 86 { 87 output->w = input.w(); 88 output->x = input.x(); 89 output->y = input.y(); 90 output->z = input.z(); 91 return true; 92 } 93 }; 94 } 92 95 93 96 #endif /* _BulletConversions_H__ */ -
code/branches/physics_merge/src/orxonox/tools/Mesh.cc
r2171 r2442 31 31 32 32 #include <sstream> 33 #include <OgreEntity.h> 33 34 #include <OgreSceneManager.h> 34 35 #include <cassert> -
code/branches/physics_merge/src/orxonox/tools/Mesh.h
r2087 r2442 33 33 34 34 #include <string> 35 #include <Ogre Entity.h>35 #include <OgrePrerequisites.h> 36 36 37 37 namespace orxonox -
code/branches/physics_merge/src/orxonox/tools/ParticleInterface.cc
r2171 r2442 57 57 58 58 this->scenemanager_ = scenemanager; 59 this->sceneNode_ = 0;60 59 this->particleSystem_ = 0; 61 60 … … 87 86 { 88 87 this->particleSystem_->removeAllEmitters(); 89 this->detachFromSceneNode();90 88 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;113 89 } 114 90 } -
code/branches/physics_merge/src/orxonox/tools/ParticleInterface.h
r2087 r2442 33 33 34 34 #include <string> 35 #include <OgreP articleEmitter.h>35 #include <OgrePrerequisites.h> 36 36 37 37 #include "core/OrxonoxClass.h" … … 53 53 inline Ogre::ParticleSystem* getParticleSystem() const 54 54 { return this->particleSystem_; } 55 56 void addToSceneNode(Ogre::SceneNode* sceneNode);57 void detachFromSceneNode();58 55 59 56 Ogre::ParticleEmitter* createNewEmitter(); … … 96 93 static unsigned int counter_s; 97 94 98 Ogre::SceneNode* sceneNode_;99 95 Ogre::ParticleSystem* particleSystem_; 100 96 bool bVisible_;
Note: See TracChangeset
for help on using the changeset viewer.