Changeset 2408 for code/branches
- Timestamp:
- Dec 11, 2008, 2:18:34 PM (16 years ago)
- Location:
- code/branches/physics
- Files:
-
- 2 deleted
- 10 edited
- 2 copied
Legend:
- Unmodified
- Added
- Removed
-
code/branches/physics/src/orxonox/CMakeLists.txt
r2405 r2408 57 57 objects/worldentities/StaticEntity.cc 58 58 objects/worldentities/MovableEntity.cc 59 objects/worldentities/ LinearEntity.cc59 objects/worldentities/MobileEntity.cc 60 60 objects/worldentities/ControllableEntity.cc 61 61 objects/worldentities/Model.cc -
code/branches/physics/src/orxonox/OrxonoxPrereqs.h
r2374 r2408 104 104 class WorldEntity; 105 105 class StaticEntity; 106 class MobileEntity; 107 class ControllableEntity; 106 108 class MovableEntity; 107 class ControllableEntity;108 class LinearEntity;109 109 class Sublevel; 110 110 -
code/branches/physics/src/orxonox/objects/weaponSystem/projectiles/Projectile.cc
r2100 r2408 46 46 float Projectile::speed_s = 5000; 47 47 48 Projectile::Projectile(BaseObject* creator, Weapon* owner) : Mo vableEntity(creator), owner_(owner)48 Projectile::Projectile(BaseObject* creator, Weapon* owner) : MobileEntity(creator), owner_(owner) 49 49 { 50 50 RegisterObject(Projectile); -
code/branches/physics/src/orxonox/objects/weaponSystem/projectiles/Projectile.h
r2099 r2408 32 32 #include "OrxonoxPrereqs.h" 33 33 34 #include "objects/worldentities/Mo vableEntity.h"34 #include "objects/worldentities/MobileEntity.h" 35 35 #include "tools/Timer.h" 36 36 37 37 namespace orxonox 38 38 { 39 class _OrxonoxExport Projectile : public Mo vableEntity39 class _OrxonoxExport Projectile : public MobileEntity 40 40 { 41 41 public: -
code/branches/physics/src/orxonox/objects/worldentities/ControllableEntity.cc
r2407 r2408 44 44 CreateFactory(ControllableEntity); 45 45 46 ControllableEntity::ControllableEntity(BaseObject* creator) : Mo vableEntity(creator)46 ControllableEntity::ControllableEntity(BaseObject* creator) : MobileEntity(creator) 47 47 { 48 48 RegisterObject(ControllableEntity); … … 226 226 void ControllableEntity::tick(float dt) 227 227 { 228 Mo vableEntity::tick(dt);228 MobileEntity::tick(dt); 229 229 230 230 if (this->isActive()) -
code/branches/physics/src/orxonox/objects/worldentities/ControllableEntity.h
r2407 r2408 32 32 #include "OrxonoxPrereqs.h" 33 33 34 #include "Mo vableEntity.h"34 #include "MobileEntity.h" 35 35 36 36 namespace orxonox 37 37 { 38 class _OrxonoxExport ControllableEntity : public Mo vableEntity38 class _OrxonoxExport ControllableEntity : public MobileEntity 39 39 { 40 40 public: -
code/branches/physics/src/orxonox/objects/worldentities/MobileEntity.cc
r2407 r2408 28 28 29 29 #include "OrxonoxStableHeaders.h" 30 #include "Mo vableEntity.h"30 #include "MobileEntity.h" 31 31 32 32 #include "BulletDynamics/Dynamics/btRigidBody.h" … … 42 42 namespace orxonox 43 43 { 44 Mo vableEntity::MovableEntity(BaseObject* creator) : WorldEntity(creator)45 { 46 RegisterObject(Mo vableEntity);44 MobileEntity::MobileEntity(BaseObject* creator) : WorldEntity(creator) 45 { 46 RegisterObject(MobileEntity); 47 47 48 48 this->linearAcceleration_ = Vector3::ZERO; … … 54 54 } 55 55 56 Mo vableEntity::~MovableEntity()57 { 58 } 59 60 void Mo vableEntity::XMLPort(Element& xmlelement, XMLPort::Mode mode)61 { 62 SUPER(Mo vableEntity, XMLPort, xmlelement, mode);63 64 XMLPortParamTemplate(Mo vableEntity, "velocity", setVelocity, getVelocity, xmlelement, mode, const Vector3&);65 XMLPortParamTemplate(Mo vableEntity, "rotationaxis", setRotationAxis, getRotationAxis, xmlelement, mode, const Vector3&);66 XMLPortParam(Mo vableEntity, "rotationrate", setRotationRate, getRotationRate, xmlelement, mode);67 } 68 69 void Mo vableEntity::registerVariables()70 { 71 } 72 73 void Mo vableEntity::tick(float dt)56 MobileEntity::~MobileEntity() 57 { 58 } 59 60 void MobileEntity::XMLPort(Element& xmlelement, XMLPort::Mode mode) 61 { 62 SUPER(MobileEntity, XMLPort, xmlelement, mode); 63 64 XMLPortParamTemplate(MobileEntity, "velocity", setVelocity, getVelocity, xmlelement, mode, const Vector3&); 65 XMLPortParamTemplate(MobileEntity, "rotationaxis", setRotationAxis, getRotationAxis, xmlelement, mode, const Vector3&); 66 XMLPortParam(MobileEntity, "rotationrate", setRotationRate, getRotationRate, xmlelement, mode); 67 } 68 69 void MobileEntity::registerVariables() 70 { 71 } 72 73 void MobileEntity::tick(float dt) 74 74 { 75 75 if (this->isActive()) … … 104 104 } 105 105 106 void Mo vableEntity::setPosition(const Vector3& position)106 void MobileEntity::setPosition(const Vector3& position) 107 107 { 108 108 if (this->isDynamic()) … … 117 117 } 118 118 119 void Mo vableEntity::translate(const Vector3& distance, Ogre::Node::TransformSpace relativeTo)119 void MobileEntity::translate(const Vector3& distance, Ogre::Node::TransformSpace relativeTo) 120 120 { 121 121 if (this->isDynamic()) … … 130 130 } 131 131 132 void Mo vableEntity::setOrientation(const Quaternion& orientation)132 void MobileEntity::setOrientation(const Quaternion& orientation) 133 133 { 134 134 if (this->isDynamic()) … … 143 143 } 144 144 145 void Mo vableEntity::rotate(const Quaternion& rotation, Ogre::Node::TransformSpace relativeTo)145 void MobileEntity::rotate(const Quaternion& rotation, Ogre::Node::TransformSpace relativeTo) 146 146 { 147 147 if (this->isDynamic()) … … 157 157 } 158 158 159 void Mo vableEntity::yaw(const Degree& angle, Ogre::Node::TransformSpace relativeTo)159 void MobileEntity::yaw(const Degree& angle, Ogre::Node::TransformSpace relativeTo) 160 160 { 161 161 if (this->isDynamic()) … … 172 172 } 173 173 174 void Mo vableEntity::pitch(const Degree& angle, Ogre::Node::TransformSpace relativeTo)174 void MobileEntity::pitch(const Degree& angle, Ogre::Node::TransformSpace relativeTo) 175 175 { 176 176 if (this->isDynamic()) … … 187 187 } 188 188 189 void Mo vableEntity::roll(const Degree& angle, Ogre::Node::TransformSpace relativeTo)189 void MobileEntity::roll(const Degree& angle, Ogre::Node::TransformSpace relativeTo) 190 190 { 191 191 if (this->isDynamic()) … … 202 202 } 203 203 204 void Mo vableEntity::lookAt(const Vector3& target, Ogre::Node::TransformSpace relativeTo, const Vector3& localDirectionVector)204 void MobileEntity::lookAt(const Vector3& target, Ogre::Node::TransformSpace relativeTo, const Vector3& localDirectionVector) 205 205 { 206 206 if (this->isDynamic()) … … 215 215 } 216 216 217 void Mo vableEntity::setDirection(const Vector3& direction, Ogre::Node::TransformSpace relativeTo, const Vector3& localDirectionVector)217 void MobileEntity::setDirection(const Vector3& direction, Ogre::Node::TransformSpace relativeTo, const Vector3& localDirectionVector) 218 218 { 219 219 if (this->isDynamic()) … … 228 228 } 229 229 230 void Mo vableEntity::setVelocity(const Vector3& velocity)230 void MobileEntity::setVelocity(const Vector3& velocity) 231 231 { 232 232 if (this->isDynamic()) … … 237 237 } 238 238 239 void Mo vableEntity::setAngularVelocity(const Vector3& velocity)239 void MobileEntity::setAngularVelocity(const Vector3& velocity) 240 240 { 241 241 if (this->isDynamic()) … … 246 246 } 247 247 248 void Mo vableEntity::setAcceleration(const Vector3& acceleration)248 void MobileEntity::setAcceleration(const Vector3& acceleration) 249 249 { 250 250 if (this->isDynamic()) … … 254 254 } 255 255 256 void Mo vableEntity::setAngularAcceleration(const Vector3& acceleration)256 void MobileEntity::setAngularAcceleration(const Vector3& acceleration) 257 257 { 258 258 if (this->isDynamic()) … … 265 265 } 266 266 267 bool Mo vableEntity::isCollisionTypeLegal(WorldEntity::CollisionType type) const267 bool MobileEntity::isCollisionTypeLegal(WorldEntity::CollisionType type) const 268 268 { 269 269 if (type == WorldEntity::Static) 270 270 { 271 ThrowException(PhysicsViolation, "Cannot tell a Mo vableEntity to have static collision type");271 ThrowException(PhysicsViolation, "Cannot tell a MobileEntity to have static collision type"); 272 272 return false; 273 273 } … … 276 276 } 277 277 278 void Mo vableEntity::setWorldTransform(const btTransform& worldTrans)278 void MobileEntity::setWorldTransform(const btTransform& worldTrans) 279 279 { 280 280 // We use a dynamic body. So we translate our node accordingly. … … 293 293 } 294 294 295 void Mo vableEntity::getWorldTransform(btTransform& worldTrans) const295 void MobileEntity::getWorldTransform(btTransform& worldTrans) const 296 296 { 297 297 // We use a kinematic body -
code/branches/physics/src/orxonox/objects/worldentities/MobileEntity.h
r2407 r2408 27 27 */ 28 28 29 #ifndef _Mo vableEntity_H__30 #define _Mo vableEntity_H__29 #ifndef _MobileEntity_H__ 30 #define _MobileEntity_H__ 31 31 32 32 #include "OrxonoxPrereqs.h" … … 37 37 namespace orxonox 38 38 { 39 class _OrxonoxExport Mo vableEntity : public WorldEntity, public Tickable39 class _OrxonoxExport MobileEntity : public WorldEntity, public Tickable 40 40 { 41 41 public: 42 Mo vableEntity(BaseObject* creator);43 virtual ~Mo vableEntity();42 MobileEntity(BaseObject* creator); 43 virtual ~MobileEntity(); 44 44 45 45 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); … … 121 121 } 122 122 123 #endif /* _Mo vableEntity_H__ */123 #endif /* _MobileEntity_H__ */ -
code/branches/physics/src/orxonox/objects/worldentities/MovableEntity.cc
r2407 r2408 21 21 * 22 22 * Author: 23 * Reto Grieder23 * Fabian 'x3n' Landau 24 24 * Co-authors: 25 * Martin Stypinski25 * ... 26 26 * 27 27 */ … … 30 30 #include "MovableEntity.h" 31 31 32 #include "BulletDynamics/Dynamics/btRigidBody.h"33 34 #include "util/Debug.h"35 #include "util/MathConvert.h"36 #include "util/Exception.h"37 32 #include "core/CoreIncludes.h" 38 33 #include "core/XMLPort.h" 39 40 #include " objects/Scene.h"34 #include "core/Executor.h" 35 #include "tools/Timer.h" 41 36 42 37 namespace orxonox 43 38 { 44 MovableEntity::MovableEntity(BaseObject* creator) : WorldEntity(creator) 39 static const float MAX_RESYNCHRONIZE_TIME = 3.0f; 40 41 CreateFactory(MovableEntity); 42 43 MovableEntity::MovableEntity(BaseObject* creator) : MobileEntity(creator) 45 44 { 46 45 RegisterObject(MovableEntity); 47 46 48 this->linearAcceleration_ = Vector3::ZERO; 49 this->linearVelocity_ = Vector3::ZERO; 50 this->angularAcceleration_ = Vector3::ZERO; 51 this->angularVelocity_ = Vector3::ZERO; 47 this->overwrite_position_ = Vector3::ZERO; 48 this->overwrite_orientation_ = Quaternion::IDENTITY; 52 49 53 50 this->registerVariables(); … … 61 58 { 62 59 SUPER(MovableEntity, XMLPort, xmlelement, mode); 63 64 XMLPortParamTemplate(MovableEntity, "velocity", setVelocity, getVelocity, xmlelement, mode, const Vector3&);65 XMLPortParamTemplate(MovableEntity, "rotationaxis", setRotationAxis, getRotationAxis, xmlelement, mode, const Vector3&);66 XMLPortParam(MovableEntity, "rotationrate", setRotationRate, getRotationRate, xmlelement, mode);67 60 } 68 61 69 62 void MovableEntity::registerVariables() 70 63 { 64 REGISTERDATA(this->linearVelocity_, network::direction::toclient, new network::NetworkCallback<MovableEntity>(this, &MovableEntity::processLinearVelocity)); 65 REGISTERDATA(this->angularVelocity_, network::direction::toclient, new network::NetworkCallback<MovableEntity>(this, &MovableEntity::processAngularVelocity)); 66 67 REGISTERDATA(this->overwrite_position_, network::direction::toclient, new network::NetworkCallback<MovableEntity>(this, &MovableEntity::overwritePosition)); 68 REGISTERDATA(this->overwrite_orientation_, network::direction::toclient, new network::NetworkCallback<MovableEntity>(this, &MovableEntity::overwriteOrientation)); 71 69 } 72 70 73 71 void MovableEntity::tick(float dt) 74 72 { 73 MobileEntity::tick(dt); 74 75 75 if (this->isActive()) 76 76 { 77 // Check whether Bullet doesn't do the physics for us78 if (!this->isDynamic())79 {80 // Linear part81 this->linearVelocity_.x += this->linearAcceleration_.x * dt;82 this->linearVelocity_.y += this->linearAcceleration_.y * dt;83 this->linearVelocity_.z += this->linearAcceleration_.z * dt;84 linearVelocityChanged(true);85 this->node_->translate(this->linearVelocity_ * dt);86 positionChanged(true);87 88 // Angular part89 // Note: angularVelocity_ is a Quaternion with w = 0 while angularAcceleration_ is a Vector390 this->angularVelocity_.x += angularAcceleration_.x * dt;91 this->angularVelocity_.y += angularAcceleration_.y * dt;92 this->angularVelocity_.z += angularAcceleration_.z * dt;93 angularVelocityChanged(true);94 // Calculate new orientation with quaternion derivative. This is about 30% faster than with angle/axis method.95 float mult = dt * 0.5;96 // TODO: this could be optimized by writing it out. The calls currently create 4 new Quaternions!97 Quaternion newOrientation(0.0f, this->angularVelocity_.x * mult, this->angularVelocity_.y * mult, this->angularVelocity_.z * mult);98 newOrientation = this->node_->getOrientation() + newOrientation * this->node_->getOrientation();99 newOrientation.normalise();100 this->node_->setOrientation(newOrientation);101 orientationChanged(true);102 }103 77 } 104 78 } 105 79 106 void MovableEntity:: setPosition(const Vector3& position)80 void MovableEntity::overwritePosition() 107 81 { 108 if (this->isDynamic()) 109 { 110 btTransform transf = this->physicalBody_->getWorldTransform(); 111 transf.setOrigin(btVector3(position.x, position.y, position.z)); 112 this->physicalBody_->setWorldTransform(transf); 113 } 114 115 this->node_->setPosition(position); 116 positionChanged(false); 82 this->setPosition(this->overwrite_position_); 117 83 } 118 84 119 void MovableEntity:: translate(const Vector3& distance, Ogre::Node::TransformSpace relativeTo)85 void MovableEntity::overwriteOrientation() 120 86 { 121 if (this->isDynamic()) 122 { 123 OrxAssert(relativeTo == Ogre::Node::TS_LOCAL, "Cannot translate physical object relative \ 124 to any other space than TS_LOCAL."); 125 this->physicalBody_->translate(btVector3(distance.x, distance.y, distance.z)); 126 } 127 128 this->node_->translate(distance, relativeTo); 129 positionChanged(false); 87 this->setOrientation(this->overwrite_orientation_); 130 88 } 131 89 132 void MovableEntity:: setOrientation(const Quaternion& orientation)90 void MovableEntity::clientConnected(unsigned int clientID) 133 91 { 134 if (this->isDynamic()) 135 { 136 btTransform transf = this->physicalBody_->getWorldTransform(); 137 transf.setRotation(btQuaternion(orientation.x, orientation.y, orientation.z, orientation.w)); 138 this->physicalBody_->setWorldTransform(transf); 139 } 92 resynchronize(); 93 new Timer<MovableEntity>(rnd() * MAX_RESYNCHRONIZE_TIME, true, this, createExecutor(createFunctor(&MovableEntity::resynchronize)), false); 94 } 140 95 141 this->node_->setOrientation(orientation); 96 void MovableEntity::clientDisconnected(unsigned int clientID) 97 { 98 } 99 100 void MovableEntity::resynchronize() 101 { 102 positionChanged(false); 142 103 orientationChanged(false); 143 104 } 144 105 145 void MovableEntity:: rotate(const Quaternion& rotation, Ogre::Node::TransformSpace relativeTo)106 void MovableEntity::positionChanged(bool bContinuous) 146 107 { 147 if (this->isDynamic()) 148 { 149 OrxAssert(relativeTo == Ogre::Node::TS_LOCAL, "Cannot rotate physical object relative \ 150 to any other space than TS_LOCAL."); 151 btTransform transf = this->physicalBody_->getWorldTransform(); 152 this->physicalBody_->setWorldTransform(transf * btTransform(btQuaternion(rotation.x, rotation.y, rotation.z, rotation.w))); 153 } 154 155 this->node_->rotate(rotation, relativeTo); 156 orientationChanged(false); 108 if (!bContinuous) 109 this->overwrite_position_ = this->getPosition(); 157 110 } 158 111 159 void MovableEntity:: yaw(const Degree& angle, Ogre::Node::TransformSpace relativeTo)112 void MovableEntity::orientationChanged(bool bContinuous) 160 113 { 161 if (this->isDynamic()) 162 { 163 OrxAssert(relativeTo == Ogre::Node::TS_LOCAL, "Cannot yaw physical object relative \ 164 to any other space than TS_LOCAL."); 165 btTransform transf = this->physicalBody_->getWorldTransform(); 166 btTransform rotation(btQuaternion(angle.valueRadians(), 0.0f, 0.0f)); 167 this->physicalBody_->setWorldTransform(transf * rotation); 168 } 169 170 this->node_->yaw(angle, relativeTo); 171 orientationChanged(false); 172 } 173 174 void MovableEntity::pitch(const Degree& angle, Ogre::Node::TransformSpace relativeTo) 175 { 176 if (this->isDynamic()) 177 { 178 OrxAssert(relativeTo == Ogre::Node::TS_LOCAL, "Cannot pitch physical object relative \ 179 to any other space than TS_LOCAL."); 180 btTransform transf = this->physicalBody_->getWorldTransform(); 181 btTransform rotation(btQuaternion(0.0f, angle.valueRadians(), 0.0f)); 182 this->physicalBody_->setWorldTransform(transf * rotation); 183 } 184 185 this->node_->pitch(angle, relativeTo); 186 orientationChanged(false); 187 } 188 189 void MovableEntity::roll(const Degree& angle, Ogre::Node::TransformSpace relativeTo) 190 { 191 if (this->isDynamic()) 192 { 193 OrxAssert(relativeTo == Ogre::Node::TS_LOCAL, "Cannot roll physical object relative \ 194 to any other space than TS_LOCAL."); 195 btTransform transf = this->physicalBody_->getWorldTransform(); 196 btTransform rotation(btQuaternion(angle.valueRadians(), 0.0f, 0.0f)); 197 this->physicalBody_->setWorldTransform(transf * rotation); 198 } 199 200 this->node_->roll(angle, relativeTo); 201 orientationChanged(false); 202 } 203 204 void MovableEntity::lookAt(const Vector3& target, Ogre::Node::TransformSpace relativeTo, const Vector3& localDirectionVector) 205 { 206 if (this->isDynamic()) 207 { 208 ThrowException(NotImplemented, "ControllableEntity::lookAt() is not yet supported for physical objects."); 209 OrxAssert(relativeTo == Ogre::Node::TS_LOCAL, "Cannot align physical object relative \ 210 to any other space than TS_LOCAL."); 211 } 212 213 this->node_->lookAt(target, relativeTo, localDirectionVector); 214 orientationChanged(false); 215 } 216 217 void MovableEntity::setDirection(const Vector3& direction, Ogre::Node::TransformSpace relativeTo, const Vector3& localDirectionVector) 218 { 219 if (this->isDynamic()) 220 { 221 ThrowException(NotImplemented, "ControllableEntity::setDirection() is not yet supported for physical objects."); 222 OrxAssert(relativeTo == Ogre::Node::TS_LOCAL, "Cannot align physical object relative \ 223 to any other space than TS_LOCAL."); 224 } 225 226 this->node_->setDirection(direction, relativeTo, localDirectionVector); 227 orientationChanged(false); 228 } 229 230 void MovableEntity::setVelocity(const Vector3& velocity) 231 { 232 if (this->isDynamic()) 233 this->physicalBody_->setLinearVelocity(btVector3(velocity.x, velocity.y, velocity.z)); 234 235 this->linearVelocity_ = velocity; 236 linearVelocityChanged(false); 237 } 238 239 void MovableEntity::setAngularVelocity(const Vector3& velocity) 240 { 241 if (this->isDynamic()) 242 this->physicalBody_->setAngularVelocity(btVector3(velocity.x, velocity.y, velocity.z)); 243 244 this->angularVelocity_ = velocity; 245 angularVelocityChanged(false); 246 } 247 248 void MovableEntity::setAcceleration(const Vector3& acceleration) 249 { 250 if (this->isDynamic()) 251 this->physicalBody_->applyCentralForce(btVector3(acceleration.x * this->getMass(), acceleration.y * this->getMass(), acceleration.z * this->getMass())); 252 253 this->linearAcceleration_ = acceleration; 254 } 255 256 void MovableEntity::setAngularAcceleration(const Vector3& acceleration) 257 { 258 if (this->isDynamic()) 259 { 260 btVector3 inertia(btVector3(1, 1, 1) / this->physicalBody_->getInvInertiaDiagLocal()); 261 this->physicalBody_->applyTorque(btVector3(acceleration.x, acceleration.y, acceleration.z) * inertia); 262 } 263 264 this->angularAcceleration_ = acceleration; 265 } 266 267 bool MovableEntity::isCollisionTypeLegal(WorldEntity::CollisionType type) const 268 { 269 if (type == WorldEntity::Static) 270 { 271 ThrowException(PhysicsViolation, "Cannot tell a MovableEntity to have static collision type"); 272 return false; 273 } 274 else 275 return true; 276 } 277 278 void MovableEntity::setWorldTransform(const btTransform& worldTrans) 279 { 280 // We use a dynamic body. So we translate our node accordingly. 281 this->node_->setPosition(Vector3(worldTrans.getOrigin().x(), worldTrans.getOrigin().y(), worldTrans.getOrigin().z())); 282 this->node_->setOrientation(Quaternion(worldTrans.getRotation().w(), worldTrans.getRotation().x(), worldTrans.getRotation().y(), worldTrans.getRotation().z())); 283 this->linearVelocity_.x = this->physicalBody_->getLinearVelocity().x(); 284 this->linearVelocity_.y = this->physicalBody_->getLinearVelocity().y(); 285 this->linearVelocity_.z = this->physicalBody_->getLinearVelocity().z(); 286 this->angularVelocity_.x = this->physicalBody_->getAngularVelocity().x(); 287 this->angularVelocity_.y = this->physicalBody_->getAngularVelocity().y(); 288 this->angularVelocity_.z = this->physicalBody_->getAngularVelocity().z(); 289 linearVelocityChanged(true); 290 angularVelocityChanged(true); 291 positionChanged(true); 292 orientationChanged(true); 293 } 294 295 void MovableEntity::getWorldTransform(btTransform& worldTrans) const 296 { 297 // We use a kinematic body 298 worldTrans.setOrigin(btVector3(node_->getPosition().x, node_->getPosition().y, node_->getPosition().z)); 299 worldTrans.setRotation(btQuaternion(node_->getOrientation().x, node_->getOrientation().y, node_->getOrientation().z, node_->getOrientation().w)); 300 if (this->isDynamic()) 301 { 302 // This function gets called only once for dynamic objects to set the initial conditions 303 // We have to set the velocities too. 304 this->physicalBody_->setLinearVelocity(btVector3(linearVelocity_.x, linearVelocity_.y, linearVelocity_.z)); 305 this->physicalBody_->setAngularVelocity(btVector3(angularVelocity_.x, angularVelocity_.y, angularVelocity_.z)); 306 } 114 if (!bContinuous) 115 this->overwrite_orientation_ = this->getOrientation(); 307 116 } 308 117 } -
code/branches/physics/src/orxonox/objects/worldentities/MovableEntity.h
r2407 r2408 21 21 * 22 22 * Author: 23 * Reto Grieder23 * Fabian 'x3n' Landau 24 24 * Co-authors: 25 * Martin Stypinski25 * ... 26 26 * 27 27 */ … … 32 32 #include "OrxonoxPrereqs.h" 33 33 34 #include " WorldEntity.h"35 #include " objects/Tickable.h"34 #include "MobileEntity.h" 35 #include "network/ClientConnectionListener.h" 36 36 37 37 namespace orxonox 38 38 { 39 class _OrxonoxExport MovableEntity : public WorldEntity, public Tickable39 class _OrxonoxExport MovableEntity : public MobileEntity, public network::ClientConnectionListener 40 40 { 41 41 public: … … 47 47 void registerVariables(); 48 48 49 using WorldEntity::setPosition; 50 using WorldEntity::translate; 51 using WorldEntity::setOrientation; 52 using WorldEntity::rotate; 53 using WorldEntity::yaw; 54 using WorldEntity::pitch; 55 using WorldEntity::roll; 56 using WorldEntity::lookAt; 57 using WorldEntity::setDirection; 49 private: 50 void clientConnected(unsigned int clientID); 51 void clientDisconnected(unsigned int clientID); 52 void resynchronize(); 58 53 59 void setPosition(const Vector3& position); 60 void translate(const Vector3& distance, Ogre::Node::TransformSpace relativeTo = Ogre::Node::TS_LOCAL); 61 void setOrientation(const Quaternion& orientation); 62 void rotate(const Quaternion& rotation, Ogre::Node::TransformSpace relativeTo = Ogre::Node::TS_LOCAL); 63 void yaw(const Degree& angle, Ogre::Node::TransformSpace relativeTo = Ogre::Node::TS_LOCAL); 64 void pitch(const Degree& angle, Ogre::Node::TransformSpace relativeTo = Ogre::Node::TS_LOCAL); 65 void roll(const Degree& angle, Ogre::Node::TransformSpace relativeTo = Ogre::Node::TS_LOCAL); 66 void lookAt(const Vector3& target, Ogre::Node::TransformSpace relativeTo = Ogre::Node::TS_LOCAL, const Vector3& localDirectionVector = Vector3::NEGATIVE_UNIT_Z); 67 void setDirection(const Vector3& direction, Ogre::Node::TransformSpace relativeTo = Ogre::Node::TS_LOCAL, const Vector3& localDirectionVector = Vector3::NEGATIVE_UNIT_Z); 54 inline void processLinearVelocity() 55 { this->setVelocity(this->linearVelocity_); } 56 inline void processAngularVelocity() 57 { this->setAngularVelocity(this->angularVelocity_); } 68 58 69 void setVelocity(const Vector3& velocity); 70 inline void setVelocity(float x, float y, float z) 71 { this->setVelocity(Vector3(x, y, z)); } 72 inline const Vector3& getVelocity() const 73 { return this->linearVelocity_; } 59 void overwritePosition(); 60 void overwriteOrientation(); 74 61 75 void setAngularVelocity(const Vector3& velocity); 76 inline void setAngularVelocity(float x, float y, float z) 77 { this->setAngularVelocity(Vector3(x, y, z)); } 78 inline const Vector3& getAngularVelocity() const 79 { return this->linearAcceleration_; } 62 void positionChanged(bool bContinuous); 63 void orientationChanged(bool bContinuous); 80 64 81 void setAcceleration(const Vector3& acceleration); 82 inline void setAcceleration(float x, float y, float z) 83 { this->setAcceleration(Vector3(x, y, z)); } 84 inline const Vector3& getAcceleration() const 85 { return this->linearAcceleration_; } 86 87 void setAngularAcceleration(const Vector3& acceleration); 88 inline void setAngularAcceleration(float x, float y, float z) 89 { this->setAngularAcceleration(Vector3(x, y, z)); } 90 inline const Vector3& getAngularAcceleration() const 91 { return this->angularAcceleration_; } 92 93 inline void setRotationRate(Degree rate) 94 { this->setAngularVelocity(this->getAngularVelocity().normalisedCopy() * rate.valueRadians()); } 95 inline Degree getRotationRate() const 96 { return Degree(this->getAngularVelocity().length()); } 97 98 inline void setRotationAxis(const Vector3& axis) 99 { this->setAngularVelocity(axis * this->getAngularVelocity().length()); } 100 inline Vector3 getRotationAxis() const 101 { return this->getAngularVelocity().normalisedCopy(); } 102 103 protected: 104 Vector3 linearAcceleration_; 105 Vector3 linearVelocity_; 106 Vector3 angularAcceleration_; 107 Vector3 angularVelocity_; 108 109 private: 110 virtual void positionChanged (bool bContinuous) = 0; 111 virtual void orientationChanged (bool bContinuous) = 0; 112 virtual void linearVelocityChanged (bool bContinuous) { } 113 virtual void angularVelocityChanged(bool bContinuous) { } 114 115 virtual bool isCollisionTypeLegal(WorldEntity::CollisionType type) const; 116 117 // Bullet btMotionState related 118 void setWorldTransform(const btTransform& worldTrans); 119 void getWorldTransform(btTransform& worldTrans) const; 65 Vector3 overwrite_position_; 66 Quaternion overwrite_orientation_; 120 67 }; 121 68 } -
code/branches/physics/src/orxonox/objects/worldentities/WorldEntity.cc
r2407 r2408 344 344 ThrowException(PhysicsViolation, "Warning: Cannot set the collision type at run time."); 345 345 346 // Check for type legality. Could be StaticEntity or Mo vableEntity346 // Check for type legality. Could be StaticEntity or MobileEntity 347 347 if (!this->isCollisionTypeLegal(type)) 348 348 return; // exception gets issued anyway -
code/branches/physics/visual_studio/vc8/orxonox.vcproj
r2405 r2408 281 281 </File> 282 282 <File 283 RelativePath="..\..\src\orxonox\objects\worldentities\ LinearEntity.cc"283 RelativePath="..\..\src\orxonox\objects\worldentities\MobileEntity.cc" 284 284 > 285 285 </File> … … 1201 1201 </File> 1202 1202 <File 1203 RelativePath="..\..\src\orxonox\objects\worldentities\ LinearEntity.h"1203 RelativePath="..\..\src\orxonox\objects\worldentities\MobileEntity.h" 1204 1204 > 1205 1205 </File>
Note: See TracChangeset
for help on using the changeset viewer.