Changeset 2292 for code/branches/physics/src
- Timestamp:
- Nov 28, 2008, 1:25:16 AM (16 years ago)
- Location:
- code/branches/physics/src/orxonox/objects
- Files:
-
- 14 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/physics/src/orxonox/objects/Scene.cc
r2192 r2292 39 39 #include "core/XMLPort.h" 40 40 41 #include "BulletCollision/BroadphaseCollision/btAxisSweep3.h" 42 #include "BulletDynamics/ConstraintSolver/btSequentialImpulseConstraintSolver.h" 43 #include "BulletCollision/CollisionDispatch/btDefaultCollisionConfiguration.h" 44 41 45 namespace orxonox 42 46 { … … 70 74 } 71 75 72 ///////////// 73 // Physics // 74 ///////////// 75 76 // create bullet world; bullet solver etc. 77 78 // int maxProxies = 1024; 79 80 btVector3 worldAabbMin(-10000,-10000,-10000); 81 btVector3 worldAabbMax(10000,10000,10000); 82 bt32BitAxisSweep3* broadphase = new bt32BitAxisSweep3(worldAabbMin,worldAabbMax); 83 84 this -> collisionConfiguration_ = new btDefaultCollisionConfiguration(); 85 this -> dispatcher_ = new btCollisionDispatcher(collisionConfiguration_); 86 87 this -> solver_ = new btSequentialImpulseConstraintSolver; 88 89 this -> dynamicsWorld_ = new btDiscreteDynamicsWorld(dispatcher_,broadphase,solver_,collisionConfiguration_); 90 91 dynamicsWorld_->setGravity(btVector3(0,-10,0)); 92 76 // No physics for default 77 this->physicalWorld_ = 0; 93 78 94 79 // test test test … … 130 115 XMLPortParam(Scene, "shadow", setShadow, getShadow, xmlelement, mode).defaultValues(true); 131 116 117 const int defaultMaxWorldSize = 100000; 118 Vector3 worldAabbMin(-defaultMaxWorldSize, -defaultMaxWorldSize, -defaultMaxWorldSize); 119 Vector3 worldAabbMax( defaultMaxWorldSize, defaultMaxWorldSize, defaultMaxWorldSize); 120 XMLPortParamVariable(Scene, "negativeWorldRange", worldAabbMin, xmlelement, mode); 121 XMLPortParamVariable(Scene, "positiveWorldRange", worldAabbMax, xmlelement, mode); 122 XMLPortParam(Scene, "hasPhysics", setPhysicalWorld, hasPhysics, xmlelement, mode).defaultValue(0, true).defaultValue(1, worldAabbMin).defaultValue(2, worldAabbMax); 123 132 124 XMLPortObjectExtended(Scene, BaseObject, "", addObject, getObject, xmlelement, mode, true, false); 133 125 } … … 137 129 REGISTERSTRING(this->skybox_, network::direction::toclient, new network::NetworkCallback<Scene>(this, &Scene::networkcallback_applySkybox)); 138 130 REGISTERDATA(this->ambientLight_, network::direction::toclient, new network::NetworkCallback<Scene>(this, &Scene::networkcallback_applyAmbientLight)); 131 } 132 133 void Scene::setPhysicalWorld(bool wantPhysics, const Vector3& worldAabbMin, const Vector3& worldAabbMax) 134 { 135 if (wantPhysics && !hasPhysics()) 136 { 137 btVector3 worldAabbMin(worldAabbMin.x, worldAabbMin.y, worldAabbMin.z); 138 btVector3 worldAabbMax(worldAabbMax.x, worldAabbMax.y, worldAabbMax.z); 139 140 btDefaultCollisionConfiguration* collisionConfig = new btDefaultCollisionConfiguration(); 141 btCollisionDispatcher* dispatcher = new btCollisionDispatcher(collisionConfig); 142 bt32BitAxisSweep3* broadphase = new bt32BitAxisSweep3(worldAabbMin,worldAabbMax); 143 btSequentialImpulseConstraintSolver* solver = new btSequentialImpulseConstraintSolver; 144 145 this->physicalWorld_ = new btDiscreteDynamicsWorld(dispatcher, broadphase, solver, collisionConfig); 146 147 // test test test 148 this->physicalWorld_->setGravity(btVector3(0,0,0)); 149 // test test test 150 } 151 else 152 { 153 // TODO: Destroy Bullet physics 154 } 155 } 156 157 void Scene::tick(float dt) 158 { 159 if (physicalWorld_) 160 physicalWorld_->stepSimulation(dt,10); 139 161 } 140 162 -
code/branches/physics/src/orxonox/objects/Scene.h
r2192 r2292 35 35 #include "core/BaseObject.h" 36 36 #include "util/Math.h" 37 #include "objects/Tickable.h" 37 38 38 #include " ogrebullet/Dynamics/OgreBulletDynamics.h"39 #include "BulletDynamics/Dynamics/btDiscreteDynamicsWorld.h" 39 40 40 41 namespace orxonox 41 42 { 42 class _OrxonoxExport Scene : public BaseObject, public network::Synchronisable 43 class _OrxonoxExport Scene : public BaseObject, public network::Synchronisable, public Tickable 43 44 { 44 45 public: … … 55 56 56 57 inline btDiscreteDynamicsWorld* getPhysicalWorld() const 57 { return this-> dynamicsWorld_; }58 { return this->physicalWorld_; } 58 59 59 60 void setSkybox(const std::string& skybox); … … 69 70 { return this->bShadows_; } 70 71 72 inline const Vector3& getWorldAabbMax() 73 { 74 this->physicalWorld_->getBroadphase(); 75 } 76 77 inline bool hasPhysics() 78 { return this->physicalWorld_ != 0; } 79 void setPhysicalWorld(bool wantsPhysics, const Vector3& worldAabbMin, const Vector3& worldAabbMax); 80 81 void tick(float dt); 82 71 83 private: 72 84 void addObject(BaseObject* object); … … 81 93 Ogre::SceneNode* rootSceneNode_; 82 94 83 btDiscreteDynamicsWorld* dynamicsWorld_; 84 btSequentialImpulseConstraintSolver* solver_; 85 btDefaultCollisionConfiguration* collisionConfiguration_; 86 btCollisionDispatcher* dispatcher_; 87 // Point auf Bullet btDynamics world && solver 95 btDiscreteDynamicsWorld* physicalWorld_; 88 96 89 97 std::string skybox_; -
code/branches/physics/src/orxonox/objects/worldentities/ControllableEntity.cc
r2201 r2292 229 229 if (this->isActive()) 230 230 { 231 this->velocity_ += (dt * this->acceleration_); 232 this->node_->translate(dt * this->velocity_, Ogre::Node::TS_LOCAL); 231 if (!this->isDynamic()) 232 { 233 this->velocity_ += (dt * this->acceleration_); 234 this->node_->translate(dt * this->velocity_, Ogre::Node::TS_LOCAL); 235 } 233 236 234 237 if (Core::isMaster()) … … 325 328 } 326 329 327 328 // virtual void PositionChanged() { } 329 void ControllableEntity::positionChanged(const Vector3& position) 330 void ControllableEntity::positionChanged() 330 331 { 331 332 if (Core::isMaster()) 332 333 { 333 this->server_position_ = this->getPosition();334 ++this->server_overwrite_;335 }336 else if (this->bControlled_)337 {338 this->client_position_ = position;339 }340 }341 342 void ControllableEntity::setVelocity(const Vector3& velocity)343 {344 if (Core::isMaster())345 {346 this->velocity_ = velocity;347 this->server_velocity_ = velocity;348 ++this->server_overwrite_;349 }350 else if (this->bControlled_)351 {352 this->velocity_ = velocity;353 this->client_velocity_ = velocity;354 }355 }356 // virtual void translateChanged() { }357 void ControllableEntity::translateChanged(const Vector3& distance, Ogre::Node::TransformSpace relativeTo)358 {359 if (Core::isMaster())360 {361 this->node_->translate(distance, relativeTo);362 334 this->server_position_ = this->node_->getPosition(); 363 335 ++this->server_overwrite_; … … 365 337 else if (this->bControlled_) 366 338 { 367 this->node_->translate(distance, relativeTo);368 339 this->client_position_ = this->node_->getPosition(); 369 340 } 370 341 } 371 // virtual void orientationChanged() { } 372 void ControllableEntity::orientationChanged( const Quaternion& orientation)342 343 void ControllableEntity::orientationChanged() 373 344 { 374 345 if (Core::isMaster()) 375 346 { 376 this->node_->setOrientation(orientation);377 this->server_orientation_ = orientation;378 ++this->server_overwrite_;379 }380 else if (this->bControlled_)381 {382 this->node_->setOrientation(orientation);383 this->client_orientation_ = orientation;384 }385 }386 // virtual void rotateChanged() { }387 void ControllableEntity::rotateChanged(const Quaternion& rotation, Ogre::Node::TransformSpace relativeTo)388 {389 if (Core::isMaster())390 {391 this->node_->rotate(rotation, relativeTo);392 347 this->server_orientation_ = this->node_->getOrientation(); 393 348 ++this->server_overwrite_; … … 395 350 else if (this->bControlled_) 396 351 { 397 this->node_->rotate(rotation, relativeTo);398 352 this->client_orientation_ = this->node_->getOrientation(); 399 353 } 400 354 } 401 // virtual void yawChanged() { } 402 void ControllableEntity:: yawChanged(const Degree& angle, Ogre::Node::TransformSpace relativeTo)355 356 void ControllableEntity::velocityChanged() 403 357 { 404 358 if (Core::isMaster()) 405 359 { 406 this->node_->yaw(angle, relativeTo); 407 this->server_orientation_ = this->node_->getOrientation(); 360 this->server_velocity_ = this->velocity_; 408 361 ++this->server_overwrite_; 409 362 } 410 363 else if (this->bControlled_) 411 364 { 412 this->node_->yaw(angle, relativeTo); 413 this->client_orientation_ = this->node_->getOrientation(); 414 } 415 } 416 // virtual void pitchChanged() { } 417 void ControllableEntity::pitchChanged(const Degree& angle, Ogre::Node::TransformSpace relativeTo) 418 { 419 if (Core::isMaster()) 420 { 421 this->node_->pitch(angle, relativeTo); 422 this->server_orientation_ = this->node_->getOrientation(); 423 ++this->server_overwrite_; 424 } 425 else if (this->bControlled_) 426 { 427 this->node_->pitch(angle, relativeTo); 428 this->client_orientation_ = this->node_->getOrientation(); 429 } 430 } 431 // virtual void rollChanged() { } 432 void ControllableEntity::rollChanged(const Degree& angle, Ogre::Node::TransformSpace relativeTo) 433 { 434 if (Core::isMaster()) 435 { 436 this->node_->roll(angle, relativeTo); 437 this->server_orientation_ = this->node_->getOrientation(); 438 ++this->server_overwrite_; 439 } 440 else if (this->bControlled_) 441 { 442 this->node_->roll(angle, relativeTo); 443 this->client_orientation_ = this->node_->getOrientation(); 444 } 445 } 446 //virtual void lookAtChanged() { } 447 void ControllableEntity::lookAtChanged(const Vector3& target, Ogre::Node::TransformSpace relativeTo, const Vector3& localDirectionVector) 448 { 449 if (Core::isMaster()) 450 { 451 this->node_->lookAt(target, relativeTo, localDirectionVector); 452 this->server_orientation_ = this->node_->getOrientation(); 453 ++this->server_overwrite_; 454 } 455 else if (this->bControlled_) 456 { 457 this->node_->lookAt(target, relativeTo, localDirectionVector); 458 this->client_orientation_ = this->node_->getOrientation(); 459 } 460 } 461 // virtual void directionChanged( ) { } 462 void ControllableEntity::directionChanged(const Vector3& direction, Ogre::Node::TransformSpace relativeTo, const Vector3& localDirectionVector) 463 { 464 if (Core::isMaster()) 465 { 466 this->node_->setDirection(direction, relativeTo, localDirectionVector); 467 this->server_orientation_ = this->node_->getOrientation(); 468 ++this->server_overwrite_; 469 } 470 else if (this->bControlled_) 471 { 472 this->node_->setDirection(direction, relativeTo, localDirectionVector); 473 this->client_orientation_ = this->node_->getOrientation(); 365 this->client_velocity_ = this->velocity_; 366 } 367 } 368 369 void ControllableEntity::setVelocity(const Vector3& velocity) 370 { 371 if (this->bControlled_ || Core::isMaster()) 372 { 373 if (!this->isDynamic()) 374 { 375 // no physics, we do it ourselves 376 internalSetVelocity(velocity); 377 } 378 else 379 { 380 this->physicalBody_->setLinearVelocity(btVector3(velocity.x, velocity.y, velocity.z)); 381 } 382 velocityChanged(); 474 383 } 475 384 } -
code/branches/physics/src/orxonox/objects/worldentities/ControllableEntity.h
r2201 r2292 79 79 { return this->hudtemplate_; } 80 80 81 void setPosition();82 void translate(const Vector3& distance, Ogre::Node::TransformSpace relativeTo = Ogre::Node::TS_LOCAL);83 void setOrientation(const Quaternion& orientation);84 void rotate(const Quaternion& rotation, Ogre::Node::TransformSpace relativeTo = Ogre::Node::TS_LOCAL);85 void yaw(const Degree& angle, Ogre::Node::TransformSpace relativeTo = Ogre::Node::TS_LOCAL);86 void pitch(const Degree& angle, Ogre::Node::TransformSpace relativeTo = Ogre::Node::TS_LOCAL);87 void roll(const Degree& angle, Ogre::Node::TransformSpace relativeTo = Ogre::Node::TS_LOCAL);88 void lookAt(const Vector3& target, Ogre::Node::TransformSpace relativeTo = Ogre::Node::TS_LOCAL, const Vector3& localDirectionVector = Vector3::NEGATIVE_UNIT_Z);89 void setDirection(const Vector3& direction, Ogre::Node::TransformSpace relativeTo = Ogre::Node::TS_LOCAL, const Vector3& localDirectionVector = Vector3::NEGATIVE_UNIT_Z);90 91 81 void setVelocity(const Vector3& velocity); 92 82 inline void setVelocity(float x, float y, float z) 93 { this->velocity_.x = x; this->velocity_.y = y; this->velocity_.z = z; }83 { setVelocity(Vector3(x,y,z)); } 94 84 95 85 inline void setAcceleration(const Vector3& acceleration) … … 137 127 void processClientOrientation(); 138 128 129 inline void internalSetVelocity(const Vector3& velocity) 130 { this->velocity_ = velocity; } 131 void positionChanged(); 132 void orientationChanged(); 133 void velocityChanged(); 134 139 135 void networkcallback_changedplayerID(); 140 136 -
code/branches/physics/src/orxonox/objects/worldentities/LinearEntity.cc
r2192 r2292 74 74 if (this->isActive()) 75 75 { 76 this->velocity_ += (dt * this->acceleration_); 77 this->node_->translate(dt * this->velocity_); 76 if (!this->isDynamic()) 77 { 78 // we have to do 'physics' ourselves. 79 this->velocity_ += (dt * this->acceleration_); 80 this->node_->translate(dt * this->velocity_); 78 81 79 this->rotationRate_ += (dt * this->momentum_); 80 this->node_->rotate(this->rotationAxis_, this->rotationRate_ * dt); 82 this->rotationRate_ += (dt * this->momentum_); 83 this->node_->rotate(this->rotationAxis_, this->rotationRate_ * dt); 84 } 81 85 } 82 86 } … … 123 127 } 124 128 125 void LinearEntity:: setPosition(const Vector3& position)129 void LinearEntity::positionChanged() 126 130 { 127 this->node_->setPosition(position); 128 this->overwrite_position_ = this->node_->getPosition(); 131 this->overwrite_position_ = this->node_->getPosition(); 129 132 } 130 133 131 void LinearEntity:: translate(const Vector3& distance, Ogre::Node::TransformSpace relativeTo)134 void LinearEntity::orientationChanged() 132 135 { 133 this->node_->translate(distance, relativeTo); 134 this->overwrite_position_ = this->node_->getPosition(); 136 this->overwrite_orientation_ = this->node_->getOrientation(); 135 137 } 136 138 137 void LinearEntity::set Orientation(const Quaternion& orientation)139 void LinearEntity::setVelocity(const Vector3& velocity) 138 140 { 139 this->node_->setOrientation(orientation); 140 this->overwrite_orientation_ = this->node_->getOrientation(); 141 } 142 143 void LinearEntity::rotate(const Quaternion& rotation, Ogre::Node::TransformSpace relativeTo) 144 { 145 this->node_->rotate(rotation, relativeTo); 146 this->overwrite_orientation_ = this->node_->getOrientation(); 147 } 148 149 void LinearEntity::yaw(const Degree& angle, Ogre::Node::TransformSpace relativeTo) 150 { 151 this->node_->yaw(angle, relativeTo); 152 this->overwrite_orientation_ = this->node_->getOrientation(); 153 } 154 155 void LinearEntity::pitch(const Degree& angle, Ogre::Node::TransformSpace relativeTo) 156 { 157 this->node_->pitch(angle, relativeTo); 158 this->overwrite_orientation_ = this->node_->getOrientation(); 159 } 160 161 void LinearEntity::roll(const Degree& angle, Ogre::Node::TransformSpace relativeTo) 162 { 163 this->node_->roll(angle, relativeTo); 164 this->overwrite_orientation_ = this->node_->getOrientation(); 165 } 166 167 void LinearEntity::lookAt(const Vector3& target, Ogre::Node::TransformSpace relativeTo, const Vector3& localDirectionVector) 168 { 169 this->node_->lookAt(target, relativeTo, localDirectionVector); 170 this->overwrite_orientation_ = this->node_->getOrientation(); 171 } 172 173 void LinearEntity::setDirection(const Vector3& direction, Ogre::Node::TransformSpace relativeTo, const Vector3& localDirectionVector) 174 { 175 this->node_->setDirection(direction, relativeTo, localDirectionVector); 176 this->overwrite_orientation_ = this->node_->getOrientation(); 141 if (!this->isDynamic()) 142 { 143 // no physics, we do it ourselves 144 internalSetVelocity(velocity); 145 } 146 else 147 { 148 this->physicalBody_->setLinearVelocity(btVector3(velocity.x, velocity.y, velocity.z)); 149 } 177 150 } 178 151 } -
code/branches/physics/src/orxonox/objects/worldentities/LinearEntity.h
r2192 r2292 38 38 namespace orxonox 39 39 { 40 class _OrxonoxExport LinearEntity : public MovableEntity, public network::ClientConnectionListener 40 class _OrxonoxExport LinearEntity : public MovableEntity, public network::ClientConnectionListener, public Tickable 41 41 { 42 42 public: … … 48 48 void registerVariables(); 49 49 50 using WorldEntity::setPosition; 51 using WorldEntity::translate; 52 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 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; } 50 inline void setVelocity(const Vector3& velocity); 72 51 inline void setVelocity(float x, float y, float z) 73 52 { this->velocity_.x = x; this->velocity_.y = y; this->velocity_.z = z; } … … 111 90 void overwriteOrientation(); 112 91 92 void positionChanged(); 93 void orientationChanged(); 94 inline void internalSetVelocity(const Vector3& velocity) 95 { this->velocity_ = velocity; } 96 113 97 Vector3 velocity_; 114 98 Vector3 acceleration_; -
code/branches/physics/src/orxonox/objects/worldentities/MovableEntity.cc
r2201 r2292 30 30 #include "MovableEntity.h" 31 31 32 #include "objects/Scene.h" 33 32 #include "util/Exception.h" 34 33 #include "core/CoreIncludes.h" 35 34 #include "core/XMLPort.h" 35 36 #include "objects/Scene.h" 36 37 37 38 namespace orxonox … … 57 58 } 58 59 59 void MovableEntity::setPosition(const Vector3& position){ 60 // Here the code 61 if(isDynamic() && bAddedToPhysicalWorld_){ 62 this->getScene()->getPhysicalWorld()->removeRigidBody(this->physicalBody_); 63 this->getScene()->getPhysicalWorld()->addRigidBody(this->physicalBody_); 64 } 65 this->node_->setPosition(position); 60 //void MovableEntity::setPosition(const Vector3& position) 61 //{ 62 // //if (isDynamic() && bAddedToPhysicalWorld_) 63 // //{ 64 // // this->getScene()->getPhysicalWorld()->removeRigidBody(this->physicalBody_); 65 // // this->getScene()->getPhysicalWorld()->addRigidBody(this->physicalBody_); 66 // //} 67 // this->node_->setPosition(position); 68 // positionChanged(); 69 //} 70 71 //void MovableEntity::translate(const Vector3& distance, Ogre::Node::TransformSpace relativeTo) 72 //{ 73 // //if (isDynamic() && bAddedToPhysicalWorld_) 74 // //{ 75 // // this->getScene()->getPhysicalWorld()->removeRigidBody(this->physicalBody_); 76 // // this->getScene()->getPhysicalWorld()->addRigidBody(this->physicalBody_); 77 // //} 78 // this->node_->translate(distance, relativeTo); 79 // positionChanged(); 80 //} 81 82 //void MovableEntity::setOrientation(const Quaternion& orientation) 83 //{ 84 // //if (isDynamic() && bAddedToPhysicalWorld_) 85 // //{ 86 // // this->getScene()->getPhysicalWorld()->removeRigidBody(this->physicalBody_); 87 // // this->getScene()->getPhysicalWorld()->addRigidBody(this->physicalBody_); 88 // //} 89 // this->node_->setOrientation(orientation); 90 // orientationChanged(); 91 //} 92 93 //void MovableEntity::rotate(const Quaternion& rotation, Ogre::Node::TransformSpace relativeTo) 94 //{ 95 // //if (isDynamic() && bAddedToPhysicalWorld_) 96 // //{ 97 // // this->getScene()->getPhysicalWorld()->removeRigidBody(this->physicalBody_); 98 // // this->getScene()->getPhysicalWorld()->addRigidBody(this->physicalBody_); 99 // //} 100 // this->node_->rotate(rotation, relativeTo); 101 // orientationChanged(); 102 //} 103 104 //void MovableEntity::yaw(const Degree& angle, Ogre::Node::TransformSpace relativeTo) 105 //{ 106 // //if (isDynamic() && bAddedToPhysicalWorld_) 107 // //{ 108 // // this->getScene()->getPhysicalWorld()->removeRigidBody(this->physicalBody_); 109 // // this->getScene()->getPhysicalWorld()->addRigidBody(this->physicalBody_); 110 // //} 111 // this->node_->yaw(angle, relativeTo); 112 // orientationChanged(); 113 //} 114 115 //void MovableEntity::pitch(const Degree& angle, Ogre::Node::TransformSpace relativeTo) 116 //{ 117 // //if (isDynamic() && bAddedToPhysicalWorld_) 118 // //{ 119 // // this->getScene()->getPhysicalWorld()->removeRigidBody(this->physicalBody_); 120 // // this->getScene()->getPhysicalWorld()->addRigidBody(this->physicalBody_); 121 // //} 122 // this->node_->pitch(angle, relativeTo); 123 // orientationChanged(); 124 //} 125 126 //void MovableEntity::roll(const Degree& angle, Ogre::Node::TransformSpace relativeTo) 127 //{ 128 // //if (isDynamic() && bAddedToPhysicalWorld_) 129 // //{ 130 // // this->getScene()->getPhysicalWorld()->removeRigidBody(this->physicalBody_); 131 // // this->getScene()->getPhysicalWorld()->addRigidBody(this->physicalBody_); 132 // //} 133 // this->node_->roll(angle, relativeTo); 134 // orientationChanged(); 135 //} 136 137 //void MovableEntity::lookAt(const Vector3& target, Ogre::Node::TransformSpace relativeTo, const Vector3& localDirectionVector) 138 //{ 139 // //if (isDynamic() && bAddedToPhysicalWorld_) 140 // //{ 141 // // this->getScene()->getPhysicalWorld()->removeRigidBody(this->physicalBody_); 142 // // this->getScene()->getPhysicalWorld()->addRigidBody(this->physicalBody_); 143 // //} 144 // this->node_->lookAt(target, relativeTo, localDirectionVector); 145 // orientationChanged(); 146 //} 147 148 //void MovableEntity::setDirection(const Vector3& direction, Ogre::Node::TransformSpace relativeTo, const Vector3& localDirectionVector) 149 //{ 150 // //if (isDynamic() && bAddedToPhysicalWorld_) 151 // //{ 152 // // this->getScene()->getPhysicalWorld()->removeRigidBody(this->physicalBody_); 153 // // this->getScene()->getPhysicalWorld()->addRigidBody(this->physicalBody_); 154 // //} 155 // this->node_->setDirection(direction, relativeTo, localDirectionVector); 156 // orientationChanged(); 157 //} 158 159 void MovableEntity::setPosition(const Vector3& position) 160 { 161 if (this->isDynamic()) 162 { 163 btTransform transf = this->physicalBody_->getWorldTransform(); 164 transf.setOrigin(btVector3(position.x, position.y, position.z)); 165 this->physicalBody_->setWorldTransform(transf); 166 } 167 else 168 { 169 // no physics, we do it ourselves 170 this->node_->setPosition(position); 171 } 172 } 173 174 void MovableEntity::translate(const Vector3& distance, Ogre::Node::TransformSpace relativeTo) 175 { 176 if (this->isDynamic()) 177 { 178 OrxAssert(relativeTo == Ogre::Node::TS_LOCAL, "Cannot translate physical object relative \ 179 to any other space than TS_LOCAL."); 180 this->physicalBody_->translate(btVector3(distance.x, distance.y, distance.z)); 181 } 182 else 183 { 184 // no physics, we do it ourselves 185 this->node_->translate(distance, relativeTo); 186 } 187 } 188 189 void MovableEntity::setOrientation(const Quaternion& orientation) 190 { 191 if (this->isDynamic()) 192 { 193 btTransform transf = this->physicalBody_->getWorldTransform(); 194 transf.setRotation(btQuaternion(orientation.w, orientation.x, orientation.y, orientation.z)); 195 this->physicalBody_->setWorldTransform(transf); 196 } 197 else 198 { 199 // no physics, we do it ourselves 200 this->node_->setOrientation(orientation); 201 } 202 } 203 204 void MovableEntity::rotate(const Quaternion& rotation, Ogre::Node::TransformSpace relativeTo) 205 { 206 if (this->isDynamic()) 207 { 208 OrxAssert(relativeTo == Ogre::Node::TS_LOCAL, "Cannot rotate physical object relative \ 209 to any other space than TS_LOCAL."); 210 btTransform transf = this->physicalBody_->getWorldTransform(); 211 this->physicalBody_->setWorldTransform(transf * btTransform(btQuaternion(rotation.w, rotation.x, rotation.y, rotation.z))); 212 } 213 else 214 { 215 // no physics, we do it ourselves 216 this->node_->rotate(rotation, relativeTo); 217 } 218 } 219 220 void MovableEntity::yaw(const Degree& angle, Ogre::Node::TransformSpace relativeTo) 221 { 222 if (this->isDynamic()) 223 { 224 OrxAssert(relativeTo == Ogre::Node::TS_LOCAL, "Cannot yaw physical object relative \ 225 to any other space than TS_LOCAL."); 226 btTransform transf = this->physicalBody_->getWorldTransform(); 227 btTransform rotation(btQuaternion(angle.valueRadians(), 0.0f, 0.0f)); 228 this->physicalBody_->setWorldTransform(transf * rotation); 229 } 230 else 231 { 232 // no physics, we do it ourselves 233 this->node_->yaw(angle, relativeTo); 234 } 235 } 236 237 void MovableEntity::pitch(const Degree& angle, Ogre::Node::TransformSpace relativeTo) 238 { 239 if (this->isDynamic()) 240 { 241 OrxAssert(relativeTo == Ogre::Node::TS_LOCAL, "Cannot pitch physical object relative \ 242 to any other space than TS_LOCAL."); 243 btTransform transf = this->physicalBody_->getWorldTransform(); 244 btTransform rotation(btQuaternion(0.0f, angle.valueRadians(), 0.0f)); 245 this->physicalBody_->setWorldTransform(transf * rotation); 246 } 247 else 248 { 249 // no physics, we do it ourselves 250 this->node_->pitch(angle, relativeTo); 251 } 252 } 253 254 void MovableEntity::roll(const Degree& angle, Ogre::Node::TransformSpace relativeTo) 255 { 256 if (this->isDynamic()) 257 { 258 OrxAssert(relativeTo == Ogre::Node::TS_LOCAL, "Cannot roll physical object relative \ 259 to any other space than TS_LOCAL."); 260 btTransform transf = this->physicalBody_->getWorldTransform(); 261 btTransform rotation(btQuaternion(angle.valueRadians(), 0.0f, 0.0f)); 262 this->physicalBody_->setWorldTransform(transf * rotation); 263 } 264 else 265 { 266 // no physics, we do it ourselves 267 this->node_->roll(angle, relativeTo); 268 } 269 } 270 271 void MovableEntity::lookAt(const Vector3& target, Ogre::Node::TransformSpace relativeTo, const Vector3& localDirectionVector) 272 { 273 if (this->isDynamic()) 274 { 275 ThrowException(NotImplemented, "ControllableEntity::lookAt() is not yet supported for physical objects."); 276 OrxAssert(relativeTo == Ogre::Node::TS_LOCAL, "Cannot align physical object relative \ 277 to any other space than TS_LOCAL."); 278 //btTransform transf = this->physicalBody_->getWorldTransform(); 279 //this->physicalBody_->setWorldTransform(transf); 280 } 281 else 282 { 283 // no physics, we do it ourselves 284 this->node_->lookAt(target, relativeTo, localDirectionVector); 285 } 286 } 287 288 void MovableEntity::setDirection(const Vector3& direction, Ogre::Node::TransformSpace relativeTo, const Vector3& localDirectionVector) 289 { 290 if (this->isDynamic()) 291 { 292 ThrowException(NotImplemented, "ControllableEntity::lookAt() is not yet supported for physical objects."); 293 OrxAssert(relativeTo == Ogre::Node::TS_LOCAL, "Cannot align physical object relative \ 294 to any other space than TS_LOCAL."); 295 //btTransform transf = this->physicalBody_->getWorldTransform(); 296 //this->physicalBody_->setWorldTransform(transf); 297 } 298 else 299 { 300 // no physics, we do it ourselves 301 this->node_->setDirection(direction, relativeTo, localDirectionVector); 302 } 303 } 304 305 void MovableEntity::setWorldTransform(const btTransform& worldTrans) 306 { 307 // We use a dynamic body. So we translate our node accordingly. 308 this->node_->setPosition(Vector3(worldTrans.getOrigin().x(), worldTrans.getOrigin().y(), worldTrans.getOrigin().z())); 309 this->node_->setOrientation(Quaternion(worldTrans.getRotation().w(), worldTrans.getRotation().x(), worldTrans.getRotation().y(), worldTrans.getRotation().z())); 310 const btVector3& velocity = this->physicalBody_->getLinearVelocity(); 311 internalSetVelocity(Vector3(velocity.x(), velocity.y(), velocity.z())); 66 312 positionChanged(); 67 }68 69 void MovableEntity::translate(const Vector3& distance, Ogre::Node::TransformSpace relativeTo){70 if(isDynamic() && bAddedToPhysicalWorld_){71 this->getScene()->getPhysicalWorld()->removeRigidBody(this->physicalBody_);72 this->getScene()->getPhysicalWorld()->addRigidBody(this->physicalBody_);73 }74 this->node_->translate(distance, relativeTo);75 translateChanged();76 }77 78 void MovableEntity::setOrientation(const Quaternion& orientation){79 if(isDynamic() && bAddedToPhysicalWorld_){80 this->getScene()->getPhysicalWorld()->removeRigidBody(this->physicalBody_);81 this->getScene()->getPhysicalWorld()->addRigidBody(this->physicalBody_);82 }83 this->node_->setOrientation(orientation);84 313 orientationChanged(); 85 314 } 86 315 87 void MovableEntity::rotate(const Quaternion& rotation, Ogre::Node::TransformSpace relativeTo){ 88 if(isDynamic() && bAddedToPhysicalWorld_){ 89 this->getScene()->getPhysicalWorld()->removeRigidBody(this->physicalBody_); 90 this->getScene()->getPhysicalWorld()->addRigidBody(this->physicalBody_); 91 } 92 this->node_->rotate(rotation, relativeTo); 93 rotateChanged(); 94 } 95 96 void MovableEntity::yaw(const Degree& angle, Ogre::Node::TransformSpace relativeTo){ 97 if(isDynamic() && bAddedToPhysicalWorld_){ 98 this->getScene()->getPhysicalWorld()->removeRigidBody(this->physicalBody_); 99 this->getScene()->getPhysicalWorld()->addRigidBody(this->physicalBody_); 100 } 101 this->node_->yaw(angle, relativeTo); 102 yawChanged(); 103 } 104 105 void MovableEntity::pitch(const Degree& angle, Ogre::Node::TransformSpace relativeTo){ 106 if(isDynamic() && bAddedToPhysicalWorld_){ 107 this->getScene()->getPhysicalWorld()->removeRigidBody(this->physicalBody_); 108 this->getScene()->getPhysicalWorld()->addRigidBody(this->physicalBody_); 109 } 110 this->node_->pitch(angle, relativeTo); 111 pitchChanged(); 112 } 113 114 void MovableEntity::roll(const Degree& angle, Ogre::Node::TransformSpace relativeTo){ 115 if(isDynamic() && bAddedToPhysicalWorld_){ 116 this->getScene()->getPhysicalWorld()->removeRigidBody(this->physicalBody_); 117 this->getScene()->getPhysicalWorld()->addRigidBody(this->physicalBody_); 118 } 119 this->node_->roll(angle, relativeTo); 120 rollChanged(); 121 } 122 123 void MovableEntity::lookAt(const Vector3& target, Ogre::Node::TransformSpace relativeTo, const Vector3& localDirectionVector){ 124 if(isDynamic() && bAddedToPhysicalWorld_){ 125 this->getScene()->getPhysicalWorld()->removeRigidBody(this->physicalBody_); 126 this->getScene()->getPhysicalWorld()->addRigidBody(this->physicalBody_); 127 } 128 this->node_->lookAt(target, relativeTo, localDirectionVector); 129 lookAtChanged(); 130 } 131 132 void MovableEntity::setDirection(const Vector3& direction, Ogre::Node::TransformSpace relativeTo, const Vector3& localDirectionVector){ 133 if(isDynamic() && bAddedToPhysicalWorld_){ 134 this->getScene()->getPhysicalWorld()->removeRigidBody(this->physicalBody_); 135 this->getScene()->getPhysicalWorld()->addRigidBody(this->physicalBody_); 136 } 137 this->node_->setDirection(direction, relativeTo, localDirectionVector); 138 directionChanged(); 139 } 140 316 void MovableEntity::getWorldTransform(btTransform& worldTrans) const 317 { 318 // We use a kinematic body 319 worldTrans.setOrigin(btVector3(node_->getPosition().x, node_->getPosition().y, node_->getPosition().z)); 320 worldTrans.setRotation(btQuaternion(node_->getOrientation().w, node_->getOrientation().x, node_->getOrientation().y, node_->getOrientation().z)); 321 } 141 322 } -
code/branches/physics/src/orxonox/objects/worldentities/MovableEntity.h
r2201 r2292 69 69 70 70 private: 71 72 virtual void rollChanged() { }73 virtual void positionChanged() { }74 virtual void translateChanged() { }75 virtual void orientationChanged() { }76 virtual void rotateChanged() { }77 virtual void yawChanged() { }78 virtual void pitchChanged() { }79 virtual void lookAtChanged() { }80 virtual void directionChanged( ) { }81 82 71 //void attachPhysicalObject(WorldEntity* object); 83 72 84 //// Bullet btMotionState related 85 //void setWorldTransform(const btTransform& worldTrans) 86 //{ 87 // this->node_->setPosition(worldTrans.getOrigin().x(), worldTrans.getOrigin().y(), worldTrans.getOrigin().z()); 88 // this->node_->setOrientation(worldTrans.getRotation().w(), worldTrans.getRotation().x(), worldTrans.getRotation().y(), worldTrans.getRotation().z()); 89 // //this->velocity_.x = this->physicalBody_-> 90 //} 73 virtual void internalSetVelocity(const Vector3& velocity) { } 74 virtual void positionChanged() { } 75 virtual void orientationChanged() { } 91 76 92 //// Bullet btMotionState related 93 //void getWorldTransform(btTransform& worldTrans) const 94 //{ 95 // worldTrans.setOrigin(btVector3(node_->getPosition().x, node_->getPosition().y, node_->getPosition().z)); 96 // worldTrans.setRotation(btQuaternion(node_->getOrientation().w, node_->getOrientation().x, node_->getOrientation().y, node_->getOrientation().z)); 97 //} 77 // Bullet btMotionState related 78 void setWorldTransform(const btTransform& worldTrans); 79 void getWorldTransform(btTransform& worldTrans) const; 98 80 }; 99 81 } -
code/branches/physics/src/orxonox/objects/worldentities/PositionableEntity.h
r2192 r2292 43 43 void registerVariables(); 44 44 45 using WorldEntity::setPosition;46 using WorldEntity::translate;47 using WorldEntity::setOrientation;48 using WorldEntity::rotate;49 using WorldEntity::yaw;50 using WorldEntity::pitch;51 using WorldEntity::roll;52 using WorldEntity::lookAt;53 using WorldEntity::setDirection;54 55 inline void setPosition(const Vector3& position)56 { this->node_->setPosition(position); }57 inline void translate(const Vector3& distance, Ogre::Node::TransformSpace relativeTo = Ogre::Node::TS_LOCAL)58 { this->node_->translate(distance, relativeTo); }59 inline void setOrientation(const Quaternion& orientation)60 { this->node_->setOrientation(orientation); }61 inline void rotate(const Quaternion& rotation, Ogre::Node::TransformSpace relativeTo = Ogre::Node::TS_LOCAL)62 { this->node_->rotate(rotation, relativeTo); }63 inline void yaw(const Degree& angle, Ogre::Node::TransformSpace relativeTo = Ogre::Node::TS_LOCAL)64 { this->node_->yaw(angle, relativeTo); }65 inline void pitch(const Degree& angle, Ogre::Node::TransformSpace relativeTo = Ogre::Node::TS_LOCAL)66 { this->node_->pitch(angle, relativeTo); }67 inline void roll(const Degree& angle, Ogre::Node::TransformSpace relativeTo = Ogre::Node::TS_LOCAL)68 { this->node_->roll(angle, relativeTo); }69 inline void lookAt(const Vector3& target, Ogre::Node::TransformSpace relativeTo = Ogre::Node::TS_LOCAL, const Vector3& localDirectionVector = Vector3::NEGATIVE_UNIT_Z)70 { this->node_->lookAt(target, relativeTo, localDirectionVector); }71 inline void setDirection(const Vector3& direction, Ogre::Node::TransformSpace relativeTo = Ogre::Node::TS_LOCAL, const Vector3& localDirectionVector = Vector3::NEGATIVE_UNIT_Z)72 { this->node_->setDirection(direction, relativeTo, localDirectionVector); }73 74 45 private: 75 46 //void attachPhysicalObject(WorldEntity* object); -
code/branches/physics/src/orxonox/objects/worldentities/StaticEntity.cc
r2192 r2292 29 29 #include "OrxonoxStableHeaders.h" 30 30 #include "StaticEntity.h" 31 32 #include "util/Exception.h" 31 33 #include "core/CoreIncludes.h" 32 34 … … 57 59 REGISTERDATA(this->getOrientation().z, network::direction::toclient); 58 60 } 61 62 void StaticEntity::setCollisionType(CollisionType type) 63 { 64 if (!this->physicalBody_) 65 return; 66 if (type != Static) 67 ThrowException(Argument, "Cannot tell a StaticEntity to be kinematic or dynamic"); 68 69 this->physicalBody_->setCollisionFlags(this->physicalBody_->getCollisionFlags() & !btCollisionObject::CF_KINEMATIC_OBJECT | btCollisionObject::CF_STATIC_OBJECT); 70 } 71 72 void StaticEntity::setWorldTransform(const btTransform& worldTrans) 73 { 74 OrxAssert(false, "Setting world transform of a StaticEntity, which is static!"); 75 //COUT(0) << "Setting world transform of a StaticEntity, which is static!" << std::endl; 76 } 77 78 void StaticEntity::getWorldTransform(btTransform& worldTrans) const 79 { 80 worldTrans.setOrigin(btVector3(node_->getPosition().x, node_->getPosition().y, node_->getPosition().z)); 81 worldTrans.setRotation(btQuaternion(node_->getOrientation().w, node_->getOrientation().x, node_->getOrientation().y, node_->getOrientation().z)); 82 } 59 83 } -
code/branches/physics/src/orxonox/objects/worldentities/StaticEntity.h
r2192 r2292 71 71 inline void setDirection(const Vector3& direction, Ogre::Node::TransformSpace relativeTo = Ogre::Node::TS_LOCAL, const Vector3& localDirectionVector = Vector3::NEGATIVE_UNIT_Z) 72 72 { this->node_->setDirection(direction, relativeTo, localDirectionVector); } 73 74 private: 75 76 void setCollisionType(CollisionType type); 77 78 // Bullet btMotionState related 79 void setWorldTransform(const btTransform& worldTrans); 80 void getWorldTransform(btTransform& worldTrans) const; 73 81 }; 74 82 } -
code/branches/physics/src/orxonox/objects/worldentities/WorldEntity.cc
r2201 r2292 32 32 #include <cassert> 33 33 #include <OgreSceneManager.h> 34 34 35 #include "BulletCollision/CollisionShapes/btSphereShape.h" 35 36 37 #include "util/Exception.h" 38 #include "util/Convert.h" 36 39 #include "core/CoreIncludes.h" 37 40 #include "core/XMLPort.h" 38 #include "util/Convert.h"39 41 40 42 #include "objects/Scene.h" 43 44 #include "StaticEntity.h" 41 45 42 46 namespace orxonox … … 65 69 66 70 // Default behaviour does not include physics 67 this->bAddedToPhysicalWorld_ = false;68 71 this->physicalBody_ = 0; 69 72 … … 82 85 if (this->physicalBody_) 83 86 { 84 if (this-> bAddedToPhysicalWorld_)87 if (this->physicalBody_->isInWorld()) 85 88 this->getScene()->getPhysicalWorld()->removeRigidBody(this->physicalBody_); 86 89 if (this->physicalBody_->getCollisionShape()) … … 104 107 XMLPortParamTemplate(WorldEntity, "scale3D", setScale3D, getScale3D, xmlelement, mode, const Vector3&); 105 108 XMLPortParam(WorldEntity, "scale", setScale, getScale, xmlelement, mode); 106 XMLPortParam(WorldEntity, "collisionRadius", setcollisionRadius, getcollisionRadius, xmlelement, mode); 109 110 XMLPortParam(WorldEntity, "collisionRadius", setCollisionRadius, getCollisionRadius, xmlelement, mode); 111 XMLPortParam(WorldEntity, "collisionType", setCollisionTypeStr, getCollisionTypeStr, xmlelement, mode); 112 XMLPortParam(WorldEntity, "mass", setMass, getMass, xmlelement, mode); 113 114 if (this->physicalBody_) 115 this->getScene()->getPhysicalWorld()->addRigidBody(this->physicalBody_); 107 116 108 117 XMLPortObject(WorldEntity, WorldEntity, "attached", attach, getAttachedObject, xmlelement, mode); … … 145 154 146 155 // Do the physical connection if required 147 this->attachPhysicalObject(object); 148 } 149 150 void WorldEntitiy::attachPhysicalObject(WorldEntity* object){ 151 //function attachhysicalObject 152 StaticEntity* staticObject = dynamic_cast<WorldEntity*>(object); 153 if (staticObject != 0 && hasPhysics()){ 154 btCompountShape* compoundShape = dynamic_cast<btCompoundShape*>(physicalBody_->getCollisionShape()); 155 if(compoundShape == 0){ 156 //NEW 157 btCompoundShape* newShape = new btCompoundShape(); 158 newShape->addChildShape(this->physcialBody_->getCollisionShape()); 159 newShape->addChildShape(staticObject->getCollisionShape()); 160 this->physicalBody_->setCollisionShape(); 161 } 162 else{ 163 compoundShape -> addChildShape(staticObject->getCollisionShape()); 164 } 165 } 166 } 156 //this->attachPhysicalObject(object); 157 } 158 159 //void WorldEntity::attachPhysicalObject(WorldEntity* object) 160 //{ 161 // StaticEntity* staticObject = dynamic_cast<StaticEntity*>(object); 162 // if (staticObject != 0 && this->hasPhysics()) 163 // { 164 // btCompoundShape* compoundShape = dynamic_cast<btCompoundShape*>(this->physicalBody_->getCollisionShape()); 165 // if (compoundShape == 0) 166 // { 167 // // create a compound shape and add both 168 // compoundShape = new btCompoundShape(); 169 // compoundShape->addChildShape(this->physicalBody_->getCollisionShape()); 170 // compoundShape->addChildShape(staticObject->getCollisionShape()); 171 // this->physicalBody_->setCollisionShape(); 172 // } 173 // else 174 // { 175 // compoundShape -> addChildShape(staticObject->getCollisionShape()); 176 // } 177 // } 178 //} 167 179 168 180 void WorldEntity::detach(WorldEntity* object) … … 193 205 btRigidBody::btRigidBodyConstructionInfo bodyConstructionInfo(0, this, 0, btVector3(0,0,0)); 194 206 this->physicalBody_ = new btRigidBody(bodyConstructionInfo); 195 this->getScene()->getPhysicalWorld()->addRigidBody(this->physicalBody_); 196 this->bAddedToPhysicalWorld_ = true; 197 } 198 199 void WorldEntity::setcollisionRadius(float radius) 207 } 208 209 float WorldEntity::getMass() 210 { 211 if (!this->physicalBody_) 212 return 0.0f; 213 214 return 1.0f/this->physicalBody_->getInvMass(); 215 } 216 217 void WorldEntity::setMass(float mass) 218 { 219 if (!this->physicalBody_) 220 this->createPhysicalBody(); 221 222 this->physicalBody_->setMassProps(mass, btVector3(0,0,0)); 223 } 224 225 void WorldEntity::setCollisionType(WorldEntity::CollisionType type) 226 { 227 if (!this->physicalBody_) 228 this->createPhysicalBody(); 229 230 switch (type) 231 { 232 case Dynamic: 233 this->physicalBody_->setCollisionFlags(this->physicalBody_->getCollisionFlags() & !(btCollisionObject::CF_STATIC_OBJECT | btCollisionObject::CF_KINEMATIC_OBJECT)); 234 break; 235 case Kinematic: 236 this->physicalBody_->setCollisionFlags(this->physicalBody_->getCollisionFlags() & !btCollisionObject::CF_STATIC_OBJECT | btCollisionObject::CF_KINEMATIC_OBJECT); 237 break; 238 case Static: 239 this->physicalBody_->setCollisionFlags(this->physicalBody_->getCollisionFlags() & !btCollisionObject::CF_KINEMATIC_OBJECT | btCollisionObject::CF_STATIC_OBJECT); 240 break; 241 } 242 } 243 244 WorldEntity::CollisionType WorldEntity::getCollisionType() 245 { 246 if (!this->physicalBody_) 247 ThrowException(Argument, "Cannot retrieve collision type of a non physical object."); 248 249 int flags = this->physicalBody_->getCollisionFlags(); 250 if (flags & btCollisionObject::CF_STATIC_OBJECT) 251 return Static; 252 else if (flags & btCollisionObject::CF_KINEMATIC_OBJECT) 253 return Kinematic; 254 else 255 return Dynamic; 256 } 257 258 void WorldEntity::setCollisionTypeStr(const std::string& type) 259 { 260 std::string lower = getLowercase(type); 261 if (lower == "dynamic") 262 setCollisionType(Dynamic); 263 else if (lower == "static") 264 setCollisionType(Static); 265 else if (lower == "kinematic") 266 setCollisionType(Kinematic); 267 else 268 ThrowException(Argument, std::string("Trying to set an unknown collision type: '") + type + "'."); 269 } 270 271 std::string WorldEntity::getCollisionTypeStr() 272 { 273 switch (this->getCollisionType()) 274 { 275 case Dynamic: 276 return "dynamic"; 277 case Kinematic: 278 return "kinematic"; 279 case Static: 280 return "static"; 281 default: 282 ThrowException(Argument, "Encountered unknown collision Type."); 283 } 284 } 285 286 void WorldEntity::setCollisionRadius(float radius) 200 287 { 201 288 if (!this->physicalBody_) 202 289 createPhysicalBody(); 203 290 204 // destroy old on wfirst291 // destroy old one first 205 292 btCollisionShape* oldShape = this->physicalBody_->getCollisionShape(); 206 293 if (oldShape) … … 210 297 } 211 298 212 float WorldEntity::get collisionRadius()299 float WorldEntity::getCollisionRadius() 213 300 { 214 301 if (this->physicalBody_) -
code/branches/physics/src/orxonox/objects/worldentities/WorldEntity.h
r2192 r2292 46 46 class _OrxonoxExport WorldEntity : public BaseObject, public network::Synchronisable, public btMotionState 47 47 { 48 public: 49 enum CollisionType 50 { 51 Dynamic, 52 Kinematic, 53 Static 54 }; 55 48 56 public: 49 57 WorldEntity(BaseObject* creator); … … 127 135 { this->node_->scale(scale, scale, scale); } 128 136 129 void setcollisionRadius(float radius);130 float getcollisionRadius();131 132 137 bool hasPhysics() { return this->physicalBody_; } 133 138 bool isKinematic() { return this->physicalBody_ && this->physicalBody_->isKinematicObject(); } … … 147 152 { return this->parent_; } 148 153 154 void setCollisionRadius(float radius); 155 float getCollisionRadius(); 156 157 void setCollisionTypeStr(const std::string& type); 158 std::string getCollisionTypeStr(); 159 160 void setMass(float mass); 161 float getMass(); 162 163 CollisionType getCollisionType(); 164 149 165 protected: 150 166 //virtual btCollisionShape* getCollisionShape() = 0; 151 167 152 168 void createPhysicalBody(); 153 virtual void attachPhysicalObject(WorldEntity* object) { } 169 //virtual void attachPhysicalObject(WorldEntity* object); 170 virtual void setCollisionType(CollisionType type); 154 171 155 172 Ogre::SceneNode* node_; 156 bool bAddedToPhysicalWorld_;157 173 btRigidBody* physicalBody_; 158 174 … … 171 187 { this->roll(angle); } 172 188 173 // Bullet btMotionState related174 virtual void setWorldTransform(const btTransform& worldTrans)175 {176 }177 178 // Bullet btMotionState related179 virtual void getWorldTransform(btTransform& worldTrans) const180 {181 }182 183 189 WorldEntity* parent_; 184 190 unsigned int parentID_; -
code/branches/physics/src/orxonox/objects/worldentities/pawns/SpaceShip.cc
r2087 r2292 30 30 #include "SpaceShip.h" 31 31 32 #include "util/Math.h" 33 #include "util/Exception.h" 32 34 #include "core/CoreIncludes.h" 33 35 #include "core/ConfigValueIncludes.h" 34 36 #include "core/XMLPort.h" 35 #include "util/Math.h"36 37 37 38 namespace orxonox … … 59 60 60 61 this->setDestroyWhenPlayerLeft(true); 62 63 // create a phyisical body 64 OrxAssert(this->physicalBody_ == 0, " Check why there is already a physical body in the space ship."); 65 this->createPhysicalBody(); 61 66 62 67 this->setConfigValues(); … … 165 170 void SpaceShip::moveFrontBack(const Vector2& value) 166 171 { 167 this->acceleration_.z = -this->translationAcceleration_ * value.x; 172 assert(this->physicalBody_); 173 this->physicalBody_->applyCentralForce(btVector3(0.0f, 0.0f, -1.0f/this->physicalBody_->getInvMass() * value.x)); 174 // this->acceleration_.z = -this->translationAcceleration_ * value.x; 168 175 } 169 176 170 177 void SpaceShip::moveRightLeft(const Vector2& value) 171 178 { 172 this->acceleration_.x = this->translationAcceleration_ * value.x; 179 this->physicalBody_->applyCentralForce(btVector3(1.0f/this->physicalBody_->getInvMass() * value.x, 0.0f, 0.0f)); 180 // this->acceleration_.x = this->translationAcceleration_ * value.x; 173 181 } 174 182 175 183 void SpaceShip::moveUpDown(const Vector2& value) 176 184 { 177 this->acceleration_.y = this->translationAcceleration_ * value.x; 185 this->physicalBody_->applyCentralForce(btVector3(0.0f, 1.0f/this->physicalBody_->getInvMass() * value.x, 0.0f)); 186 // this->acceleration_.y = this->translationAcceleration_ * value.x; 178 187 } 179 188
Note: See TracChangeset
for help on using the changeset viewer.