Changeset 2374 for code/branches/physics/src/orxonox/objects/worldentities
- Timestamp:
- Dec 10, 2008, 1:38:17 PM (16 years ago)
- Location:
- code/branches/physics/src/orxonox/objects/worldentities
- Files:
-
- 20 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/physics/src/orxonox/objects/worldentities/ControllableEntity.cc
r2300 r2374 57 57 this->bDestroyWhenPlayerLeft_ = false; 58 58 59 this-> acceleration_= Vector3::ZERO;60 61 this->server_ position_= Vector3::ZERO;62 this->client_ position_= Vector3::ZERO;63 this->server_ velocity_ = Vector3::ZERO;64 this->client_ velocity_ = Vector3::ZERO;65 this->server_ orientation_ = Quaternion::IDENTITY;66 this->client_ orientation_ = Quaternion::IDENTITY;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 67 68 68 this->registerVariables(); … … 226 226 void ControllableEntity::tick(float dt) 227 227 { 228 MovableEntity::tick(dt); 229 228 230 if (this->isActive()) 229 231 { 230 if (!this->isDynamic())231 {232 this->velocity_ += (dt * this->acceleration_);233 this->node_->translate(dt * this->velocity_, Ogre::Node::TS_LOCAL);234 }235 236 if (Core::isMaster())237 {238 this->server_velocity_ = this->velocity_;239 this->server_position_ = this->node_->getPosition();240 }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 232 } 248 233 } … … 252 237 REGISTERSTRING(this->cameraPositionTemplate_, network::direction::toclient); 253 238 254 REGISTERDATA(this->server_position_, network::direction::toclient, new network::NetworkCallback<ControllableEntity>(this, &ControllableEntity::processServerPosition)); 255 REGISTERDATA(this->server_velocity_, network::direction::toclient, new network::NetworkCallback<ControllableEntity>(this, &ControllableEntity::processServerVelocity)); 256 REGISTERDATA(this->server_orientation_, network::direction::toclient, new network::NetworkCallback<ControllableEntity>(this, &ControllableEntity::processServerOrientation)); 257 258 REGISTERDATA(this->server_overwrite_, network::direction::toclient, new network::NetworkCallback<ControllableEntity>(this, &ControllableEntity::processOverwrite)); 259 REGISTERDATA(this->client_overwrite_, network::direction::toserver); 260 261 REGISTERDATA(this->client_position_, network::direction::toserver, new network::NetworkCallback<ControllableEntity>(this, &ControllableEntity::processClientPosition)); 262 REGISTERDATA(this->client_velocity_, network::direction::toserver, new network::NetworkCallback<ControllableEntity>(this, &ControllableEntity::processClientVelocity)); 263 REGISTERDATA(this->client_orientation_, network::direction::toserver, new network::NetworkCallback<ControllableEntity>(this, &ControllableEntity::processClientOrientation)); 264 239 REGISTERDATA(this->server_position_, network::direction::toclient, new network::NetworkCallback<ControllableEntity>(this, &ControllableEntity::processServerPosition)); 240 REGISTERDATA(this->server_linear_velocity_, network::direction::toclient, new network::NetworkCallback<ControllableEntity>(this, &ControllableEntity::processServerLinearVelocity)); 241 REGISTERDATA(this->server_orientation_, network::direction::toclient, new network::NetworkCallback<ControllableEntity>(this, &ControllableEntity::processServerOrientation)); 242 REGISTERDATA(this->server_angular_velocity_, network::direction::toclient, new network::NetworkCallback<ControllableEntity>(this, &ControllableEntity::processServerAngularVelocity)); 243 244 REGISTERDATA(this->server_overwrite_, network::direction::toclient, new network::NetworkCallback<ControllableEntity>(this, &ControllableEntity::processOverwrite)); 245 REGISTERDATA(this->client_overwrite_, network::direction::toserver); 246 247 REGISTERDATA(this->client_position_, network::direction::toserver, new network::NetworkCallback<ControllableEntity>(this, &ControllableEntity::processClientPosition)); 248 REGISTERDATA(this->client_linear_velocity_, network::direction::toserver, new network::NetworkCallback<ControllableEntity>(this, &ControllableEntity::processClientLinearVelocity)); 249 REGISTERDATA(this->client_orientation_, network::direction::toserver, new network::NetworkCallback<ControllableEntity>(this, &ControllableEntity::processClientOrientation)); 250 REGISTERDATA(this->client_angular_velocity_, network::direction::toserver, new network::NetworkCallback<ControllableEntity>(this, &ControllableEntity::processClientAngularVelocity)); 265 251 266 252 REGISTERDATA(this->playerID_, network::direction::toclient, new network::NetworkCallback<ControllableEntity>(this, &ControllableEntity::networkcallback_changedplayerID)); … … 270 256 { 271 257 if (!this->bControlled_) 272 this->node_->setPosition(this->server_position_); 273 } 274 275 void ControllableEntity::processServerVelocity() 276 { 277 if (!this->bControlled_) 278 this->velocity_ = this->server_velocity_; 258 { 259 //COUT(0) << "override with server position: " << this << std::endl; 260 this->setPosition(this->server_position_); 261 } 262 } 263 264 void ControllableEntity::processServerLinearVelocity() 265 { 266 if (!this->bControlled_) 267 this->setVelocity(this->server_linear_velocity_); 279 268 } 280 269 … … 282 271 { 283 272 if (!this->bControlled_) 284 this->node_->setOrientation(this->server_orientation_); 273 this->setOrientation(this->server_orientation_); 274 } 275 276 void ControllableEntity::processServerAngularVelocity() 277 { 278 if (!this->bControlled_) 279 this->setAngularVelocity(this->server_angular_velocity_); 285 280 } 286 281 287 282 void ControllableEntity::processOverwrite() 288 283 { 289 if (this->bControlled_) 290 { 291 this->setPosition(this->server_position_); 292 this->setVelocity(this->server_velocity_); 293 this->setOrientation(this->server_orientation_); 294 295 this->client_overwrite_ = this->server_overwrite_; 296 } 284 //if (this->bControlled_) 285 //{ 286 // COUT(0) << "complete override: " << this << std::endl; 287 // this->setPosition(this->server_position_); 288 // this->setVelocity(this->server_velocity_); 289 // this->setOrientation(this->server_orientation_); 290 291 // this->client_overwrite_ = this->server_overwrite_; 292 //} 297 293 } 298 294 299 295 void ControllableEntity::processClientPosition() 300 296 { 301 if (this->server_overwrite_ == this->client_overwrite_) 302 { 297 //if (this->server_overwrite_ == this->client_overwrite_) 298 if (!this->bControlled_) 299 { 300 //COUT(0) << "override with client position: " << this << std::endl; 303 301 // 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() 312 { 313 if (this->server_overwrite_ == this->client_overwrite_) 314 { 315 this->velocity_ = this->client_velocity_; 316 this->server_velocity_ = this->client_velocity_; 302 this->setPosition(this->client_position_); 303 //this->server_position_ = this->client_position_; 304 } 305 //else 306 // COUT(2) << "callback: not setting client position" << endl; 307 } 308 309 void ControllableEntity::processClientLinearVelocity() 310 { 311 if (!this->bControlled_) 312 //if (this->server_overwrite_ == this->client_overwrite_) 313 { 314 this->setVelocity(this->client_linear_velocity_); 315 //this->server_velocity_ = this->client_velocity_; 317 316 } 318 317 } … … 320 319 void ControllableEntity::processClientOrientation() 321 320 { 322 if (this->server_overwrite_ == this->client_overwrite_) 323 { 324 this->node_->setOrientation(this->client_orientation_); 325 this->server_orientation_ = this->client_orientation_; 326 } 327 } 328 329 void ControllableEntity::positionChanged() 321 if (!this->bControlled_) 322 //if (this->server_overwrite_ == this->client_overwrite_) 323 { 324 this->setOrientation(this->client_orientation_); 325 //this->server_orientation_ = this->client_orientation_; 326 } 327 } 328 329 void ControllableEntity::processClientAngularVelocity() 330 { 331 if (!this->bControlled_) 332 //if (this->server_overwrite_ == this->client_overwrite_) 333 { 334 this->setAngularVelocity(this->client_angular_velocity_); 335 //this->server_velocity_ = this->client_velocity_; 336 } 337 } 338 339 void ControllableEntity::positionChanged(bool bContinuous) 330 340 { 331 341 if (Core::isMaster()) … … 340 350 } 341 351 342 void ControllableEntity::orientationChanged( )352 void ControllableEntity::orientationChanged(bool bContinuous) 343 353 { 344 354 if (Core::isMaster()) … … 353 363 } 354 364 355 void ControllableEntity:: velocityChanged()365 void ControllableEntity::linearVelocityChanged(bool bContinuous) 356 366 { 357 367 if (Core::isMaster()) 358 368 { 359 this->server_ velocity_ = this->getVelocity();369 this->server_linear_velocity_ = this->getVelocity(); 360 370 ++this->server_overwrite_; 361 371 } 362 372 else if (this->bControlled_) 363 373 { 364 this->client_velocity_ = this->getVelocity(); 374 this->client_linear_velocity_ = this->getVelocity(); 375 } 376 } 377 378 void ControllableEntity::angularVelocityChanged(bool bContinuous) 379 { 380 if (Core::isMaster()) 381 { 382 this->server_angular_velocity_ = this->getAngularVelocity(); 383 ++this->server_overwrite_; 384 } 385 else if (this->bControlled_) 386 { 387 this->client_angular_velocity_ = this->getAngularVelocity(); 365 388 } 366 389 } -
code/branches/physics/src/orxonox/objects/worldentities/ControllableEntity.h
r2300 r2374 33 33 34 34 #include "MovableEntity.h" 35 #include "objects/Tickable.h"36 35 37 36 namespace orxonox 38 37 { 39 class _OrxonoxExport ControllableEntity : public MovableEntity , public Tickable38 class _OrxonoxExport ControllableEntity : public MovableEntity 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 inline void setAcceleration(const Vector3& acceleration)82 { this->acceleration_ = acceleration; }83 inline void setAcceleration(float x, float y, float z)84 { this->acceleration_.x = x; this->acceleration_.y = y; this->acceleration_.z = z; }85 75 86 76 inline Camera* getCamera() const … … 109 99 { return this->bControlled_; } 110 100 111 Vector3 acceleration_;112 113 101 private: 114 102 void overwrite(); … … 116 104 117 105 void processServerPosition(); 118 void processServer Velocity();106 void processServerLinearVelocity(); 119 107 void processServerOrientation(); 108 void processServerAngularVelocity(); 120 109 121 110 void processClientPosition(); 122 void processClient Velocity();111 void processClientLinearVelocity(); 123 112 void processClientOrientation(); 113 void processClientAngularVelocity(); 124 114 125 void positionChanged(); 126 void orientationChanged(); 127 void velocityChanged(); 115 void positionChanged (bool bContinuous); 116 void orientationChanged (bool bContinuous); 117 void linearVelocityChanged (bool bContinuous); 118 void angularVelocityChanged(bool bContinuous); 128 119 129 120 void networkcallback_changedplayerID(); … … 135 126 Vector3 server_position_; 136 127 Vector3 client_position_; 137 Vector3 server_ velocity_;138 Vector3 client_ velocity_;128 Vector3 server_linear_velocity_; 129 Vector3 client_linear_velocity_; 139 130 Quaternion server_orientation_; 140 131 Quaternion client_orientation_; 132 Vector3 server_angular_velocity_; 133 Vector3 client_angular_velocity_; 141 134 142 135 PlayerInfo* player_; -
code/branches/physics/src/orxonox/objects/worldentities/LinearEntity.cc
r2300 r2374 45 45 RegisterObject(LinearEntity); 46 46 47 this->acceleration_ = Vector3::ZERO; 48 this->rotationAxis_ = Vector3::ZERO; 49 this->rotationRate_ = 0; 50 this->momentum_ = 0; 51 52 this->overwrite_position_ = Vector3::ZERO; 47 this->overwrite_position_ = Vector3::ZERO; 53 48 this->overwrite_orientation_ = Quaternion::IDENTITY; 54 49 … … 63 58 { 64 59 SUPER(LinearEntity, XMLPort, xmlelement, mode); 65 66 XMLPortParamTemplate(LinearEntity, "rotationaxis", setRotationAxis, getRotationAxis, xmlelement, mode, const Vector3&);67 XMLPortParamTemplate(LinearEntity, "rotationrate", setRotationRate, getRotationRate, xmlelement, mode, const Degree&);68 }69 70 void LinearEntity::tick(float dt)71 {72 if (this->isActive())73 {74 if (!this->isDynamic())75 {76 // we have to do 'physics' ourselves.77 this->velocity_ += (dt * this->acceleration_);78 this->node_->translate(dt * this->velocity_);79 80 this->rotationRate_ += (dt * this->momentum_);81 this->node_->rotate(this->rotationAxis_, this->rotationRate_ * dt);82 }83 }84 60 } 85 61 86 62 void LinearEntity::registerVariables() 87 63 { 88 REGISTERDATA(this->velocity_.x, network::direction::toclient); 89 REGISTERDATA(this->velocity_.y, network::direction::toclient); 90 REGISTERDATA(this->velocity_.z, network::direction::toclient); 91 92 REGISTERDATA(this->rotationAxis_.x, network::direction::toclient); 93 REGISTERDATA(this->rotationAxis_.y, network::direction::toclient); 94 REGISTERDATA(this->rotationAxis_.z, network::direction::toclient); 95 96 REGISTERDATA(this->rotationRate_, network::direction::toclient); 64 REGISTERDATA(this->linearVelocity_, network::direction::toclient, new network::NetworkCallback<LinearEntity>(this, &LinearEntity::processLinearVelocity)); 65 REGISTERDATA(this->angularVelocity_, network::direction::toclient, new network::NetworkCallback<LinearEntity>(this, &LinearEntity::processAngularVelocity)); 97 66 98 67 REGISTERDATA(this->overwrite_position_, network::direction::toclient, new network::NetworkCallback<LinearEntity>(this, &LinearEntity::overwritePosition)); … … 100 69 } 101 70 71 void LinearEntity::tick(float dt) 72 { 73 MovableEntity::tick(dt); 74 75 if (this->isActive()) 76 { 77 } 78 } 79 102 80 void LinearEntity::overwritePosition() 103 81 { 104 this->node_->setPosition(this->overwrite_position_); 82 //COUT(0) << "Setting position on client: " << this->overwrite_position_ << std::endl; 83 this->setPosition(this->overwrite_position_); 105 84 } 106 85 107 86 void LinearEntity::overwriteOrientation() 108 87 { 109 this->node_->setOrientation(this->overwrite_orientation_); 88 //COUT(0) << "Setting orientation on client: " << this->overwrite_orientation_ << std::endl; 89 this->setOrientation(this->overwrite_orientation_); 110 90 } 111 91 112 92 void LinearEntity::clientConnected(unsigned int clientID) 113 93 { 114 new Timer<LinearEntity>(rnd() * MAX_RESYNCHRONIZE_TIME, false, this, createExecutor(createFunctor(&LinearEntity::resynchronize)), true); 94 resynchronize(); 95 new Timer<LinearEntity>(rnd() * MAX_RESYNCHRONIZE_TIME, true, this, createExecutor(createFunctor(&LinearEntity::resynchronize)), false); 115 96 } 116 97 … … 121 102 void LinearEntity::resynchronize() 122 103 { 123 this->overwrite_position_ = this->getPosition();124 this->overwrite_orientation_ = this->getOrientation();104 positionChanged(false); 105 orientationChanged(false); 125 106 } 126 107 127 void LinearEntity::positionChanged( )108 void LinearEntity::positionChanged(bool bContinuous) 128 109 { 129 this->overwrite_position_ = this->getPosition(); 110 if (!bContinuous) 111 { 112 //if (Core::isMaster()) 113 // COUT(0) << "Setting position on server: " << this->getPosition() << std::endl; 114 this->overwrite_position_ = this->getPosition(); 115 } 130 116 } 131 117 132 void LinearEntity::orientationChanged( )118 void LinearEntity::orientationChanged(bool bContinuous) 133 119 { 134 this->overwrite_orientation_ = this->getOrientation(); 120 if (!bContinuous) 121 { 122 //if (Core::isMaster()) 123 // COUT(0) << "Setting orientation on server: " << this->getOrientation() << std::endl; 124 this->overwrite_orientation_ = this->getOrientation(); 125 } 135 126 } 136 127 } -
code/branches/physics/src/orxonox/objects/worldentities/LinearEntity.h
r2300 r2374 33 33 34 34 #include "MovableEntity.h" 35 #include "objects/Tickable.h"36 35 #include "network/ClientConnectionListener.h" 37 36 38 37 namespace orxonox 39 38 { 40 class _OrxonoxExport LinearEntity : public MovableEntity, public network::ClientConnectionListener , public Tickable39 class _OrxonoxExport LinearEntity : public MovableEntity, public network::ClientConnectionListener 41 40 { 42 41 public: … … 48 47 void registerVariables(); 49 48 50 inline void setAcceleration(const Vector3& acceleration)51 { this->acceleration_ = acceleration; }52 inline void setAcceleration(float x, float y, float z)53 { this->acceleration_.x = x; this->acceleration_.y = y; this->acceleration_.z = z; }54 inline const Vector3& getAcceleration() const55 { return this->acceleration_; }56 57 inline void setRotationAxis(const Vector3& axis)58 { this->rotationAxis_ = axis; this->rotationAxis_.normalise(); }59 inline void setRotationAxis(float x, float y, float z)60 { this->rotationAxis_.x = x; this->rotationAxis_.y = y; this->rotationAxis_.z = z; rotationAxis_.normalise(); }61 inline const Vector3& getRotationAxis() const62 { return this->rotationAxis_; }63 64 inline void setRotationRate(const Degree& angle)65 { this->rotationRate_ = angle; }66 inline void setRotationRate(const Radian& angle)67 { this->rotationRate_ = angle; }68 inline const Degree& getRotationRate() const69 { return this->rotationRate_; }70 71 inline void setMomentum(const Degree& angle)72 { this->momentum_ = angle; }73 inline void setMomentum(const Radian& angle)74 { this->momentum_ = angle; }75 inline const Degree& getMomentum() const76 { return this->momentum_; }77 78 49 private: 79 50 void clientConnected(unsigned int clientID); … … 81 52 void resynchronize(); 82 53 54 inline void processLinearVelocity() 55 { this->setVelocity(this->linearVelocity_); } 56 inline void processAngularVelocity() 57 { this->setAngularVelocity(this->angularVelocity_); } 58 83 59 void overwritePosition(); 84 60 void overwriteOrientation(); 85 61 86 void positionChanged(); 87 void orientationChanged(); 88 89 Vector3 acceleration_; 90 Vector3 rotationAxis_; 91 Degree rotationRate_; 92 Degree momentum_; 62 void positionChanged(bool bContinuous); 63 void orientationChanged(bool bContinuous); 93 64 94 65 Vector3 overwrite_position_; -
code/branches/physics/src/orxonox/objects/worldentities/MovableEntity.cc
r2306 r2374 33 33 34 34 #include "util/Debug.h" 35 #include "util/MathConvert.h" 35 36 #include "util/Exception.h" 36 37 #include "core/CoreIncludes.h" … … 45 46 RegisterObject(MovableEntity); 46 47 47 this->velocity_ = Vector3::ZERO; 48 this->linearAcceleration_ = Vector3::ZERO; 49 this->linearVelocity_ = Vector3::ZERO; 50 this->angularAcceleration_ = Vector3::ZERO; 51 this->angularVelocity_ = Vector3::ZERO; 48 52 49 53 this->registerVariables(); … … 58 62 SUPER(MovableEntity, XMLPort, xmlelement, mode); 59 63 60 XMLPortParamTemplate(MovableEntity, "velocity", setVelocity, getVelocity, xmlelement, mode, const Vector3&); 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); 61 67 } 62 68 … … 65 71 } 66 72 73 void MovableEntity::tick(float dt) 74 { 75 if (this->isActive()) 76 { 77 // Check whether Bullet doesn't do the physics for us 78 if (!this->isDynamic()) 79 { 80 // Linear part 81 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 part 89 // Note: angularVelocity_ is a Quaternion with w = 0 while angularAcceleration_ is a Vector3 90 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 } 104 } 105 67 106 void MovableEntity::setPosition(const Vector3& position) 68 107 { 69 108 if (this->isDynamic()) 70 109 { 110 //if (this->isPhysicsRunning()) 111 // return; 71 112 btTransform transf = this->physicalBody_->getWorldTransform(); 72 113 transf.setOrigin(btVector3(position.x, position.y, position.z)); … … 74 115 } 75 116 117 //COUT(0) << "setting position: " << position << std::endl; 76 118 this->node_->setPosition(position); 77 positionChanged( );119 positionChanged(false); 78 120 } 79 121 … … 88 130 89 131 this->node_->translate(distance, relativeTo); 90 positionChanged( );132 positionChanged(false); 91 133 } 92 134 … … 96 138 { 97 139 btTransform transf = this->physicalBody_->getWorldTransform(); 98 transf.setRotation(btQuaternion(orientation. w, orientation.x, orientation.y, orientation.z));140 transf.setRotation(btQuaternion(orientation.x, orientation.y, orientation.z, orientation.w)); 99 141 this->physicalBody_->setWorldTransform(transf); 100 142 } 101 143 102 144 this->node_->setOrientation(orientation); 103 orientationChanged( );145 orientationChanged(false); 104 146 } 105 147 … … 111 153 to any other space than TS_LOCAL."); 112 154 btTransform transf = this->physicalBody_->getWorldTransform(); 113 this->physicalBody_->setWorldTransform(transf * btTransform(btQuaternion(rotation. w, rotation.x, rotation.y, rotation.z)));155 this->physicalBody_->setWorldTransform(transf * btTransform(btQuaternion(rotation.x, rotation.y, rotation.z, rotation.w))); 114 156 } 115 157 116 158 this->node_->rotate(rotation, relativeTo); 117 orientationChanged( );159 orientationChanged(false); 118 160 } 119 161 … … 130 172 131 173 this->node_->yaw(angle, relativeTo); 132 orientationChanged( );174 orientationChanged(false); 133 175 } 134 176 … … 145 187 146 188 this->node_->pitch(angle, relativeTo); 147 orientationChanged( );189 orientationChanged(false); 148 190 } 149 191 … … 160 202 161 203 this->node_->roll(angle, relativeTo); 162 orientationChanged( );204 orientationChanged(false); 163 205 } 164 206 … … 175 217 176 218 this->node_->lookAt(target, relativeTo, localDirectionVector); 177 orientationChanged( );219 orientationChanged(false); 178 220 } 179 221 … … 190 232 191 233 this->node_->setDirection(direction, relativeTo, localDirectionVector); 192 orientationChanged( );234 orientationChanged(false); 193 235 } 194 236 … … 196 238 { 197 239 if (this->isDynamic()) 198 {199 240 this->physicalBody_->setLinearVelocity(btVector3(velocity.x, velocity.y, velocity.z)); 200 } 201 202 this->velocity_ = velocity; 203 velocityChanged(); 241 242 this->linearVelocity_ = velocity; 243 linearVelocityChanged(false); 244 } 245 246 void MovableEntity::setAngularVelocity(const Vector3& velocity) 247 { 248 if (this->isDynamic()) 249 this->physicalBody_->setAngularVelocity(btVector3(velocity.x, velocity.y, velocity.z)); 250 251 this->angularVelocity_ = velocity; 252 angularVelocityChanged(false); 253 } 254 255 void MovableEntity::setAcceleration(const Vector3& acceleration) 256 { 257 if (this->isDynamic()) 258 this->physicalBody_->applyCentralForce(btVector3(acceleration.x * this->getMass(), acceleration.y * this->getMass(), acceleration.z * this->getMass())); 259 260 this->linearAcceleration_ = acceleration; 261 } 262 263 void MovableEntity::setAngularAcceleration(const Vector3& acceleration) 264 { 265 if (this->isDynamic()) 266 { 267 btVector3 inertia(btVector3(1, 1, 1) / this->physicalBody_->getInvInertiaDiagLocal()); 268 this->physicalBody_->applyTorque(btVector3(acceleration.x, acceleration.y, acceleration.z) * inertia); 269 } 270 271 this->angularAcceleration_ = acceleration; 204 272 } 205 273 … … 220 288 this->node_->setPosition(Vector3(worldTrans.getOrigin().x(), worldTrans.getOrigin().y(), worldTrans.getOrigin().z())); 221 289 this->node_->setOrientation(Quaternion(worldTrans.getRotation().w(), worldTrans.getRotation().x(), worldTrans.getRotation().y(), worldTrans.getRotation().z())); 222 const btVector3& velocity = this->physicalBody_->getLinearVelocity(); 223 this->velocity_.x = velocity.x(); 224 this->velocity_.y = velocity.y(); 225 this->velocity_.z = velocity.z(); 226 velocityChanged(); 227 positionChanged(); 228 orientationChanged(); 290 COUT(0) << "setting world transform: " << omni_cast<std::string>(node_->getPosition()) << std::endl; 291 this->linearVelocity_.x = this->physicalBody_->getLinearVelocity().x(); 292 this->linearVelocity_.y = this->physicalBody_->getLinearVelocity().y(); 293 this->linearVelocity_.z = this->physicalBody_->getLinearVelocity().z(); 294 this->angularVelocity_.x = this->physicalBody_->getAngularVelocity().x(); 295 this->angularVelocity_.y = this->physicalBody_->getAngularVelocity().y(); 296 this->angularVelocity_.z = this->physicalBody_->getAngularVelocity().z(); 297 linearVelocityChanged(true); 298 angularVelocityChanged(true); 299 positionChanged(true); 300 orientationChanged(true); 229 301 } 230 302 231 303 void MovableEntity::getWorldTransform(btTransform& worldTrans) const 232 304 { 233 // We use a kinematic body 305 // We use a kinematic body 234 306 worldTrans.setOrigin(btVector3(node_->getPosition().x, node_->getPosition().y, node_->getPosition().z)); 235 worldTrans.setRotation(btQuaternion(node_->getOrientation(). w, node_->getOrientation().x, node_->getOrientation().y, node_->getOrientation().z));307 worldTrans.setRotation(btQuaternion(node_->getOrientation().x, node_->getOrientation().y, node_->getOrientation().z, node_->getOrientation().w)); 236 308 if (this->isDynamic()) 237 309 { 238 310 // This function gets called only once for dynamic objects to set the initial conditions 239 // We have to set the velocity too. 240 this->physicalBody_->setLinearVelocity(btVector3(velocity_.x, velocity_.y, velocity_.z)); 311 // We have to set the velocities too. 312 this->physicalBody_->setLinearVelocity(btVector3(linearVelocity_.x, linearVelocity_.y, linearVelocity_.z)); 313 this->physicalBody_->setAngularVelocity(btVector3(angularVelocity_.x, angularVelocity_.y, angularVelocity_.z)); 241 314 } 242 315 } -
code/branches/physics/src/orxonox/objects/worldentities/MovableEntity.h
r2304 r2374 34 34 #include "WorldEntity.h" 35 35 #include "objects/Tickable.h" 36 #include "network/ClientConnectionListener.h"37 36 38 37 namespace orxonox 39 38 { 40 class _OrxonoxExport MovableEntity : public WorldEntity 39 class _OrxonoxExport MovableEntity : public WorldEntity, public Tickable 41 40 { 42 41 public: … … 45 44 46 45 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); 46 virtual void tick(float dt); 47 47 void registerVariables(); 48 48 … … 69 69 void setVelocity(const Vector3& velocity); 70 70 inline void setVelocity(float x, float y, float z) 71 { this-> velocity_.x = x; this->velocity_.y = y; this->velocity_.z = z; }71 { this->setVelocity(Vector3(x, y, z)); } 72 72 inline const Vector3& getVelocity() const 73 { return this->velocity_; } 73 { return this->linearVelocity_; } 74 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_; } 80 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(); } 74 102 75 103 protected: 76 Vector3 velocity_; 104 Vector3 linearAcceleration_; 105 Vector3 linearVelocity_; 106 Vector3 angularAcceleration_; 107 Vector3 angularVelocity_; 77 108 78 109 private: 79 //void attachPhysicalObject(WorldEntity* object); 80 81 virtual void positionChanged() { } 82 virtual void orientationChanged() { } 83 virtual void velocityChanged() { } 110 virtual void positionChanged (bool bContinuous) { } 111 virtual void orientationChanged (bool bContinuous) { } 112 virtual void linearVelocityChanged (bool bContinuous) { } 113 virtual void angularVelocityChanged(bool bContinuous) { } 84 114 85 115 virtual bool isCollisionTypeLegal(WorldEntity::CollisionType type) const; -
code/branches/physics/src/orxonox/objects/worldentities/StaticEntity.cc
r2304 r2374 31 31 #include "StaticEntity.h" 32 32 33 #include "BulletDynamics/Dynamics/btRigidBody.h" 34 33 35 #include "util/Exception.h" 34 36 #include "core/CoreIncludes.h" … … 51 53 void StaticEntity::registerVariables() 52 54 { 53 REGISTERDATA(this->getPosition().x, network::direction::toclient); 54 REGISTERDATA(this->getPosition().y, network::direction::toclient); 55 REGISTERDATA(this->getPosition().z, network::direction::toclient); 56 57 REGISTERDATA(this->getOrientation().w, network::direction::toclient); 58 REGISTERDATA(this->getOrientation().x, network::direction::toclient); 59 REGISTERDATA(this->getOrientation().y, network::direction::toclient); 60 REGISTERDATA(this->getOrientation().z, network::direction::toclient); 55 REGISTERDATA(this->getPosition(), network::direction::toclient, new network::NetworkCallback<StaticEntity>(this, &StaticEntity::positionChanged)); 56 REGISTERDATA(this->getOrientation(), network::direction::toclient, new network::NetworkCallback<StaticEntity>(this, &StaticEntity::orientationChanged)); 57 } 58 59 60 void StaticEntity::setPosition(const Vector3& position) 61 { 62 if (this->isPhysicsRunning()) 63 ThrowException(PhysicsViolation, "Cannot change position or orientation of a StaticEntity with physics at run time."); 64 if (this->isStatic()) 65 { 66 btTransform transf = this->physicalBody_->getWorldTransform(); 67 transf.setOrigin(btVector3(position.x, position.y, position.z)); 68 this->physicalBody_->setWorldTransform(transf); 69 } 70 71 this->node_->setPosition(position); 72 } 73 74 void StaticEntity::translate(const Vector3& distance, Ogre::Node::TransformSpace relativeTo) 75 { 76 if (this->isPhysicsRunning()) 77 ThrowException(PhysicsViolation, "Cannot change position or orientation of a StaticEntity with physics at run time."); 78 if (this->isStatic()) 79 { 80 OrxAssert(relativeTo == Ogre::Node::TS_LOCAL, "Cannot translate physical object relative \ 81 to any other space than TS_LOCAL."); 82 this->physicalBody_->translate(btVector3(distance.x, distance.y, distance.z)); 83 } 84 85 this->node_->translate(distance, relativeTo); 86 } 87 88 void StaticEntity::setOrientation(const Quaternion& orientation) 89 { 90 if (this->isPhysicsRunning()) 91 ThrowException(PhysicsViolation, "Cannot change position or orientation of a StaticEntity with physics at run time."); 92 if (this->isStatic()) 93 { 94 btTransform transf = this->physicalBody_->getWorldTransform(); 95 transf.setRotation(btQuaternion(orientation.x, orientation.y, orientation.z, orientation.w)); 96 this->physicalBody_->setWorldTransform(transf); 97 } 98 99 this->node_->setOrientation(orientation); 100 } 101 102 void StaticEntity::rotate(const Quaternion& rotation, Ogre::Node::TransformSpace relativeTo) 103 { 104 if (this->isPhysicsRunning()) 105 ThrowException(PhysicsViolation, "Cannot change position or orientation of a StaticEntity with physics at run time."); 106 if (this->isStatic()) 107 { 108 OrxAssert(relativeTo == Ogre::Node::TS_LOCAL, "Cannot rotate physical object relative \ 109 to any other space than TS_LOCAL."); 110 btTransform transf = this->physicalBody_->getWorldTransform(); 111 this->physicalBody_->setWorldTransform(transf * btTransform(btQuaternion(rotation.x, rotation.y, rotation.z, rotation.w))); 112 } 113 114 this->node_->rotate(rotation, relativeTo); 115 } 116 117 void StaticEntity::yaw(const Degree& angle, Ogre::Node::TransformSpace relativeTo) 118 { 119 if (this->isPhysicsRunning()) 120 ThrowException(PhysicsViolation, "Cannot change position or orientation of a StaticEntity with physics at run time."); 121 if (this->isStatic()) 122 { 123 OrxAssert(relativeTo == Ogre::Node::TS_LOCAL, "Cannot yaw physical object relative \ 124 to any other space than TS_LOCAL."); 125 btTransform transf = this->physicalBody_->getWorldTransform(); 126 btTransform rotation(btQuaternion(angle.valueRadians(), 0.0f, 0.0f)); 127 this->physicalBody_->setWorldTransform(transf * rotation); 128 } 129 130 this->node_->yaw(angle, relativeTo); 131 } 132 133 void StaticEntity::pitch(const Degree& angle, Ogre::Node::TransformSpace relativeTo) 134 { 135 if (this->isPhysicsRunning()) 136 ThrowException(PhysicsViolation, "Cannot change position or orientation of a StaticEntity with physics at run time."); 137 if (this->isStatic()) 138 { 139 OrxAssert(relativeTo == Ogre::Node::TS_LOCAL, "Cannot pitch physical object relative \ 140 to any other space than TS_LOCAL."); 141 btTransform transf = this->physicalBody_->getWorldTransform(); 142 btTransform rotation(btQuaternion(0.0f, angle.valueRadians(), 0.0f)); 143 this->physicalBody_->setWorldTransform(transf * rotation); 144 } 145 146 this->node_->pitch(angle, relativeTo); 147 } 148 149 void StaticEntity::roll(const Degree& angle, Ogre::Node::TransformSpace relativeTo) 150 { 151 if (this->isPhysicsRunning()) 152 ThrowException(PhysicsViolation, "Cannot change position or orientation of a StaticEntity with physics at run time."); 153 if (this->isStatic()) 154 { 155 OrxAssert(relativeTo == Ogre::Node::TS_LOCAL, "Cannot roll physical object relative \ 156 to any other space than TS_LOCAL."); 157 btTransform transf = this->physicalBody_->getWorldTransform(); 158 btTransform rotation(btQuaternion(angle.valueRadians(), 0.0f, 0.0f)); 159 this->physicalBody_->setWorldTransform(transf * rotation); 160 } 161 162 this->node_->roll(angle, relativeTo); 163 } 164 165 void StaticEntity::lookAt(const Vector3& target, Ogre::Node::TransformSpace relativeTo, const Vector3& localDirectionVector) 166 { 167 if (this->isPhysicsRunning()) 168 ThrowException(PhysicsViolation, "Cannot change position or orientation of a StaticEntity with physics at run time."); 169 if (this->isStatic()) 170 { 171 ThrowException(NotImplemented, "ControllableEntity::lookAt() is not yet supported for physical objects."); 172 OrxAssert(relativeTo == Ogre::Node::TS_LOCAL, "Cannot align physical object relative \ 173 to any other space than TS_LOCAL."); 174 } 175 176 this->node_->lookAt(target, relativeTo, localDirectionVector); 177 } 178 179 void StaticEntity::setDirection(const Vector3& direction, Ogre::Node::TransformSpace relativeTo, const Vector3& localDirectionVector) 180 { 181 if (this->isPhysicsRunning()) 182 ThrowException(PhysicsViolation, "Cannot change position or orientation of a StaticEntity with physics at run time."); 183 if (this->isStatic()) 184 { 185 ThrowException(NotImplemented, "ControllableEntity::setDirection() is not yet supported for physical objects."); 186 OrxAssert(relativeTo == Ogre::Node::TS_LOCAL, "Cannot align physical object relative \ 187 to any other space than TS_LOCAL."); 188 } 189 190 this->node_->setDirection(direction, relativeTo, localDirectionVector); 61 191 } 62 192 … … 81 211 { 82 212 worldTrans.setOrigin(btVector3(node_->getPosition().x, node_->getPosition().y, node_->getPosition().z)); 83 worldTrans.setRotation(btQuaternion(node_->getOrientation(). w, node_->getOrientation().x, node_->getOrientation().y, node_->getOrientation().z));213 worldTrans.setRotation(btQuaternion(node_->getOrientation().x, node_->getOrientation().y, node_->getOrientation().z, node_->getOrientation().w)); 84 214 } 85 215 } -
code/branches/physics/src/orxonox/objects/worldentities/StaticEntity.h
r2304 r2374 54 54 using WorldEntity::setDirection; 55 55 56 inline void setPosition(const Vector3& position) 57 { this->node_->setPosition(position); } 58 inline void translate(const Vector3& distance, Ogre::Node::TransformSpace relativeTo = Ogre::Node::TS_LOCAL) 59 { this->node_->translate(distance, relativeTo); } 60 inline void setOrientation(const Quaternion& orientation) 61 { this->node_->setOrientation(orientation); } 62 inline void rotate(const Quaternion& rotation, Ogre::Node::TransformSpace relativeTo = Ogre::Node::TS_LOCAL) 63 { this->node_->rotate(rotation, relativeTo); } 64 inline void yaw(const Degree& angle, Ogre::Node::TransformSpace relativeTo = Ogre::Node::TS_LOCAL) 65 { this->node_->yaw(angle, relativeTo); } 66 inline void pitch(const Degree& angle, Ogre::Node::TransformSpace relativeTo = Ogre::Node::TS_LOCAL) 67 { this->node_->pitch(angle, relativeTo); } 68 inline void roll(const Degree& angle, Ogre::Node::TransformSpace relativeTo = Ogre::Node::TS_LOCAL) 69 { this->node_->roll(angle, relativeTo); } 70 inline void lookAt(const Vector3& target, Ogre::Node::TransformSpace relativeTo = Ogre::Node::TS_LOCAL, const Vector3& localDirectionVector = Vector3::NEGATIVE_UNIT_Z) 71 { this->node_->lookAt(target, relativeTo, localDirectionVector); } 72 inline void setDirection(const Vector3& direction, Ogre::Node::TransformSpace relativeTo = Ogre::Node::TS_LOCAL, const Vector3& localDirectionVector = Vector3::NEGATIVE_UNIT_Z) 73 { this->node_->setDirection(direction, relativeTo, localDirectionVector); } 56 void setPosition(const Vector3& position); 57 void translate(const Vector3& distance, Ogre::Node::TransformSpace relativeTo = Ogre::Node::TS_LOCAL); 58 void setOrientation(const Quaternion& orientation); 59 void rotate(const Quaternion& rotation, Ogre::Node::TransformSpace relativeTo = Ogre::Node::TS_LOCAL); 60 void yaw(const Degree& angle, Ogre::Node::TransformSpace relativeTo = Ogre::Node::TS_LOCAL); 61 void pitch(const Degree& angle, Ogre::Node::TransformSpace relativeTo = Ogre::Node::TS_LOCAL); 62 void roll(const Degree& angle, Ogre::Node::TransformSpace relativeTo = Ogre::Node::TS_LOCAL); 63 void lookAt(const Vector3& target, Ogre::Node::TransformSpace relativeTo = Ogre::Node::TS_LOCAL, const Vector3& localDirectionVector = Vector3::NEGATIVE_UNIT_Z); 64 void setDirection(const Vector3& direction, Ogre::Node::TransformSpace relativeTo = Ogre::Node::TS_LOCAL, const Vector3& localDirectionVector = Vector3::NEGATIVE_UNIT_Z); 74 65 75 66 private: 67 bool isCollisionTypeLegal(CollisionType type) const; 76 68 77 bool isCollisionTypeLegal(CollisionType type) const; 69 inline void positionChanged() 70 { this->setPosition(this->getPosition()); } 71 inline void orientationChanged() 72 { this->setOrientation(this->getOrientation()); } 78 73 79 74 // Bullet btMotionState related -
code/branches/physics/src/orxonox/objects/worldentities/WorldEntity.cc
r2313 r2374 14 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 * GNU General Public License for more details. 16 * GNU General Public License for more details. 17 17 * 18 18 * You should have received a copy of the GNU General Public License … … 73 73 // Default behaviour does not include physics 74 74 this->physicalBody_ = 0; 75 this->collisionShape_ = 0;75 this->collisionShape_ = new CompoundCollisionShape(this); 76 76 this->mass_ = 0; 77 77 this->childMass_ = 0; 78 78 this->collisionType_ = None; 79 this->collisionTypeSynchronised_ = None; 79 80 80 81 this->registerVariables(); … … 113 114 XMLPortParam(WorldEntity, "scale", setScale, getScale, xmlelement, mode); 114 115 116 // Physics 115 117 XMLPortParam(WorldEntity, "collisionType", setCollisionTypeStr, getCollisionTypeStr, xmlelement, mode); 116 //XMLPortParam(WorldEntity, "collisionRadius", setCollisionRadius, getCollisionRadius, xmlelement, mode);117 118 XMLPortParam(WorldEntity, "mass", setMass, getMass, xmlelement, mode); 118 119 120 // Other attached WorldEntities 119 121 XMLPortObject(WorldEntity, WorldEntity, "attached", attach, getAttachedObject, xmlelement, mode); 122 // Attached collision shapes 120 123 XMLPortObject(WorldEntity, CollisionShape, "collisionShapes", attachCollisionShape, getAttachedCollisionShape, xmlelement, mode); 121 124 } … … 123 126 void WorldEntity::registerVariables() 124 127 { 125 REGISTERDATA(this->bActive_, network::direction::toclient, new network::NetworkCallback<WorldEntity>(this, &WorldEntity::changedActivity)); 126 REGISTERDATA(this->bVisible_, network::direction::toclient, new network::NetworkCallback<WorldEntity>(this, &WorldEntity::changedVisibility)); 127 128 REGISTERDATA(this->getScale3D().x, network::direction::toclient); 129 REGISTERDATA(this->getScale3D().y, network::direction::toclient); 130 REGISTERDATA(this->getScale3D().z, network::direction::toclient); 128 REGISTERDATA(this->bActive_, network::direction::toclient, new network::NetworkCallback<WorldEntity>(this, &WorldEntity::changedActivity)); 129 REGISTERDATA(this->bVisible_, network::direction::toclient, new network::NetworkCallback<WorldEntity>(this, &WorldEntity::changedVisibility)); 130 131 // HACK: Removed the call because it gets called the first time as well 132 REGISTERDATA(this->getScale3D(), network::direction::toclient);//, new network::NetworkCallback<WorldEntity>(this, &WorldEntity::scaleChanged)); 133 134 int* collisionType = (int*)&this->collisionTypeSynchronised_; 135 REGISTERDATA(*collisionType, network::direction::toclient, new network::NetworkCallback<WorldEntity>(this, &WorldEntity::collisionTypeChanged)); 136 REGISTERDATA(this->mass_, network::direction::toclient, new network::NetworkCallback<WorldEntity>(this, &WorldEntity::massChanged)); 131 137 132 138 REGISTERDATA(this->parentID_, network::direction::toclient, new network::NetworkCallback<WorldEntity>(this, &WorldEntity::updateParent)); … … 138 144 if (parent) 139 145 this->attachToParent(parent); 146 } 147 148 void WorldEntity::collisionTypeChanged() 149 { 150 if (this->collisionTypeSynchronised_ != Dynamic && 151 this->collisionTypeSynchronised_ != Kinematic && 152 this->collisionTypeSynchronised_ != Static && 153 this->collisionTypeSynchronised_ != None) 154 { 155 CCOUT(1) << "Error when collsion Type was received over network. Unknown enum value:" << this->collisionTypeSynchronised_ << std::endl; 156 } 157 else if (this->collisionTypeSynchronised_ != collisionType_) 158 { 159 if (this->parent_) 160 CCOUT(2) << "Warning: Network connection tried to set the collision type of an attached WE. Ignoring." << std::endl; 161 else 162 this->setCollisionType(this->collisionTypeSynchronised_); 163 } 164 } 165 166 void WorldEntity::massChanged() 167 { 168 this->setMass(this->mass_); 140 169 } 141 170 … … 210 239 void WorldEntity::attachCollisionShape(CollisionShape* shape) 211 240 { 212 this->attachedShapes_.push_back(shape); 213 214 if (!this->collisionShape_ && shape->hasNoTransform()) 215 { 216 // Set local scaling right when adding it. It can include both scaling parameters 217 // and shape parameters (like sphere radius) 218 shape->getCollisionShape()->setLocalScaling(shape->getTotalScaling()); 219 this->collisionShape_ = shape; 220 // recalculate inertia tensor 221 if (this->isDynamic()) 222 internalSetMassProps(); 223 } 224 else 225 { 226 if (this->collisionShape_ && !this->collisionShape_->isCompoundShape()) 227 { 228 // We have to create a new compound shape and add the old one first. 229 CollisionShape* thisShape = this->collisionShape_; 230 this->collisionShape_ = 0; 231 this->mergeCollisionShape(thisShape); 232 } 233 this->mergeCollisionShape(shape); 234 } 241 this->collisionShape_->addChildShape(shape); 235 242 236 243 if (this->physicalBody_) … … 241 248 removeFromPhysicalWorld(); 242 249 } 243 this->physicalBody_->setCollisionShape(this->collisionShape_->getCollisionShape()); 244 } 245 246 addToPhysicalWorld(); 250 if (this->collisionShape_->getCollisionShape()) 251 this->physicalBody_->setCollisionShape(this->collisionShape_->getCollisionShape()); 252 // recalculate inertia tensor 253 internalSetMassProps(); 254 addToPhysicalWorld(); 255 } 247 256 } 248 257 249 258 CollisionShape* WorldEntity::getAttachedCollisionShape(unsigned int index) const 250 259 { 251 if (index < this->attachedShapes_.size()) 252 return attachedShapes_[index]; 253 else 254 return 0; 255 } 256 257 void WorldEntity::mergeCollisionShape(CollisionShape* shape) 258 { 259 if (!this->collisionShape_) 260 this->collisionShape_ = new CompoundCollisionShape(this); 261 assert(this->collisionShape_->isCompoundShape()); 262 263 // merge with transform 264 CompoundCollisionShape* compoundShape = static_cast<CompoundCollisionShape*>(this->collisionShape_); 265 assert(compoundShape); 266 compoundShape->addChildShape(shape); 267 268 // recalculate inertia tensor 269 internalSetMassProps(); 260 return this->collisionShape_->getChildShape(index); 270 261 } 271 262 … … 302 293 this->mass_ = mass; 303 294 if (!this->hasPhysics()) 304 COUT(3) << "Warning: Setting the mass of a WorldEntity with no physics has no effect." << std::endl; 295 return; 296 // TODO: Add this again when new network callbacks work properly 297 //COUT(3) << "Warning: Setting the mass of a WorldEntity with no physics has no effect." << std::endl; 305 298 else 306 299 { … … 320 313 assert(hasPhysics()); 321 314 322 if ( (this->isKinematic() || this->isStatic()) && (this->mass_ + this->childMass_) != 0.0f)323 { 324 // Mass non zero is a bad idea for kinematic and static objects315 if (this->isStatic()) 316 { 317 // Just set everything to zero 325 318 this->physicalBody_->setMassProps(0.0f, btVector3(0, 0, 0)); 326 319 } 327 else if (this->isDynamic() && (this->mass_ + this->childMass_) == 0.0f) 328 { 329 // Mass zero is not such a good idea for dynamic objects 320 else if ((this->mass_ + this->childMass_) == 0.0f) 321 { 322 // Use default values to avoid very large or very small values 323 CCOUT(2) << "Warning: Setting the internal physical mass to 1.0 because mass_ is 0.0." << std::endl; 330 324 this->physicalBody_->setMassProps(1.0f, this->getLocalInertia(1.0f)); 331 325 } … … 337 331 { 338 332 btVector3 inertia(0, 0, 0); 339 if (this->collisionShape_ )333 if (this->collisionShape_->getCollisionShape()) 340 334 this->collisionShape_->getCollisionShape()->calculateLocalInertia(mass, inertia); 341 335 return inertia; … … 368 362 this->physicalBody_ = new btRigidBody(bodyConstructionInfo); 369 363 this->physicalBody_->setUserPointer(this); 364 this->physicalBody_->setActivationState(DISABLE_DEACTIVATION); 370 365 } 371 366 else if (type == None && this->collisionType_ != None) … … 377 372 this->physicalBody_ = 0; 378 373 this->collisionType_ = None; 374 this->collisionTypeSynchronised_ = None; 379 375 return; 380 376 } … … 401 397 402 398 // update mass and inertia tensor 403 internalSetMassProps(); // type is not None! See case None :in switch399 internalSetMassProps(); // type is not None! See case None in switch 404 400 405 401 addToPhysicalWorld(); … … 451 447 else 452 448 this->collisionType_ = Dynamic; 449 this->collisionTypeSynchronised_ = this->collisionType_; 450 } 451 452 bool WorldEntity::isPhysicsRunning() const 453 { 454 return this->physicalBody_ && this->physicalBody_->isInWorld(); 453 455 } 454 456 -
code/branches/physics/src/orxonox/objects/worldentities/WorldEntity.h
r2313 r2374 164 164 { this->roll(angle); } 165 165 166 inline void scaleChanged() 167 { this->setScale3D(this->getScale3D()); } 168 166 169 WorldEntity* parent_; 167 170 unsigned int parentID_; … … 186 189 bool isKinematic() const { return getCollisionType() == Kinematic; } 187 190 bool isDynamic() const { return getCollisionType() == Dynamic ; } 191 bool isPhysicsRunning() const; 188 192 189 193 inline CollisionType getCollisionType() const … … 201 205 CollisionShape* getAttachedCollisionShape(unsigned int index) const; 202 206 203 inline Co llisionShape* getCollisionShape()207 inline CompoundCollisionShape* getCollisionShape() 204 208 { return this->collisionShape_; } 205 209 inline btRigidBody* getPhysicalBody() … … 220 224 void removeFromPhysicalWorld() const; 221 225 226 // network callbacks 227 void collisionTypeChanged(); 228 void massChanged(); 229 222 230 CollisionType collisionType_; 223 std::vector<CollisionShape*> attachedShapes_;224 Co llisionShape*collisionShape_;231 CollisionType collisionTypeSynchronised_; 232 CompoundCollisionShape* collisionShape_; 225 233 btScalar mass_; 226 234 btScalar childMass_; -
code/branches/physics/src/orxonox/objects/worldentities/collisionshapes/CollisionShape.cc
r2306 r2374 37 37 #include "tools/BulletConversions.h" 38 38 39 #include "CompoundCollisionShape.h" 40 39 41 namespace orxonox 40 42 { 41 43 CreateFactory(CollisionShape); 42 44 43 CollisionShape::CollisionShape(BaseObject* creator) : StaticEntity(creator) 45 CollisionShape::CollisionShape(BaseObject* creator) 46 : BaseObject(creator) 47 , network::Synchronisable(creator) 44 48 { 45 49 RegisterObject(CollisionShape); 46 50 47 this->bIsCompound_ = false; 51 this->parent_ = 0; 52 this->parentID_ = (unsigned int)-1; 53 this->collisionShape_ = 0; 48 54 } 49 55 … … 55 61 { 56 62 SUPER(CollisionShape, XMLPort, xmlelement, mode); 63 64 XMLPortParamTemplate(CollisionShape, "position", setPosition, getPosition, xmlelement, mode, const Vector3&); 65 XMLPortParamTemplate(CollisionShape, "orientation", setOrientation, getOrientation, xmlelement, mode, const Quaternion&); 66 XMLPortParamLoadOnly(CollisionShape, "yaw", yaw, xmlelement, mode); 67 XMLPortParamLoadOnly(CollisionShape, "pitch", pitch, xmlelement, mode); 68 XMLPortParamLoadOnly(CollisionShape, "roll", roll, xmlelement, mode); 69 XMLPortParamTemplate(CollisionShape, "scale3D", setScale3D, getScale3D, xmlelement, mode, const Vector3&); 70 XMLPortParamLoadOnly(CollisionShape, "scale", setScale, xmlelement, mode); 57 71 } 58 72 59 bool CollisionShape::isCollisionTypeLegal(WorldEntity::CollisionType type) const73 void CollisionShape::registerVariables() 60 74 { 61 if (type != WorldEntity::None) 62 { 63 ThrowException(PhysicsViolation, "A CollisionShape can only have CollisionType 'None'."); 64 return false; 65 } 66 else 67 return true; 75 REGISTERDATA(this->parentID_, network::direction::toclient, new network::NetworkCallback<CollisionShape>(this, &CollisionShape::updateParent)); 68 76 } 69 77 70 bool CollisionShape::hasNoTransform() const78 void CollisionShape::updateParent() 71 79 { 72 return (this->getPosition().positionEquals(Vector3(0, 0, 0), 0.001) && 73 this->getOrientation().equals(Quaternion(1,0,0,0), Degree(0.1))); 80 CompoundCollisionShape* parent = dynamic_cast<CompoundCollisionShape*>(Synchronisable::getSynchronisable(this->parentID_)); 81 if (parent) 82 parent->addChildShape(this); 74 83 } 75 84 76 b tVector3 CollisionShape::getTotalScaling()85 bool CollisionShape::hasTransform() const 77 86 { 78 return omni_cast<btVector3>(this->node_->getScale()); 87 return (!this->position_.positionEquals(Vector3(0, 0, 0), 0.001) || 88 !this->orientation_.equals(Quaternion(1,0,0,0), Degree(0.1))); 79 89 } 80 90 … … 84 94 } 85 95 86 void CollisionShape::s cale3D(const Vector3&scale)96 void CollisionShape::setScale(float scale) 87 97 { 88 98 ThrowException(NotImplemented, "Cannot set the scale of a collision shape: Not yet implemented."); -
code/branches/physics/src/orxonox/objects/worldentities/collisionshapes/CollisionShape.h
r2306 r2374 32 32 #include "OrxonoxPrereqs.h" 33 33 34 #include "objects/worldentities/StaticEntity.h" 34 #include "util/Math.h" 35 #include "core/BaseObject.h" 35 36 36 37 namespace orxonox 37 38 { 38 class _OrxonoxExport CollisionShape : public StaticEntity39 class _OrxonoxExport CollisionShape : public BaseObject, public network::Synchronisable 39 40 { 40 41 public: … … 43 44 44 45 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); 46 void registerVariables(); 45 47 46 btCollisionShape* getCollisionShape() const { return this->collisionShape_; } 47 bool isCompoundShape() const { return this->bIsCompound_; } 48 inline void setPosition(const Vector3& position) 49 { this->position_ = position; } 50 inline const Vector3& getPosition() const 51 { return this->position_; } 48 52 49 bool hasNoTransform() const; 50 virtual btVector3 getTotalScaling(); 53 inline void setOrientation(const Quaternion& orientation) 54 { this->orientation_ = orientation; } 55 inline const Quaternion& getOrientation() const 56 { return this->orientation_; } 57 58 void yaw(const Degree& angle) { this->orientation_ = this->orientation_ * Quaternion(angle, Vector3::UNIT_Y); } 59 void pitch(const Degree& angle) { this->orientation_ = this->orientation_ * Quaternion(angle, Vector3::UNIT_X); } 60 void roll(const Degree& angle) { this->orientation_ = this->orientation_ * Quaternion(angle, Vector3::UNIT_Z); } 61 62 virtual void setScale3D(const Vector3& scale); 63 virtual void setScale(float scale); 64 inline const Vector3& getScale3D(void) const 65 { return this->scale_; } 66 67 virtual inline btCollisionShape* getCollisionShape() const 68 { return this->collisionShape_; } 69 70 bool hasTransform() const; 71 72 inline void setParent(CompoundCollisionShape* shape, unsigned int ID) 73 { this->parent_ = shape; this->parentID_ = ID; } 51 74 52 75 protected: 53 bool bIsCompound_;54 76 btCollisionShape* collisionShape_; 55 77 56 78 private: 57 virtual void setScale3D(const Vector3& scale); 58 virtual void scale3D(const Vector3& scale); 79 void updateParent(); 59 80 60 bool isCollisionTypeLegal(WorldEntity::CollisionType type) const; 81 Vector3 position_; 82 Quaternion orientation_; 83 Vector3 scale_; 84 CompoundCollisionShape* parent_; 85 unsigned int parentID_; 61 86 }; 62 87 } -
code/branches/physics/src/orxonox/objects/worldentities/collisionshapes/CompoundCollisionShape.cc
r2304 r2374 44 44 RegisterObject(CompoundCollisionShape); 45 45 46 this-> bIsCompound_ = true;46 this->collisionShape_ = 0; 47 47 this->compoundShape_ = new btCompoundShape(); 48 this->collisionShape_ = this->compoundShape_;49 48 } 50 49 … … 58 57 { 59 58 SUPER(CompoundCollisionShape, XMLPort, xmlelement, mode); 59 // Attached collision shapes 60 XMLPortObject(CompoundCollisionShape, CollisionShape, "", addChildShape, getChildShape, xmlelement, mode); 61 } 60 62 61 XMLPortObject(CompoundCollisionShape, CollisionShape, "", addChildShape, getChildShape, xmlelement, mode); 63 btCollisionShape* CompoundCollisionShape::getCollisionShape() const 64 { 65 // Note: Returning collisionShape_ means that it's the only one and has no transform. 66 // So we can get rid of the additional overhead with the compound shape. 67 if (this->collisionShape_) 68 return this->collisionShape_; 69 else if (this->childShapes_.size() != 0) 70 return this->compoundShape_; 71 else 72 return 0; 62 73 } 63 74 64 75 void CompoundCollisionShape::addChildShape(CollisionShape* shape) 65 76 { 66 this->childShapes_.push_back(shape); 77 if (!shape || !shape->getCollisionShape()) 78 return; 79 assert(this->compoundShape_); 67 80 btTransform transf(omni_cast<btQuaternion>(shape->getOrientation()), omni_cast<btVector3>(shape->getPosition())); 68 shape->getCollisionShape()->setLocalScaling(shape->getTotalScaling());69 81 this->compoundShape_->addChildShape(transf, shape->getCollisionShape()); 82 83 if (this->childShapes_.size() == 1 && this->childShapes_[0] && !this->childShapes_[0]->hasTransform()) 84 { 85 // --> Only shape to be added, no transform; add it directly 86 this->collisionShape_ = shape->getCollisionShape(); 87 } 88 else 89 { 90 // Make sure we use the compound shape 91 this->collisionShape_ = 0; 92 } 93 94 // network synchro 95 shape->setParent(this, this->getObjectID()); 70 96 } 71 97 -
code/branches/physics/src/orxonox/objects/worldentities/collisionshapes/CompoundCollisionShape.h
r2304 r2374 48 48 CollisionShape* getChildShape(unsigned int index) const; 49 49 50 virtual btCollisionShape* getCollisionShape() const; 51 50 52 private: 51 53 btCompoundShape* compoundShape_; -
code/branches/physics/src/orxonox/objects/worldentities/collisionshapes/PlaneCollisionShape.cc
r2323 r2374 21 21 * 22 22 * Author: 23 * Reto Grieder23 * Martin Stypinski 24 24 * Co-authors: 25 25 * ... … … 30 30 #include "PlaneCollisionShape.h" 31 31 32 #include "BulletCollision/CollisionShapes/btStaticPlaneShape.h"33 34 #include "tools/BulletConversions.h"35 32 #include "core/CoreIncludes.h" 36 33 #include "core/XMLPort.h" … … 45 42 RegisterObject(PlaneCollisionShape); 46 43 47 this->planeShape_ = new btStaticPlaneShape(btVector3(1, 1,1), 0);44 this->planeShape_ = new btStaticPlaneShape(btVector3(1, 1, 1), 0); 48 45 this->collisionShape_ = this->planeShape_; 46 this->planeNormal_ = Vector3(1, 1, 1); 47 this->planeOffset_ = 0.0f; 49 48 } 50 49 … … 52 51 { 53 52 if (this->isInitialized()) 54 delete this-> collisionShape_;53 delete this->planeShape_; 55 54 } 56 55 57 void PlaneCollisionShape:: setNormal(const Vector3& normal)56 void PlaneCollisionShape::registerVariables() 58 57 { 59 btScalar offset = this->planeShape_->getPlaneConstant(); 60 delete this->collisionShape_; 61 this->planeShape_ = new btStaticPlaneShape(omni_cast<btVector3>(normal), offset); 62 this->collisionShape_ = this->planeShape_; 63 } 64 65 void PlaneCollisionShape::setOffset(float offset) 66 { 67 btVector3 normal = this->planeShape_->getPlaneNormal(); 68 delete this->collisionShape_; 69 this->planeShape_ = new btStaticPlaneShape(normal, offset); 70 this->collisionShape_ = this ->planeShape_; 58 REGISTERDATA(this->planeNormal_, network::direction::toclient, new network::NetworkCallback<PlaneCollisionShape>(this, &PlaneCollisionShape::planeNormalChanged)); 59 REGISTERDATA(this->planeOffset_, network::direction::toclient, new network::NetworkCallback<PlaneCollisionShape>(this, &PlaneCollisionShape::planeOffsetChanged)); 71 60 } 72 61 … … 75 64 SUPER(PlaneCollisionShape, XMLPort, xmlelement, mode); 76 65 77 XMLPortParam(PlaneCollisionShape, " normal", setNormal, getNormal, xmlelement, mode);78 XMLPortParam(PlaneCollisionShape, " offset", setOffset, getOffset, xmlelement, mode);66 XMLPortParam(PlaneCollisionShape, "planeNormal", setNormal, getNormal, xmlelement, mode); 67 XMLPortParam(PlaneCollisionShape, "planeOffset", setOffset, getOffset, xmlelement, mode); 79 68 } 80 69 81 btVector3 PlaneCollisionShape::getTotalScaling()70 void PlaneCollisionShape::setNormal(const Vector3& normal) 82 71 { 83 return omni_cast<btVector3>(this->node_->getScale()); //* this->radius_; 72 delete this->planeShape_; 73 this->planeNormal_ = normal; 74 this->planeShape_ = new btStaticPlaneShape(omni_cast<btVector3>(normal), this->planeOffset_); 75 this->collisionShape_ = this->planeShape_; 76 } 77 78 void PlaneCollisionShape::setOffset(float offset) 79 { 80 delete this->planeShape_; 81 this->planeOffset_ = offset; 82 this->planeShape_ = new btStaticPlaneShape(omni_cast<btVector3>(this->planeNormal_), offset); 83 this->collisionShape_ = this->planeShape_; 84 84 } 85 85 } -
code/branches/physics/src/orxonox/objects/worldentities/collisionshapes/PlaneCollisionShape.h
r2323 r2374 21 21 * 22 22 * Author: 23 * Reto Grieder23 * Martin Stypinski 24 24 * Co-authors: 25 25 * ... … … 33 33 34 34 #include "BulletCollision/CollisionShapes/btStaticPlaneShape.h" 35 36 35 #include "CollisionShape.h" 37 36 … … 44 43 virtual ~PlaneCollisionShape(); 45 44 45 void registerVariables(); 46 46 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); 47 47 48 49 50 48 inline float getOffset() 51 49 { return this->planeShape_->getPlaneConstant();} 50 void setOffset(float offset); 52 51 53 52 inline btVector3 getNormal() 54 53 { return this->planeShape_->getPlaneNormal();} 55 void setOffset(float offset);56 54 void setNormal(const Vector3& normal); 57 55 58 private:59 virtual btVector3 getTotalScaling();56 inline void planeNormalChanged() 57 { this->setNormal(this->planeNormal_); } 60 58 59 inline void planeOffsetChanged() 60 { this->setOffset(this->planeOffset_); } 61 62 private: 61 63 btStaticPlaneShape* planeShape_; 64 Vector3 planeNormal_; 65 float planeOffset_; 62 66 }; 63 67 } -
code/branches/physics/src/orxonox/objects/worldentities/collisionshapes/SphereCollisionShape.cc
r2304 r2374 46 46 this->sphereShape_ = new btSphereShape(1.0f); 47 47 this->collisionShape_ = this->sphereShape_; 48 49 this->registerVariables(); 48 50 } 49 51 … … 52 54 if (this->isInitialized()) 53 55 delete this->collisionShape_; 56 } 57 58 void SphereCollisionShape::registerVariables() 59 { 60 REGISTERDATA(this->radius_, network::direction::toclient, new network::NetworkCallback<SphereCollisionShape>(this, &SphereCollisionShape::radiusChanged)); 54 61 } 55 62 … … 61 68 } 62 69 63 btVector3 SphereCollisionShape::getTotalScaling()70 void SphereCollisionShape::setRadius(float radius) 64 71 { 65 return omni_cast<btVector3>(this->node_->getScale()) * this->radius_; 72 // TODO: Think about where this could be referenced already. 73 this->radius_ = radius; 74 delete this->sphereShape_; 75 this->sphereShape_ = new btSphereShape(radius); 66 76 } 67 77 } -
code/branches/physics/src/orxonox/objects/worldentities/collisionshapes/SphereCollisionShape.h
r2304 r2374 42 42 virtual ~SphereCollisionShape(); 43 43 44 void registerVariables(); 44 45 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); 45 46 46 inline void setRadius(float radius) 47 { this->radius_ = radius; } 47 void setRadius(float radius); 48 48 inline float getRadius() const 49 49 { return this->radius_;} 50 50 51 inline void radiusChanged() 52 { this->setRadius(this->radius_); } 53 51 54 private: 52 virtual btVector3 getTotalScaling();53 54 55 btSphereShape* sphereShape_; 55 56 float radius_; -
code/branches/physics/src/orxonox/objects/worldentities/pawns/SpaceShip.cc
r2314 r2374 40 40 namespace orxonox 41 41 { 42 const float orientationGain = 100; 42 43 CreateFactory(SpaceShip); 43 44 … … 84 85 if (this->physicalBody_) 85 86 { 86 this->physicalBody_->setDamping(0.8, 0.9); 87 this->physicalBody_->setActivationState(DISABLE_DEACTIVATION); 87 this->physicalBody_->setDamping(0.7, 0.3); 88 88 } 89 89 } … … 106 106 void SpaceShip::tick(float dt) 107 107 { 108 if (this->isLocallyControlled())109 {110 // #####################################111 // ############# STEERING ##############112 // #####################################113 114 //Vector3 velocity = this->getVelocity();115 //if (velocity.x > this->maxSecondarySpeed_)116 // velocity.x = this->maxSecondarySpeed_;117 //if (velocity.x < -this->maxSecondarySpeed_)118 // velocity.x = -this->maxSecondarySpeed_;119 //if (velocity.y > this->maxSecondarySpeed_)120 // velocity.y = this->maxSecondarySpeed_;121 //if (velocity.y < -this->maxSecondarySpeed_)122 // velocity.y = -this->maxSecondarySpeed_;123 //if (velocity.z > this->maxSecondarySpeed_)124 // velocity.z = this->maxSecondarySpeed_;125 //if (velocity.z < -this->maxSpeed_)126 // velocity.z = -this->maxSpeed_;127 128 // normalize velocity and acceleration129 //for (size_t dimension = 0; dimension < 3; ++dimension)130 //{131 // if (this->acceleration_[dimension] == 0)132 // {133 // if (velocity[dimension] > 0)134 // {135 // velocity[dimension] -= (this->translationDamping_ * dt);136 // if (velocity[dimension] < 0)137 // velocity[dimension] = 0;138 // }139 // else if (velocity[dimension] < 0)140 // {141 // velocity[dimension] += (this->translationDamping_ * dt);142 // if (velocity[dimension] > 0)143 // velocity[dimension] = 0;144 // }145 // }146 //}147 148 //this->setVelocity(velocity);149 }150 151 152 108 SUPER(SpaceShip, tick, dt); 153 154 155 //if (this->isLocallyControlled())156 //{157 // this->yaw(this->yawRotation_ * dt);158 // if (this->bInvertYAxis_)159 // this->pitch(Degree(-this->pitchRotation_ * dt));160 // else161 // this->pitch(Degree( this->pitchRotation_ * dt));162 // this->roll(this->rollRotation_ * dt);163 164 // this->acceleration_.x = 0;165 // this->acceleration_.y = 0;166 // this->acceleration_.z = 0;167 168 // this->yawRotation_ = this->zeroDegree_;169 // this->pitchRotation_ = this->zeroDegree_;170 // this->rollRotation_ = this->zeroDegree_;171 //}172 109 } 173 110 … … 176 113 assert(this->physicalBody_); 177 114 this->physicalBody_->applyCentralForce(physicalBody_->getWorldTransform().getBasis() * btVector3(0.0f, 0.0f, -getMass() * value.x * 100)); 178 // this->acceleration_.z = -this->translationAcceleration_ * value.x;179 115 } 180 116 … … 182 118 { 183 119 this->physicalBody_->applyCentralForce(physicalBody_->getWorldTransform().getBasis() * btVector3(getMass() * value.x * 100, 0.0f, 0.0f)); 184 // this->acceleration_.x = this->translationAcceleration_ * value.x;185 120 } 186 121 … … 188 123 { 189 124 this->physicalBody_->applyCentralForce(physicalBody_->getWorldTransform().getBasis() * btVector3(0.0f, getMass() * value.x * 100, 0.0f)); 190 // this->acceleration_.y = this->translationAcceleration_ * value.x;191 125 } 192 126 193 127 void SpaceShip::rotateYaw(const Vector2& value) 194 128 { 195 this->physicalBody_->applyTorque(physicalBody_->getWorldTransform().getBasis() * btVector3(0.0f, getMass() * value.x * 10000, 0.0f)); 196 //Degree temp = value.x * value.x * sgn(value.x) * this->rotationAcceleration_; 197 //if (temp > this->maxRotation_) 198 // temp = this->maxRotation_; 199 //if (temp < -this->maxRotation_) 200 // temp = -this->maxRotation_; 201 //this->yawRotation_ = Degree(temp); 129 this->physicalBody_->applyTorque(physicalBody_->getWorldTransform().getBasis() * btVector3(0.0f, 1 / this->physicalBody_->getInvInertiaDiagLocal().y() * value.y * orientationGain, 0.0f)); 202 130 } 203 131 204 132 void SpaceShip::rotatePitch(const Vector2& value) 205 133 { 206 this->physicalBody_->applyTorque(physicalBody_->getWorldTransform().getBasis() * btVector3(getMass() * value.x * 10000, 0.0f, 0.0f)); 207 //Degree temp = value.x * value.x * sgn(value.x) * this->rotationAcceleration_; 208 //if (temp > this->maxRotation_) 209 // temp = this->maxRotation_; 210 //if (temp < -this->maxRotation_) 211 // temp = -this->maxRotation_; 212 //this->pitchRotation_ = Degree(temp); 134 this->physicalBody_->applyTorque(physicalBody_->getWorldTransform().getBasis() * btVector3(1 / this->physicalBody_->getInvInertiaDiagLocal().x() * value.y * orientationGain, 0.0f, 0.0f)); 213 135 } 214 136 215 137 void SpaceShip::rotateRoll(const Vector2& value) 216 138 { 217 this->physicalBody_->applyTorque(physicalBody_->getWorldTransform().getBasis() * btVector3(0.0f, 0.0f, -getMass() * value.x * 10000)); 218 //Degree temp = value.x * value.x * sgn(value.x) * this->rotationAcceleration_; 219 //if (temp > this->maxRotation_) 220 // temp = this->maxRotation_; 221 //if (temp < -this->maxRotation_) 222 // temp = -this->maxRotation_; 223 //this->rollRotation_ = Degree(temp); 139 this->physicalBody_->applyTorque(physicalBody_->getWorldTransform().getBasis() * btVector3(0.0f, 0.0f, -1 / this->physicalBody_->getInvInertiaDiagLocal().z() * value.y * orientationGain)); 224 140 } 225 141 -
code/branches/physics/src/orxonox/objects/worldentities/pawns/Spectator.cc
r2297 r2374 108 108 Vector3 velocity = this->getVelocity(); 109 109 velocity.normalise(); 110 this->setVelocity( velocity * this->speed_);110 this->setVelocity(this->getOrientation() * velocity * this->speed_); 111 111 112 112 this->yaw(Radian(this->yaw_ * this->rotationSpeed_));
Note: See TracChangeset
for help on using the changeset viewer.