Changeset 2427 for code/branches
- Timestamp:
- Dec 13, 2008, 9:38:30 PM (16 years ago)
- Location:
- code/branches/physics/src/orxonox/objects/worldentities
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/physics/src/orxonox/objects/worldentities/ControllableEntity.cc
r2408 r2427 230 230 if (this->isActive()) 231 231 { 232 // Check whether Bullet doesn't do the physics for us 233 if (!this->isDynamic()) 234 { 235 if (Core::isMaster()) 236 { 237 this->server_position_ = this->getPosition(); 238 this->server_orientation_ = this->getOrientation(); 239 this->server_linear_velocity_ = this->getVelocity(); 240 this->server_angular_velocity_ = this->getAngularVelocity(); 241 } 242 else if (this->bControlled_) 243 { 244 this->client_position_ = this->getPosition(); 245 this->client_orientation_ = this->getOrientation(); 246 this->client_linear_velocity_ = this->getVelocity(); 247 this->client_angular_velocity_ = this->getAngularVelocity(); 248 } 249 } 232 250 } 233 251 } … … 330 348 } 331 349 332 void ControllableEntity:: positionChanged(bool bContinuous)350 void ControllableEntity::setPosition(const Vector3& position) 333 351 { 334 352 if (Core::isMaster()) 335 353 { 354 MobileEntity::setPosition(position); 336 355 this->server_position_ = this->getPosition(); 337 if (!bContinuous) 338 ++this->server_overwrite_; 356 ++this->server_overwrite_; 339 357 } 340 358 else if (this->bControlled_) 341 359 { 360 MobileEntity::setPosition(position); 342 361 this->client_position_ = this->getPosition(); 343 362 } 344 363 } 345 364 346 void ControllableEntity:: orientationChanged(bool bContinuous)365 void ControllableEntity::setOrientation(const Quaternion& orientation) 347 366 { 348 367 if (Core::isMaster()) 349 368 { 369 MobileEntity::setOrientation(orientation); 350 370 this->server_orientation_ = this->getOrientation(); 351 if (!bContinuous) 352 ++this->server_overwrite_; 371 ++this->server_overwrite_; 353 372 } 354 373 else if (this->bControlled_) 355 374 { 375 MobileEntity::setOrientation(orientation); 356 376 this->client_orientation_ = this->getOrientation(); 357 377 } 358 378 } 359 379 360 void ControllableEntity:: linearVelocityChanged(bool bContinuous)380 void ControllableEntity::setVelocity(const Vector3& velocity) 361 381 { 362 382 if (Core::isMaster()) 363 383 { 384 MobileEntity::setVelocity(velocity); 364 385 this->server_linear_velocity_ = this->getVelocity(); 365 if (!bContinuous) 366 ++this->server_overwrite_; 386 ++this->server_overwrite_; 367 387 } 368 388 else if (this->bControlled_) 369 389 { 390 MobileEntity::setVelocity(velocity); 370 391 this->client_linear_velocity_ = this->getVelocity(); 371 392 } 372 393 } 373 394 374 void ControllableEntity:: angularVelocityChanged(bool bContinuous)395 void ControllableEntity::setAngularVelocity(const Vector3& velocity) 375 396 { 376 397 if (Core::isMaster()) 377 398 { 399 MobileEntity::setAngularVelocity(velocity); 378 400 this->server_angular_velocity_ = this->getAngularVelocity(); 379 if (!bContinuous) 380 ++this->server_overwrite_; 401 ++this->server_overwrite_; 381 402 } 382 403 else if (this->bControlled_) 383 404 { 405 MobileEntity::setAngularVelocity(velocity); 384 406 this->client_angular_velocity_ = this->getAngularVelocity(); 385 407 } 386 408 } 409 410 void ControllableEntity::setWorldTransform(const btTransform& worldTrans) 411 { 412 MobileEntity::setWorldTransform(worldTrans); 413 if (Core::isMaster()) 414 { 415 this->server_position_ = this->getPosition(); 416 this->server_orientation_ = this->getOrientation(); 417 this->server_linear_velocity_ = this->getVelocity(); 418 this->server_angular_velocity_ = this->getAngularVelocity(); 419 } 420 else if (this->bControlled_) 421 { 422 this->client_position_ = this->getPosition(); 423 this->client_orientation_ = this->getOrientation(); 424 this->client_linear_velocity_ = this->getVelocity(); 425 this->client_angular_velocity_ = this->getAngularVelocity(); 426 } 427 } 387 428 } -
code/branches/physics/src/orxonox/objects/worldentities/ControllableEntity.h
r2408 r2427 89 89 { return this->cameraPositionTemplate_; } 90 90 91 using WorldEntity::setPosition; 92 using WorldEntity::setOrientation; 93 using MobileEntity::setVelocity; 94 using MobileEntity::setAngularVelocity; 95 96 void setPosition(const Vector3& position); 97 void setOrientation(const Quaternion& orientation); 98 void setVelocity(const Vector3& velocity); 99 void setAngularVelocity(const Vector3& velocity); 100 91 101 protected: 92 102 virtual void startLocalControl(); … … 113 123 void processClientAngularVelocity(); 114 124 115 void positionChanged (bool bContinuous); 116 void orientationChanged (bool bContinuous); 117 void linearVelocityChanged (bool bContinuous); 118 void angularVelocityChanged(bool bContinuous); 125 void networkcallback_changedplayerID(); 119 126 120 void networkcallback_changedplayerID(); 127 // Bullet btMotionState related 128 void setWorldTransform(const btTransform& worldTrans); 121 129 122 130 unsigned int server_overwrite_; -
code/branches/physics/src/orxonox/objects/worldentities/MobileEntity.cc
r2426 r2427 83 83 this->linearVelocity_.y += this->linearAcceleration_.y * dt; 84 84 this->linearVelocity_.z += this->linearAcceleration_.z * dt; 85 linearVelocityChanged(true);86 85 this->node_->translate(this->linearVelocity_ * dt); 87 positionChanged(true);88 86 89 87 // Angular part … … 92 90 this->angularVelocity_.y += angularAcceleration_.y * dt; 93 91 this->angularVelocity_.z += angularAcceleration_.z * dt; 94 angularVelocityChanged(true);95 92 // Calculate new orientation with quaternion derivative. This is about 30% faster than with angle/axis method. 96 93 float mult = dt * 0.5; … … 100 97 newOrientation.normalise(); 101 98 this->node_->setOrientation(newOrientation); 102 orientationChanged(true);103 99 } 104 100 } … … 115 111 116 112 this->node_->setPosition(position); 117 positionChanged(false);118 113 } 119 114 … … 128 123 129 124 this->node_->setOrientation(orientation); 130 orientationChanged(false);131 125 } 132 126 … … 137 131 138 132 this->linearVelocity_ = velocity; 139 linearVelocityChanged(false);140 133 } 141 134 … … 146 139 147 140 this->angularVelocity_ = velocity; 148 angularVelocityChanged(false);149 141 } 150 142 … … 190 182 this->angularVelocity_.y = this->physicalBody_->getAngularVelocity().y(); 191 183 this->angularVelocity_.z = this->physicalBody_->getAngularVelocity().z(); 192 linearVelocityChanged(true);193 angularVelocityChanged(true);194 positionChanged(true);195 orientationChanged(true);196 184 } 197 185 -
code/branches/physics/src/orxonox/objects/worldentities/MobileEntity.h
r2426 r2427 47 47 void registerVariables(); 48 48 49 using WorldEntity::setPosition;50 using WorldEntity::setOrientation;49 virtual void setPosition(const Vector3& position); 50 virtual void setOrientation(const Quaternion& orientation); 51 51 52 void setPosition(const Vector3& position); 53 void setOrientation(const Quaternion& orientation); 54 55 void setVelocity(const Vector3& velocity); 52 virtual void setVelocity(const Vector3& velocity); 56 53 inline void setVelocity(float x, float y, float z) 57 54 { this->setVelocity(Vector3(x, y, z)); } … … 59 56 { return this->linearVelocity_; } 60 57 61 v oid setAngularVelocity(const Vector3& velocity);58 virtual void setAngularVelocity(const Vector3& velocity); 62 59 inline void setAngularVelocity(float x, float y, float z) 63 60 { this->setAngularVelocity(Vector3(x, y, z)); } … … 88 85 89 86 protected: 87 // Bullet btMotionState related 88 virtual void setWorldTransform(const btTransform& worldTrans); 89 void getWorldTransform(btTransform& worldTrans) const; 90 90 91 Vector3 linearAcceleration_; 91 92 Vector3 linearVelocity_; … … 94 95 95 96 private: 96 virtual void positionChanged (bool bContinuous) = 0;97 virtual void orientationChanged (bool bContinuous) = 0;98 virtual void linearVelocityChanged (bool bContinuous) { }99 virtual void angularVelocityChanged(bool bContinuous) { }100 101 97 virtual bool isCollisionTypeLegal(WorldEntity::CollisionType type) const; 102 103 // Bullet btMotionState related104 void setWorldTransform(const btTransform& worldTrans);105 void getWorldTransform(btTransform& worldTrans) const;106 98 }; 107 99 } -
code/branches/physics/src/orxonox/objects/worldentities/MovableEntity.cc
r2421 r2427 22 22 * Author: 23 23 * Fabian 'x3n' Landau 24 * Reto Grieder 24 25 * Co-authors: 25 26 * ... … … 76 77 } 77 78 78 void MovableEntity::tick(float dt)79 {80 MobileEntity::tick(dt);81 82 if (this->isActive())83 {84 }85 }86 87 void MovableEntity::overwritePosition()88 {89 this->setPosition(this->overwrite_position_);90 }91 92 void MovableEntity::overwriteOrientation()93 {94 this->setOrientation(this->overwrite_orientation_);95 }96 97 79 void MovableEntity::clientConnected(unsigned int clientID) 98 80 { … … 106 88 void MovableEntity::resynchronize() 107 89 { 108 positionChanged(false); 109 orientationChanged(false); 110 } 111 112 void MovableEntity::positionChanged(bool bContinuous) 113 { 114 if (!bContinuous) 115 this->overwrite_position_ = this->getPosition(); 116 } 117 118 void MovableEntity::orientationChanged(bool bContinuous) 119 { 120 if (!bContinuous) 121 this->overwrite_orientation_ = this->getOrientation(); 90 this->overwrite_position_ = this->getPosition(); 91 this->overwrite_orientation_ = this->getOrientation(); 122 92 } 123 93 } -
code/branches/physics/src/orxonox/objects/worldentities/MovableEntity.h
r2421 r2427 22 22 * Author: 23 23 * Fabian 'x3n' Landau 24 * Reto Grieder 24 25 * Co-authors: 25 26 * ... … … 44 45 45 46 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); 46 virtual void tick(float dt);47 47 void registerVariables(); 48 49 using WorldEntity::setPosition; 50 using WorldEntity::setOrientation; 51 52 inline void setPosition(const Vector3& position) 53 { MobileEntity::setPosition(position); this->overwrite_position_ = this->getPosition(); } 54 inline void setOrientation(const Quaternion& orientation) 55 { MobileEntity::setOrientation(orientation); this->overwrite_orientation_ = this->getOrientation(); } 48 56 49 57 private: … … 57 65 { this->setAngularVelocity(this->angularVelocity_); } 58 66 59 void overwritePosition(); 60 void overwriteOrientation(); 67 inline void overwritePosition() 68 { this->setPosition(this->overwrite_position_); } 69 inline void overwriteOrientation() 70 { this->setOrientation(this->overwrite_orientation_); } 61 71 62 void positionChanged(bool bContinuous); 63 void orientationChanged(bool bContinuous); 64 65 Vector3 overwrite_position_; 72 Vector3 overwrite_position_; 66 73 Quaternion overwrite_orientation_; 67 74 Timer<MovableEntity>* continuousResynchroTimer_;
Note: See TracChangeset
for help on using the changeset viewer.