- Timestamp:
- Dec 14, 2008, 4:16:52 PM (16 years ago)
- Location:
- code/branches/physics_merge
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/physics_merge
- Property svn:mergeinfo changed
-
code/branches/physics_merge/src/orxonox/objects/worldentities/MovableEntity.cc
r2415 r2442 22 22 * Author: 23 23 * Fabian 'x3n' Landau 24 * Reto Grieder 24 25 * Co-authors: 25 26 * ... … … 38 39 { 39 40 static const float MAX_RESYNCHRONIZE_TIME = 3.0f; 41 static const float CONTINUOUS_SYNCHRONIZATION_TIME = 10.0f; 40 42 41 43 CreateFactory(MovableEntity); 42 44 43 MovableEntity::MovableEntity(BaseObject* creator) : WorldEntity(creator)45 MovableEntity::MovableEntity(BaseObject* creator) : MobileEntity(creator) 44 46 { 45 47 RegisterObject(MovableEntity); 46 48 47 this->velocity_ = Vector3::ZERO; 48 this->acceleration_ = Vector3::ZERO; 49 this->rotationAxis_ = Vector3::ZERO; 50 this->rotationRate_ = 0; 51 this->momentum_ = 0; 52 53 this->overwrite_position_ = Vector3::ZERO; 49 this->overwrite_position_ = Vector3::ZERO; 54 50 this->overwrite_orientation_ = Quaternion::IDENTITY; 55 51 56 52 this->setPriority( priority::low ); 53 54 // Resynchronise every few seconds because we only work with velocities (no positions) 55 continuousResynchroTimer_ = new Timer<MovableEntity>(CONTINUOUS_SYNCHRONIZATION_TIME + rnd(-1, 1), 56 true, this, createExecutor(createFunctor(&MovableEntity::resynchronize)), false); 57 57 58 58 this->registerVariables(); … … 61 61 MovableEntity::~MovableEntity() 62 62 { 63 if (this->isInitialized()) 64 delete this->continuousResynchroTimer_; 63 65 } 64 66 … … 66 68 { 67 69 SUPER(MovableEntity, XMLPort, xmlelement, mode); 68 69 XMLPortParamTemplate(MovableEntity, "velocity", setVelocity, getVelocity, xmlelement, mode, const Vector3&);70 XMLPortParamTemplate(MovableEntity, "rotationaxis", setRotationAxis, getRotationAxis, xmlelement, mode, const Vector3&);71 XMLPortParamTemplate(MovableEntity, "rotationrate", setRotationRate, getRotationRate, xmlelement, mode, const Degree&);72 }73 74 void MovableEntity::tick(float dt)75 {76 if (this->isActive())77 {78 this->velocity_ += (dt * this->acceleration_);79 this->node_->translate(dt * this->velocity_);80 81 this->rotationRate_ += (dt * this->momentum_);82 this->node_->rotate(this->rotationAxis_, this->rotationRate_ * dt);83 }84 70 } 85 71 86 72 void MovableEntity::registerVariables() 87 73 { 88 registerVariable(this->velocity_.x, variableDirection::toclient); 89 registerVariable(this->velocity_.y, variableDirection::toclient); 90 registerVariable(this->velocity_.z, variableDirection::toclient); 91 92 registerVariable(this->rotationAxis_.x, variableDirection::toclient); 93 registerVariable(this->rotationAxis_.y, variableDirection::toclient); 94 registerVariable(this->rotationAxis_.z, variableDirection::toclient); 95 96 registerVariable(this->rotationRate_, variableDirection::toclient); 97 74 registerVariable(this->linearVelocity_, variableDirection::toclient, new NetworkCallback<MovableEntity>(this, &MovableEntity::processLinearVelocity)); 75 registerVariable(this->angularVelocity_, variableDirection::toclient, new NetworkCallback<MovableEntity>(this, &MovableEntity::processAngularVelocity)); 76 98 77 registerVariable(this->overwrite_position_, variableDirection::toclient, new NetworkCallback<MovableEntity>(this, &MovableEntity::overwritePosition)); 99 78 registerVariable(this->overwrite_orientation_, variableDirection::toclient, new NetworkCallback<MovableEntity>(this, &MovableEntity::overwriteOrientation)); 100 }101 102 void MovableEntity::overwritePosition()103 {104 this->node_->setPosition(this->overwrite_position_);105 }106 107 void MovableEntity::overwriteOrientation()108 {109 this->node_->setOrientation(this->overwrite_orientation_);110 79 } 111 80 … … 124 93 this->overwrite_orientation_ = this->getOrientation(); 125 94 } 126 127 void MovableEntity::setPosition(const Vector3& position)128 {129 this->node_->setPosition(position);130 this->overwrite_position_ = this->node_->getPosition();131 }132 133 void MovableEntity::translate(const Vector3& distance, Ogre::Node::TransformSpace relativeTo)134 {135 this->node_->translate(distance, relativeTo);136 this->overwrite_position_ = this->node_->getPosition();137 }138 139 void MovableEntity::setOrientation(const Quaternion& orientation)140 {141 this->node_->setOrientation(orientation);142 this->overwrite_orientation_ = this->node_->getOrientation();143 }144 145 void MovableEntity::rotate(const Quaternion& rotation, Ogre::Node::TransformSpace relativeTo)146 {147 this->node_->rotate(rotation, relativeTo);148 this->overwrite_orientation_ = this->node_->getOrientation();149 }150 151 void MovableEntity::yaw(const Degree& angle, Ogre::Node::TransformSpace relativeTo)152 {153 this->node_->yaw(angle, relativeTo);154 this->overwrite_orientation_ = this->node_->getOrientation();155 }156 157 void MovableEntity::pitch(const Degree& angle, Ogre::Node::TransformSpace relativeTo)158 {159 this->node_->pitch(angle, relativeTo);160 this->overwrite_orientation_ = this->node_->getOrientation();161 }162 163 void MovableEntity::roll(const Degree& angle, Ogre::Node::TransformSpace relativeTo)164 {165 this->node_->roll(angle, relativeTo);166 this->overwrite_orientation_ = this->node_->getOrientation();167 }168 169 void MovableEntity::lookAt(const Vector3& target, Ogre::Node::TransformSpace relativeTo, const Vector3& localDirectionVector)170 {171 this->node_->lookAt(target, relativeTo, localDirectionVector);172 this->overwrite_orientation_ = this->node_->getOrientation();173 }174 175 void MovableEntity::setDirection(const Vector3& direction, Ogre::Node::TransformSpace relativeTo, const Vector3& localDirectionVector)176 {177 this->node_->setDirection(direction, relativeTo, localDirectionVector);178 this->overwrite_orientation_ = this->node_->getOrientation();179 }180 95 }
Note: See TracChangeset
for help on using the changeset viewer.