- Timestamp:
- Dec 10, 2008, 1:38:17 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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 }
Note: See TracChangeset
for help on using the changeset viewer.